-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/goTest: support running sub-tests
Changes the logic for creating sub-tests on the fly. Prevously, test IDs were created in such a way that it was impractical to support running subtests. This changes the way IDs are created for subtests such that running subtests is simple. Additionally, this CL updates 'goTest' to run `go test -run=^$ -bench ^BenchmarkFoo/Bar$` (without the parentheses) when a single benchmark is selected, as a hack to get around golang/go#47800. Updates #1641 Change-Id: I26eac8a5a396df3923073274ed93d9c59107d9c3 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/343433 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Trust: Hyang-Ah Hana Kim <[email protected]> Trust: Rebecca Stambler <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]>
- Loading branch information
1 parent
9021bff
commit 6019957
Showing
13 changed files
with
199 additions
and
67 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
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,83 @@ | ||
import assert = require('assert'); | ||
import path = require('path'); | ||
import sinon = require('sinon'); | ||
import { Uri, workspace } from 'vscode'; | ||
import * as testUtils from '../../src/testUtils'; | ||
import { forceDidOpenTextDocument } from './goTest.utils'; | ||
import { GoTestExplorer } from '../../src/goTest/explore'; | ||
import { MockExtensionContext } from '../mocks/MockContext'; | ||
import { GoTest } from '../../src/goTest/utils'; | ||
|
||
suite('Go Test Runner', () => { | ||
const sandbox = sinon.createSandbox(); | ||
const fixtureDir = path.join(__dirname, '..', '..', '..', 'test', 'testdata', 'subTest'); | ||
|
||
let testExplorer: GoTestExplorer; | ||
let runSpy: sinon.SinonSpy<[testUtils.TestConfig], Promise<boolean>>; | ||
|
||
setup(() => { | ||
runSpy = sinon.spy(testUtils, 'goTest'); | ||
}); | ||
|
||
teardown(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
suite('Subtest', () => { | ||
const ctx = MockExtensionContext.new(); | ||
let uri: Uri; | ||
|
||
suiteSetup(async () => { | ||
testExplorer = GoTestExplorer.setup(ctx); | ||
|
||
uri = Uri.file(path.join(fixtureDir, 'sub_test.go')); | ||
await forceDidOpenTextDocument(workspace, testExplorer, uri); | ||
}); | ||
|
||
suiteTeardown(() => { | ||
ctx.teardown(); | ||
}); | ||
|
||
test('discover and run', async () => { | ||
// Locate TestMain and TestOther | ||
const tests = testExplorer.resolver.find(uri).filter((x) => GoTest.parseId(x.id).kind === 'test'); | ||
tests.sort((a, b) => a.label.localeCompare(b.label)); | ||
assert.deepStrictEqual( | ||
tests.map((x) => x.label), | ||
['TestMain', 'TestOther'] | ||
); | ||
const [tMain, tOther] = tests; | ||
|
||
// Run TestMain | ||
await testExplorer.runner.run({ include: [tMain] }); | ||
assert(runSpy.calledOnce, 'goTest was not called'); | ||
|
||
// Verify TestMain was run | ||
let call = runSpy.lastCall.args[0]; | ||
assert.strictEqual(call.dir, fixtureDir); | ||
assert.deepStrictEqual(call.functions, ['TestMain']); | ||
runSpy.resetHistory(); | ||
|
||
// Locate subtest | ||
const tSub = tMain.children.get(GoTest.id(uri, 'test', 'TestMain/Sub')); | ||
assert(tSub, 'Subtest was not created'); | ||
|
||
// Run subtest by itself | ||
await testExplorer.runner.run({ include: [tSub] }); | ||
assert(runSpy.calledOnce, 'goTest was not called'); | ||
|
||
// Verify TestMain/Sub was run | ||
call = runSpy.lastCall.args[0]; | ||
assert.strictEqual(call.dir, fixtureDir); | ||
assert.deepStrictEqual(call.functions, ['TestMain/Sub']); | ||
runSpy.resetHistory(); | ||
|
||
// Ensure the subtest hasn't been disposed | ||
assert(tSub.parent, 'Subtest was disposed'); | ||
|
||
// Attempt to run subtest and other test - should not work | ||
await testExplorer.runner.run({ include: [tSub, tOther] }); | ||
assert(!runSpy.called, 'goTest was called'); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.