forked from golang/vscode-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/goCover: display coverage correctly for multiple packages
The output file from test coverage contains import paths, but when vscode-go displays the coverage it only knows file system paths. The code replaced by this CL used a heuristic that only got the mapping right for a single package. The tests do not start an editing session, but only check that the import paths in the coverage file are properly converted to the file system paths that vscode needs. Change-Id: I60c8622a90134a18d0e64a239a865f0ba13ffb09 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/238697 Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
- Loading branch information
Showing
8 changed files
with
198 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package a | ||
|
||
func main() { | ||
x := 12 | ||
y := x + 17 | ||
panic(y) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package b | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func main() { | ||
v := os.Env() | ||
fmt.Print(v) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mode: set | ||
github.com/microsoft/vscode-go/gofixtures/coveragetest/a/a.go:19.71,22.25 3 1 | ||
github.com/microsoft/vscode-go/gofixtures/coveragetest/b/b.go:35.2,35.14 1 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/microsoft/vscode-go/gofixtures/coveragetest | ||
|
||
go 1.14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright 2020 The Go Authors. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for license information. | ||
*--------------------------------------------------------*/ | ||
|
||
'use strict'; | ||
|
||
import * as assert from 'assert'; | ||
import fs = require('fs-extra'); | ||
import path = require('path'); | ||
import sinon = require('sinon'); | ||
import vscode = require('vscode'); | ||
import { applyCodeCoverageToAllEditors, coverageFilesForTest, initForTest } from '../../src/goCover'; | ||
import { updateGoVarsFromConfig } from '../../src/goInstallTools'; | ||
import { getCurrentGoPath, getWorkspaceFolderPath } from '../../src/util'; | ||
|
||
// The ideal test would check that each open editor containing a file with coverage | ||
// information is displayed correctly. We cannot see the applied decorations, so the | ||
// test checks that the cover.out file has been read correctly, and the import paths | ||
// have been correctly converted to file system paths, which are what vscode uses. | ||
suite('Coverage for tests', function () { | ||
this.timeout(10000); | ||
|
||
let fixtureSourcePath: string; | ||
let coverFilePath: string; | ||
|
||
suiteSetup(async () => { | ||
await updateGoVarsFromConfig(); | ||
|
||
// Set up the test fixtures. | ||
fixtureSourcePath = path.join(__dirname, '..', '..', '..', 'test', 'fixtures', 'coverage'); | ||
coverFilePath = path.join(fixtureSourcePath, 'cover.out'); | ||
return; | ||
}); | ||
test('resolve import paths', async () => { | ||
initForTest(); | ||
const x = vscode.workspace.openTextDocument(coverFilePath); | ||
await applyCodeCoverageToAllEditors(coverFilePath, fixtureSourcePath); | ||
let aDotGo: boolean; | ||
let bDotGo: boolean; | ||
for (const fn in coverageFilesForTest()) { | ||
if (true) { // TSLint insists the body for for..in.. be an if-statement | ||
if (fn === `${fixtureSourcePath}/a/a.go`) { aDotGo = true; } | ||
if (fn === `${fixtureSourcePath}/b/b.go`) { bDotGo = true; } | ||
} | ||
} | ||
assert.equal(aDotGo && bDotGo, true); | ||
}); | ||
}); |