Skip to content

Go - Test break if output invalid utf8 char in TestXXX funcs. #44

@unifreak

Description

@unifreak

I'm new to go, and typically learn by running various test cases. I encountered this issue while trying to run codes in test case following https://go.dev/blog/strings.

How to reproduce:

Create a test file with a test func like:

func TestString(t *testing.T) {
	const sample = "\xbd\xb2\x3d\xbc\x20\xe2\x8c\x98"
	t.Log(sample)
}

Then run Go - Test. The test output is empty due to those invalid utf8 characters.

Here is the test output:

> Environment:
>   GOPATH=/home/me/go
> Directory: /home/me/projects/learn/go/ckbk/string
> Command: /usr/local/go/bin/go test -v
> Output:
=== RUN   TestString
> Elapsed: 0.182s
> Result: Success

Expected Output (with my manually created sublime build script or run go test -v in command line, this test case output something like):

=== RUN   TestString
    string_test.go:11: ��=� ⌘
--- PASS: TestString (0.00s)
=== RUN   TestCountRune
    string_test.go:19: 24
    string_test.go:24: 14
    string_test.go:26: 14
--- PASS: TestCountRune (0.00s)
PASS
ok  	learn/go/ckbk/string	0.001s
[Finished in 178ms]

Here is the sublime text trace back when this happen:

command: build
command: show_panel {"panel": "output.golang_build"}
command: insert {"characters": "> Environment:\n>   GOPATH=/home/me/go\n> Directory: /home/me/projects/learn/go/ckbk/string\n> Command: /usr/local/go/bin/go test -v\n> Output:\n"}
Exception in thread Thread-118:
Traceback (most recent call last):
  File "./python3.3/threading.py", line 901, in _bootstrap_inner
  File "./python3.3/threading.py", line 858, in run
  File "/home/hao/.config/sublime-text/Installed Packages/Golang Build.sublime-package/golang_build.py", line 740, in _read_output
    output_queue.put((output_type, chunk.decode('utf-8')))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 23: invalid start byte

command: insert {"characters": "=== RUN   TestString\n"}
command: insert {"characters": "> Elapsed: 0.182s\n> Result: Success"}

This may or may not be any issue, depending on whether there is really a use case outputting invalid utf8 chars when testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions