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 <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/tools/src/cmd/test-runner/main.go b/tools/src/cmd/test-runner/main.go
index f30025a..6dbcd12 100644
--- a/tools/src/cmd/test-runner/main.go
+++ b/tools/src/cmd/test-runner/main.go
@@ -71,6 +71,7 @@
 
 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 @@
 	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 @@
 	// 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 @@
 		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 @@
 		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)