Skip to content

Commit

Permalink
format: handle 'testing: warning: no tests to run' event
Browse files Browse the repository at this point in the history
An output event with this text is sent when 'go test' runs a package that has test files
but no tests.

Update two formts that were printing this message in a way that was confusing. Now the standard-quiet format
properly matches 'go test' format, and the testname format omits the text. Since gotestsum includes a count
of tests run in the summary line, this message doesn't seem like it provides much value.
  • Loading branch information
dnephin committed Mar 28, 2021
1 parent e46e163 commit b9fe0e1
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions internal/junitxml/testdata/junitxml-report.golden
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@
<testcase classname="github.com/gotestyourself/gotestyourself/testjson/internal/stub" name="TestParallelTheSecond" time="0.010000"></testcase>
<testcase classname="github.com/gotestyourself/gotestyourself/testjson/internal/stub" name="TestParallelTheFirst" time="0.010000"></testcase>
</testsuite>
<testsuite tests="0" failures="0" time="0.000000" name="gotest.tools/gotestsum/internal/empty">
<properties>
<property name="go.version" value="go7.7.7"></property>
</properties>
</testsuite>
</testsuites>
2 changes: 2 additions & 0 deletions testjson/dotformat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
)

func TestScanTestOutput_WithDotsFormatter(t *testing.T) {
skip.If(t, runtime.GOOS == "windows")

defer patchPkgPathPrefix("github.com/gotestyourself/gotestyourself")()

out := new(bytes.Buffer)
Expand Down
11 changes: 8 additions & 3 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ func standardQuietFormat(event TestEvent, _ *Execution) (string, error) {
if !event.PackageEvent() {
return "", nil
}
if event.Output != "PASS\n" && !isCoverageOutput(event.Output) {
return event.Output, nil
if event.Output == "PASS\n" || isCoverageOutput(event.Output) {
return "", nil
}
return "", nil
if event.Output == "testing: warning: no tests to run\n" {
return "", nil
}

return event.Output, nil
}

func testNameFormat(event TestEvent, exec *Execution) (string, error) {
Expand Down Expand Up @@ -111,6 +115,7 @@ func isPkgFailureOutput(event TestEvent) bool {
event.Action == ActionOutput,
out != "PASS\n",
out != "FAIL\n",
out != "testing: warning: no tests to run\n",
!strings.HasPrefix(out, "FAIL\t"+event.Package),
!strings.HasPrefix(out, "ok \t"+event.Package),
!strings.HasPrefix(out, "? \t"+event.Package),
Expand Down
3 changes: 3 additions & 0 deletions testjson/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ var expectedExecution = &Execution{
action: ActionFail,
running: map[string]TestCase{},
},
"gotest.tools/gotestsum/internal/empty": {
action: ActionPass,
},
},
}

Expand Down
8 changes: 8 additions & 0 deletions testjson/testdata/dots-format.out
Original file line number Diff line number Diff line change
Expand Up @@ -702,3 +702,11 @@
20ms testjson/internal/stub ···↷↷✖·✖····✖··✖············

46 tests, 4 skipped, 5 failures, 1 error


testjson/internal/badmain
🖴 testjson/internal/good ···↷↷·············
20ms testjson/internal/stub ···↷↷✖·✖····✖··✖············
gotest.tools/gotestsum/internal/empty

46 tests, 4 skipped, 5 failures, 1 error
4 changes: 4 additions & 0 deletions testjson/testdata/go-test-json.out
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,7 @@
{"Time":"2018-03-22T22:33:35.288005158Z","Action":"output","Package":"github.com/gotestyourself/gotestyourself/testjson/internal/stub","Output":"FAIL\n"}
{"Time":"2018-03-22T22:33:35.288154141Z","Action":"output","Package":"github.com/gotestyourself/gotestyourself/testjson/internal/stub","Output":"FAIL\tgit.luolix.top/gotestyourself/gotestyourself/testjson/internal/stub\t0.011s\n"}
{"Time":"2018-03-22T22:33:35.288167612Z","Action":"fail","Package":"github.com/gotestyourself/gotestyourself/testjson/internal/stub","Elapsed":0.011}
{"Time":"2021-03-28T13:58:17.979131051-04:00","Action":"output","Package":"gotest.tools/gotestsum/internal/empty","Output":"testing: warning: no tests to run\n"}
{"Time":"2021-03-28T13:58:17.979525677-04:00","Action":"output","Package":"gotest.tools/gotestsum/internal/empty","Output":"PASS\n"}
{"Time":"2021-03-28T13:58:17.979689639-04:00","Action":"output","Package":"gotest.tools/gotestsum/internal/empty","Output":"ok \tgotest.tools/gotestsum/internal/empty\t0.004s [no tests to run]\n"}
{"Time":"2021-03-28T13:58:17.979759254-04:00","Action":"pass","Package":"gotest.tools/gotestsum/internal/empty","Elapsed":0.004}
3 changes: 3 additions & 0 deletions testjson/testdata/go-test-verbose.out
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ this is stderr
--- PASS: TestParallelTheFirst (0.01s)
FAIL
FAIL github.com/gotestyourself/gotestyourself/testjson/internal/stub 0.011s
testing: warning: no tests to run
PASS
ok gotest.tools/gotestsum/internal/empty 0.004s [no tests to run]
1 change: 1 addition & 0 deletions testjson/testdata/short-format.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
✖ testjson/internal/badmain (10ms)
✓ testjson/internal/good (cached)
✖ testjson/internal/stub (11ms)
✓ gotest.tools/gotestsum/internal/empty (4ms)
1 change: 1 addition & 0 deletions testjson/testdata/short-verbose-format.out
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ PASS testjson/internal/stub.TestParallelTheThird (0.00s)
PASS testjson/internal/stub.TestParallelTheSecond (0.01s)
PASS testjson/internal/stub.TestParallelTheFirst (0.01s)
FAIL testjson/internal/stub
PASS gotest.tools/gotestsum/internal/empty
1 change: 1 addition & 0 deletions testjson/testdata/standard-quiet-format.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ FAIL github.com/gotestyourself/gotestyourself/testjson/internal/badmain 0.010s
ok github.com/gotestyourself/gotestyourself/testjson/internal/good (cached)
FAIL
FAIL github.com/gotestyourself/gotestyourself/testjson/internal/stub 0.011s
ok gotest.tools/gotestsum/internal/empty 0.004s [no tests to run]

0 comments on commit b9fe0e1

Please sign in to comment.