Skip to content

Commit

Permalink
Merge pull request #123 from dnephin/bug-missing-skip-msg
Browse files Browse the repository at this point in the history
summary: Fixed missing skip message bug
  • Loading branch information
dnephin committed May 23, 2020
2 parents 271af14 + c983e4c commit 157775e
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 11 deletions.
31 changes: 23 additions & 8 deletions testjson/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (p Package) OutputLines(tc TestCase) []string {
// If this is a subtest, or a root test case with subtest failures the
// subtest failure output should contain the relevant lines, so we don't need
// extra lines.
if sub != "" || tc.subTestFailed {
if sub != "" || tc.hasSubTestFailed {
return lines
}
//
Expand Down Expand Up @@ -189,9 +189,12 @@ type TestCase struct {
Package string
Test string
Elapsed time.Duration
// subTestFailed is true when a subtest of this TestCase has failed. It is
// hasSubTestFailed is true when a subtest of this TestCase has failed. It is
// used to find root TestCases which have no failing subtests.
subTestFailed bool
hasSubTestFailed bool
// hasSubTestFailed is true when a subtest of this TestCase was skipped. It is
// used to find root TestCases which have skipped tests.
hasSubTestSkipped bool
}

func newPackage() *Package {
Expand Down Expand Up @@ -257,23 +260,35 @@ func (e *Execution) addTestEvent(pkg *Package, event TestEvent) {
delete(pkg.running, event.Test)
tc.Elapsed = elapsedDuration(event.Elapsed)

root, subTest := splitTestName(event.Test)

switch event.Action {
case ActionFail:
pkg.Failed = append(pkg.Failed, tc)

// If this is a subtest, mark the root test as having subtests.
root, subTest := splitTestName(event.Test)
// If this is a subtest, mark the root test as having a failed subtest
if subTest != "" {
rootTestCase := pkg.running[root]
rootTestCase.subTestFailed = true
rootTestCase.hasSubTestFailed = true
pkg.running[root] = rootTestCase
}
case ActionSkip:
pkg.Skipped = append(pkg.Skipped, tc)

// If this is a subtest, mark the root test as having a skipped subtest
if subTest != "" {
rootTestCase := pkg.running[root]
rootTestCase.hasSubTestSkipped = true
pkg.running[root] = rootTestCase
}
case ActionPass:
pkg.Passed = append(pkg.Passed, tc)
// Remove test output once a test passes, it wont be used
delete(pkg.output, event.Test)

// Remove test output once a test passes, it wont be used. But do not
// remove output if there is a skipped subtest. That output will be used.
if !tc.hasSubTestSkipped {
delete(pkg.output, event.Test)
}
}
}

Expand Down
18 changes: 15 additions & 3 deletions testjson/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ func TestPrintSummary_MissingTestFailEvent(t *testing.T) {

exec, err := ScanTestOutput(ScanConfig{
Stdout: bytes.NewReader(golden.Get(t, "go-test-json-missing-test-fail.out")),
Stderr: bytes.NewReader(nil),
})
assert.NilError(t, err)

Expand All @@ -247,7 +246,6 @@ func TestPrintSummary_WithMisattributedOutput(t *testing.T) {

exec, err := ScanTestOutput(ScanConfig{
Stdout: bytes.NewReader(golden.Get(t, "go-test-json-misattributed.out")),
Stderr: bytes.NewBuffer(nil),
})
assert.NilError(t, err)

Expand All @@ -262,11 +260,25 @@ func TestPrintSummary_WithSubtestFailures(t *testing.T) {

exec, err := ScanTestOutput(ScanConfig{
Stdout: bytes.NewReader(golden.Get(t, "go-test-json.out")),
Stderr: bytes.NewBuffer(nil),
})
assert.NilError(t, err)

buf := new(bytes.Buffer)
PrintSummary(buf, exec, SummarizeAll)
golden.Assert(t, buf.String(), "summary-root-test-has-subtest-failures")
}

func TestPrintSummary_WithMissingSkipMessage(t *testing.T) {
_, reset := patchClock()
defer reset()

exec, err := ScanTestOutput(ScanConfig{
Stdout: bytes.NewReader(golden.Get(t, "go-test-json-missing-skip-msg.out")),
})
assert.NilError(t, err)

buf := new(bytes.Buffer)
PrintSummary(buf, exec, SummarizeAll)
//q.Q(exec)
golden.Assert(t, buf.String(), "bug-missing-skip-message-summary.out")
}
12 changes: 12 additions & 0 deletions testjson/testdata/bug-missing-skip-message-summary.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

=== Skipped
=== SKIP: testjson TestNewDotFormatter (0.00s)
WARN Failed to detect terminal width for dots format, error: inappropriate ioctl for device
TestNewDotFormatter: dotformat_test.go:161: !ok: no terminal width

=== SKIP: testjson TestGetPkgPathPrefix/with_go_path (0.00s)
TestGetPkgPathPrefix/with_go_path: pkgpathprefix_test.go:22: isGoModuleEnabled()
--- SKIP: TestGetPkgPathPrefix/with_go_path (0.00s)


DONE 42 tests, 2 skipped in 0.000s
Loading

0 comments on commit 157775e

Please sign in to comment.