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 Apr 17, 2021
1 parent 50d8cb4 commit 68539ea
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 15 deletions.
5 changes: 5 additions & 0 deletions internal/junitxml/testdata/junitxml-report.golden
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
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
14 changes: 14 additions & 0 deletions testjson/execution.go
Expand Up @@ -32,6 +32,16 @@ const (
ActionSkip Action = "skip"
)

// IsTerminal returns true if the Action is one of: pass, fail, skip.
func (a Action) IsTerminal() bool {
switch a {
case ActionPass, ActionFail, ActionSkip:
return true
default:
return false
}
}

// TestEvent is a structure output by go tool test2json and go test -json.
type TestEvent struct {
// Time encoded as an RFC3339-format string
Expand Down Expand Up @@ -392,6 +402,10 @@ func isCachedOutput(output string) bool {
return strings.Contains(output, "\t(cached)")
}

func isWarningNoTestsToRunOutput(output string) bool {
return output == "testing: warning: no tests to run\n"
}

// OutputLines returns the full test output for a test as an slice of lines.
// This function is a convenient wrapper around Package.OutputLines() to
// support the hiding of output in the summary.
Expand Down
40 changes: 25 additions & 15 deletions testjson/format.go
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 isWarningNoTestsToRunOutput(event.Output) {
return "", nil
}

return event.Output, nil
}

func testNameFormat(event TestEvent, exec *Execution) (string, error) {
Expand All @@ -54,21 +58,23 @@ func testNameFormat(event TestEvent, exec *Execution) (string, error) {
return event.Output, nil

case event.PackageEvent():
switch event.Action {
case ActionSkip:
if !event.Action.IsTerminal() {
return "", nil
}
pkg := exec.Package(event.Package)
if event.Action == ActionSkip || (event.Action == ActionPass && pkg.Total == 0) {
result = colorEvent(event)("EMPTY")
fallthrough
case ActionPass, ActionFail:
var cached string
if exec.Package(event.Package).cached {
cached = cachedMessage
}
return fmt.Sprintf("%s %s%s\n",
result,
RelativePackagePath(event.Package),
cached), nil
}

var cached string
if pkg.cached {
cached = cachedMessage
}
return fmt.Sprintf("%s %s%s\n",
result,
RelativePackagePath(event.Package),
cached), nil

case event.Action == ActionFail:
pkg := exec.Package(event.Package)
tc := pkg.LastFailedByName(event.Test)
Expand Down Expand Up @@ -111,6 +117,7 @@ func isPkgFailureOutput(event TestEvent) bool {
event.Action == ActionOutput,
out != "PASS\n",
out != "FAIL\n",
!isWarningNoTestsToRunOutput(out),
!strings.HasPrefix(out, "FAIL\t"+event.Package),
!strings.HasPrefix(out, "ok \t"+event.Package),
!strings.HasPrefix(out, "? \t"+event.Package),
Expand Down Expand Up @@ -167,6 +174,9 @@ func shortFormatPackageEvent(event TestEvent, exec *Execution) (string, error) {
case ActionSkip:
return fmtEvent(withColor("∅"))
case ActionPass:
if pkg.Total == 0 {
return fmtEvent(withColor("∅"))
}
return fmtEvent(withColor("✓"))
case ActionFail:
return fmtEvent(withColor("✖"))
Expand Down
3 changes: 3 additions & 0 deletions testjson/format_test.go
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
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
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\tgithub.com/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
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
@@ -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
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
EMPTY gotest.tools/gotestsum/internal/empty
1 change: 1 addition & 0 deletions testjson/testdata/standard-quiet-format.out
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 68539ea

Please sign in to comment.