diff --git a/pkg/parser/gotest/gotest.go b/pkg/parser/gotest/gotest.go index b817775..413e11b 100644 --- a/pkg/parser/gotest/gotest.go +++ b/pkg/parser/gotest/gotest.go @@ -128,10 +128,9 @@ func (p *parser) coverage(percent string) { } func (p *parser) output(line string) { - // TODO: Count indentations, however don't assume every tab is an indentation var indent int - for indent = 0; strings.HasPrefix(line, "\t"); indent++ { - line = line[1:] + for indent = 0; strings.HasPrefix(line, " "); indent++ { + line = line[4:] } p.add(Event{ Type: "output", diff --git a/pkg/parser/gotest/gotest_test.go b/pkg/parser/gotest/gotest_test.go index 5d8a257..14dc1df 100644 --- a/pkg/parser/gotest/gotest_test.go +++ b/pkg/parser/gotest/gotest_test.go @@ -27,10 +27,10 @@ var tests = []struct { []Event{ {Type: "run_test", Id: 1, Name: "TestOne"}, {Type: "end_test", Id: 1, Name: "TestOne", Result: "FAIL", Duration: 20 * time.Millisecond}, - {Type: "output", Data: "file_test.go:11: Error message", Indent: 1}, - {Type: "output", Data: "file_test.go:11: Longer", Indent: 1}, - {Type: "output", Data: "error", Indent: 2}, - {Type: "output", Data: "message.", Indent: 2}, + {Type: "output", Data: "\tfile_test.go:11: Error message"}, + {Type: "output", Data: "\tfile_test.go:11: Longer"}, + {Type: "output", Data: "\t\terror"}, + {Type: "output", Data: "\t\tmessage."}, {Type: "run_test", Id: 2, Name: "TestTwo"}, {Type: "end_test", Id: 2, Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond}, {Type: "status", Result: "FAIL"}, @@ -41,7 +41,7 @@ var tests = []struct { []Event{ {Type: "run_test", Id: 1, Name: "TestOne"}, {Type: "end_test", Id: 1, Name: "TestOne", Result: "SKIP", Duration: 20 * time.Millisecond}, - {Type: "output", Data: "file_test.go:11: Skip message", Indent: 1}, + {Type: "output", Data: "\tfile_test.go:11: Skip message"}, {Type: "run_test", Id: 2, Name: "TestTwo"}, {Type: "end_test", Id: 2, Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond}, {Type: "status", Result: "PASS"}, @@ -67,10 +67,10 @@ var tests = []struct { {Type: "summary", Result: "ok", Name: "package/name1", Duration: 160 * time.Millisecond}, {Type: "run_test", Id: 3, Name: "TestOne"}, {Type: "end_test", Id: 3, Name: "TestOne", Result: "FAIL", Duration: 20 * time.Millisecond}, - {Type: "output", Data: "file_test.go:11: Error message", Indent: 1}, - {Type: "output", Data: "file_test.go:11: Longer", Indent: 1}, - {Type: "output", Data: "error", Indent: 2}, - {Type: "output", Data: "message.", Indent: 2}, + {Type: "output", Data: "\tfile_test.go:11: Error message"}, + {Type: "output", Data: "\tfile_test.go:11: Longer"}, + {Type: "output", Data: "\t\terror"}, + {Type: "output", Data: "\t\tmessage."}, {Type: "run_test", Id: 4, Name: "TestTwo"}, {Type: "end_test", Id: 4, Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond}, {Type: "status", Result: "FAIL"}, @@ -90,11 +90,11 @@ var tests = []struct { {Type: "run_test", Id: 1, Name: "TestDoFoo"}, {Type: "run_test", Id: 2, Name: "TestDoFoo2"}, {Type: "end_test", Id: 1, Name: "TestDoFoo", Result: "PASS", Duration: 270 * time.Millisecond}, - {Type: "output", Data: "cov_test.go:10: DoFoo log 1", Indent: 1}, - {Type: "output", Data: "cov_test.go:10: DoFoo log 2", Indent: 1}, + {Type: "output", Data: "\tcov_test.go:10: DoFoo log 1"}, + {Type: "output", Data: "\tcov_test.go:10: DoFoo log 2"}, {Type: "end_test", Id: 2, Name: "TestDoFoo2", Result: "PASS", Duration: 160 * time.Millisecond}, - {Type: "output", Data: "cov_test.go:21: DoFoo2 log 1", Indent: 1}, - {Type: "output", Data: "cov_test.go:21: DoFoo2 log 2", Indent: 1}, + {Type: "output", Data: "\tcov_test.go:21: DoFoo2 log 1"}, + {Type: "output", Data: "\tcov_test.go:21: DoFoo2 log 2"}, {Type: "status", Result: "PASS"}, {Type: "summary", Result: "ok", Name: "package/name", Duration: 440 * time.Millisecond}, }}, @@ -132,6 +132,52 @@ var tests = []struct { {Type: "status", Result: "PASS"}, {Type: "summary", Result: "ok", Name: "package/name", Duration: 50 * time.Millisecond}, }}, + {"12-go_1_7.txt", + []Event{ + {Type: "run_test", Id: 1, Name: "TestOne"}, + {Type: "run_test", Id: 2, Name: "TestOne/Child"}, + {Type: "run_test", Id: 3, Name: "TestOne/Child#01"}, + {Type: "run_test", Id: 4, Name: "TestOne/Child=02"}, + {Type: "end_test", Id: 1, Name: "TestOne", Result: "PASS", Duration: 10 * time.Millisecond}, + {Type: "end_test", Id: 2, Name: "TestOne/Child", Result: "PASS", Duration: 20 * time.Millisecond}, + {Type: "end_test", Id: 3, Name: "TestOne/Child#01", Result: "PASS", Duration: 30 * time.Millisecond}, + {Type: "end_test", Id: 4, Name: "TestOne/Child=02", Result: "PASS", Duration: 40 * time.Millisecond}, + {Type: "run_test", Id: 5, Name: "TestTwo"}, + {Type: "run_test", Id: 6, Name: "TestTwo/Child"}, + {Type: "run_test", Id: 7, Name: "TestTwo/Child#01"}, + {Type: "run_test", Id: 8, Name: "TestTwo/Child=02"}, + {Type: "end_test", Id: 5, Name: "TestTwo", Result: "PASS", Duration: 10 * time.Millisecond}, + {Type: "end_test", Id: 6, Name: "TestTwo/Child", Result: "PASS", Duration: 20 * time.Millisecond}, + {Type: "end_test", Id: 7, Name: "TestTwo/Child#01", Result: "PASS", Duration: 30 * time.Millisecond}, + {Type: "end_test", Id: 8, Name: "TestTwo/Child=02", Result: "PASS", Duration: 40 * time.Millisecond}, + {Type: "run_test", Id: 9, Name: "TestThree"}, + {Type: "run_test", Id: 10, Name: "TestThree/a#1"}, + {Type: "run_test", Id: 11, Name: "TestThree/a#1/b#1"}, + {Type: "run_test", Id: 12, Name: "TestThree/a#1/b#1/c#1"}, + {Type: "end_test", Id: 9, Name: "TestThree", Result: "PASS", Duration: 10 * time.Millisecond}, + {Type: "end_test", Id: 10, Name: "TestThree/a#1", Result: "PASS", Duration: 20 * time.Millisecond}, + {Type: "end_test", Id: 11, Name: "TestThree/a#1/b#1", Result: "PASS", Duration: 30 * time.Millisecond}, + {Type: "end_test", Id: 12, Name: "TestThree/a#1/b#1/c#1", Result: "PASS", Duration: 40 * time.Millisecond}, + {Type: "run_test", Id: 13, Name: "TestFour"}, + {Type: "run_test", Id: 14, Name: "TestFour/#00"}, + {Type: "run_test", Id: 15, Name: "TestFour/#01"}, + {Type: "run_test", Id: 16, Name: "TestFour/#02"}, + {Type: "end_test", Id: 13, Name: "TestFour", Result: "FAIL", Duration: 20 * time.Millisecond}, + {Type: "end_test", Id: 14, Name: "TestFour/#00", Result: "FAIL", Duration: 0}, + {Type: "output", Data: "\texample.go:12: Expected abc OBTAINED:"}, + {Type: "output", Data: "\t\txyz"}, + {Type: "output", Data: "\texample.go:123: Expected and obtained are different."}, + {Type: "end_test", Id: 15, Name: "TestFour/#01", Result: "SKIP", Duration: 0}, + {Type: "end_test", Id: 16, Name: "TestFour/#02", Result: "PASS", Duration: 0}, + {Type: "run_test", Id: 17, Name: "TestFive"}, + {Type: "end_test", Id: 17, Name: "TestFive", Result: "SKIP", Duration: 0}, + {Type: "output", Data: "example.go:1392: Not supported yet."}, + {Type: "run_test", Id: 18, Name: "TestSix"}, + {Type: "end_test", Id: 18, Name: "TestSix", Result: "FAIL", Duration: 0}, + {Type: "output", Data: "example.go:371: This should not fail!"}, + {Type: "status", Result: "FAIL"}, + {Type: "summary", Result: "FAIL", Name: "package/name", Duration: 50 * time.Millisecond}, + }}, } func TestParse(t *testing.T) { diff --git a/testdata/22-whitespace.txt b/testdata/22-whitespace.txt new file mode 100644 index 0000000..2633e56 --- /dev/null +++ b/testdata/22-whitespace.txt @@ -0,0 +1,88 @@ +=== RUN TestFlat +printf 1 +printf 2 +--- PASS: TestFlat (0.00s) + whitespace_test.go:9: log 1 + whitespace_test.go:10: log 2 +=== RUN TestWithSpace +no-space + one-space + two-space + four-space + eight-space +no-space +--- PASS: TestWithSpace (0.00s) + whitespace_test.go:16: no-space + whitespace_test.go:17: one-space + whitespace_test.go:18: two-space + whitespace_test.go:19: four-space + whitespace_test.go:20: eight-space + whitespace_test.go:21: no-space +=== RUN TestWithTab +no-tab + one-tab + two-tab +--- PASS: TestWithTab (0.00s) + whitespace_test.go:31: no-tab + whitespace_test.go:32: one-tab + whitespace_test.go:33: two-tab +=== RUN TestWithNewlinesFlat +no-newline +one-newline +one-newline +two-newlines +two-newlines +two-newlines +--- PASS: TestWithNewlinesFlat (0.00s) + whitespace_test.go:40: no-newline + whitespace_test.go:41: one-newline + one-newline + whitespace_test.go:42: two-newlines + two-newlines + two-newlines +=== RUN TestSubTests +=== RUN TestSubTests/TestFlat +printf 1 +printf 2 +=== RUN TestSubTests/TestWithSpace +no-space + one-space + two-space + four-space + eight-space +no-space +=== RUN TestSubTests/TestWithTab +no-tab + one-tab + two-tab +=== RUN TestSubTests/TestWithNewlinesFlat +no-newline +one-newline +one-newline +two-newlines +two-newlines +two-newlines +--- PASS: TestSubTests (0.00s) + --- PASS: TestSubTests/TestFlat (0.00s) + whitespace_test.go:9: log 1 + whitespace_test.go:10: log 2 + --- PASS: TestSubTests/TestWithSpace (0.00s) + whitespace_test.go:16: no-space + whitespace_test.go:17: one-space + whitespace_test.go:18: two-space + whitespace_test.go:19: four-space + whitespace_test.go:20: eight-space + whitespace_test.go:21: no-space + --- PASS: TestSubTests/TestWithTab (0.00s) + whitespace_test.go:31: no-tab + whitespace_test.go:32: one-tab + whitespace_test.go:33: two-tab + --- PASS: TestSubTests/TestWithNewlinesFlat (0.00s) + whitespace_test.go:40: no-newline + whitespace_test.go:41: one-newline + one-newline + whitespace_test.go:42: two-newlines + two-newlines + two-newlines +PASS +ok github.com/jstemmer/test/whitespace 0.001s