Commit Graph

278 Commits

Author SHA1 Message Date
c87388ae59 parser/gotest,junit: Move benchmark grouping to parser/gotest package
Having multiple benchmarks for a single name is something specific to
the gotest output, so grouping benchmarks by name is not something that
belongs in the junit package.
2022-06-08 23:01:01 +01:00
f33a746c85 junit: Simplify the formatOutput function
This function was used in the past to perform some operations on the
individual output lines before joining them together. However, now it's
only used to combine the collection of lines into a single output
string.
2022-06-08 23:01:01 +01:00
395886ab94 Revert "internal: make timestampFunc private"
This reverts commit dcbbd9fb22 and fixes
testdata/generate-golden-reports.go.
2022-05-22 20:56:39 +01:00
84074a188c parser/gotest: remove debugging printf from reportBuilder 2022-05-22 00:50:12 +01:00
9ad16898a8 Add -subtest-mode flag to configure SubtestMode 2022-05-22 00:44:20 +01:00
1b7027fde7 parser/gotest: add SubtestMode to configure how to deal with subtests 2022-05-22 00:32:17 +01:00
6c038bc425 parser/gotest: never reset nextID in report builder to ensure unique ids 2022-05-21 23:29:24 +01:00
01f41237f7 parser/gotest: continue with next item when we find a test or benchmark 2022-05-21 23:19:41 +01:00
0655053883 junit: Move testcase creation from tests and benchmarks to functions 2022-05-21 23:06:44 +01:00
b4847b2e36 internal: move gotest.Options creation into separate function
The gotest and gojson parsers use the same options (for now). To avoid
duplication the list of parser options is created in a separate
function.
2022-05-21 22:44:38 +01:00
dcbbd9fb22 internal: make timestampFunc private 2022-05-21 22:42:36 +01:00
b5d2695c26 parser/gotest: return a separate bool instead of a negative id in find* 2022-05-21 22:26:00 +01:00
f97910c4b9 parser/gotest: Make reportBuilder options private 2022-05-21 22:16:55 +01:00
ae7e71c599 parser/gotest: rename Id -> ID 2022-05-21 18:48:07 +01:00
9bc291d7ca junit: Make Testsuites.ID a required field 2022-05-21 14:28:22 +01:00
fb0aeb9fda testdata: gofmt testdata/src 2022-05-21 14:19:38 +01:00
d2592490b6 junit: Include output in JUnit report for successful tests and benchmarks 2022-05-14 23:36:18 +01:00
a4c479dbbb gtr: Reset builder state after the end of a test or benchmark
The consequence of this is that any output emitted after the test or
benchmark result, will no longer belong to the last test. Instead it
will be appended to the global log. This is necessary to correctly
attribute output to the correct test or benchmark, for example in cases
where both tests and benchmarks appear.

In the past, Go test output printed test logs after the test result.
However, from Go 1.14 this behaviour was changed and test logs are now
printed before the test result.

With this commit, we effectively no longer support the old behaviour in
Go1.13 and earlier. The output will still appear in the generated
report, however it will no longer belong to the correct test.
2022-05-14 23:25:41 +01:00
4d05b2dc3f Regenerate testdata files
Many of the testdata files were generated a long time ago with very old
versions of Go. The Go test output has changed over time, and these test
inputs no longer reflect the current state. The intention is to fully
support the test output of the most recent Go versions.

This commit also includes the source used to generate the test output,
so the output can be more easily updated in the future.
2022-05-14 23:21:56 +01:00
df7394c77c Fix cmp.Diff argument order in tests 2022-05-13 21:45:38 +01:00
7c195be87f Do not trim output whitespace prefix
Whitespace prefix of output lines was carried over from the old v1
version, but in some cases it removes too much whitespace. Ideally it
would detect the common prefix of all output lines for a given text and
only trim that. Until that's fixed, let's just stop removing the
whitespace.

Fixes #131
2022-05-13 21:01:49 +01:00
4976b9b9ae Strip testdata path from subtests name v2.0.0-beta1 2022-04-21 20:42:22 +01:00
49cfa14c14 Update flags section in README.md 2022-04-20 23:23:04 +01:00
3260a9d2e0 Move common go-junit-report code into separate internal package
There was some code duplication between the go-junit-report binary, its
tests and the testdata/generate-golden script. This has been moved into
an internal package. The go-junit-report binary can now just focus on
flag parsing and validation, and it should be less likely that the
binary, tests and golden report generator behave differently.
2022-04-20 19:43:03 +01:00
d84b066208 Move packages out of pkg/ 2022-04-20 19:39:05 +01:00
7b21e70768 parser/gotest: rename New/NewJSON -> NewParser/NewJSONParser 2022-04-20 19:38:48 +01:00
c289a62ec0 Update README.md and mention support for go test -json + example 2022-04-02 01:09:06 +01:00
1b70a28601 Create report.xml files for remaining json tests 2022-04-01 00:58:11 +01:00
d966e01f2a Create report.xml for failed and skipped benchmarks testcase 2022-04-01 00:58:11 +01:00
84c3710523 junit: Improve benchmark total time calculation 2022-04-01 00:58:11 +01:00
969fc17b96 junit: Improve benchmark grouping and add tests 2022-04-01 00:58:11 +01:00
125573d6fc Fix incorrect diff error messages in tests 2022-04-01 00:58:11 +01:00
044e2fc120 parser/gotest: Add support for skipped and failed benchmarks 2022-04-01 00:58:11 +01:00
9cd24c25d1 Add -id flag to generate-golden to generate report for a single testcase 2022-04-01 00:58:11 +01:00
bbb5123976 junit: Don't lose benchmark results when converting to junit testsuites 2022-04-01 00:58:11 +01:00
d63613f07a Add testdata for json go test output 2022-04-01 00:58:11 +01:00
44187d369e Add testcase for failed and skipped benchmarks 2022-04-01 00:58:11 +01:00
f355bc72cc Add -parser flag to choose which parser to use
The two parsers that are supported are `gotest` (default), and `gojson`.
They handle the standard `go test -v` and `go test -json` output
respectively.
2022-03-31 21:51:25 +01:00
1b2039eca6 parser/gotest: Create go test -json parser 2022-03-31 21:51:25 +01:00
75d0972dd6 parser/gotest: Only set TimestampFunc when it's not nil
Otherwise the ReportBuilder won't generate a timestamp.
2022-03-31 21:51:25 +01:00
6e3153dd44 Refactor and simplify tests
For most testcases we shouldn't need to specify the input and report
files, instead just look at the testdata/ dir and process each input
file. For the few testcases that need a non-standard config, an entry
can be added to `testConfigs` map (indexed by the test number).

The testdata files must follow a certain naming pattern to be valid.
They should start with a number, followed by a dash, then any text
describing the test and finally end with `.txt`. The corresponding
report file must start with the same number, a dash, followed by
`report.xml`.
2022-03-31 21:49:30 +01:00
752d873a6e testdata: Add extra leading 0 to testdata files 2022-03-27 23:55:59 +01:00
03a83721a2 Fix name and add missing test file to testcases 2022-03-27 23:55:59 +01:00
0b843fc2b7 gtr,parser/gotest: Move ReportBuilder to gotest package
The ReportBuilder was made specifically for building a gtr.Report from
parsed go test output. At this point it's unclear whether this will be
reusable if we ever introduce other parser. For now let's move it closer
to where it's used and let's not make it part of the public API yet.
2022-03-27 23:55:59 +01:00
9c3fda9259 Move XML writing into separate function 2022-03-27 23:55:59 +01:00
733873e344 Update README.md for changes made in v2 2022-03-22 23:43:34 +00:00
26cb3d5eb3 Print JSON instead of raw Go structs for -debug.print-events 2022-03-22 22:41:50 +00:00
9e3af115d3 Update flag usage text for some of the flags 2022-03-22 22:05:23 +00:00
985100c8e8 junit: Move test output within the XML tag for skipped tests
For consistency with failed tests and tests with unknown status.
2022-03-22 22:05:23 +00:00
1c7fff6728 junit: Rename "Run error" to "Runtime error" for dummy error tests
In cases where a test result is not found, for example when a panic
happened, a dummy failing test is added to the report. Since we don't
know exactly what failed, its error message was simply "Run error". This
has been renamed to "Runtime error".
2022-03-22 22:05:23 +00:00