Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matepek committed Oct 22, 2018
1 parent d94aa6f commit 4065368
Show file tree
Hide file tree
Showing 10 changed files with 1,494 additions and 850 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
18 changes: 15 additions & 3 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion 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
26 changes: 6 additions & 20 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 Down Expand Up @@ -424,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 @@ -458,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 @@ -507,20 +505,8 @@ export class C2TestAdapter implements TestAdapter, vscode.Disposable {
}

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);
}
return c2fs.spawnAsync(path, ['--help']).then((res) => {
return res.stdout.indexOf('Catch v2.') != -1;
});
}

Expand Down
128 changes: 65 additions & 63 deletions src/C2TestSuiteInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 {ChildProcess, execFile, spawn, SpawnOptions} from 'child_process';
import {ChildProcess, spawn, SpawnOptions} from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import {promisify} from 'util';
Expand All @@ -11,6 +11,7 @@ import * as xml2js from 'xml2js';

import {C2TestAdapter} from './C2TestAdapter';
import {C2TestInfo} from './C2TestInfo';
import * as c2fs from './FsWrapper';
import {generateUniqueId} from './IdGenerator';
import {TaskPool} from './TaskPool';

Expand Down Expand Up @@ -269,74 +270,75 @@ export class C2TestSuiteInfo implements TestSuiteInfo {
if (!exists)
throw Error('reloadSuiteChildren: Should exists: ' + this.execPath);

return new Promise<void>((resolve, reject) => {
execFile(
this.execPath,
[
'[.],*', '--verbosity', 'high', '--list-tests', '--use-colour',
'no'
],
(error: Error|null, stdout: string, stderr: string) => {
const oldChildren = this.children;
this.children = [];

let lines = stdout.split(/\r?\n/);

if (lines.length == 0) this.adapter.log.error('Empty test list.');

while (lines[lines.length - 1].trim().length == 0) lines.pop();

let i = 1;
while (i < lines.length - 1) {
if (lines[i][0] != ' ')
this.adapter.log.error(
'Wrong test list output format: ' + lines.toString());

const testNameFull = lines[i++].substr(2);

let filePath = '';
let line = 0;
{
const fileLine = lines[i++].substr(4);
const match =
fileLine.match(/(?:(.+):([0-9]+)|(.+)\(([0-9]+)\))/);
if (match && match.length == 5) {
filePath = match[1] ? match[1] : match[3];
if (this.execOptions.cwd)
filePath = path.resolve(this.execOptions.cwd, filePath);
line = Number(match[2] ? match[2] : match[4]);
return c2fs
.spawnAsync(
this.execPath,
[
'[.],*', '--verbosity', 'high', '--list-tests', '--use-colour',
'no'
],
this.execOptions)
.then((r) => {
const oldChildren = this.children;
this.children = [];

let lines = r.stdout.split(/\r?\n/);

if (lines.length == 0) this.adapter.log.error('Empty test list.');

while (lines[lines.length - 1].trim().length == 0) lines.pop();

let i = 1;
while (i < lines.length - 1) {
if (lines[i][0] != ' ')
this.adapter.log.error(
'Wrong test list output format: ' + lines.toString());

const testNameFull = lines[i++].substr(2);

let filePath = '';
let line = 0;
{
const fileLine = lines[i++].substr(4);
const match =
fileLine.match(/(?:(.+):([0-9]+)|(.+)\(([0-9]+)\))/);
if (match && match.length == 5) {
filePath = match[1] ? match[1] : match[3];
filePath =
path.resolve(path.dirname(this.execPath), filePath);
if (!c2fs.existsSync(filePath) && this.execOptions.cwd) {
const r = path.resolve(this.execOptions.cwd, filePath);
if (c2fs.existsSync(r)) filePath = r;
}
line = Number(match[2] ? match[2] : match[4]);
}
}

let description = lines[i++].substr(4);
if (description.startsWith('(NO DESCRIPTION)'))
description = '';

let tags: string[] = [];
if (lines[i].length > 6 && lines[i][6] === '[') {
tags = lines[i].trim().split(']');
tags.pop();
for (let j = 0; j < tags.length; ++j) tags[j] += ']';
++i;
}
let description = lines[i++].substr(4);
if (description.startsWith('(NO DESCRIPTION)')) description = '';

const index = oldChildren.findIndex(
(c: C2TestInfo): boolean => {return c.testNameFull ==
testNameFull});
if (index != -1 &&
oldChildren[index].label ==
C2TestInfo.generateLabel(
testNameFull, description, tags)) {
this.children.push(oldChildren[index]);
} else {
this.createChildTest(
testNameFull, description, tags, filePath, line);
}
let tags: string[] = [];
if (lines[i].length > 6 && lines[i][6] === '[') {
tags = lines[i].trim().split(']');
tags.pop();
for (let j = 0; j < tags.length; ++j) tags[j] += ']';
++i;
}

resolve();
});
});
const index = oldChildren.findIndex(
(c: C2TestInfo): boolean => {return c.testNameFull ==
testNameFull});
if (index != -1 &&
oldChildren[index].label ==
C2TestInfo.generateLabel(
testNameFull, description, tags)) {
this.children.push(oldChildren[index]);
} else {
this.createChildTest(
testNameFull, description, tags, filePath, line);
}
}
});
});
}
}
47 changes: 47 additions & 0 deletions src/FsWrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//-----------------------------------------------------------------------------
// 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 * as cp from 'child_process';
import * as fs from 'fs';

export function spawnAsync(
cmd: string, args?: string[],
options?: cp.SpawnOptions): Promise<cp.SpawnSyncReturns<string>> {
return new Promise((resolve) => {
const command = cp.spawn(cmd, args, options);
const ret: cp.SpawnSyncReturns<string> = {
pid: command.pid,
output: [],
stdout: '',
stderr: '',
status: 0,
signal: '',
error: new Error()
};
command.stdout.on('data', function(data) {
ret.stdout += data;
ret.output.push(data);
});
command.on('close', function(code) {
ret.status = code;
resolve(ret)
});
command.on('error', function(err) {
ret.error = err;
resolve(ret);
});
})
}

export function statSync(path: string): fs.Stats {
return fs.statSync(path);
}

export function existsSync(path: string): boolean {
return fs.existsSync(path);
}

export function readdirSync(path: string): string[] {
return fs.readdirSync(path, 'utf8');
}
Loading

0 comments on commit 4065368

Please sign in to comment.