/
default-environment.ts
60 lines (50 loc) · 2.35 KB
/
default-environment.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as sinon from 'sinon';
import * as vscode from 'vscode';
import {ProjectRootHelper} from '../cmake/project-root-helper';
import {TestProgramResult} from '../testprogram/test-program-result';
import {FakeContextDefinition} from '../vscodefake/extensioncontext';
import {QuickPickerHandleStrategy, SelectKitPickerHandle} from '../vscodefake/quick-picker';
import {CMakeToolsSettingFile} from '../vscodefake/workspace-configuration';
export class DefaultEnvironment {
sandbox: sinon.SinonSandbox = sinon.sandbox.create();
projectFolder: ProjectRootHelper;
kitSelection: SelectKitPickerHandle;
result: TestProgramResult;
public vsContext: FakeContextDefinition = new FakeContextDefinition();
setting: CMakeToolsSettingFile;
errorMessagesQueue: string[] = [];
public constructor(projectRoot: string, buildLocation: string, executableResult: string, defaultkitRegExp?: string) {
this.projectFolder = new ProjectRootHelper(projectRoot, buildLocation);
this.result = new TestProgramResult(this.projectFolder.buildDirectory.location, executableResult);
if (!defaultkitRegExp) {
if (process.platform == 'win32') {
defaultkitRegExp = '^Visual ?Studio';
} else {
defaultkitRegExp = '.';
}
}
this.kitSelection = new SelectKitPickerHandle(defaultkitRegExp);
this.setupShowQuickPickerStub([this.kitSelection]);
this.setting = new CMakeToolsSettingFile(this.sandbox);
const errorQueue = this.errorMessagesQueue;
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}));
}
private setupShowQuickPickerStub(selections: QuickPickerHandleStrategy[]) {
this.sandbox.stub(vscode.window, 'showQuickPick').callsFake((items, options): Thenable<string|undefined> => {
if (options.placeHolder == selections[0].identifier) {
return Promise.resolve(selections[0].handleQuickPick(items));
}
return Promise.reject(`Unknown quick pick "${options.placeHolder}"`);
});
}
public teardown(): void { this.sandbox.verifyAndRestore(); }
public clean(): void {
this.errorMessagesQueue.length = 0;
this.vsContext.clean();
this.setting.restore();
}
}