Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Code coverage decorator does not work on Windows. #1847

Closed
BenLubar opened this issue Aug 14, 2018 · 14 comments
Closed

Code coverage decorator does not work on Windows. #1847

BenLubar opened this issue Aug 14, 2018 · 14 comments

Comments

@BenLubar
Copy link

BenLubar commented Aug 14, 2018

If this is a bug report, please share

  • a sample code which can be used to reproduce the issue

This issue is reproducible with any Go package that contains tests.

  • any Go related settings you might have added/changed

I doubt these are relevant, but here is my entire settings.json file:

{
    "debug.inlineValues": true,
    "editor.fontLigatures": true,
    "editor.formatOnPaste": true,
    "editor.formatOnSave": true,
    "editor.formatOnType": true,
    "editor.renderControlCharacters": false,
    "editor.renderWhitespace": "all",
    "files.eol": "\n",
    "files.hotExit": "onExitAndWindowClose",
    "files.insertFinalNewline": true,
    "files.trimFinalNewlines": true,
    "files.trimTrailingWhitespace": true,
    "go.autocompleteUnimportedPackages": true,
    "go.buildOnSave": "workspace",
    "go.coverOnSave": true,
    "go.docsTool": "guru",
    "go.formatTool": "goimports",
    "go.gocodeAutoBuild": true,
    "go.gotoSymbol.includeGoroot": true,
    "go.gotoSymbol.includeImports": true,
    "go.lintOnSave": "workspace",
    "go.lintTool": "gometalinter",
    "go.testOnSave": true,
    "go.vetOnSave": "workspace"
}

Steps to Reproduce:

  1. Run tests in a Go package on a Windows machine.
  2. There is no code coverage highlighting visible in the editor.

I suspect this is because Go's code coverage output always uses forward slashes but Visual Studio Code uses backslashes for file paths on Windows.

This is visible in the Go: Install Current Package command, but go install github.com\foo\bar works exactly as the expected command does.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Aug 16, 2018

  • Do you see the code coverage when you run the command Go: Toggle Test Coverage In Current Package
  • The output channel for Go tests will have output for all the test runs. Can you share the output from there when you run the tests?

@BenLubar
Copy link
Author

  • Do you see the code coverage when you run the command Go: Toggle Test Coverage In Current Package

No, the command runs the tests but does not show any code coverage. Re-running the command seems to have the same effect (ie. it is not toggling in a different direction).

  • The output channel for Go tests will have output for all the test runs. Can you share the output from there when you run the tests?
Running tool: C:\tools\go\bin\go.exe test -coverprofile=C:\Users\Owner\AppData\Local\Temp\go-code-cover -timeout 30s github.com\BenLubar\git-last-modified

ok  	github.com/BenLubar/git-last-modified	2.119s	coverage: 39.6% of statements
Success: Tests passed.

@ramya-rao-a
Copy link
Contributor

From the output, we can see that the coverage was calculated successfully.
Can you open that file where the coverprofile is stored and share the results?

@amsokol
Copy link

amsokol commented Aug 16, 2018

Hi,

I have the same problem with Windows 10 and go 1.11rc1.
Go tests output:

Running tool: C:\Bin\go1.11beta3\bin\go.exe test -coverprofile=C:\Users\amsokol\AppData\Local\Temp\go-code-cover -timeout 30s github.com\amsokol\go-errors

ok  	github.com/amsokol/go-errors	0.248s	coverage: 100.0% of statements
Success: Tests passed.

C:\Users\amsokol\AppData\Local\Temp\go-code-cover is:

mode: set
github.com/amsokol/go-errors/error.go:10.31,12.2 1 1
github.com/amsokol/go-errors/error.go:16.52,18.2 1 1
github.com/amsokol/go-errors/verifier.go:6.48,8.17 1 1
github.com/amsokol/go-errors/verifier.go:12.2,12.11 1 1
github.com/amsokol/go-errors/verifier.go:8.17,10.3 1 1
github.com/amsokol/go-errors/verifier.go:12.11,14.3 1 1
github.com/amsokol/go-errors/verifier.go:20.69,22.17 1 1
github.com/amsokol/go-errors/verifier.go:26.2,26.11 1 1
github.com/amsokol/go-errors/verifier.go:22.17,24.3 1 1
github.com/amsokol/go-errors/verifier.go:26.11,28.3 1 1
github.com/amsokol/go-errors/wrapper.go:10.41,12.2 1 1
github.com/amsokol/go-errors/wrapper.go:16.62,18.2 1 1

@BenLubar
Copy link
Author

Can you open that file where the coverprofile is stored and share the results?

mode: set
github.com/BenLubar/git-last-modified/modtime.go:13.49,15.17 2 1
github.com/BenLubar/git-last-modified/modtime.go:20.2,24.16 4 1
github.com/BenLubar/git-last-modified/modtime.go:28.2,29.13 2 1
github.com/BenLubar/git-last-modified/modtime.go:33.2,34.74 2 1
github.com/BenLubar/git-last-modified/modtime.go:15.17,17.3 1 1
github.com/BenLubar/git-last-modified/modtime.go:24.16,26.3 1 1
github.com/BenLubar/git-last-modified/modtime.go:29.13,31.3 1 1
github.com/BenLubar/git-last-modified/modtime.go:37.36,39.16 2 0
github.com/BenLubar/git-last-modified/modtime.go:43.2,43.16 1 0
github.com/BenLubar/git-last-modified/modtime.go:56.2,56.18 1 0
github.com/BenLubar/git-last-modified/modtime.go:60.2,60.17 1 0
github.com/BenLubar/git-last-modified/modtime.go:64.2,64.85 1 0
github.com/BenLubar/git-last-modified/modtime.go:39.16,41.3 1 0
github.com/BenLubar/git-last-modified/modtime.go:43.16,44.19 1 0
github.com/BenLubar/git-last-modified/modtime.go:48.3,48.18 1 0
github.com/BenLubar/git-last-modified/modtime.go:53.3,53.13 1 0
github.com/BenLubar/git-last-modified/modtime.go:44.19,46.4 1 0
github.com/BenLubar/git-last-modified/modtime.go:48.18,50.4 1 0
github.com/BenLubar/git-last-modified/modtime.go:56.18,58.3 1 0
github.com/BenLubar/git-last-modified/modtime.go:60.17,62.3 1 0
github.com/BenLubar/git-last-modified/walk.go:8.63,9.16 1 0
github.com/BenLubar/git-last-modified/walk.go:13.2,13.17 1 0
github.com/BenLubar/git-last-modified/walk.go:18.2,18.43 1 0
github.com/BenLubar/git-last-modified/walk.go:22.2,22.25 1 0
github.com/BenLubar/git-last-modified/walk.go:9.16,11.3 1 0
github.com/BenLubar/git-last-modified/walk.go:13.17,16.3 1 0
github.com/BenLubar/git-last-modified/walk.go:18.43,20.3 1 0
github.com/BenLubar/git-last-modified/main.go:19.14,23.2 3 1
github.com/BenLubar/git-last-modified/main.go:25.28,26.16 1 1
github.com/BenLubar/git-last-modified/main.go:26.16,27.19 1 1
github.com/BenLubar/git-last-modified/main.go:32.3,32.10 1 1
github.com/BenLubar/git-last-modified/main.go:27.19,29.4 1 1
github.com/BenLubar/git-last-modified/main.go:29.9,31.4 1 1
github.com/BenLubar/git-last-modified/main.go:36.13,38.51 2 0
github.com/BenLubar/git-last-modified/main.go:41.2,41.17 1 0
github.com/BenLubar/git-last-modified/main.go:45.2,46.21 2 0
github.com/BenLubar/git-last-modified/main.go:38.51,40.3 1 0
github.com/BenLubar/git-last-modified/main.go:41.17,43.3 1 0
github.com/BenLubar/git-last-modified/main.go:46.21,49.3 2 0
github.com/BenLubar/git-last-modified/main.go:49.8,50.30 1 0
github.com/BenLubar/git-last-modified/main.go:50.30,52.4 1 0

@ramya-rao-a
Copy link
Contributor

I suspect this is because Go's code coverage output always uses forward slashes but Visual Studio Code uses backslashes for file paths on Windows.

@BenLubar But I see backward slashes in the coverage output on my Windows machines.
@amsokol is using Go 1.11. What version are you using?

I am using 1.9

@BenLubar
Copy link
Author

go version go1.11rc1 windows/amd64

@amsokol
Copy link

amsokol commented Aug 17, 2018

Update:
coverage decorator WORKS FINE with go1.10.3 windows/amd64
It does not work with go1.11rc1 windows/amd64

@amsokol
Copy link

amsokol commented Aug 25, 2018

Update:
Code coverage decorator does not work for go1.11 windows/amd64 (Win10).

@ramya-rao-a
Copy link
Contributor

@amsokol, @BenLubar I have pushed a fix to the master branch. Can you try it out and let me know if it works for you as well? To try the fix, just follow the instructions at https://github.com/Microsoft/vscode-go/wiki/Use-the-beta-version-of-the-latest-Go-extension

@BenLubar
Copy link
Author

It seems to have exactly the same effect (that is, no coverage information is displayed in the editor, but it does generate coverage information in the temp folder). Here's the result of go tool cover -html: coverage.html.zip

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Aug 30, 2018

cc @bcmills

The file produced bygo test -coverprofile in Windows in go 1.11 has forward slashes instead of backward slashes as in the previous versions of go

@ramya-rao-a
Copy link
Contributor

@BenLubar I've pushed another fix, can you try
https://github.com/Microsoft/vscode-go/wiki/Use-the-beta-version-of-the-latest-Go-extension again?

@haritsfahreza
Copy link

haritsfahreza commented Sep 4, 2018

Hi @ramya-rao-a, I got the same problem with @BenLubar and I tried the beta version of Go extension. Now, the code coverage works fine just like the previous Go version! Thankyou 🙏

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants