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

Commit

Permalink
Prevent running both 'go build' and 'go test' on save
Browse files Browse the repository at this point in the history
Utilize 'go test -run=^$ ./...' when building entire workspace, 'go build'
for current package and 'go test -c' for the current package when the
current file is a test file.
  • Loading branch information
vapourismo committed Jun 8, 2017
1 parent 7f5022c commit 32d1e83
Showing 1 changed file with 8 additions and 38 deletions.
46 changes: 8 additions & 38 deletions src/goCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,56 +149,26 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration)
let tmpPath = path.normalize(path.join(os.tmpdir(), 'go-code-check'));

let buildWorkDir = cwd;
let buildWorkspace = goConfig['buildOnSave'] === 'workspace';
let buildArgs: string[];

let args = ['build', '-i'];

if (!buildWorkspace) {
args.push('-o', tmpPath);
}

args.push('-tags', buildTags, ...buildFlags);

if (buildWorkspace) {
if (goConfig['buildOnSave'] === 'workspace') {
buildWorkDir = vscode.workspace.rootPath;
args.push('./...');
buildArgs = ['test', '-run=^$', '-tags', buildTags, ...buildFlags, './...'];
} else if (filename.match(/_test.go$/i)) {
buildArgs = ['test', '-c', '-copybinary', '-o', tmpPath, '-tags', buildTags, ...buildFlags];
} else {
buildArgs = ['build', '-i', '-o', tmpPath, '-tags', buildTags, ...buildFlags];
}

runningToolsPromises.push(runTool(
args,
buildArgs,
buildWorkDir,
'error',
true,
null,
env,
true
));

// This will test only the current package.
if (filename.match(/_test.go$/i) && !buildWorkspace) {
runningToolsPromises.push(runTool(
['test', '-c', '-copybinary', '-o', tmpPath + '-test', '-tags', buildTags, ...buildFlags],
cwd,
'error',
true,
null,
env,
true
));
}

// Compile tests for entire workspace.
if (buildWorkspace) {
runningToolsPromises.push(runTool(
['test', '-tags', buildTags, ...buildFlags, '-run', '!', './...'], // Doesn't run any tests.
buildWorkDir,
'error',
true,
null,
env,
true
));
}
}

if (!!goConfig['testOnSave']) {
Expand Down

0 comments on commit 32d1e83

Please sign in to comment.