Skip to content

Commit 20e4dd1

Browse files
authored
Enable support for Integration Tests (#1441)
* Enable support for Integration Tests Added Logger to help tests retrieve output from the installation of the extension.
1 parent c9ca994 commit 20e4dd1

File tree

18 files changed

+332
-44
lines changed

18 files changed

+332
-44
lines changed

.travis.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,41 @@ language: node_js
33
node_js:
44
- "8"
55

6+
before_install:
7+
# Do not modify. Required for GUI based tests: See https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-xvfb-to-Run-Tests-That-Require-a-GUI
8+
- if [ $TRAVIS_OS_NAME == "linux" ]; then
9+
export CXX="g++-4.9" CC="gcc-4.9" DISPLAY=:99.0;
10+
sh -e /etc/init.d/xvfb start;
11+
sleep 3;
12+
fi
13+
614
addons:
715
apt:
816
sources:
917
- ubuntu-toolchain-r-test
1018
- sourceline: 'deb https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main'
1119
key_url: 'https://packages.microsoft.com/keys/microsoft.asc'
20+
packages:
21+
- gdb
22+
- g++-4.9
23+
1224

1325
script:
26+
# Download debugAdapters from an existing extension version. See TravisCI settings to set CPPTOOL_VERSION
27+
- mkdir -p ~/.vscode/extensions/ms-vscode.cpptools-$CPPTOOL_VERSION
28+
- wget https://github.com/Microsoft/vscode-cpptools/releases/download/$CPPTOOL_VERSION/cpptools.vsix -O ~/cpptools.vsix
29+
- unzip ~/cpptools.vsix "extension/debugAdapters/*" -d ~/.
30+
- mv ~/extension/debugAdapters ~/.vscode/extensions/ms-vscode.cpptools-$CPPTOOL_VERSION/debugAdapters
31+
# Build and then run tests
1432
- cd Extension
1533
- npm install
1634
- npm run tslint
17-
- npm run pretest
35+
- npm run compile
1836
- npm run test
1937

2038
after_failure:
21-
- ./.travis/printLogs.sh
39+
- find ~ -name "integrationTests.log" -type f -exec cat {} \;
2240

2341
after_success:
24-
- ./.travis/printLogs.sh
42+
- find ~ -name "integrationTests.log" -type f -exec cat {} \;
2543

Extension/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ bin/Microsoft.VSCode.CPP.*
1414
install.lock
1515

1616
# ignore generated packages
17-
*.vsix
17+
*.vsix
18+
19+
# ignore vscode test
20+
.vscode-test/

Extension/.vscode/launch.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@
2929
"type": "node",
3030
"request": "attach",
3131
"port": 5858
32-
}
32+
},
33+
{
34+
"name": "Launch Integration Tests",
35+
"type": "extensionHost",
36+
"request": "launch",
37+
"runtimeExecutable": "${execPath}",
38+
"args": [
39+
"${workspaceRoot}/test/integrationTests/testAssets/SimpleCppProject",
40+
"--extensionDevelopmentPath=${workspaceRoot}",
41+
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
42+
],
43+
"stopOnEntry": false,
44+
"sourceMaps": true,
45+
"outFiles": [
46+
"${workspaceRoot}/out/test/**/*.js"
47+
]
48+
},
3349
]
3450
}

Extension/gulpfile.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,45 @@
66
'use strict';
77

88
const gulp = require('gulp');
9+
const env = require('gulp-env')
910
const tslint = require('gulp-tslint');
1011
const mocha = require('gulp-mocha');
1112

12-
gulp.task('unitTest', () => {
13+
gulp.task('allTests', () => {
14+
gulp.start('unitTests');
15+
gulp.start('integrationTests');
16+
});
17+
18+
gulp.task('unitTests', () => {
1319
gulp.src('./out/test/unitTests', {read: false}).pipe(
1420
mocha({
1521
ui: "tdd"
1622
})
23+
).once('error', err => {
24+
process.exit(1);
25+
})
26+
.once('end', () => {
27+
process.exit();
28+
})
29+
});
30+
31+
gulp.task('integrationTests', () => {
32+
env.set({
33+
CODE_TESTS_PATH: "./out/test/integrationTests",
34+
CODE_TESTS_WORKSPACE: "./test/integrationTests/testAssets/SimpleCppProject"
35+
}
1736
);
37+
gulp.src('./test/runVsCodeTestsWithAbsolutePaths.js', {read: false}).pipe(
38+
mocha({
39+
ui: "tdd",
40+
delay: true
41+
})
42+
).once('error', err => {
43+
process.exit(1);
44+
})
45+
.once('end', () => {
46+
process.exit();
47+
})
1848
});
1949

2050
/// Misc Tasks

Extension/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Extension/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,16 +1041,19 @@
10411041
},
10421042
"scripts": {
10431043
"compile": "npm run vscode:prepublish && tsc -p ./",
1044+
"integrationTests": "gulp integrationTests",
10441045
"postinstall": "node ./node_modules/vscode/bin/install",
10451046
"pretest": "tsc -p ./",
1046-
"test": "gulp unitTest",
1047+
"test": "gulp allTests",
10471048
"tslint": "gulp tslint",
1049+
"unitTests": "gulp unitTests",
10481050
"vscode:prepublish": "npm install && tsc -p ./ && node ./out/src/Debugger/copyScript.js",
10491051
"watch": "tsc -watch -p ./"
10501052
},
10511053
"devDependencies": {
10521054
"@types/mocha": "^2.2.43",
10531055
"@types/node": "^8.0.46",
1056+
"gulp-env": "0.4.0",
10541057
"gulp-mocha": "5.0.0",
10551058
"gulp-tslint": "8.1.2",
10561059
"gulp": "3.9.1",

Extension/src/LanguageServer/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ClientCollection } from './clientCollection';
2020
import { createProtocolFilter } from './protocolFilter';
2121
import { DataBinding } from './dataBinding';
2222
import minimatch = require("minimatch");
23+
import * as logger from '../logger';
2324

2425
let ui: UI;
2526

@@ -491,7 +492,7 @@ class DefaultClient implements Client {
491492
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1) {
492493
this.outputChannel = vscode.window.createOutputChannel(`C/C++: ${this.Name}`);
493494
} else {
494-
this.outputChannel = util.getOutputChannel();
495+
this.outputChannel = logger.getOutputChannel();
495496
}
496497
this.disposables.push(this.outputChannel);
497498
}

Extension/src/common.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as Telemetry from './telemetry';
1212
import HttpsProxyAgent = require('https-proxy-agent');
1313
import * as url from 'url';
1414
import { PlatformInformation } from './platform';
15+
import { getOutputChannelLogger, showOutputChannel } from './logger';
1516

1617
export let extensionContext: vscode.ExtensionContext;
1718
export function setExtensionContext(context: vscode.ExtensionContext): void {
@@ -45,9 +46,9 @@ export function displayExtensionNotReadyPrompt(): void {
4546

4647
if (!isExtensionNotReadyPromptDisplayed) {
4748
isExtensionNotReadyPromptDisplayed = true;
48-
outputChannel.show();
49+
showOutputChannel();
4950

50-
vscode.window.showInformationMessage(extensionNotReadyString).then(
51+
getOutputChannelLogger().showInformationMessage(extensionNotReadyString).then(
5152
() => { isExtensionNotReadyPromptDisplayed = false; },
5253
() => { isExtensionNotReadyPromptDisplayed = false; }
5354
);
@@ -347,15 +348,6 @@ export function spawnChildProcess(process: string, args: string[], workingDirect
347348
});
348349
}
349350

350-
let outputChannel: vscode.OutputChannel;
351-
352-
export function getOutputChannel(): vscode.OutputChannel {
353-
if (outputChannel == undefined) {
354-
outputChannel = vscode.window.createOutputChannel("C/C++");
355-
}
356-
return outputChannel;
357-
}
358-
359351
export function allowExecution(file: string): Promise<void> {
360352
return new Promise<void>((resolve, reject) => {
361353
if (process.platform != 'win32') {
@@ -369,8 +361,8 @@ export function allowExecution(file: string): Promise<void> {
369361
resolve();
370362
});
371363
} else {
372-
getOutputChannel().appendLine("");
373-
getOutputChannel().appendLine(`Warning: Expected file ${file} is missing.`);
364+
getOutputChannelLogger().appendLine("");
365+
getOutputChannelLogger().appendLine(`Warning: Expected file ${file} is missing.`);
374366
resolve();
375367
}
376368
});
@@ -397,6 +389,6 @@ export function checkDistro(platformInfo: PlatformInformation): void {
397389
if (platformInfo.platform != 'win32' && platformInfo.platform != 'linux' && platformInfo.platform != 'darwin') {
398390
// this should never happen because VSCode doesn't run on FreeBSD
399391
// or SunOS (the other platforms supported by node)
400-
outputChannel.appendLine(`Warning: Debugging has not been tested for this platform. ${getReadmeMessage()}`);
392+
getOutputChannelLogger().appendLine(`Warning: Debugging has not been tested for this platform. ${getReadmeMessage()}`);
401393
}
402394
}

Extension/src/logger.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* --------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All Rights Reserved.
3+
* See 'LICENSE' in the project root for license information.
4+
* ------------------------------------------------------------------------------------------ */
5+
'use strict';
6+
7+
import * as vscode from 'vscode';
8+
import * as os from 'os';
9+
10+
// This is used for testing purposes
11+
let Subscriber: (message: string) => void;
12+
export function subscribeToAllLoggers(subscriber: (message: string) => void): void {
13+
Subscriber = subscriber;
14+
}
15+
16+
export class Logger {
17+
private writer: (message: string) => void;
18+
19+
constructor(writer: (message: string) => void) {
20+
this.writer = writer;
21+
}
22+
23+
public append(message: string): void {
24+
this.writer(message);
25+
if (Subscriber) {
26+
Subscriber(message);
27+
}
28+
}
29+
30+
public appendLine(message: string): void {
31+
this.writer(message + os.EOL);
32+
if (Subscriber) {
33+
Subscriber(message + os.EOL);
34+
}
35+
}
36+
37+
public showInformationMessage(message: string, items?: string[]): Thenable<string> {
38+
this.appendLine(message);
39+
40+
return vscode.window.showInformationMessage(message, ...items);
41+
}
42+
43+
public showWarningMessage(message: string, items?: string[]): Thenable<string> {
44+
this.appendLine(message);
45+
46+
return vscode.window.showWarningMessage(message, ...items);
47+
}
48+
49+
public showErrorMessage(message: string, items?: string[]): Thenable<string> {
50+
this.appendLine(message);
51+
52+
return vscode.window.showErrorMessage(message, ...items);
53+
}
54+
}
55+
56+
let outputChannel: vscode.OutputChannel;
57+
58+
export function getOutputChannel(): vscode.OutputChannel {
59+
if (outputChannel == undefined) {
60+
outputChannel = vscode.window.createOutputChannel("C/C++");
61+
}
62+
return outputChannel;
63+
}
64+
65+
export function showOutputChannel(): void {
66+
getOutputChannel().show();
67+
}
68+
69+
let outputChannelLogger: Logger;
70+
71+
export function getOutputChannelLogger(): Logger {
72+
if (!outputChannelLogger) {
73+
outputChannelLogger = new Logger(message => getOutputChannel().append(message));
74+
}
75+
return outputChannelLogger;
76+
}

0 commit comments

Comments
 (0)