2022-05-17 12:15:06 -05:00
|
|
|
import * as assert from "assert";
|
|
|
|
import { prepareEnv } from "../../src/run";
|
2023-07-10 16:10:00 -05:00
|
|
|
import type { RunnableEnvCfg } from "../../src/config";
|
|
|
|
import type { Context } from ".";
|
|
|
|
import type * as ra from "../../src/lsp_ext";
|
2020-07-02 13:33:26 -05:00
|
|
|
|
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: [],
|
2020-09-05 08:21:14 -05:00
|
|
|
executableArgs: [],
|
2022-05-17 12:15:06 -05:00
|
|
|
cargoExtraArgs: [],
|
|
|
|
},
|
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);
|
|
|
|
}
|
|
|
|
|
2021-12-02 00:20:10 -06:00
|
|
|
export async function getTests(ctx: Context) {
|
2022-05-17 12:15:06 -05:00
|
|
|
await ctx.suite("Runnable env", (suite) => {
|
|
|
|
suite.addTest("Global config works", async () => {
|
|
|
|
const binEnv = fakePrepareEnv("run project_name", { GLOBAL: "g" });
|
2021-12-02 00:20:10 -06:00
|
|
|
assert.strictEqual(binEnv["GLOBAL"], "g");
|
|
|
|
|
2022-05-17 12:15:06 -05:00
|
|
|
const testEnv = fakePrepareEnv("test some::mod::test_name", { GLOBAL: "g" });
|
2021-12-02 00:20:10 -06:00
|
|
|
assert.strictEqual(testEnv["GLOBAL"], "g");
|
|
|
|
});
|
|
|
|
|
2022-05-17 12:15:06 -05:00
|
|
|
suite.addTest("null mask works", async () => {
|
2021-12-02 00:20:10 -06:00
|
|
|
const config = [
|
|
|
|
{
|
2022-05-17 12:15:06 -05:00
|
|
|
env: { DATA: "data" },
|
|
|
|
},
|
2021-12-02 00:20:10 -06:00
|
|
|
];
|
|
|
|
const binEnv = fakePrepareEnv("run project_name", config);
|
|
|
|
assert.strictEqual(binEnv["DATA"], "data");
|
|
|
|
|
|
|
|
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
|
|
|
|
assert.strictEqual(testEnv["DATA"], "data");
|
|
|
|
});
|
|
|
|
|
2022-05-17 12:15:06 -05:00
|
|
|
suite.addTest("order works", async () => {
|
2021-12-02 00:20:10 -06:00
|
|
|
const config = [
|
|
|
|
{
|
2022-05-17 12:15:06 -05:00
|
|
|
env: { DATA: "data" },
|
2021-12-02 00:20:10 -06:00
|
|
|
},
|
|
|
|
{
|
2022-05-17 12:15:06 -05:00
|
|
|
env: { DATA: "newdata" },
|
|
|
|
},
|
2021-12-02 00:20:10 -06:00
|
|
|
];
|
|
|
|
const binEnv = fakePrepareEnv("run project_name", config);
|
|
|
|
assert.strictEqual(binEnv["DATA"], "newdata");
|
|
|
|
|
|
|
|
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
|
|
|
|
assert.strictEqual(testEnv["DATA"], "newdata");
|
|
|
|
});
|
|
|
|
|
2022-05-17 12:15:06 -05:00
|
|
|
suite.addTest("mask works", async () => {
|
2021-12-02 00:20:10 -06:00
|
|
|
const config = [
|
|
|
|
{
|
2022-05-17 12:15:06 -05:00
|
|
|
env: { DATA: "data" },
|
2021-12-02 00:20:10 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
mask: "^run",
|
2022-05-17 12:15:06 -05:00
|
|
|
env: { DATA: "rundata" },
|
2021-12-02 00:20:10 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
mask: "special_test$",
|
2022-05-17 12:15:06 -05:00
|
|
|
env: { DATA: "special_test" },
|
|
|
|
},
|
2021-12-02 00:20:10 -06:00
|
|
|
];
|
|
|
|
const binEnv = fakePrepareEnv("run project_name", config);
|
|
|
|
assert.strictEqual(binEnv["DATA"], "rundata");
|
|
|
|
|
|
|
|
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
|
|
|
|
assert.strictEqual(testEnv["DATA"], "data");
|
|
|
|
|
|
|
|
const specialTestEnv = fakePrepareEnv("test some::mod::special_test", config);
|
|
|
|
assert.strictEqual(specialTestEnv["DATA"], "special_test");
|
|
|
|
});
|
|
|
|
|
2022-05-17 12:15:06 -05:00
|
|
|
suite.addTest("exact test name works", async () => {
|
2021-12-02 00:20:10 -06:00
|
|
|
const config = [
|
|
|
|
{
|
2022-05-17 12:15:06 -05:00
|
|
|
env: { DATA: "data" },
|
2021-12-02 00:20:10 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
mask: "some::mod::test_name",
|
2022-05-17 12:15:06 -05:00
|
|
|
env: { DATA: "test special" },
|
|
|
|
},
|
2021-12-02 00:20:10 -06:00
|
|
|
];
|
|
|
|
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
|
|
|
|
assert.strictEqual(testEnv["DATA"], "test special");
|
|
|
|
|
|
|
|
const specialTestEnv = fakePrepareEnv("test some::mod::another_test", config);
|
|
|
|
assert.strictEqual(specialTestEnv["DATA"], "data");
|
|
|
|
});
|
|
|
|
|
2022-05-17 12:15:06 -05:00
|
|
|
suite.addTest("test mod name works", async () => {
|
2021-12-02 00:20:10 -06:00
|
|
|
const config = [
|
|
|
|
{
|
2022-05-17 12:15:06 -05:00
|
|
|
env: { DATA: "data" },
|
2021-12-02 00:20:10 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
mask: "some::mod",
|
2022-05-17 12:15:06 -05:00
|
|
|
env: { DATA: "mod special" },
|
|
|
|
},
|
2021-12-02 00:20:10 -06:00
|
|
|
];
|
|
|
|
const testEnv = fakePrepareEnv("test some::mod::test_name", config);
|
|
|
|
assert.strictEqual(testEnv["DATA"], "mod special");
|
|
|
|
|
|
|
|
const specialTestEnv = fakePrepareEnv("test some::mod::another_test", config);
|
|
|
|
assert.strictEqual(specialTestEnv["DATA"], "mod special");
|
|
|
|
});
|
2020-07-02 13:33:26 -05:00
|
|
|
});
|
2021-12-02 00:20:10 -06:00
|
|
|
}
|