diff --git a/src/goBuild.ts b/src/goBuild.ts index 885f243f5..af4b7d577 100644 --- a/src/goBuild.ts +++ b/src/goBuild.ts @@ -45,7 +45,7 @@ export function buildPkg(goConfig: vscode.WorkspaceConfiguration, pkg: string, c export function buildTest(goConfig: vscode.WorkspaceConfiguration, pkg: string, cwd: string): Promise { let tmppath = path.normalize(path.join(os.tmpdir(), 'go-code-check')); - // FIXME: allow to disable -cover in some builds? - let args = ['test', '-c', '-cover', '-o', tmppath, ...buildFlags(goConfig), '.']; + // FIXME: -cover changes output if the source has syntax errors; can we still compile code only one time for buildOnSave and coverOnSave? + let args = ['test', '-c', '-o', tmppath, ...buildFlags(goConfig), '.']; return runTool(args, cwd).then(result => tmppath); } diff --git a/src/goCheck.ts b/src/goCheck.ts index 86cbf4e67..3a65b50dc 100644 --- a/src/goCheck.ts +++ b/src/goCheck.ts @@ -18,6 +18,8 @@ import { runTest } from './goTest'; import { buildPkg, buildTest } from './goBuild'; import { getBinPath, parseFilePrelude } from './util'; +let statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); + export interface ICheckResult { file: string; line: number; @@ -169,13 +171,24 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration) runningToolsPromises.push(buildPromise); } if (!!goConfig['testOnSave']) { + statusBarItem.show(); + statusBarItem.text = 'building'; buildCurrentTest().then(result => { + statusBarItem.text = 'testing'; // FIXME: args? can we be backward compatible with testFlags? - runTest(goConfig, result, [], cwd); + return runTest(goConfig, result, [], cwd); + }).then(success => { + if (success) { + statusBarItem.text = 'OK :-)'; + } else { + statusBarItem.text = 'FAIL :-('; + } }).catch(err => { + statusBarItem.text = 'syntax error'; // FIXME: failed to build, just ignore? - return []; }); + } else { + statusBarItem.hide(); } if (!!goConfig['lintOnSave']) { let lintTool = goConfig['lintTool'] || 'golint'; @@ -208,6 +221,7 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration) } if (!!goConfig['coverOnSave']) { + // FIXME: broken, test built without -cover flag let coverPromise = buildCurrentTest().then( result => getCoverage(result, cwd), err => { diff --git a/src/goTest.ts b/src/goTest.ts index b2d0073de..7053142c7 100644 --- a/src/goTest.ts +++ b/src/goTest.ts @@ -191,21 +191,22 @@ function goTest(testconfig: TestConfig): Thenable { * * @param FIXME */ -export function runTest(goConfig: vscode.WorkspaceConfiguration, command: string, args: any, cwd: string) { - outputChannel.clear(); - let testEnvVars = Object.assign({}, process.env, goConfig['testEnvVars']); - let proc = cp.spawn(command, args, { env: testEnvVars, cwd: cwd }); - proc.stdout.on('data', chunk => outputChannel.append(chunk.toString())); - proc.stderr.on('data', chunk => outputChannel.append(chunk.toString())); - proc.on('close', code => { - if (code) { - outputChannel.append('Error: Tests failed.'); - outputChannel.show(true); - } else { - outputChannel.append('Success: Tests passed.'); - } - // FIXME: return promise? - // resolve(code === 0); +export function runTest(goConfig: vscode.WorkspaceConfiguration, command: string, args: any, cwd: string): Promise { + return new Promise((resolve, reject) => { + outputChannel.clear(); + let testEnvVars = Object.assign({}, process.env, goConfig['testEnvVars']); + let proc = cp.spawn(command, args, { env: testEnvVars, cwd: cwd }); + proc.stdout.on('data', chunk => outputChannel.append(chunk.toString())); + proc.stderr.on('data', chunk => outputChannel.append(chunk.toString())); + proc.on('close', code => { + if (code) { + outputChannel.append('Error: Tests failed.'); + outputChannel.show(true); + } else { + outputChannel.append('Success: Tests passed.'); + } + resolve(code === 0); + }); }); }