run-cts: Default enable colors iff stdout is a terminal.

Don't emit colors if we're piping to a file, or the terminal does not support colors.

Always strip color escape code when writing to the --log file

Change-Id: Id15169f694563f06e950fdcab7344614b3f15e23
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88665
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2022-05-03 16:15:23 +00:00 committed by Dawn LUCI CQ
parent e23283f497
commit 74b8483ba4
1 changed files with 10 additions and 4 deletions

View File

@ -234,6 +234,7 @@ func run() error {
return fmt.Sprintf(`require('./src/common/tools/setup-ts-in-node.js');require('./src/common/runtime/%v.ts');`, main)
},
stdout: stdout,
colors: colors,
}
if logFilename != "" {
@ -333,7 +334,7 @@ type logger struct {
// newLogger creates a new logger instance.
func newLogger(writer io.Writer) logger {
return logger{writer, 0, map[int]result{}}
return logger{colorable.NewNonColorable(writer), 0, map[int]result{}}
}
// logResult writes the test results to the log file in sequential order.
@ -348,7 +349,7 @@ func (l *logger) logResults(res result) {
if !ok {
break
}
fmt.Fprintf(l.writer, "%v [%v]\n", logRes.testcase, logRes.status)
fmt.Fprintf(l.writer, "%v [%v]\n%v", logRes.testcase, logRes.status, logRes.message)
l.idx++
}
}
@ -390,6 +391,7 @@ type runner struct {
results testcaseStatuses
log logger
stdout io.WriteCloser
colors bool // Colors enabled?
}
// scanSourceTimestamps scans all the .js and .ts files in all subdirectories of
@ -609,6 +611,9 @@ func (r *runner) runServer(id int, caseIndices <-chan int, results chan<- result
// Actual arguments begin here
"--gpu-provider", r.dawnNode,
}
if r.colors {
args = append(args, "--colors")
}
for _, f := range r.flags {
args = append(args, "--gpu-provider-flag", f)
}
@ -644,8 +649,6 @@ func (r *runner) runServer(id int, caseIndices <-chan int, results chan<- result
case <-ctx.Done(): // cancelled
return ctx.Err()
}
return nil
}
stopServer = func() {
if port > 0 {
@ -950,6 +953,9 @@ func (r *runner) runTestcase(query string) result {
"--verbose",
"--quiet",
}
if r.colors {
args = append(args, "--colors")
}
for _, f := range r.flags {
args = append(args, "--gpu-provider-flag", f)
}