Skip to content

Commit

Permalink
Merge pull request #13 from matepek/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
matepek authored Oct 22, 2018
2 parents 9782445 + db66463 commit 730c8ef
Show file tree
Hide file tree
Showing 11 changed files with 1,841 additions and 596 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.2]

Bugfix release.

## [1.1.1]

### Added
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Catch2 Test Explorer for Visual Studio Code

[![Build Status](https://travis-ci.org/matepek/vscode-catch2-test-adapter.svg?branch=master)](https://travis-ci.org/matepek/vscode-catch2-test-adapter)
[![GitHub issues](https://img.shields.io/github/issues/matepek/vscode-catch2-test-adapter.svg)](https://github.com/matepek/vscode-catch2-test-adapter/issues)
[![GitHub license](https://img.shields.io/github/license/matepek/vscode-catch2-test-adapter.svg)](https://github.com/matepek/vscode-catch2-test-adapter/blob/master/LICENSE)
[![Visual Studio Marketplace](https://img.shields.io/vscode-marketplace/d/matepek.vscode-catch2-test-adapter.svg)](https://marketplace.visualstudio.com/items?itemName=matepek.vscode-catch2-test-adapter)
[![Visual Studio Marketplace](https://img.shields.io/vscode-marketplace/v/matepek.vscode-catch2-test-adapter.svg)](https://marketplace.visualstudio.com/items?itemName=matepek.vscode-catch2-test-adapter)


This extension allows you to run your [Catch2 tests](https://github.com/catchorg/Catch2) using the
[Test Explorer for VS Code](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-test-explorer).
Expand All @@ -19,6 +24,8 @@ This adapter doesn't support everything.
| `catch2TestExplorer.workerMaxNumber` | The variable maximize the number of the parallel test execution. |
| `catch2TestExplorer.enableSourceDecoration` | Sets the source code decorations: Errored lines will be highlited. |
| `catch2TestExplorer.debugConfigurationTemplate` | Set the necessary debug configuraitons and the debug button will work. Details: [below](#catch2TestExplorer.debugConfigurationTemplate) |
| `testExplorer.onStart` | (This is part of the [dependency extension](https://github.com/hbenl/vscode-test-explorer#configuration)'s settings.) |
| `testExplorer.onReload` | (This is part of the [dependency extension](https://github.com/hbenl/vscode-test-explorer#configuration)'s settings.) |

### catch2TestExplorer.executables

Expand Down Expand Up @@ -115,11 +122,8 @@ Example:
## TODOs

- Implement more [Catch command line options](https://github.com/catchorg/Catch2/blob/master/docs/command-line.md#specifying-which-tests-to-run), such as:

- `--nothrow`

- Tests

## Contribution

Any contribution is welcome.
20 changes: 16 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"hbenl.vscode-test-explorer"
],
"dependencies": {
"entities": "^1.1.1",
"entities": "^1.1.2",
"tslib": "^1.9.3",
"vscode-test-adapter-api": "^1.1.0",
"vscode-test-adapter-util": "^0.5.0",
Expand All @@ -52,10 +52,12 @@
"@types/xml-parser": "^1.2.29",
"@types/xml2js": "^0.4.3",
"@types/mocha": "^5.2.5",
"@types/chai": "^4.1.6",
"@types/fs-extra": "^5.0.4",
"fs-extra": "^7.0.0",
"@types/deep-equal": "^1.0.1",
"deep-equal": "^1.0.1",
"@types/sinon": "^5.0.5",
"sinon": "^7.0.0",
"typescript": "^2.9.2",
"vsce": "^1.51.1",
Expand Down Expand Up @@ -150,4 +152,4 @@
}
}
}
}
}
112 changes: 53 additions & 59 deletions src/C2TestAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// vscode-catch2-test-adapter was written by Mate Pek, and is placed in the
// public domain. The author hereby disclaims copyright to this source code.

import {execFile} from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
Expand All @@ -11,6 +10,7 @@ import * as util from 'vscode-test-adapter-util';

import {C2AllTestSuiteInfo} from './C2AllTestSuiteInfo';
import {C2TestInfo} from './C2TestInfo';
import * as c2fs from './FsWrapper';

export class C2TestAdapter implements TestAdapter, vscode.Disposable {
private readonly testsEmitter =
Expand Down Expand Up @@ -80,8 +80,6 @@ export class C2TestAdapter implements TestAdapter, vscode.Disposable {
this.disposables.forEach(d => {
d.dispose();
});
while (this.disposables.shift() !== undefined)
;
}

get testStates(): vscode.Event<TestRunStartedEvent|TestRunFinishedEvent|
Expand All @@ -97,7 +95,7 @@ export class C2TestAdapter implements TestAdapter, vscode.Disposable {
return this.autorunEmitter.event;
}

private loadSuite(exe: ExecutableConfig): Promise<void> {
loadSuite(exe: ExecutableConfig): Promise<void> {
const suite = this.allTests.createChildSuite(
exe.name, exe.path, {cwd: exe.cwd, env: exe.env});

Expand All @@ -106,39 +104,43 @@ export class C2TestAdapter implements TestAdapter, vscode.Disposable {
if (watcher != undefined) {
watcher.close();
}

watcher = fs.watch(suite.execPath);
this.watchers.set(suite.execPath, watcher);
const allTests = this.allTests; // alltest may has changed

watcher.on('change', (eventType: string, filename: string) => {
// need some time here:
const waitAndThenTry = (remainingIteration: number, delay: number) => {
if (remainingIteration == 0) {
watcher!.close();
this.watchers.delete(suite.execPath);
this.testsEmitter.fire({type: 'started'});
allTests.removeChild(suite);
this.testsEmitter.fire({type: 'finished', suite: this.allTests});
} else if (!fs.existsSync(suite.execPath)) {
setTimeout(
waitAndThenTry, delay,
[remainingIteration - 1, Math.max(delay * 2, 2000)]);
} else {
this.testsEmitter.fire({type: 'started'});
suite.reloadChildren().then(() => {
try {
watcher = fs.watch(suite.execPath);
this.watchers.set(suite.execPath, watcher);
const allTests = this.allTests; // alltest may has changed

watcher.on('change', (eventType: string, filename: string) => {
// need some time here:
const waitAndThenTry = (remainingIteration: number, delay: number) => {
if (remainingIteration == 0) {
watcher!.close();
this.watchers.delete(suite.execPath);
this.testsEmitter.fire({type: 'started'});
allTests.removeChild(suite);
this.testsEmitter.fire({type: 'finished', suite: this.allTests});
});
}
};
} else if (!fs.existsSync(suite.execPath)) {
setTimeout(
waitAndThenTry, delay,
[remainingIteration - 1, Math.max(delay * 2, 2000)]);
} else {
this.testsEmitter.fire({type: 'started'});
suite.reloadChildren().then(() => {
this.testsEmitter.fire({type: 'finished', suite: this.allTests});
});
}
};

// change event can arrive during debug session on osx (why?)
if (!this.isDebugging) {
waitAndThenTry(10, 128);
}
// change event can arrive during debug session on osx (why?)
if (!this.isDebugging) {
waitAndThenTry(10, 128);
}
});
} catch (e) {
this.log.warn('watcher couldn\'t watch: ' + suite.execPath);
}
return suite.reloadChildren().catch((e) => {
this.allTests.removeChild(suite);
});

return suite.reloadChildren();
}

load(): Promise<void> {
Expand Down Expand Up @@ -172,13 +174,17 @@ export class C2TestAdapter implements TestAdapter, vscode.Disposable {

return testListReaders;
})
.then(() => {
this.testsEmitter.fire({type: 'finished', suite: this.allTests});
})
.catch((err: Error) => {
this.testsEmitter.fire(
{type: 'finished', suite: undefined, errorMessage: err.message});
});
.then(
() => {
this.testsEmitter.fire({type: 'finished', suite: this.allTests});
},
(err: Error) => {
this.testsEmitter.fire({
type: 'finished',
suite: undefined,
errorMessage: err.message
});
});
}

cancel(): void {
Expand Down Expand Up @@ -416,10 +422,10 @@ export class C2TestAdapter implements TestAdapter, vscode.Disposable {

if (regex.length > 0) {
const recursiveAdd = (directory: string): void => {
const children = fs.readdirSync(directory, 'utf8');
const children = c2fs.readdirSync(directory);
children.forEach(child => {
const childPath = path.resolve(directory, child);
const childStat = fs.statSync(childPath);
const childStat = c2fs.statSync(childPath);
if (childPath.match(regex) && childStat.isFile()) {
let resolvedName = name + ' : ' + child;
let resolvedCwd = cwd;
Expand Down Expand Up @@ -450,7 +456,7 @@ export class C2TestAdapter implements TestAdapter, vscode.Disposable {
});
};
try {
const stat = fs.statSync(p);
const stat = c2fs.statSync(p);
if (stat.isDirectory()) {
recursiveAdd(p);
} else if (stat.isFile()) {
Expand Down Expand Up @@ -498,21 +504,9 @@ export class C2TestAdapter implements TestAdapter, vscode.Disposable {
return this.filterVerifiedCatch2TestExecutables(executables);
}

private verifyIsCatch2TestExecutable(path: string): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
try {
execFile(
path, ['--help'],
(error: Error|null, stdout: string, stderr: string) => {
if (stdout.indexOf('Catch v2.') != -1) {
resolve(true);
} else {
resolve(false);
}
});
} catch (e) {
resolve(false);
}
verifyIsCatch2TestExecutable(path: string): Promise<boolean> {
return c2fs.spawnAsync(path, ['--help']).then((res) => {
return res.stdout.indexOf('Catch v2.') != -1;
});
}

Expand Down
Loading

0 comments on commit 730c8ef

Please sign in to comment.