Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test.xml doesn't report a test case properly when it panic #4280

Open
linzhp opened this issue Feb 21, 2025 · 0 comments
Open

test.xml doesn't report a test case properly when it panic #4280

linzhp opened this issue Feb 21, 2025 · 0 comments

Comments

@linzhp
Copy link
Contributor

linzhp commented Feb 21, 2025

With a test like this:

func TestPanic(t *testing.T) {
	var buff *bytes.Buffer
	buff.WriteString("hello")
}

rules_go would produce a test.xml like this:

<testsuites>
	<testsuite errors="1" failures="0" skipped="0" tests="1" time="" name="example.com/panic" timestamp="2025-02-21T00:05:35.143Z">
		<testcase classname="panic" name="TestPanic" time="">
			<error message="No pass/skip/fail event found for test" type="">=== RUN   TestPanic&#xA;--- FAIL: TestPanic (0.00s)&#xA;panic: runtime error: invalid memory address or nil pointer dereference [recovered]&#xA;&#x9;panic: runtime error: invalid memory address or nil pointer dereference&#xA;[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x39e09f7]</error>
		</testcase>
	</testsuite>
</testsuites>

Due to this issue, the duration of the test case and the test suite are not populated.


Some debugging notes:

From the test.log, we can see the the --- FAIL event is there:

�=== RUN   TestPanic
�--- FAIL: TestPanic (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x39e09f7]
...

Running this test with go test -json, we can see there is a "Action":"fail":

{"Time":"2025-02-20T16:11:18.654146-08:00","Action":"start","Package":"uber.com/panic"}
{"Time":"2025-02-20T16:11:18.914593-08:00","Action":"run","Package":"uber.com/panic","Test":"TestPanic"}
{"Time":"2025-02-20T16:11:18.914655-08:00","Action":"output","Package":"uber.com/panic","Test":"TestPanic","Output":"=== RUN   TestPanic\n"}
{"Time":"2025-02-20T16:11:18.914704-08:00","Action":"output","Package":"uber.com/panic","Test":"TestPanic","Output":"--- FAIL: TestPanic (0.00s)\n"}
{"Time":"2025-02-20T16:11:18.917198-08:00","Action":"output","Package":"uber.com/panic","Test":"TestPanic","Output":"panic: runtime error: invalid memory address or nil pointer dereference [recovered]\n"}
{"Time":"2025-02-20T16:11:18.917214-08:00","Action":"output","Package":"uber.com/panic","Test":"TestPanic","Output":"\tpanic: runtime error: invalid memory address or nil pointer dereference\n"}
{"Time":"2025-02-20T16:11:18.91722-08:00","Action":"output","Package":"uber.com/panic","Test":"TestPanic","Output":"[signal SIGSEGV: segmentation violation code=0x2 addr=0x20 pc=0x1008aa80c]\n"}
{"Time":"2025-02-20T16:11:18.917705-08:00","Action":"output","Package":"uber.com/panic","Test":"TestPanic","Output":"exit status 2\n"}
{"Time":"2025-02-20T16:11:18.917726-08:00","Action":"fail","Package":"uber.com/panic","Test":"TestPanic","Elapsed":0}
{"Time":"2025-02-20T16:11:18.917731-08:00","Action":"output","Package":"uber.com/panic","Output":"FAIL\tuber.com/panic\t0.263s\n"}
{"Time":"2025-02-20T16:11:18.91774-08:00","Action":"fail","Package":"uber.com/panic","Elapsed":0.264}

However, if I feed the test.log into the JSON converter, the resulting JSON doesn't have the "Action":"fail" for TestPanic. So it seems the information is lost when converting text to JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant