rust/editors/code/tests/unit/runnable_env.test.ts

120 lines
3.6 KiB
TypeScript
Raw Normal View History

2020-07-02 13:33:26 -05:00
import * as assert from 'assert';
import { prepareEnv } from '../../src/run';
import { RunnableEnvCfg } from '../../src/config';
import * as ra from '../../src/lsp_ext';
2020-07-02 14:08:33 -05:00
function makeRunnable(label: string): ra.Runnable {
2020-07-02 13:33:26 -05:00
return {
label,
kind: "cargo",
args: {
cargoArgs: [],
executableArgs: [],
cargoExtraArgs: []
2020-07-02 13:33:26 -05:00
}
2020-07-02 14:08:33 -05:00
};
2020-07-02 13:33:26 -05:00
}
2020-07-02 14:08:33 -05:00
function fakePrepareEnv(runnableName: string, config: RunnableEnvCfg): Record<string, string> {
const runnable = makeRunnable(runnableName);
2020-07-02 13:33:26 -05:00
return prepareEnv(runnable, config);
}
suite('Runnable env', () => {
test('Global config works', () => {
2020-07-02 14:08:33 -05:00
const binEnv = fakePrepareEnv("run project_name", { "GLOBAL": "g" });
assert.strictEqual(binEnv["GLOBAL"], "g");
2020-07-02 13:33:26 -05:00
2020-07-02 14:08:33 -05:00
const testEnv = fakePrepareEnv("test some::mod::test_name", { "GLOBAL": "g" });
assert.strictEqual(testEnv["GLOBAL"], "g");
2020-07-02 13:33:26 -05:00
});
test('null mask works', () => {
const config = [
{
env: { DATA: "data" }
}
];
2020-07-02 14:08:33 -05:00
const binEnv = fakePrepareEnv("run project_name", config);
assert.strictEqual(binEnv["DATA"], "data");
2020-07-02 13:33:26 -05:00
2020-07-02 14:08:33 -05:00
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
assert.strictEqual(testEnv["DATA"], "data");
2020-07-02 13:33:26 -05:00
});
test('order works', () => {
const config = [
{
env: { DATA: "data" }
},
{
env: { DATA: "newdata" }
}
];
2020-07-02 14:08:33 -05:00
const binEnv = fakePrepareEnv("run project_name", config);
assert.strictEqual(binEnv["DATA"], "newdata");
2020-07-02 13:33:26 -05:00
2020-07-02 14:08:33 -05:00
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
assert.strictEqual(testEnv["DATA"], "newdata");
2020-07-02 13:33:26 -05:00
});
test('mask works', () => {
const config = [
{
env: { DATA: "data" }
},
{
mask: "^run",
env: { DATA: "rundata" }
},
{
mask: "special_test$",
env: { DATA: "special_test" }
}
];
2020-07-02 14:08:33 -05:00
const binEnv = fakePrepareEnv("run project_name", config);
assert.strictEqual(binEnv["DATA"], "rundata");
2020-07-02 13:33:26 -05:00
2020-07-02 14:08:33 -05:00
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
assert.strictEqual(testEnv["DATA"], "data");
2020-07-02 13:33:26 -05:00
2020-07-02 14:08:33 -05:00
const specialTestEnv = fakePrepareEnv("test some::mod::special_test", config);
assert.strictEqual(specialTestEnv["DATA"], "special_test");
2020-07-02 13:33:26 -05:00
});
test('exact test name works', () => {
const config = [
{
env: { DATA: "data" }
},
{
mask: "some::mod::test_name",
env: { DATA: "test special" }
}
];
2020-07-02 14:08:33 -05:00
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
assert.strictEqual(testEnv["DATA"], "test special");
2020-07-02 13:33:26 -05:00
2020-07-02 14:08:33 -05:00
const specialTestEnv = fakePrepareEnv("test some::mod::another_test", config);
assert.strictEqual(specialTestEnv["DATA"], "data");
2020-07-02 13:33:26 -05:00
});
test('test mod name works', () => {
const config = [
{
env: { DATA: "data" }
},
{
mask: "some::mod",
env: { DATA: "mod special" }
}
];
2020-07-02 14:08:33 -05:00
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
assert.strictEqual(testEnv["DATA"], "mod special");
2020-07-02 13:33:26 -05:00
2020-07-02 14:08:33 -05:00
const specialTestEnv = fakePrepareEnv("test some::mod::another_test", config);
assert.strictEqual(specialTestEnv["DATA"], "mod special");
2020-07-02 13:33:26 -05:00
});
});