Skip to content

Commit

Permalink
skipped tests will appear with yellow colour in spec document output …
Browse files Browse the repository at this point in the history
…format
  • Loading branch information
adamluzsi committed Jul 3, 2024
1 parent a1c2c30 commit d71a38f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions Spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ func (spec *Spec) runTB(tb testing.TB, blk func(*T)) {
spec.doc.results = append(spec.doc.results, doc.TestingCase{
ContextPath: contextPath,
TestFailed: tb.Failed(),
TestSkipped: tb.Skipped(),
})
}()

Expand Down
11 changes: 9 additions & 2 deletions internal/doc/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type TestingCase struct {
ContextPath []string
// TestFailed tells if the test failed
TestFailed bool
// TestSkipped tells if the given test was skipped
TestSkipped bool
}

type DocumentFormat struct{}
Expand All @@ -37,8 +39,9 @@ func (gen DocumentFormat) MakeDocument(ctx context.Context, tcs []TestingCase) (
type colourCode string

const (
red colourCode = "91m"
green colourCode = "92m"
red colourCode = "91m"
green colourCode = "92m"
yellow colourCode = "93m"
)

func colourise(code colourCode, text string) string {
Expand Down Expand Up @@ -97,6 +100,10 @@ func (gen DocumentFormat) generateDocumentString(n *node, indent string) string
line = key
colour = green
)
if child.TestingCase.TestSkipped {
line += " [SKIP]"
colour = yellow
}
if child.TestingCase.TestFailed {
line += " [FAIL]"
colour = red
Expand Down
34 changes: 34 additions & 0 deletions internal/doc/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,31 @@ func TestTestDocumentGenerator(t *testing.T) {
a.Case(func(t assert.It) { assert.Contain(t, d, exp2) })
})
})

t.Run("skipped tests are greyed out", func(t *testing.T) {
testcase.SetEnv(t, "TERM", "xterm-256color")
internal.StubVerbose(t, func() bool {
return true
})

docw := doc.DocumentFormat{}

d, err := docw.MakeDocument(context.Background(), []doc.TestingCase{
{
ContextPath: []string{
"TestTestDocumentGenerator",
"smoke",
"testA",
},
TestFailed: false,
TestSkipped: true,
},
})
assert.NoError(t, err)

exp := "TestTestDocumentGenerator\n smoke\n \x1b[93mtestA [SKIP]\x1b[0m\n"
assert.Contain(t, d, exp)
})
}

func Test_spike(t *testing.T) {
Expand All @@ -155,6 +180,15 @@ func Test_spike(t *testing.T) {
},
TestFailed: true,
},
{
ContextPath: []string{
"subject",
"when",
"and",
"then C",
},
TestSkipped: true,
},
})
assert.NoError(t, err)

Expand Down

0 comments on commit d71a38f

Please sign in to comment.