Skip to content

Commit

Permalink
Properly handle Skip in sub-test
Browse files Browse the repository at this point in the history
  • Loading branch information
knz committed Nov 28, 2019
1 parent 24d7b00 commit 3ae76c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
13 changes: 6 additions & 7 deletions datadriven.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@ func runTestInternal(
d := &r.data
actual := func() string {
defer func() {
if t.Skipped() {
// The skip status does not propagate to the parent test
// automatically. If we want to catch the skip outside
// of the sub-test below, we need to remember it here.
subTestSkipped = true
}
if r := recover(); r != nil {
if t.Skipped() {
// The skip status does not propagate to the parent test
// automatically. If we want to catch the skip outside
// of the sub-test below, we need to remember it here.
subTestSkipped = true
}

fmt.Printf("\npanic during %s:\n%s\n", d.Pos, d.Input)
panic(r)
}
Expand Down
16 changes: 13 additions & 3 deletions datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,22 @@ xx a=b b=c c=(1,2,3)

func TestSubTestSkip(t *testing.T) {
RunTestFromString(t, `
skip
----
# This error should never happen.
error
----
`, func(t *testing.T, d *TestData) string {
// Verify that calling t.Skip() does not fail with an API error on
// testing.T.
t.Skip("woo")
switch d.Cmd {
case "skip":
// Verify that calling t.Skip() does not fail with an API error on
// testing.T.
t.Skip("woo")
case "error":
// The skip should mask the error afterwards.
t.Error("never reached")
}
return d.Expected
})
}
Expand Down

0 comments on commit 3ae76c2

Please sign in to comment.