diff --git a/internal/doc/doc.go b/internal/doc/doc.go index 767106d..06cfa92 100644 --- a/internal/doc/doc.go +++ b/internal/doc/doc.go @@ -81,6 +81,12 @@ func (n *node) cd(path []string) *node { } func (gen DocumentFormat) hasFailed(n *node) bool { + if n == nil { + return false + } + if n.TestingCase.TestFailed { + return true + } for _, child := range n.Nodes { if child.TestingCase.TestFailed { return true @@ -92,10 +98,21 @@ func (gen DocumentFormat) hasFailed(n *node) bool { return false } +func (gen DocumentFormat) hasFailedInSubnodes(n *node) bool { + if n == nil { + return false + } + for _, child := range n.Nodes { + if gen.hasFailed(child) { + return true + } + } + return false +} + func (gen DocumentFormat) generateDocumentString(n *node, indent string) string { var sb strings.Builder for key, child := range n.Nodes { - sb.WriteString(indent) var ( line = key colour = green @@ -111,9 +128,14 @@ func (gen DocumentFormat) generateDocumentString(n *node, indent string) string if len(child.Nodes) == 0 { line = colourise(colour, line) } - sb.WriteString(line) - sb.WriteString("\n") - sb.WriteString(gen.generateDocumentString(child, indent+" ")) + if internal.Verbose() || gen.hasFailed(child) { + sb.WriteString(indent) + sb.WriteString(line) + sb.WriteString("\n") + } + if internal.Verbose() || gen.hasFailedInSubnodes(child) { + sb.WriteString(gen.generateDocumentString(child, indent+" ")) + } } return sb.String() } diff --git a/internal/doc/doc_test.go b/internal/doc/doc_test.go index d6bd740..9e463fc 100644 --- a/internal/doc/doc_test.go +++ b/internal/doc/doc_test.go @@ -63,6 +63,9 @@ func TestTestDocumentGenerator(t *testing.T) { t.Run("many - colourless", func(t *testing.T) { testcase.SetEnv(t, "TERM", "dumb") + internal.StubVerbose(t, func() bool { + return true + }) docw := doc.DocumentFormat{} @@ -99,6 +102,9 @@ func TestTestDocumentGenerator(t *testing.T) { t.Run("many - colourised", func(t *testing.T) { testcase.SetEnv(t, "TERM", "xterm-256color") + internal.StubVerbose(t, func() bool { + return true + }) docw := doc.DocumentFormat{} @@ -131,7 +137,7 @@ func TestTestDocumentGenerator(t *testing.T) { }) }) - t.Run("skipped tests are greyed out", func(t *testing.T) { + t.Run("skipped tests are yellow", func(t *testing.T) { testcase.SetEnv(t, "TERM", "xterm-256color") internal.StubVerbose(t, func() bool { return true @@ -155,6 +161,38 @@ func TestTestDocumentGenerator(t *testing.T) { exp := "TestTestDocumentGenerator\n smoke\n \x1b[93mtestA [SKIP]\x1b[0m\n" assert.Contain(t, d, exp) }) + + t.Run("non verbose - documentation limited to errors", func(t *testing.T) { + testcase.SetEnv(t, "TERM", "dumb") + internal.StubVerbose(t, func() bool { + return false + }) + + docw := doc.DocumentFormat{} + + d, err := docw.MakeDocument(context.Background(), []doc.TestingCase{ + { + ContextPath: []string{ + "TestTestDocumentGenerator", + "smoke", + "testA", + }, + TestFailed: false, + }, + { + ContextPath: []string{ + "TestTestDocumentGenerator", + "smoke", + "testB", + }, + TestFailed: true, + }, + }) + assert.NoError(t, err) + + exp := "TestTestDocumentGenerator\n smoke\n testB [FAIL]\n" + assert.Contain(t, d, exp) + }) } func Test_spike(t *testing.T) {