From d71a38f9030015fc3d20f1d7cd2f2bfc906f00f2 Mon Sep 17 00:00:00 2001 From: Adam Luzsi Date: Wed, 3 Jul 2024 22:13:54 +0200 Subject: [PATCH] skipped tests will appear with yellow colour in spec document output format --- Spec.go | 1 + internal/doc/doc.go | 11 +++++++++-- internal/doc/doc_test.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Spec.go b/Spec.go index 2df0ba4..ceeaa09 100644 --- a/Spec.go +++ b/Spec.go @@ -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(), }) }() diff --git a/internal/doc/doc.go b/internal/doc/doc.go index 2b87f56..767106d 100644 --- a/internal/doc/doc.go +++ b/internal/doc/doc.go @@ -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{} @@ -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 { @@ -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 diff --git a/internal/doc/doc_test.go b/internal/doc/doc_test.go index 85828e7..d6bd740 100644 --- a/internal/doc/doc_test.go +++ b/internal/doc/doc_test.go @@ -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) { @@ -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)