Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format: handle 'testing: warning: no tests to run' event #185

Merged
merged 1 commit into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 additions & 0 deletions testjson/execution.go
Original file line number Diff line number Diff line change
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
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 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
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
EMPTY 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]