From facb5ced00aef7f00a81c9daabf8e2ef8a1d0fe4 Mon Sep 17 00:00:00 2001 From: James Price Date: Tue, 6 Jul 2021 18:31:15 +0000 Subject: [PATCH] tools: Add --filename-column-width to test runner If provided, this option truncates long filenames to avoid unpleasant line wrapping behavior for those of us that use narrow terminals. Change-Id: I684b91b7aa4b0ae86a4cf9ed9f047b685ab97550 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57100 Auto-Submit: James Price Reviewed-by: Ben Clayton Commit-Queue: James Price Kokoro: Kokoro --- tools/src/cmd/test-runner/main.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/src/cmd/test-runner/main.go b/tools/src/cmd/test-runner/main.go index f30025ae63..6dbcd12ed5 100644 --- a/tools/src/cmd/test-runner/main.go +++ b/tools/src/cmd/test-runner/main.go @@ -71,6 +71,7 @@ optional flags:`) func run() error { var formatList, filter, dxcPath, xcrunPath string + var maxFilenameColumnWidth int numCPU := runtime.NumCPU() fxc, verbose, generateExpected, generateSkip := false, false, false, false flag.StringVar(&formatList, "format", "all", "comma separated list of formats to emit. Possible values are: all, wgsl, spvasm, msl, hlsl") @@ -82,6 +83,7 @@ func run() error { flag.BoolVar(&generateExpected, "generate-expected", false, "create or update all expected outputs") flag.BoolVar(&generateSkip, "generate-skip", false, "create or update all expected outputs that fail with SKIP") flag.IntVar(&numCPU, "j", numCPU, "maximum number of concurrent threads to run tests") + flag.IntVar(&maxFilenameColumnWidth, "filename-column-width", 0, "maximum width of the filename column") flag.Usage = showUsage flag.Parse() @@ -260,6 +262,9 @@ func run() error { // Print the table of file x format and gather per-format stats failures := []failure{} filenameColumnWidth := maxStringLen(files) + if maxFilenameColumnWidth > 0 { + filenameColumnWidth = maxFilenameColumnWidth + } red := color.New(color.FgRed) green := color.New(color.FgGreen) @@ -276,7 +281,7 @@ func run() error { fmt.Println() } printHorizontalLine := func() { - fmt.Printf(strings.Repeat("━", maxStringLen(files))) + fmt.Printf(strings.Repeat("━", filenameColumnWidth)) fmt.Printf("━╋━") for _, format := range formats { fmt.Printf(strings.Repeat("━", formatWidth(format))) @@ -296,7 +301,13 @@ func run() error { row := &strings.Builder{} rowAllPassed := true - fmt.Fprintf(row, alignRight(file, filenameColumnWidth)) + filenameLength := utf8.RuneCountInString(file) + shortFile := file + if filenameLength > filenameColumnWidth { + shortFile = "..." + file[filenameLength-filenameColumnWidth+3:] + } + + fmt.Fprintf(row, alignRight(shortFile, filenameColumnWidth)) fmt.Fprintf(row, " ┃ ") for _, format := range formats { columnWidth := formatWidth(format)