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 logging no longer affects retrieval of file name and line number #19

Merged
merged 1 commit into from
Apr 14, 2022

Conversation

IsaacLambat
Copy link
Contributor

@IsaacLambat IsaacLambat commented Apr 4, 2022

Currently, if any logging is in the output of the test before the assert failure, the file name and line number is not detected properly causing GitHub to not be able to do the annotations. This change makes it so the assert failures are extracted (using regex), and then the file name and line number is extracted from that.

For example, a Go test with the following code on in main_test.go with the failure on line 18:

func TestReproLog(t *testing.T) {
	log.Println("This is a test")
	require.True(t, false)
}

used to cause Github to receive the annotation text:

::error file=/2022/04/04 18,line=40::=== RUN   TestReproLog%0A2022/04/04 18:40:10 This is a test%0A    main_test.go:18: %0A        	Error Trace:	main_test.go:18%0A        	Error:      	Should be true%0A        	Test:       	TestReproLog%0A--- FAIL: TestReproLog (0.00s)%0A

and now it would receive:

::error file=main_test.go,line=18::    main_test.go:18: %0A        	Error Trace:	main_test.go:18%0A        	Error:      	Should be true%0A        	Test:       	TestReproLog%0A

Example tests for this change can be seen here (along with tests that can be ran locally if needed using https://github.com/nektos/act): https://github.com/IsaacLambat/golang-test-annotations-testing

Example of annotations on a PR: https://github.com/IsaacLambat/golang-test-annotations-testing/pull/1/files

@IsaacLambat IsaacLambat marked this pull request as draft April 6, 2022 11:04
@IsaacLambat IsaacLambat marked this pull request as ready for review April 6, 2022 12:23
@IsaacLambat IsaacLambat marked this pull request as draft April 6, 2022 12:41
@IsaacLambat IsaacLambat marked this pull request as ready for review April 6, 2022 13:57
@IsaacLambat IsaacLambat force-pushed the master branch 2 times, most recently from d0abb43 to 3163021 Compare April 9, 2022 02:39
index.js Show resolved Hide resolved
@guyarb guyarb merged commit cdc8ef7 into guyarb:master Apr 14, 2022
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

Successfully merging this pull request may close these issues.

2 participants