Skip to content

Testing tab and test result window gets confused if the code uses fmt.Printf without a final line break #2549

@julienadam

Description

@julienadam

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.19.3 windows/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • Build info

golang.org/x/tools/gopls v0.10.1
golang.org/x/tools/gopls@v0.10.1 h1:JoHe17pdZ8Vsa24/GUO8iTVTKPh0EOBiWpPop7XJybI=
github.com/BurntSushi/toml@v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/google/go-cmp@v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
golang.org/x/exp@v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
golang.org/x/exp/typeparams@v0.0.0-20220722155223-a9213eeb770e h1:7Xs2YCOpMlNqSQSmrrnhlzBXIE/bpMecZplbLePTJvE=
golang.org/x/mod@v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
golang.org/x/sync@v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
golang.org/x/sys@v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/text@v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/tools@v0.2.1-0.20221101170700-b5bc717366b2 h1:KBm+UwBaO/tdQ35tfGvxH1FUCiXRg4MoTzkznsdeab8=
golang.org/x/vuln@v0.0.0-20221010193109-563322be2ea9 h1:KaYZQUtEEaV8aVADIHAuYBTjo77aUcCvC7KTGKM3J1I=
honnef.co/go/tools@v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA=
mvdan.cc/gofumpt@v0.3.1 h1:avhhrOmv0IuvQVK7fvwV91oFSGAk5/6Po8GXTzICeu8=
mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.19.3

  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.

    • 1.73.1
      6261075646f055b99068d3688932416f2346dd3b
      x64
  • Check your installed extensions to get the version of the VS Code Go extension

  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

    • Checking configured tools....
      GOBIN: undefined
      toolsGopath:
      gopath: C:\Users\Nidhogg\go
      GOROOT: C:\Program Files\Go
      PATH: C:\Program Files\PowerShell\7;C:\ruby31\bin;C:\Python310\Scripts;C:\Python310;C:\ruby30\bin;C:\ruby27\bin;C:\Python39\Scripts;C:\Python39;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\libnvvp;C:\Python27;C:\Python27\Scripts;C:\Program Files\AdoptOpenJDK\jre-14.0.1.7-hotspot\bin;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\Program Files\AdoptOpenJDK\jre-13.0.2.8-hotspot\bin;C:\Python38\Scripts;C:\Python38;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\Oculus\Support\oculus-runtime;c:\windows;c:\windows\system32;C:\Windows\system32\WindowsPowerShell\v1.0;C:\sysinternals;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\QuickTime Alternative\QTSystem;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\Common Files\Acronis\SnapAPI;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\OpenSSH-Win64;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\Calibre2;C:\Program Files\nodejs;C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\Microsoft SQL Server\150\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn;C:\Program Files\Azure Data Studio\bin;C:\Program Files (x86)\dotnet;C:\Program Files\Git\cmd;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\PowerShell\7;C:\Program Files\Go\bin;C:\Ruby24-x64\bin;C:\Users\Nidhogg.dnx\bin;C:\Program Files\Git\bin;C:\Program Files (x86)\Nmap;C:\PROGRA~2\Oracle\VirtualBox;C:\HashiCorp\Vagrant\bin;C:\Program Files\Git\usr\bin;C:\Users\Nidhogg\AppData\Local\Microsoft\WindowsApps;C:\Users\Nidhogg.dotnet\tools;C:\Cmder;C:\Users\Nidhogg\AppData\Local\Programs\Fiddler;C:\Program Files\SourceGear\Common\DiffMerge;C:\Program Files (x86)\LinqPad5;C:\Users\Nidhogg\AppData\Local\Microsoft\WindowsApps;C:\Users\Nidhogg.dotnet\tools;C:\Program Files (x86)\LinqPad6;C:\Program Files (x86)\LinqPad7;C:\Users\Nidhogg\AppData\Roaming\npm;C:\Program Files\Multipass\bin;C:\Users\Nidhogg\go\bin

    go: C:\Program Files\Go\bin\go.exe: go version go1.19.3 windows/amd64

    gotests: not installed
    gomodifytags: not installed
    impl: not installed
    goplay: not installed
    dlv: C:\Users\Nidhogg\go\bin\dlv.exe (version: v1.9.1 built with go: go1.19.3)
    staticcheck: not installed
    gopls: C:\Users\Nidhogg\go\bin\gopls.exe (version: v0.10.1 built with go: go1.19.3)

go env
Workspace Folder (vscode_go_printf_bug): f:\coding\Projects\vscode_go_printf_bug
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Nidhogg\AppData\Local\go-build
set GOENV=C:\Users\Nidhogg\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Nidhogg\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Nidhogg\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19.3
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=f:\coding\Projects\vscode_go_printf_bug\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\TMP\Nidhogg\go-build2482470173=/tmp/go-build -gno-record-gcc-switches

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

nothing changed

Describe the bug

The problem occurs when testing code that uses fmt.Printf to print some text without a \n at the end. If the test fails, the testing system tries to open a file called whatever you printed + the actual file name. Obviously the file doesn't exist and vs code shows an error tab with the message "The editor could not be opened because the file was not found". This appears to have other consequences on the test explorer. e.g. tests stay red even after correcting the code.

Restarting VS Code appears to fix this temporarily until the next time the test fails.

Appending a \n in the fmt.Printf call also fixes the problem.

The expected behavior would be to handle fmt.Printf in tests.

Steps to reproduce the behavior:

  1. Open the repro here : https://github.com/julienadam/vscode_go_printf_bug
  2. Run the test using the Testing tab
  3. This should open a tab with the error message
  4. Fix the test code and re-run the test
  5. The test stays red

Screenshots or recordings

2022-11-30 18_42_11-Loading data from Foo Foo_test go - vscode_go_printf_bug - Visual Studio Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgego-testissues related to go test support (test output, test explorer, ...)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions