aboutsummaryrefslogtreecommitdiff
path: root/editors/code/tests/unit/runnable_env.test.ts
blob: c5600cf64f3888d376f534f795303ae38087bd79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import * as assert from 'assert';
import { prepareEnv } from '../../src/run';
import { RunnableEnvCfg } from '../../src/config';
import * as ra from '../../src/lsp_ext';

function makeRunnable(label: string): ra.Runnable {
    return {
        label,
        kind: "cargo",
        args: {
            cargoArgs: [],
            executableArgs: [],
            cargoExtraArgs: []
        }
    };
}

function fakePrepareEnv(runnableName: string, config: RunnableEnvCfg): Record<string, string> {
    const runnable = makeRunnable(runnableName);
    return prepareEnv(runnable, config);
}

suite('Runnable env', () => {
    test('Global config works', () => {
        const binEnv = fakePrepareEnv("run project_name", { "GLOBAL": "g" });
        assert.equal(binEnv["GLOBAL"], "g");

        const testEnv = fakePrepareEnv("test some::mod::test_name", { "GLOBAL": "g" });
        assert.equal(testEnv["GLOBAL"], "g");
    });

    test('null mask works', () => {
        const config = [
            {
                env: { DATA: "data" }
            }
        ];
        const binEnv = fakePrepareEnv("run project_name", config);
        assert.equal(binEnv["DATA"], "data");

        const testEnv = fakePrepareEnv("test some::mod::test_name", config);
        assert.equal(testEnv["DATA"], "data");
    });

    test('order works', () => {
        const config = [
            {
                env: { DATA: "data" }
            },
            {
                env: { DATA: "newdata" }
            }
        ];
        const binEnv = fakePrepareEnv("run project_name", config);
        assert.equal(binEnv["DATA"], "newdata");

        const testEnv = fakePrepareEnv("test some::mod::test_name", config);
        assert.equal(testEnv["DATA"], "newdata");
    });

    test('mask works', () => {
        const config = [
            {
                env: { DATA: "data" }
            },
            {
                mask: "^run",
                env: { DATA: "rundata" }
            },
            {
                mask: "special_test$",
                env: { DATA: "special_test" }
            }
        ];
        const binEnv = fakePrepareEnv("run project_name", config);
        assert.equal(binEnv["DATA"], "rundata");

        const testEnv = fakePrepareEnv("test some::mod::test_name", config);
        assert.equal(testEnv["DATA"], "data");

        const specialTestEnv = fakePrepareEnv("test some::mod::special_test", config);
        assert.equal(specialTestEnv["DATA"], "special_test");
    });

    test('exact test name works', () => {
        const config = [
            {
                env: { DATA: "data" }
            },
            {
                mask: "some::mod::test_name",
                env: { DATA: "test special" }
            }
        ];
        const testEnv = fakePrepareEnv("test some::mod::test_name", config);
        assert.equal(testEnv["DATA"], "test special");

        const specialTestEnv = fakePrepareEnv("test some::mod::another_test", config);
        assert.equal(specialTestEnv["DATA"], "data");
    });

    test('test mod name works', () => {
        const config = [
            {
                env: { DATA: "data" }
            },
            {
                mask: "some::mod",
                env: { DATA: "mod special" }
            }
        ];
        const testEnv = fakePrepareEnv("test some::mod::test_name", config);
        assert.equal(testEnv["DATA"], "mod special");

        const specialTestEnv = fakePrepareEnv("test some::mod::another_test", config);
        assert.equal(specialTestEnv["DATA"], "mod special");
    });

});