Navigation Menu

Skip to content

Commit

Permalink
Clean up test imports and run a format pass over the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
vector-of-bool committed Mar 25, 2018
1 parent df2ef06 commit 2d83dcf
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 93 deletions.
14 changes: 7 additions & 7 deletions src/cmake-tools.ts
Expand Up @@ -330,7 +330,7 @@ export class CMakeTools implements vscode.Disposable, api.CMakeToolsAPI {

try {
await this._cmakeDriver;
} catch( ex) {
} catch (ex) {
this._cmakeDriver = Promise.resolve(null);
throw ex;
}
Expand Down Expand Up @@ -611,12 +611,12 @@ export class CMakeTools implements vscode.Disposable, api.CMakeToolsAPI {
return false;
}

return drv.stopCurrentProcess().then(() => {
this._cmakeDriver = Promise.resolve(null);
return true;
}, () =>{
return false;
});
return drv.stopCurrentProcess().then(
() => {
this._cmakeDriver = Promise.resolve(null);
return true;
},
() => { return false; });
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ctest.ts
Expand Up @@ -115,7 +115,7 @@ function decodeOutputMeasurement(node: EncodedMeasurementValue|string): string {

function cleanupResultsXML(messy: MessyResults): CTestResults {
const testing_head = messy.Site.Testing[0];
if (testing_head.TestList.length === 1 && (testing_head.TestList[0] as any as string) === "") {
if (testing_head.TestList.length === 1 && (testing_head.TestList[0] as any as string) === '') {
// XML parsing is obnoxious. This condition means that there are no tests,
// but CTest is still enabled.
return {
Expand Down
2 changes: 1 addition & 1 deletion src/driver.ts
Expand Up @@ -542,7 +542,7 @@ export abstract class CMakeDriver implements vscode.Disposable {
}
}
vscode.window.showErrorMessage(
`Unable to determine what CMake generator to use.
`Unable to determine what CMake generator to use.
Please install or configure a preferred generator, or update settings.json or your Kit configuration.`);
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions test/extension-tests/successful-build/index.ts
Expand Up @@ -16,8 +16,8 @@ var testRunner = require('vscode/lib/testrunner');
// You can directly control Mocha options by uncommenting the following lines
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
testRunner.configure({
ui : 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
useColors : true // colored output from test results
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
useColors: true // colored output from test results
});

module.exports = testRunner;
@@ -1,13 +1,6 @@
import * as chai from 'chai';
import {expect} from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);

import {clearExistingKitConfigurationFile} from '../../../test-helpers';
import {DefaultEnvironment} from '../../../helpers/test/default-environment';

import {CMakeTools} from '../../../../src/cmake-tools';
import config from '../../../../src/config';
import {CMakeTools} from '@cmt/cmake-tools';
import config from '@cmt/config';
import {clearExistingKitConfigurationFile, DefaultEnvironment, expect} from '@test/util';

suite('Build', async () => {
let cmt: CMakeTools;
Expand All @@ -19,8 +12,7 @@ suite('Build', async () => {
const build_loc = 'build';
const exe_res = 'output.txt';

testEnv
= new DefaultEnvironment('test/extension-tests/successful-build/project-folder', build_loc, exe_res);
testEnv = new DefaultEnvironment('test/extension-tests/successful-build/project-folder', build_loc, exe_res);
cmt = await CMakeTools.create(testEnv.vsContext);

// This test will use all on the same kit.
Expand Down
14 changes: 4 additions & 10 deletions test/extension-tests/successful-build/test/environment.test.ts
@@ -1,15 +1,9 @@
import * as chai from 'chai';
import {expect} from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);

import {clearExistingKitConfigurationFile} from '../../../test-helpers';
import {DefaultEnvironment} from '../../../helpers/test/default-environment';
import * as api from '@cmt/api';
import {CMakeCache} from '@cmt/cache';
import {CMakeTools} from '@cmt/cmake-tools';
import {clearExistingKitConfigurationFile, DefaultEnvironment, expect} from '@test/util';

import * as path from 'path';
import * as api from '../../../../src/api';
import {CMakeCache} from '../../../../src/cache';
import {CMakeTools} from '../../../../src/cmake-tools';

suite('[Environment]', async () => {
let cmt: CMakeTools;
Expand Down
@@ -1,12 +1,5 @@
import * as chai from 'chai';
import {expect} from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);

import {clearExistingKitConfigurationFile} from '../../../test-helpers';
import {DefaultEnvironment} from '../../../helpers/test/default-environment';

import {CMakeTools} from '../../../../src/cmake-tools';
import {CMakeTools} from '@cmt/cmake-tools';
import {clearExistingKitConfigurationFile, DefaultEnvironment, expect} from '@test/util';
import {ITestCallbackContext} from 'mocha';

interface KitEnvironment {
Expand Down Expand Up @@ -77,7 +70,9 @@ interface CMakeContext {
buildSystem: KitEnvironment;
}

function isPreferedGeneratorInKit(defaultKit: string): boolean { return RegExp("^Visual[ ]{0,1}Studio").test(defaultKit); }
function isPreferedGeneratorInKit(defaultKit: string): boolean {
return RegExp('^Visual[ ]{0,1}Studio').test(defaultKit);
}

function skipTestWithoutPreferredGeneratorInKit(testContext: any, context: CMakeContext): void {
if (!isPreferedGeneratorInKit(context.buildSystem.defaultKit)) {
Expand All @@ -86,7 +81,7 @@ function skipTestWithoutPreferredGeneratorInKit(testContext: any, context: CMake
}

// Needed by test "Non preferred generators configured in settings and kit"
function skipTestWithPreferredGeneratorInKit(testContext: any, context :CMakeContext): void {
function skipTestWithPreferredGeneratorInKit(testContext: any, context: CMakeContext): void {
if (isPreferedGeneratorInKit(context.buildSystem.defaultKit)) {
testContext.skip();
}
Expand Down Expand Up @@ -172,26 +167,25 @@ KITS_BY_PLATFORM[workername].forEach(buildSystem => {
expect(context.testEnv.errorMessagesQueue.length).to.be.eq(0);
});

test('Use invalid preferred generators from settings.json', async function(this: ITestCallbackContext)
{
test('Use invalid preferred generators from settings.json', async function(this: ITestCallbackContext) {
skipTestWithPreferredGeneratorInKit(this, context);
this.timeout(BUILD_TIMEOUT);

await context.cmt.selectKit();
await context.testEnv.setting.changeSetting('preferredGenerators', ['BlaBla']);
await context.cmt.build().then(() =>{ }).then(()=>{}, () => {});
await context.cmt.build().then(() => {}).then(() => {}, () => {});

expect(context.testEnv.errorMessagesQueue.length).to.be.eq(1);
expect(context.testEnv.errorMessagesQueue[0]).to.be.contains('Unable to determine what CMake generator to use.');
});

test('Non preferred generators configured in settings and kit', async function(this : ITestCallbackContext) {
test('Non preferred generators configured in settings and kit', async function(this: ITestCallbackContext) {
skipTestWithPreferredGeneratorInKit(this, context);
this.timeout(BUILD_TIMEOUT);
await context.cmt.selectKit();
await context.testEnv.setting.changeSetting('preferredGenerators', []);

await context.cmt.build().then(() =>{ }).then(()=>{}, () => {});
await context.cmt.build().then(() => {}).then(() => {}, () => {});

expect(context.testEnv.errorMessagesQueue.length).to.be.eq(1);
expect(context.testEnv.errorMessagesQueue[0]).to.be.contains('Unable to determine what CMake generator to use.');
Expand Down
@@ -1,16 +1,10 @@
import * as chai from 'chai';
import {expect} from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
import * as api from '@cmt/api';
import {CMakeCache} from '@cmt/cache';
import {CMakeTools} from '@cmt/cmake-tools';
import {normalizePath} from '@cmt/util';
import {clearExistingKitConfigurationFile, DefaultEnvironment, expect} from '@test/util';

import {clearExistingKitConfigurationFile} from '../../../test-helpers';
import {DefaultEnvironment} from '../../../helpers/test/default-environment';

import * as api from '../../../../src/api';
import * as path from 'path';
import {CMakeCache} from '../../../../src/cache';
import {CMakeTools} from '../../../../src/cmake-tools';
import {normalizePath} from '../../../../src/util';

suite('[Variable Substitution]', async () => {
let cmt: CMakeTools;
Expand Down
4 changes: 2 additions & 2 deletions test/extension-tests/vs-preferred-gen/index.ts
Expand Up @@ -16,8 +16,8 @@ var testRunner = require('vscode/lib/testrunner');
// You can directly control Mocha options by uncommenting the following lines
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
testRunner.configure({
ui : 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
useColors : true // colored output from test results
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
useColors: true // colored output from test results
});

module.exports = testRunner;
@@ -1,13 +1,7 @@
import * as chai from 'chai';
import {expect} from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
import {CMakeTools} from '@cmt/cmake-tools';
import config from '@cmt/config';

import {clearExistingKitConfigurationFile} from '../../../test-helpers';
import {DefaultEnvironment} from '../../../helpers/test/default-environment';

import {CMakeTools} from '../../../../src/cmake-tools';
import config from '../../../../src/config';
import {clearExistingKitConfigurationFile, DefaultEnvironment, expect} from '@test/util';

suite('Build', async () => {
let cmt: CMakeTools;
Expand Down
@@ -1,10 +1,4 @@
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);

import {expect} from 'chai';

import {clearExistingKitConfigurationFile, getExtension} from '../../../test-helpers';
import {clearExistingKitConfigurationFile, expect, getExtension} from '@test/util';

// This tests will be skipped when a Visual Studio installation marker (Env.HasVs=true) is present.
// It is not possible to hide an installation against the test. In that case
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/cmake/build-directory-helper.ts
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path';
import * as rimraf from 'rimraf';

export class BuildDirectoryHelper {
public constructor(private readonly _location: string) { }
public constructor(private readonly _location: string) {}

public clear() {
if (fs.existsSync(this._location)) {
Expand Down
6 changes: 2 additions & 4 deletions test/helpers/test/default-environment.ts
Expand Up @@ -8,7 +8,6 @@ import {QuickPickerHandleStrategy, SelectKitPickerHandle} from '../vscodefake/qu
import {CMakeToolsSettingFile} from '../vscodefake/workspace-configuration';

export class DefaultEnvironment {

sandbox: sinon.SinonSandbox = sinon.sandbox.create();
projectFolder: ProjectRootHelper;
kitSelection: SelectKitPickerHandle;
Expand All @@ -34,13 +33,12 @@ export class DefaultEnvironment {
this.setting = new CMakeToolsSettingFile(this.sandbox);

const errorQueue = this.errorMessagesQueue;
this.sandbox.stub(vscode.window, 'showErrorMessage').callsFake((message: string) : Thenable<string | undefined> => {
this.sandbox.stub(vscode.window, 'showErrorMessage').callsFake((message: string): Thenable<string|undefined> => {
errorQueue.push(message);

return Promise.resolve(undefined);
});
this.sandbox.stub(vscode.window, 'showInformationMessage').callsFake(() => (
{doOpen: false}));
this.sandbox.stub(vscode.window, 'showInformationMessage').callsFake(() => ({doOpen: false}));
}

private setupShowQuickPickerStub(selections: QuickPickerHandleStrategy[]) {
Expand Down
10 changes: 6 additions & 4 deletions test/helpers/vscodefake/workspace-configuration.ts
Expand Up @@ -25,7 +25,10 @@ class CMakeToolsWorkspaceConfiguration implements vscode.WorkspaceConfiguration
return fakeHasSection || origHasSection;
}
inspect<T>(): {
key: string; defaultValue?: T | undefined; globalValue?: T | undefined; workspaceValue?: T | undefined;
key: string;
defaultValue?: T | undefined;
globalValue?: T | undefined;
workspaceValue?: T | undefined;
workspaceFolderValue?: T | undefined;
}|undefined {
throw new Error('Method not implemented.');
Expand All @@ -45,9 +48,8 @@ export class CMakeToolsSettingFile {
readonly originalFunction: any = vscode.workspace.getConfiguration;

constructor(sandbox: sinon.SinonSandbox) {
sandbox.stub(vscode.workspace, 'getConfiguration').callsFake(((section?: string, resource?: vscode.Uri) => {
return this.getConfiguration(section, resource);
}));
sandbox.stub(vscode.workspace, 'getConfiguration')
.callsFake(((section?: string, resource?: vscode.Uri) => { return this.getConfiguration(section, resource); }));
}

public changeSetting(key: string, element: any): Thenable<void> { return this.fakeValues.update(key, element); }
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/kit-scan.test.ts
Expand Up @@ -188,7 +188,7 @@ suite('Kits scan test', async () => {
});

test('check empty kit file', async () => {
delete process.env["PATH"];
delete process.env['PATH'];

await km.initialize();

Expand Down
17 changes: 13 additions & 4 deletions test/test-helpers.ts → test/util.ts
@@ -1,10 +1,19 @@
import {CMakeTools} from '@cmt/cmake-tools';
import paths from '@cmt/paths';
import {fs} from '@cmt/pr';

import * as chai from 'chai';
import {expect} from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as path from 'path';
import * as vscode from 'vscode';

import {CMakeTools} from '../src/cmake-tools';
// re-exports:
export {DefaultEnvironment} from './helpers/test/default-environment';

chai.use(chaiAsPromised);

import paths from '../src/paths';
import {fs} from '../src/pr';
export {expect};

export async function clearExistingKitConfigurationFile() {
await fs.writeFile(path.join(paths.dataDir, 'cmake-kits.json'), '[]');
Expand All @@ -16,4 +25,4 @@ export async function getExtension() {
throw new Error('Extension doesn\'t exist');
}
return cmt.isActive ? Promise.resolve(cmt.exports) : cmt.activate();
}
}
5 changes: 5 additions & 0 deletions tsconfig.json
Expand Up @@ -3,9 +3,14 @@
"module": "commonjs",
"target": "es2017",
"outDir": "out",
"baseUrl": "./",
"lib": [
"es6"
],
"paths": {
"@cmt/*": ["src/*"],
"@test/*": ["test/*"]
},
"sourceMap": true,
"rootDir": ".",
"noImplicitReturns": true,
Expand Down
3 changes: 2 additions & 1 deletion tslint.json
Expand Up @@ -12,7 +12,8 @@
"ban-comma-operator": true,
"no-console": [true, "info", "error", "warn"],
"no-floating-promises": [true, "PromisedAssertion"],
"no-implicit-dependencies": [true, "dev"],
/// Errors when we use `tsconfig` "paths" option. Check for a fix in newer TSLint:
// "no-implicit-dependencies": [true, "dev"],
"no-shadowed-variable": true,
"no-return-await": true,
"no-string-throw": true,
Expand Down

0 comments on commit 2d83dcf

Please sign in to comment.