Clean up test imports and run a format pass over the codebase

This commit is contained in:
vector-of-bool 2018-03-25 16:44:50 -06:00
Родитель df2ef066ea
Коммит 2d83dcfe61
18 изменённых файлов: 70 добавлений и 93 удалений

Просмотреть файл

@ -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;
}
@ -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; });
}
/**

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
@ -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.

Просмотреть файл

@ -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;

Просмотреть файл

@ -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 {
@ -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)) {
@ -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();
}
@ -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.');

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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

Просмотреть файл

@ -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)) {

Просмотреть файл

@ -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;
@ -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[]) {

Просмотреть файл

@ -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.');
@ -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); }

Просмотреть файл

@ -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();

Просмотреть файл

@ -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';
import paths from '../src/paths';
import {fs} from '../src/pr';
chai.use(chaiAsPromised);
export {expect};
export async function clearExistingKitConfigurationFile() {
await fs.writeFile(path.join(paths.dataDir, 'cmake-kits.json'), '[]');
@ -16,4 +25,4 @@ export async function getExtension() {
throw new Error('Extension doesn\'t exist');
}
return cmt.isActive ? Promise.resolve(cmt.exports) : cmt.activate();
}
}

Просмотреть файл

@ -3,9 +3,14 @@
"module": "commonjs",
"target": "es2017",
"outDir": "out",
"baseUrl": "./",
"lib": [
"es6"
],
"paths": {
"@cmt/*": ["src/*"],
"@test/*": ["test/*"]
},
"sourceMap": true,
"rootDir": ".",
"noImplicitReturns": true,

Просмотреть файл

@ -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,