Skip to content

Commit

Permalink
Fix output for tests with parenthesis in their text
Browse files Browse the repository at this point in the history
The opening parenthesis was preventing the pass/fail event from being
created.

Authored-by: Matt Royal <mroyal@pivotal.io>
  • Loading branch information
matt-royal committed Aug 25, 2020
1 parent 2e1e2ba commit 7f32e5a
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
6 changes: 5 additions & 1 deletion reporters.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ func (r *gotestCompatibleReporter) SpecDidComplete(spec *types.SpecSummary) {
}

func testName(spec *types.SpecSummary) string {
return strings.Join(spec.ComponentTexts[1:len(spec.ComponentTexts)], " ")
return strings.ReplaceAll(
strings.Join(spec.ComponentTexts[1:len(spec.ComponentTexts)], " "),
"(",
"\\(",
)
}

// No-Op methods for compatibility with ginkgo.Reporter
Expand Down
66 changes: 66 additions & 0 deletions reporters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,72 @@ var _ = Describe("GoTestCompatibleReporter", func() {
}))
})
})

When("the tests have strange characters", func() {
It("outputs them in a format that GoLand parses as nested", func() {
lines := testOutputLines("./test_assets/formatting")
groups := groupByTest(lines)

Expect(groups).To(HaveLen(6))

Expect(groups[0]).To(Equal([]testJsonEntry{
{Action: "run", Test: "TestFormatting", Output: "",},
{Action: "output", Test: "TestFormatting", Output: "=== RUN TestFormatting\n",},
{Action: "output", Test: "TestFormatting", Output: "Running Suite: Formatting Suite\n",},
{Action: "output", Test: "TestFormatting", Output: "===============================\n",},
{Action: "output", Test: "TestFormatting", Output: "Random Seed: 1234\n",},
{Action: "output", Test: "TestFormatting", Output: "Will run 4 of 4 specs\n",},
{Action: "output", Test: "TestFormatting", Output: "\n",},
{Action: "output", Test: "TestFormatting", Output: "\n",},
}))

Expect(groups[1]).To(Equal([]testJsonEntry{
{Action: "run", Test: "FORMATTING this \\(level) has parenthesis test 1 passes", Output: "\n",},
{Action: "output", Test: "FORMATTING this \\(level) has parenthesis test 1 passes", Output: "=== RUN FORMATTING this \\(level) has parenthesis test 1 passes\n",},
{Action: "output", Test: "FORMATTING this \\(level) has parenthesis test 1 passes", Output: "•\n",},
{Action: "output", Test: "FORMATTING this \\(level) has parenthesis test 1 passes", Output: "--- PASS: FORMATTING this \\(level) has parenthesis test 1 passes (TIME)\n",},
{Action: "output", Test: "FORMATTING this \\(level) has parenthesis test 1 passes", Output: "\n",},
{Action: "pass", Test: "FORMATTING this \\(level) has parenthesis test 1 passes", Output: "\n",},
}))

Expect(groups[2]).To(Equal([]testJsonEntry{
{Action: "run", Test: "FORMATTING this \\(level) has parenthesis test 2 passes", Output: "\n",},
{Action: "output", Test: "FORMATTING this \\(level) has parenthesis test 2 passes", Output: "=== RUN FORMATTING this \\(level) has parenthesis test 2 passes\n",},
{Action: "output", Test: "FORMATTING this \\(level) has parenthesis test 2 passes", Output: "•\n",},
{Action: "output", Test: "FORMATTING this \\(level) has parenthesis test 2 passes", Output: "--- PASS: FORMATTING this \\(level) has parenthesis test 2 passes (TIME)\n",},
{Action: "output", Test: "FORMATTING this \\(level) has parenthesis test 2 passes", Output: "\n",},
{Action: "pass", Test: "FORMATTING this \\(level) has parenthesis test 2 passes", Output: "\n",},
}))

Expect(groups[3]).To(Equal([]testJsonEntry{
{Action: "run", Test: "FORMATTING this /level/ has slashes test 1 passes", Output: "\n",},
{Action: "output", Test: "FORMATTING this /level/ has slashes test 1 passes", Output: "=== RUN FORMATTING this /level/ has slashes test 1 passes\n",},
{Action: "output", Test: "FORMATTING this /level/ has slashes test 1 passes", Output: "•\n",},
{Action: "output", Test: "FORMATTING this /level/ has slashes test 1 passes", Output: "--- PASS: FORMATTING this /level/ has slashes test 1 passes (TIME)\n",},
{Action: "output", Test: "FORMATTING this /level/ has slashes test 1 passes", Output: "\n",},
{Action: "pass", Test: "FORMATTING this /level/ has slashes test 1 passes", Output: "\n",},
}))

Expect(groups[4]).To(Equal([]testJsonEntry{
{Action: "run", Test: "FORMATTING this /level/ has slashes test 2 passes", Output: "\n",},
{Action: "output", Test: "FORMATTING this /level/ has slashes test 2 passes", Output: "=== RUN FORMATTING this /level/ has slashes test 2 passes\n",},
{Action: "output", Test: "FORMATTING this /level/ has slashes test 2 passes", Output: "•\n",},
{Action: "output", Test: "FORMATTING this /level/ has slashes test 2 passes", Output: "--- PASS: FORMATTING this /level/ has slashes test 2 passes (TIME)\n",},
{Action: "output", Test: "FORMATTING this /level/ has slashes test 2 passes", Output: "\n",},
{Action: "output", Test: "FORMATTING this /level/ has slashes test 2 passes", Output: "Ran 4 of 4 Specs in TIME\n",},
{Action: "output", Test: "FORMATTING this /level/ has slashes test 2 passes", Output: "SUCCESS! -- 4 Passed | 0 Failed | 0 Pending | 0 Skipped\n",},
{Action: "pass", Test: "FORMATTING this /level/ has slashes test 2 passes", Output: "SUCCESS! -- 4 Passed | 0 Failed | 0 Pending | 0 Skipped\n",},
}))

Expect(groups[5]).To(Equal([]testJsonEntry{
{Action: "output", Test: "TestFormatting", Output: "--- PASS: TestFormatting (TIME)\n",},
{Action: "pass", Test: "TestFormatting", Output: "--- PASS: TestFormatting (TIME)\n",},
{Action: "output", Test: "TestFormatting", Output: "PASS\n"},
{Action: "output", Test: "TestFormatting", Output: "ok \tgithub.com/matt-royal/biloba/test_assets/formatting\tTIME\n",},
{Action: "pass", Test: "TestFormatting", Output: "ok \tgithub.com/matt-royal/biloba/test_assets/formatting\tTIME\n",},
}))
})
})
})

func groupByTest(lines []testJsonEntry) [][]testJsonEntry {
Expand Down
21 changes: 21 additions & 0 deletions test_assets/formatting/formatting_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package passing_test

import (
"github.com/matt-royal/biloba"
"os"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestFormatting(t *testing.T) {
if os.Getenv("BILOBA_INTEGRATION_TEST") == "" {
return
}

RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Formatting Suite", []Reporter{
biloba.NewGoTestCompatibleReporter(),
})
}
28 changes: 28 additions & 0 deletions test_assets/formatting/formatting_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package passing_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("FORMATTING", func() {
Describe("this (level) has parenthesis", func() {
It("test 1 passes", func() {
Expect(true).To(Equal(true))
})

It("test 2 passes", func() {
Expect(true).To(Equal(true))
})
})

Describe("this /level/ has slashes", func() {
It("test 1 passes", func() {
Expect(true).To(Equal(true))
})

It("test 2 passes", func() {
Expect(true).To(Equal(true))
})
})
})

0 comments on commit 7f32e5a

Please sign in to comment.