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

119 lines
3.5 KiB
TypeScript
Raw Normal View History

2020-07-02 18:33:26 +00: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 19:08:33 +00:00
function makeRunnable(label: string): ra.Runnable {
2020-07-02 18:33:26 +00:00
return {
label,
kind: "cargo",
args: {
cargoArgs: [],
executableArgs: []
}
2020-07-02 19:08:33 +00:00
};
2020-07-02 18:33:26 +00:00
}
2020-07-02 19:08:33 +00:00
function fakePrepareEnv(runnableName: string, config: RunnableEnvCfg): Record<string, string> {
const runnable = makeRunnable(runnableName);
2020-07-02 18:33:26 +00:00
return prepareEnv(runnable, config);
}
suite('Runnable env', () => {
test('Global config works', () => {
2020-07-02 19:08:33 +00:00
const binEnv = fakePrepareEnv("run project_name", { "GLOBAL": "g" });
assert.equal(binEnv["GLOBAL"], "g");
2020-07-02 18:33:26 +00:00
2020-07-02 19:08:33 +00:00
const testEnv = fakePrepareEnv("test some::mod::test_name", { "GLOBAL": "g" });
assert.equal(testEnv["GLOBAL"], "g");
2020-07-02 18:33:26 +00:00
});
test('null mask works', () => {
const config = [
{
env: { DATA: "data" }
}
];
2020-07-02 19:08:33 +00:00
const binEnv = fakePrepareEnv("run project_name", config);
assert.equal(binEnv["DATA"], "data");
2020-07-02 18:33:26 +00:00
2020-07-02 19:08:33 +00:00
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
assert.equal(testEnv["DATA"], "data");
2020-07-02 18:33:26 +00:00
});
test('order works', () => {
const config = [
{
env: { DATA: "data" }
},
{
env: { DATA: "newdata" }
}
];
2020-07-02 19:08:33 +00:00
const binEnv = fakePrepareEnv("run project_name", config);
assert.equal(binEnv["DATA"], "newdata");
2020-07-02 18:33:26 +00:00
2020-07-02 19:08:33 +00:00
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
assert.equal(testEnv["DATA"], "newdata");
2020-07-02 18:33:26 +00:00
});
test('mask works', () => {
const config = [
{
env: { DATA: "data" }
},
{
mask: "^run",
env: { DATA: "rundata" }
},
{
mask: "special_test$",
env: { DATA: "special_test" }
}
];
2020-07-02 19:08:33 +00:00
const binEnv = fakePrepareEnv("run project_name", config);
assert.equal(binEnv["DATA"], "rundata");
2020-07-02 18:33:26 +00:00
2020-07-02 19:08:33 +00:00
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
assert.equal(testEnv["DATA"], "data");
2020-07-02 18:33:26 +00:00
2020-07-02 19:08:33 +00:00
const specialTestEnv = fakePrepareEnv("test some::mod::special_test", config);
assert.equal(specialTestEnv["DATA"], "special_test");
2020-07-02 18:33:26 +00:00
});
test('exact test name works', () => {
const config = [
{
env: { DATA: "data" }
},
{
mask: "some::mod::test_name",
env: { DATA: "test special" }
}
];
2020-07-02 19:08:33 +00:00
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
assert.equal(testEnv["DATA"], "test special");
2020-07-02 18:33:26 +00:00
2020-07-02 19:08:33 +00:00
const specialTestEnv = fakePrepareEnv("test some::mod::another_test", config);
assert.equal(specialTestEnv["DATA"], "data");
2020-07-02 18:33:26 +00:00
});
test('test mod name works', () => {
const config = [
{
env: { DATA: "data" }
},
{
mask: "some::mod",
env: { DATA: "mod special" }
}
];
2020-07-02 19:08:33 +00:00
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
assert.equal(testEnv["DATA"], "mod special");
2020-07-02 18:33:26 +00:00
2020-07-02 19:08:33 +00:00
const specialTestEnv = fakePrepareEnv("test some::mod::another_test", config);
assert.equal(specialTestEnv["DATA"], "mod special");
2020-07-02 18:33:26 +00:00
});
});