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

Printing string with '\0' (ascii 0) truncates output #2240

Closed
FlyingOnion opened this issue May 13, 2022 · 6 comments
Closed

Printing string with '\0' (ascii 0) truncates output #2240

FlyingOnion opened this issue May 13, 2022 · 6 comments
Labels
go-test issues related to go test support (test output, test explorer, ...) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@FlyingOnion
Copy link

Go: 1.17.2 windows/amd64
VSCode: 1.67.1
VSCode-Go-Extention: 0.33.0

Example code:

func TestPrintByte0(t *testing.T) {
    b := []byte{'a', 'b', 0, 'd', 'e'}
    t.Log(string(b))     // only print ab without a '\n'
    t.Log("hello world") // makes this output messy
}

Click "run test" in VSCode:

=== RUN   TestPrintByte0
    c:\Users\Administrator\go\src\gbt\gbt_test.go:15: ab    c:\Users\Administrator\go\src\gbt\gbt_test.go:16: hello world
--- PASS: TestPrintByte0 (0.00s)

Run go test command in powershell or Git Bash:

=== RUN   TestPrintByte0
    gbt_test.go:15: abde
    gbt_test.go:16: hello world
--- PASS: TestPrintByte0 (0.00s)

Maybe there's a better way to deal with this problem?

@gopherbot gopherbot added this to the Untriaged milestone May 13, 2022
@findleyr
Copy link
Member

Thanks for reporting. IIRC we've seen problems like this in the integrated output panel, and it's not straightforward to fix on our end. Unfortunately this is not likely to get fixed soon.

Of course, for most use-cases if you have non-printing characters in your string, you may be better off escaped formatting, e.g. t.Logf("%q", string(b)). But that doesn't change the fact that this is a bug in vs code / vscode-go.

CC @hyangah

@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 17, 2022
@findleyr findleyr modified the milestones: Untriaged, Unplanned May 17, 2022
@hyangah
Copy link
Contributor

hyangah commented May 17, 2022

@FlyingOnion Have you tried the Test Explorer UI? That uses the vscode terminal, instead of output console. I think that handles '\0' better.

This is another strong reason to support #2044 and #1702 work cc @firelizzard18

@hyangah hyangah added the go-test issues related to go test support (test output, test explorer, ...) label May 17, 2022
@firelizzard18
Copy link
Contributor

If this does not reproduce with the Test Explorer UI, I'm inclined to say the fix is to use the new UI. If the new UI has the same issue, we could scrub '\0' from the output stream before handing it to VSCode. That would replicate what you see when you run go test on the CLI.

@FlyingOnion
Copy link
Author

@FlyingOnion Have you tried the Test Explorer UI? That uses the vscode terminal, instead of output console. I think that handles '\0' better.

This is another strong reason to support #2044 and #1702 work cc @firelizzard18

@hyangah @firelizzard18 The builtin terminal of vscode outputs normally.

So as @findleyr says, is it an issue of vscode rather than the extension? If so, I will pay more attentions to avoid this in writing tests.

Thanks all for the reply.

@firelizzard18
Copy link
Contributor

@FlyingOnion We're referring to using 'run test' vs using the green play button. Under the hood these use two different test support mechanisms. 'run test' and the other pre-1.59 testing UI uses the pre-1.59 test support infrastructure. The green play button uses the VSCode testing API.

image

Pre-1.59 test support prints the output to an output channel and has the problem you describe:

image

Testing API-based test support prints the output to a test console and does not have the problem:

image

I'm interpreting what @findleyr said as meaning that VSCode's output channel API does not handle special characters well. To fix this particular case (\0) we'd probably need to do string.replaceAll('\0', ''). But the goal of #2044 and #1702 is to update all of the UI to use the testing API. Eventually this would eliminate the pre-1.59 test support code that uses an output channel.

For you, we are recommending that you use the testing API-based test support when you need to deal with special characters.

@firelizzard18
Copy link
Contributor

I believe this has been fixed in VSCode. Using the 'run test' code lens, I now see:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go-test issues related to go test support (test output, test explorer, ...) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Done
Development

No branches or pull requests

5 participants