Skip to content

testing: using "go tool test2json dlv test-binary" marks the last test as failed on Mac OS  #34286

Closed
@nd

Description

@nd

This is continuation of #23033 which is still actual in go1.13.

To reproduce the issue create <GOPATH>/src/debugTest/foo_test.go:

package foo

import "testing"

func Test1(t *testing.T) {
}

compile it:

go test -c -o testBinary -gcflags "all=-N -l" debugTest

run:

go tool test2json dlv --listen=:2345 --headless exec testBinary -- -test.v

and connect debugger from another console: dlv connect :2345.

In the Delve console type continue and once the testBinary terminates, exit the delve client via the exit command.

Test2json produces output:

{"Action":"run","Test":"Test1"}
{"Action":"output","Test":"Test1","Output":"=== RUN   Test1\r\n"}
{"Action":"output","Test":"Test1","Output":"--- PASS: Test1 (0.00s)\r\n"}
{"Action":"output","Test":"Test1","Output":"PASS\r\n"}
{"Action":"fail","Test":"Test1"}

This happens because on Mac OS Delve runs programs via debugserver and debugserver uses \r\n line-endings. For most of test output it is not a problem because test2json check prefixes and is not affected by line-ending differences. But for final PASS or FAIL the exact Equal check is used and it fails due to added \r.

This behavior was accidentally fixed in d47526e, but judging by comments in #31969 the fix will be reverted later.

I understand that this is not a bug in test2json. Test2json assumes the output is produced by the test framework and the test framework always uses \n. It is possible to wrap Delve and replace PASS\r\n in its output to PASS\n, but every test2json client will have to do that. Maybe it is possible to support this case in test2json itself?

In #23033 there was a question: why one would want to debug a test and also see the its final status. The most relevant use-case I can think of is a modification of a program state during debug session. Let's say I have a complex algorithm test for which started to fail. During a debug session I've found a potential problem. I cannot easily change the sources and rerun a test because the fix is complicated, but I can change the program state at runtime. I want to verify that changing some value in a program produces a desirable effect and test starts to pass. At the moment it is not possible as the test status is always "fail".

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions