From 382b2a23c81c8e67483dbe4cb7c987eab1bcbc35 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Thu, 3 Feb 2022 20:55:03 +0000 Subject: [PATCH] Add test-name-filter flag to `get-test-plan` BUG=tint:1413 Change-Id: I6a4735a97f64003cb4999d6a64b64666d0ce08ad Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/79140 Reviewed-by: Antonio Maiorano Commit-Queue: Ryan Harrison Auto-Submit: Ryan Harrison Kokoro: Ryan Harrison --- tools/src/cmd/get-test-plan/main.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/src/cmd/get-test-plan/main.go b/tools/src/cmd/get-test-plan/main.go index c26148d235..3389d8412e 100644 --- a/tools/src/cmd/get-test-plan/main.go +++ b/tools/src/cmd/get-test-plan/main.go @@ -127,6 +127,10 @@ if file extension is 'tsv' the output format will be a tab separated file if file extension is 'json' the output format will be json if omitted, a human readable version of the rules is written to stdout`) + testNameFilter := flag.String("test-name-filter", "", + `if provided will be used to filter reported rules based on if their name +contains the provided string`) + flag.Parse() args := flag.Args() @@ -155,7 +159,7 @@ if omitted, a human readable version of the rules is written to stdout`) } } - txt, tsv := concatRules(rules) + txt, tsv := concatRules(rules, *testNameFilter) // if no output then write rules to stdout if *output == "" { fmt.Println(txt) @@ -241,13 +245,20 @@ func parseSection(in string) ([]int, error) { return out, nil } -// concatRules concatnate rule slice to and makes two string output -// txt is a human readable string -// tsv is a tab saparated string -func concatRules(rules []rule) (string, string) { +// concatRules concatenate rules slice to make two string outputs; +// txt, a human-readable string +// tsv, a tab separated string +// If testNameFilter is a non-empty string, then only rules whose TestName +// contains the string are included +func concatRules(rules []rule, testNameFilter string) (string, string) { txtLines := []string{} tsvLines := []string{"Number\tUniqueId\tSection\tURL\tDescription\tProposed Test Name\tkeyword"} + for _, r := range rules { + if testNameFilter != "" && !strings.Contains(r.TestName, testNameFilter) { + continue + } + txtLines = append(txtLines, strings.Join([]string{ "Rule Number " + strconv.Itoa(r.Number) + ":", "Unique Id: " + r.Sha,