Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.

Commit

Permalink
fix multiple binaries with integration tests and current working dir
Browse files Browse the repository at this point in the history
  • Loading branch information
hdevalke committed Jan 23, 2019
1 parent 56299d6 commit 19e453b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to the "rust-test-lens" extension will be documented in this

Check [Keep a Changelog](https://keepachangelog.com/) for recommendations on how to structure this file.

## 0.0.5

- Solves the problem if there are still multiple binaries found. E.g. integration tests.
- Sets the current working directory to the package root instead of the workspace root.

## 0.0.4

- Works now if the package contains multiple binaries.
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "rust-test-lens",
"displayName": "Rust Test Lens",
"description": "Adds a code lens to quickly run or debug a single test for your Rust code.",
"version": "0.0.4",
"version": "0.0.5",
"publisher": "hdevalke",
"engines": {
"vscode": "^1.30.1"
"vscode": "^1.30.2"
},
"categories": [
"Other",
Expand Down Expand Up @@ -37,10 +37,10 @@
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.18",
"tslint": "^5.12.0",
"typescript": "^2.9.2",
"tslint": "^5.12.1",
"typescript": "^3.2.4",
"vsce": "^1.54.0",
"vscode": "^1.1.26"
"vscode": "^1.1.27"
},
"extensionDependencies": [
"vadimcn.vscode-lldb"
Expand Down
12 changes: 9 additions & 3 deletions src/RustCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Range, TextDocument, DebugConfiguration
} from 'vscode';
import { RustTests } from './RustTests';
import { basename } from 'path';
import { basename, dirname } from 'path';

export class RustCodeLensProvider implements CodeLensProvider {

Expand Down Expand Up @@ -60,15 +60,21 @@ export class RustCodeLensProvider implements CodeLensProvider {
"test",
"--no-run",
`--package=${pkg.name}`
]
],
filter: {} as any,
},
args: [fn],
cwd: "${workspaceFolder}"
cwd: `${dirname(pkg.manifest_path)}`
};
const bin = this.rustTests.getBin(uri, pkg);
if (bin !== undefined) {
debugConfig.cargo.args.push(`--bin=${bin}`);
}
const kind = this.rustTests.getKind(uri, pkg);
if (kind !== undefined) {
debugConfig.cargo.filter.kind = kind;
}

return debugConfig;
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/RustTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,21 @@ export class RustTests {
}
return undefined;
}

/// Get the kind of the target to select.
/// For example
getKind(uri: string, pkg: Package) : String {
const targets = pkg.targets;
// fast path
if (targets.length === 1) {
return targets[0].kind[0];
}
// slow path
for( const target of pkg.targets) {
if (target.src_path === uri) {
return target.kind[0];
}
}
return "lib";
}
}
1 change: 1 addition & 0 deletions src/cargo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { spawn, SpawnOptions } from "child_process";
export interface Target {
name: string;
src_path: string;
kind: string[];
}

export interface Package {
Expand Down

0 comments on commit 19e453b

Please sign in to comment.