From 66e9ac3da6a616df97b8226230959f43533dcd9c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 10 Sep 2015 11:38:19 -0700 Subject: [PATCH 1/2] .tools: Remove redundant r.Pass check when 'fail == 0' The previous version of this script would always pass this check, because when 'fail == 0' was true, all of the messages had passed. That lead to logic like: a. If all checks passed for the commit and the verbose flag is set, print all the messages (which all passed). b. If all checks passed for the commit and the verbose flag is not set, don't print details about any messages (which all passed). c. If any checks failed, print all the failed messages. That wasn't printing successful checks when the verbose flag was true but some checks failed. This commit shifts the logic around to: A. If the verbose flag is set, print messages for all checks, using TAP's "ok" and "not ok" to distinguish between per-check pass/fail [1]. B. If the verbose flag is not set, only print the failed messages (but still keep the "not ok" prefix). In the non-verbose case, then (b/c) and (B) look the same (modulo my "not ok" prefix adjustment). And in the verbose case, I think (A) is preferable to (a/c), because there's no reason to *not* print successful checks when you've enabled the verbose flag. [1]: http://testanything.org/ Signed-off-by: W. Trevor King --- .tools/validate.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/.tools/validate.go b/.tools/validate.go index bf337dfff..7f3f28495 100644 --- a/.tools/validate.go +++ b/.tools/validate.go @@ -74,20 +74,19 @@ func main() { results = append(results, vr...) if _, fail := vr.PassFail(); fail == 0 { fmt.Println("PASS") - if *flVerbose { - for _, r := range vr { - if r.Pass { - fmt.Printf(" - %s\n", r.Msg) - } - } - } } else { fmt.Println("FAIL") - // default, only print out failed validations - for _, r := range vr { - if !r.Pass { - fmt.Printf(" - %s\n", r.Msg) + } + for _, r := range vr { + if *flVerbose { + if r.Pass { + fmt.Printf("ok") + } else { + fmt.Printf("not ok") } + fmt.Printf(" %s\n", r.Msg) + } else if !r.Pass { + fmt.Printf("not ok %s\n", r.Msg) } } } From 650828c7b23cb2c14dc31fcc88adb3463f20eeef Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 11 Sep 2015 20:56:36 -0700 Subject: [PATCH 2/2] .tools: Make -v output comply with TAP version 13 Using TAP [1] makes it easy to consume the output of this tool in a variety of existing harnesses [2]. Only the verbose results are TAP compliant, mostly because folks aren't likely to care about verbosity if they're just piping the results into a TAP harness. If we end up wanting the non-verbose output to be TAP compliant, we'll have to switch to the trailing count approach explained in the "Unknown amount and failures" section of the spec [1], and we'll have to keep a running counter of failed checks (instead of the current len(DefaultRules)-based approach). [1]: http://testanything.org/tap-version-13-specification.html [2]: http://testanything.org/consumers.html Signed-off-by: W. Trevor King --- .tools/validate.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.tools/validate.go b/.tools/validate.go index 7f3f28495..e9c090e39 100644 --- a/.tools/validate.go +++ b/.tools/validate.go @@ -68,8 +68,13 @@ func main() { } results := ValidateResults{} - for _, commit := range c { - fmt.Printf(" * %s %s ... ", commit["abbreviated_commit"], commit["subject"]) + + if *flVerbose { + fmt.Println("TAP version 13") + fmt.Printf("1..%d\n", len(c)*len(DefaultRules)) + } + for i, commit := range c { + fmt.Printf("# %s %s ... ", commit["abbreviated_commit"], commit["subject"]) vr := ValidateCommit(commit, DefaultRules) results = append(results, vr...) if _, fail := vr.PassFail(); fail == 0 { @@ -77,16 +82,16 @@ func main() { } else { fmt.Println("FAIL") } - for _, r := range vr { + for j, r := range vr { if *flVerbose { if r.Pass { fmt.Printf("ok") } else { fmt.Printf("not ok") } - fmt.Printf(" %s\n", r.Msg) + fmt.Printf(" %d - %s\n", i*len(DefaultRules)+j+1, r.Msg) } else if !r.Pass { - fmt.Printf("not ok %s\n", r.Msg) + fmt.Printf("not ok - %s\n", r.Msg) } } }