Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

goGenerateTests: resolve config file path #2342

Closed
ras0q opened this issue Jul 14, 2022 · 1 comment
Closed

goGenerateTests: resolve config file path #2342

ras0q opened this issue Jul 14, 2022 · 1 comment

Comments

@ras0q
Copy link
Contributor

ras0q commented Jul 14, 2022

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
go version go1.18.4 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
$ gopls -v version
Build info
----------
golang.org/x/tools/gopls v0.9.1
    golang.org/x/tools/gopls@v0.9.1 h1:SigsTL4Hpv3a6b/a7oPCLRv5QUeSM6PZNdta1oKY4B0=
    github.com/BurntSushi/toml@v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
    github.com/google/go-cmp@v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp/typeparams@v0.0.0-20220218215828-6cf2b201936e h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=
    golang.org/x/mod@v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
    golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
    golang.org/x/tools@v0.1.12-0.20220713141851-7464a5a40219 h1:Ljlba2fVWOA1049JjsKii44g8nZN2GjpxMlzVc8AnQM=
    golang.org/x/vuln@v0.0.0-20220613164644-4eb5ba49563c h1:r5bbIROBQtRRgoutV8Q3sFY58VzHW6jMBYl48ANSyS4=
    honnef.co/go/tools@v0.3.2 h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34=
    mvdan.cc/gofumpt@v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.18.4
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
$ code -v
1.69.1
b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a
x64
$ code-insiders -v
code-insiders: command not found
  • Check your installed extensions to get the version of the VS Code Go extension
$ code  --list-extensions --show-versions | grep golang.go
golang.go@0.34.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /home/ras/go
GOROOT: /home/linuxbrew/.linuxbrew/Cellar/go/1.18.4/libexec
PATH: /home/ras/.vscode-server/bin/b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a/bin/remote-cli:/home/ras/.asdf/shims:/home/linuxbrew/.linuxbrew/opt/asdf/libexec/bin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/ras/.wincmd/bin:/home/ras/.cargo/bin:/home/ras/.swiftenv/bin:/home/ras/.swiftenv/shims:/home/ras/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib

	go:	/home/ras/.asdf/shims/go: go version go1.18.4 linux/amd64

	gotests:	/home/ras/go/bin/gotests	(version: v1.6.0 built with go: go1.18.4)
	gomodifytags:	/home/ras/go/bin/gomodifytags	(version: v1.16.0 built with go: go1.18.4)
	impl:	/home/ras/go/bin/impl	(version: v1.1.0 built with go: go1.18.4)
	goplay:	/home/ras/go/bin/goplay	(version: v1.0.0 built with go: go1.18.4)
	dlv:	/home/ras/go/bin/dlv	(version: v1.9.0 built with go: go1.18.4)
	golangci-lint:	/home/ras/go/bin/golangci-lint	(version: v1.46.2 built with go: go1.18.4)
	gopls:	/home/ras/go/bin/gopls	(version: v0.9.1 built with go: go1.18.4)

go env
Workspace Folder (vscode-go): /home/ras/ghq/github.com/Ras96/vscode-go
	GO111MODULE=""
	GOARCH="amd64"
	GOBIN=""
	GOCACHE="/home/ras/.cache/go-build"
	GOENV="/home/ras/.config/go/env"
	GOEXE=""
	GOEXPERIMENT=""
	GOFLAGS=""
	GOHOSTARCH="amd64"
	GOHOSTOS="linux"
	GOINSECURE=""
	GOMODCACHE="/home/ras/go/pkg/mod"
	GONOPROXY=""
	GONOSUMDB=""
	GOOS="linux"
	GOPATH="/home/ras/go"
	GOPRIVATE=""
	GOPROXY="https://proxy.golang.org,direct"
	GOROOT="/home/linuxbrew/.linuxbrew/Cellar/go/1.18.4/libexec"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/home/linuxbrew/.linuxbrew/Cellar/go/1.18.4/libexec/pkg/tool/linux_amd64"
	GOVCS=""
	GOVERSION="go1.18.4"
	GCCGO="gccgo"
	GOAMD64="v1"
	AR="ar"
	CC="gcc-5"
	CXX="g++-5"
	CGO_ENABLED="1"
	GOMOD="/home/ras/ghq/github.com/Ras96/vscode-go/go.mod"
	GOWORK=""
	CGO_CFLAGS="-g -O2"
	CGO_CPPFLAGS=""
	CGO_CXXFLAGS="-g -O2"
	CGO_FFLAGS="-g -O2"
	CGO_LDFLAGS="-g -O2"
	PKG_CONFIG="pkg-config"
	GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build994236119=/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.

{
  "go.generateTestsFlags": [
    "-template_dir",
    "/path/to/templatedir"
  ]
}

Describe the bug

If you set the absolute path to go.generateTestsFlags as follows, it works fine.

// settings.json
{
  "go.generateTestsFlags": [
    "-template_dir",
    "/path/to/templatedir"
  ]
}
# output log
Generating Tests: /path/to/bin/gotests -w -template_dir /path/to/templatedir -all /path/to/main.go
Generated Test_main

However, if you set a relative path, you will get the following error.

{
  "go.generateTestsFlags": [
    "-template_dir",
    "./templatedir"
  ]
}
Generating Tests: /path/to/bin/gotests -w -template_dir ./templatedir -all /path/to/main.go
output.Process: loading custom templates: ioutil.ReadDir: open ./templatedir: no such file or directory

Also, if you set the path using ${workspaceFolder} keyword, you get an error

{
  "go.generateTestsFlags": [
    "-template_dir",
    "${workspaceFolder}/templatedir"
  ]
}
Generating Tests: /path/to/bin/gotests -w -template_dir ${workspaceFolder}/templatedir -all /path/to/main.go
output.Process: loading custom templates: ioutil.ReadDir: open ${workspaceFolder}/templatedir: no such file or directory

I hope these paths get resolved!

Steps to reproduce the behavior:

  1. Open command pallet
  2. Click on 'Generate Unit Tests for Function/File/Package'
  3. See error
@gopherbot
Copy link
Collaborator

Change https://go.dev/cl/417675 mentions this issue: goGenerateTests: resolve config file path

@jamalc jamalc modified the milestones: Untriaged, v0.36.0 Jul 19, 2022
@suzmue suzmue modified the milestones: v0.36.0, v0.35.2 Aug 11, 2022
@golang golang locked and limited conversation to collaborators Aug 11, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants