Skip to content

Commit

Permalink
Merge pull request #49 from matepek/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
matepek authored Jan 3, 2019
2 parents d02a51e + ffa4c31 commit b86250e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 28 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.3.9]

### Fixed

- a bug which caused that `files.exlude` were also applied to pattern. Not anymore.
- a bug which caused to show not file names but patterns in the explorer.
- a bug which allowed suite duplications if more patterns were matching.

## [2.3.8] - 2019-01-03

### Fixed
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ This variable can be string, an array of strings, an array of objects or an arra

If it is an object it can contains the following properties:

| Property | | Description |
| --------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name` | (optional) | The name of the test suite (file). Can contains variables related to `pattern`. |
| `pattern` | (requierd) | A relative pattern (to workspace) or an absolute file-path. ⚠️**Avoid backslash!** ([Details](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options)). Example: `{build,out}/**/test[1-9]*` |
| `path` | (alias) | Alias of `pattern`. |
| `cwd` | (optional) | The current working directory for the test executable. If it isn't provided and `defaultCwd` does, then that will be used. Can contains variables related to `pattern`. |
| `env` | (optional) | Environment variables for the test executable. If it isn't provided and `defaultEnv` does, then that will be used. Can contains variables related to `pattern`. |
| Property | | Description |
| --------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name` | (optional) | The name of the test suite (file). Can contains variables related to `pattern`. |
| `pattern` | (requierd) | A relative pattern (to workspace (also it has to be inside the workspace folder)) or an absolute file-path (this case it can be outside of the workspace folder too). ⚠️**Avoid backslash!** ([Details](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options)). Example: `{build,out}/**/test[1-9]*` |
| `path` | (alias) | Alias of `pattern`. |
| `cwd` | (optional) | The current working directory for the test executable. If it isn't provided and `defaultCwd` does, then that will be used. Can contains variables related to `pattern`. |
| `env` | (optional) | Environment variables for the test executable. If it isn't provided and `defaultEnv` does, then that will be used. Can contains variables related to `pattern`. |

Variables which can be used in `name`, `cwd` and `env` of `executables`:
**Remark**: The `pattern` (or the `executables` used as string or an array of strings)
can only contains _search-pattern_ if it points somewhere inside of the workspace folder.
Otherwise it only can point to an executable (No _search-pattern_!).

#### Variables which can be used in `name`, `cwd` and `env` of `executables`:

| Variable | Description |
| ----------------------- | ------------------------------------------------------------------------------- |
Expand All @@ -63,7 +67,7 @@ Variables which can be used in `name`, `cwd` and `env` of `executables`:
| `${workspaceDirectory}` | (You can only guess once.) |
| `${workspaceFolder}` | Alias of `${workspaceDirectory}` |

Examples:
#### Examples:

```json
"catch2TestExplorer.executables": "dir/test.exe"
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "resources/icon.png",
"author": "Mate Pek",
"publisher": "matepek",
"version": "2.3.8",
"version": "2.3.9",
"license": "Unlicense",
"homepage": "https://github.com/matepek/vscode-catch2-test-adapter",
"repository": {
Expand Down Expand Up @@ -90,7 +90,7 @@
],
"default": [
{
"name": "${filename} (${relDirpath}/)",
"name": "${filename} (${relDirpath})",
"pattern": "{build,Build,BUILD,out,Out,OUT}/**/*{test,Test,TEST}*",
"cwd": "${absDirpath}",
"env": {
Expand Down
5 changes: 5 additions & 0 deletions src/RootTestSuiteInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ export class RootTestSuiteInfo implements TestSuiteInfo, vscode.Disposable {
insertChild(suite: TestSuiteInfoBase): boolean {
if (this.children.indexOf(suite) != -1) return false;

// we want to filter the situation when 2 patterns match the same file
if (this.children.find((s: TestSuiteInfoBase) => { return suite.execPath == s.execPath; })) {
return false;
}

let i = this.children.findIndex((v: TestSuiteInfoBase) => {
return suite.label.trim().localeCompare(v.label.trim()) < 0;
});
Expand Down
6 changes: 3 additions & 3 deletions src/TestAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export class TestAdapter implements api.TestAdapter, vscode.Disposable {
{ [prop: string]: any }[] = config.get('executables');

const createFromObject = (obj: { [prop: string]: any }): TestExecutableInfo => {
const name: string = obj.hasOwnProperty('name') ? obj.name : '${relPath}';
const name: string | undefined = obj.hasOwnProperty('name') ? obj.name : undefined;

let pattern: string = '';
if (obj.hasOwnProperty('pattern') && typeof obj.pattern == 'string')
Expand All @@ -424,7 +424,7 @@ export class TestAdapter implements api.TestAdapter, vscode.Disposable {
if (typeof configExecs === 'string') {
if (configExecs.length == 0) return [];
executables.push(new TestExecutableInfo(
allTests, configExecs, configExecs, globalWorkingDirectory,
allTests, undefined, configExecs, globalWorkingDirectory,
this._getGlobalAndDefaultEnvironmentVariables(config)));
} else if (Array.isArray(configExecs)) {
for (var i = 0; i < configExecs.length; ++i) {
Expand All @@ -433,7 +433,7 @@ export class TestAdapter implements api.TestAdapter, vscode.Disposable {
const configExecsName = String(configExe);
if (configExecsName.length > 0) {
executables.push(new TestExecutableInfo(
allTests, configExecsName, configExecsName, globalWorkingDirectory,
allTests, undefined, configExecsName, globalWorkingDirectory,
this._getGlobalAndDefaultEnvironmentVariables(config)));
}
} else {
Expand Down
28 changes: 15 additions & 13 deletions src/TestExecutableInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TestSuiteInfoFactory } from './TestSuiteInfoFactory';

export class TestExecutableInfo implements vscode.Disposable {
constructor(
private _allTests: RootTestSuiteInfo, public readonly name: string,
private _allTests: RootTestSuiteInfo, public readonly name: string | undefined,
public readonly pattern: string, public readonly cwd: string,
public readonly env: { [prop: string]: any }) { }

Expand Down Expand Up @@ -64,7 +64,7 @@ export class TestExecutableInfo implements vscode.Disposable {
new vscode.RelativePattern(this._allTests.workspaceFolder, pattern);
try {
fileUris =
await vscode.workspace.findFiles(relativePattern, undefined, 1000);
await vscode.workspace.findFiles(relativePattern, null, 1000);

// abs path string or vscode.RelativePattern is required.
this._watcher = vscode.workspace.createFileSystemWatcher(
Expand All @@ -87,8 +87,9 @@ export class TestExecutableInfo implements vscode.Disposable {
const file = fileUris[i];
await this._createSuiteByUri(file).then((suite: TestSuiteInfoBase) => {
return suite.reloadChildren().then(() => {
this._executables.set(file.fsPath, suite);
this._allTests.insertChild(suite);
if (this._allTests.insertChild(suite)) {
this._executables.set(file.fsPath, suite);
}
}, (reason: any) => {
this._allTests.log.error('Couldn\'t load executable: ' + inspect([reason, suite]));
});
Expand All @@ -101,12 +102,11 @@ export class TestExecutableInfo implements vscode.Disposable {
}

private _createSuiteByUri(file: vscode.Uri): Promise<TestSuiteInfoBase> {
const wsUri = this._allTests.workspaceFolder.uri;
const relPath = path.relative(wsUri.fsPath, file.fsPath);

let varToValue: [string, string][] = [];
try {
const wsUri = this._allTests.workspaceFolder.uri;
const relPath = path.relative(wsUri.fsPath, file.fsPath);

const filename = path.basename(file.fsPath);
const extFilename = path.extname(filename);
const baseFilename = path.basename(filename, extFilename);
Expand All @@ -131,13 +131,15 @@ export class TestExecutableInfo implements vscode.Disposable {
];
} catch (e) { this._allTests.log.error(inspect(e)); }

let resolvedLabel = this.name;
try {
resolvedLabel = resolveVariables(this.name, varToValue);
let resolvedLabel = relPath;
if (this.name) {
try {
resolvedLabel = resolveVariables(this.name, varToValue);

if (resolvedLabel.match(/\$\{.*\}/))
this._allTests.log.warn('Possibly unresolved variable: ' + resolvedLabel);
} catch (e) { this._allTests.log.error(inspect(e)); }
if (resolvedLabel.match(/\$\{.*\}/))
this._allTests.log.warn('Possibly unresolved variable: ' + resolvedLabel);
} catch (e) { this._allTests.log.error(inspect(e)); }
}

let resolvedCwd = this.cwd;
try {
Expand Down

0 comments on commit b86250e

Please sign in to comment.