mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Apply suggestions from @Veetaha code review
This commit is contained in:
parent
8ee40ccbe9
commit
c41a10c293
@ -25,7 +25,7 @@ export function artifactSpec(args: readonly string[]): ArtifactSpec {
|
|||||||
switch (cargoArgs[0]) {
|
switch (cargoArgs[0]) {
|
||||||
case "run": cargoArgs[0] = "build"; break;
|
case "run": cargoArgs[0] = "build"; break;
|
||||||
case "test": {
|
case "test": {
|
||||||
if (cargoArgs.indexOf("--no-run") === -1) {
|
if (!cargoArgs.includes("--no-run")) {
|
||||||
cargoArgs.push("--no-run");
|
cargoArgs.push("--no-run");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -36,9 +36,7 @@ export function artifactSpec(args: readonly string[]): ArtifactSpec {
|
|||||||
if (cargoArgs[0] === "test") {
|
if (cargoArgs[0] === "test") {
|
||||||
// for instance, `crates\rust-analyzer\tests\heavy_tests\main.rs` tests
|
// for instance, `crates\rust-analyzer\tests\heavy_tests\main.rs` tests
|
||||||
// produce 2 artifacts: {"kind": "bin"} and {"kind": "test"}
|
// produce 2 artifacts: {"kind": "bin"} and {"kind": "test"}
|
||||||
result.filter = (artifacts) => {
|
result.filter = (artifacts) => artifacts.filter(it => it.isTest);
|
||||||
return artifacts.filter(a => a.isTest);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -48,7 +46,7 @@ export class Cargo {
|
|||||||
constructor(readonly rootFolder: string, readonly output: OutputChannel) { }
|
constructor(readonly rootFolder: string, readonly output: OutputChannel) { }
|
||||||
|
|
||||||
private async getArtifacts(spec: ArtifactSpec): Promise<CompilationArtifact[]> {
|
private async getArtifacts(spec: ArtifactSpec): Promise<CompilationArtifact[]> {
|
||||||
let artifacts: CompilationArtifact[] = [];
|
const artifacts: CompilationArtifact[] = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.runCargo(spec.cargoArgs,
|
await this.runCargo(spec.cargoArgs,
|
||||||
@ -75,11 +73,7 @@ export class Cargo {
|
|||||||
throw new Error(`Cargo invocation has failed: ${err}`);
|
throw new Error(`Cargo invocation has failed: ${err}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spec.filter) {
|
return spec.filter?.(artifacts) ?? artifacts;
|
||||||
artifacts = spec.filter(artifacts);
|
|
||||||
}
|
|
||||||
|
|
||||||
return artifacts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async executableFromArgs(args: readonly string[]): Promise<string> {
|
async executableFromArgs(args: readonly string[]): Promise<string> {
|
||||||
|
@ -4,43 +4,40 @@ import * as fs from 'fs';
|
|||||||
import { runTests } from 'vscode-test';
|
import { runTests } from 'vscode-test';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
// The folder containing the Extension Manifest package.json
|
||||||
// The folder containing the Extension Manifest package.json
|
// Passed to `--extensionDevelopmentPath`
|
||||||
// Passed to `--extensionDevelopmentPath`
|
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
|
||||||
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
|
|
||||||
|
|
||||||
// Minimum supported version.
|
// Minimum supported version.
|
||||||
const jsonData = fs.readFileSync(path.join(extensionDevelopmentPath, 'package.json'));
|
const jsonData = fs.readFileSync(path.join(extensionDevelopmentPath, 'package.json'));
|
||||||
const json = JSON.parse(jsonData.toString());
|
const json = JSON.parse(jsonData.toString());
|
||||||
let minimalVersion: string = json.engines.vscode;
|
let minimalVersion: string = json.engines.vscode;
|
||||||
if (minimalVersion.startsWith('^')) minimalVersion = minimalVersion.slice(1);
|
if (minimalVersion.startsWith('^')) minimalVersion = minimalVersion.slice(1);
|
||||||
|
|
||||||
const launchArgs = ["--disable-extensions"];
|
const launchArgs = ["--disable-extensions"];
|
||||||
|
|
||||||
// All test suites (either unit tests or integration tests) should be in subfolders.
|
// All test suites (either unit tests or integration tests) should be in subfolders.
|
||||||
const extensionTestsPath = path.resolve(__dirname, './unit/index');
|
const extensionTestsPath = path.resolve(__dirname, './unit/index');
|
||||||
|
|
||||||
// Run tests using the minimal supported version.
|
// Run tests using the minimal supported version.
|
||||||
await runTests({
|
await runTests({
|
||||||
version: minimalVersion,
|
version: minimalVersion,
|
||||||
launchArgs,
|
launchArgs,
|
||||||
extensionDevelopmentPath,
|
extensionDevelopmentPath,
|
||||||
extensionTestsPath
|
extensionTestsPath
|
||||||
});
|
});
|
||||||
|
|
||||||
// and the latest one
|
// and the latest one
|
||||||
await runTests({
|
await runTests({
|
||||||
version: 'stable',
|
version: 'stable',
|
||||||
launchArgs,
|
launchArgs,
|
||||||
extensionDevelopmentPath,
|
extensionDevelopmentPath,
|
||||||
extensionTestsPath
|
extensionTestsPath
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error('Failed to run tests', err);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main().catch(err => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error('Failed to run tests', err);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
@ -11,10 +11,10 @@ export function run(): Promise<void> {
|
|||||||
|
|
||||||
const testsRoot = __dirname;
|
const testsRoot = __dirname;
|
||||||
|
|
||||||
return new Promise((c, e) => {
|
return new Promise((resolve, reject) => {
|
||||||
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return e(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add files to the test suite
|
// Add files to the test suite
|
||||||
@ -25,13 +25,13 @@ export function run(): Promise<void> {
|
|||||||
mocha.timeout(100000);
|
mocha.timeout(100000);
|
||||||
mocha.run(failures => {
|
mocha.run(failures => {
|
||||||
if (failures > 0) {
|
if (failures > 0) {
|
||||||
e(new Error(`${failures} tests failed.`));
|
reject(new Error(`${failures} tests failed.`));
|
||||||
} else {
|
} else {
|
||||||
c();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
e(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user