Skip to content

Commit

Permalink
Replaced all (except one) "error" substring with an optionally colore…
Browse files Browse the repository at this point in the history
…d version in cptest cli.
  • Loading branch information
kuredoro committed Oct 16, 2021
1 parent 7e27594 commit bec05e0
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions cmd/cptest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ var progressBar *ProgressBar

var stdout = colorable.NewColorableStdout()

var errorLabel aurora.Value

type JobCount int

func (jc *JobCount) UnmarshalText(b []byte) error {
if bytes.Equal(b, []byte("CPU_COUNT")) {
*jc = JobCount(runtime.NumCPU())
*jc = JobCount(runtime.NumCPU())
return nil
}

val, err := strconv.ParseUint(string(b), 10, 0)
if err != nil {
return err
}
if err != nil {
return err
}

if val == 0 {
return errors.New("job count must be at least 1")
Expand All @@ -49,7 +51,7 @@ type appArgs struct {
Inputs string `arg:"-i" default:"inputs.txt" help:"file with tests"`
NoColors bool `arg:"--no-colors" help:"disable colored output"`
NoProgress bool `arg:"--no-progress" help:"disable progress bar"`
Jobs JobCount `arg:"-j" default:"CPU_COUNT" placeholder:"COUNT" help:"Number of tests to run concurrently"`
Jobs JobCount `arg:"-j" default:"CPU_COUNT" placeholder:"COUNT" help:"Number of tests to run concurrently"`
Executable string `arg:"positional,required"`
Args []string `arg:"positional" placeholder:"ARG"`
}
Expand Down Expand Up @@ -109,11 +111,13 @@ func init() {
verdictStr = map[cptest.Verdict]aurora.Value{
cptest.OK: cptest.Au.Bold("OK").Green(),
cptest.IE: cptest.Au.Bold("IE").Bold(),
cptest.WA: cptest.Au.Bold("WA").Red(),
cptest.WA: cptest.Au.Bold("WA").BrightRed(),
cptest.RE: cptest.Au.Bold("RE").Magenta(),
cptest.TL: cptest.Au.Bold("TL").Yellow(),
}

errorLabel = cptest.Au.Bold("error").BrightRed()

type duration cptest.PositiveDuration
cptest.DefaultInputsConfig = cptest.InputsConfig{
Tl: cptest.NewPositiveDuration(6 * time.Second),
Expand All @@ -124,15 +128,15 @@ func init() {
func main() {
inputsPath, err := filepath.Abs(args.Inputs)
if err != nil {
fmt.Printf("error: retreive inputs absolute path: %v\n", err)
fmt.Printf("%v: retreive inputs absolute path: %v\n", errorLabel, err)
return
}

inputs, scanErrs := readInputs(inputsPath)
if scanErrs != nil {
var lineRangeErrorType *cptest.LineRangeError
if len(scanErrs) == 1 && !errors.As(scanErrs[0], &lineRangeErrorType) {
fmt.Printf("error: %v\n", scanErrs[0])
fmt.Printf("%v: %v\n", errorLabel, scanErrs[0])
return
}

Expand All @@ -148,31 +152,29 @@ func main() {
return lineErrs[i].Begin < lineErrs[j].Begin
})

errorHeader := cptest.Au.Bold("error").BrightRed()

for _, err := range lineErrs {
fmt.Printf("%s:%d: %s: %v\n%s", args.Inputs, err.Begin, errorHeader, err.Err, err.CodeSnippet())
fmt.Printf("%s:%d: %s: %v\n%s", args.Inputs, err.Begin, errorLabel, err.Err, err.CodeSnippet())
}

return
}

execPath, err := findFile(args.Executable)
if err != nil {
fmt.Printf("error: find executable: %v\n", err)
fmt.Printf("%v: find executable: %v\n", errorLabel, err)
return
}

execStat, err := os.Stat(execPath)
if err != nil {
fmt.Printf("error: read executable's properties: %v\n", err)
return
}
execStat, err := os.Stat(execPath)
if err != nil {
fmt.Printf("%v: read executable's properties: %v\n", errorLabel, err)
return
}

if execStat.IsDir() {
fmt.Printf("error: provided executable %s is a directory\n", args.Executable)
return
}
if execStat.IsDir() {
fmt.Printf("%v: provided executable %s is a directory\n", errorLabel, args.Executable)
return
}

proc := &Executable{
Path: execPath,
Expand Down

0 comments on commit bec05e0

Please sign in to comment.