Commit Graph

296 Commits

Author SHA1 Message Date
f643780c47 parser/gotest: Add tests for internal package collector 2022-06-26 14:23:58 +01:00
079e5ce7ea parser/gotest: Add support for parsing lines longer than 64K
The gotest parser used a bufio.Scanner to read its input, which
prevented us from reading lines larger than 64K.

In order to support reading larger lines, bufio.Scanner has been
replaced with bufio.Reader. The maximum line size has been increased to
4MiB and instead of returning an error when reading lines that exceed
the maximum size, we truncate that line and continue parsing.

Fixes #135
2022-06-26 00:45:06 +01:00
7875e13422 parser/gotest: Move NewParser function below Parser struct 2022-06-26 00:43:55 +01:00
8648745762 parser/gotest: Don't ignore output when there were no tests
In some cases we may have captured some output for a package that didn't
have any tests. We should include it in the generated report as it may
contain useful information.
2022-06-26 00:43:05 +01:00
d84b41a3f9 Update gitub.com/google/go-cmp dependency to v0.5.8 2022-06-15 23:46:40 +01:00
da6551b8c0 gtr,parser/gotest: Remove gtr.Benchmark and use gtr.Test for all tests 2022-06-15 23:46:40 +01:00
dc591b8731 junit: Remove benchmark specific code from package junit
The junit package shouldn't need to know anything about benchmarks and
gtr.Benchmark will be removed in a future commit. Instead, it will be
the responsibility of the gotest parser to represent benchmarks using
gtr.Test.
2022-06-15 23:46:40 +01:00
46e0aed494 gtr: Also look at failures in benchmarks when creating a package
When we encounter a failure but there was not failing test, we create a
failing dummy test in the report. This is to prevent the failure from
being overlooked.

The case where the output contained a failing benchmark was not handled
correctly, resulting in a dummy test failure being added to the report
unnecessarily.
2022-06-13 00:47:28 +01:00
d05abd4130 junit: Include output in JUnit report for skipped and failed benchmarks 2022-06-13 00:34:20 +01:00
f1ad02b733 junit: Use the standard duration formatting for benchmark durations
Benchmark durations were originally formatted with higher precision
because they contained just the NsPerOp field. Now that we're
approximating the total duration they are more accurate and don't need
as many decimals.
2022-06-12 23:02:01 +01:00
1d905e0b1c gtr: Improve accuracy of benchmark duration calculation
The NsPerOp was previously casted to a time.Duration (int64) before
multiplying it with the number of iterations. This has been fixed by
doing the casting after the multiplication. The resulting duration
should be a bit more accurate.
2022-06-12 22:56:04 +01:00
9a1666d75c gtr,junit: Move Benchmark duration calculation to gtr package 2022-06-12 22:54:12 +01:00
cb055227b7 parser/gotest: Improve gotest output handling
The reportBuilder has been updated to use the ordered output collector
to keep track of go test output. This makes it possible to include
benchmark output in the generated report and makes sure that output is
preserved when deleting subtest parents from the report.
2022-06-08 23:01:01 +01:00
5331b9b8d6 parser/gotest: Create output collector that preserves the line order 2022-06-08 23:01:01 +01:00
d2480a6059 parser/gotest: Skip ID 0 when searching for existing tests or benchmarks 2022-06-08 23:01:01 +01:00
2f7bf7c3bc parser/gotest: Set unique Test, Benchmark and Error ID's
This will be used later to collect and store output for the right tests.
2022-06-08 23:01:01 +01:00
5d691c7896 testdata: Regenerate benchmark test data and add logging 2022-06-08 23:01:01 +01:00
b95e18cd5c gtr: Add ID fields to Test, Benchmark and Error structs
This can optionally be used to uniquely individual tests, benchmarks or
errors.
2022-06-08 23:01:01 +01:00
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