diff options
Diffstat (limited to 'editors/code/tests/unit/runnable_env.test.ts')
-rw-r--r-- | editors/code/tests/unit/runnable_env.test.ts | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/editors/code/tests/unit/runnable_env.test.ts b/editors/code/tests/unit/runnable_env.test.ts new file mode 100644 index 000000000..f2f53e91a --- /dev/null +++ b/editors/code/tests/unit/runnable_env.test.ts | |||
@@ -0,0 +1,118 @@ | |||
1 | import * as assert from 'assert'; | ||
2 | import { prepareEnv } from '../../src/run'; | ||
3 | import { RunnableEnvCfg } from '../../src/config'; | ||
4 | import * as ra from '../../src/lsp_ext'; | ||
5 | |||
6 | function makeRunnable(label: string): ra.Runnable { | ||
7 | return { | ||
8 | label, | ||
9 | kind: "cargo", | ||
10 | args: { | ||
11 | cargoArgs: [], | ||
12 | executableArgs: [] | ||
13 | } | ||
14 | }; | ||
15 | } | ||
16 | |||
17 | function fakePrepareEnv(runnableName: string, config: RunnableEnvCfg): Record<string, string> { | ||
18 | const runnable = makeRunnable(runnableName); | ||
19 | return prepareEnv(runnable, config); | ||
20 | } | ||
21 | |||
22 | suite('Runnable env', () => { | ||
23 | test('Global config works', () => { | ||
24 | const binEnv = fakePrepareEnv("run project_name", { "GLOBAL": "g" }); | ||
25 | assert.equal(binEnv["GLOBAL"], "g"); | ||
26 | |||
27 | const testEnv = fakePrepareEnv("test some::mod::test_name", { "GLOBAL": "g" }); | ||
28 | assert.equal(testEnv["GLOBAL"], "g"); | ||
29 | }); | ||
30 | |||
31 | test('null mask works', () => { | ||
32 | const config = [ | ||
33 | { | ||
34 | env: { DATA: "data" } | ||
35 | } | ||
36 | ]; | ||
37 | const binEnv = fakePrepareEnv("run project_name", config); | ||
38 | assert.equal(binEnv["DATA"], "data"); | ||
39 | |||
40 | const testEnv = fakePrepareEnv("test some::mod::test_name", config); | ||
41 | assert.equal(testEnv["DATA"], "data"); | ||
42 | }); | ||
43 | |||
44 | test('order works', () => { | ||
45 | const config = [ | ||
46 | { | ||
47 | env: { DATA: "data" } | ||
48 | }, | ||
49 | { | ||
50 | env: { DATA: "newdata" } | ||
51 | } | ||
52 | ]; | ||
53 | const binEnv = fakePrepareEnv("run project_name", config); | ||
54 | assert.equal(binEnv["DATA"], "newdata"); | ||
55 | |||
56 | const testEnv = fakePrepareEnv("test some::mod::test_name", config); | ||
57 | assert.equal(testEnv["DATA"], "newdata"); | ||
58 | }); | ||
59 | |||
60 | test('mask works', () => { | ||
61 | const config = [ | ||
62 | { | ||
63 | env: { DATA: "data" } | ||
64 | }, | ||
65 | { | ||
66 | mask: "^run", | ||
67 | env: { DATA: "rundata" } | ||
68 | }, | ||
69 | { | ||
70 | mask: "special_test$", | ||
71 | env: { DATA: "special_test" } | ||
72 | } | ||
73 | ]; | ||
74 | const binEnv = fakePrepareEnv("run project_name", config); | ||
75 | assert.equal(binEnv["DATA"], "rundata"); | ||
76 | |||
77 | const testEnv = fakePrepareEnv("test some::mod::test_name", config); | ||
78 | assert.equal(testEnv["DATA"], "data"); | ||
79 | |||
80 | const specialTestEnv = fakePrepareEnv("test some::mod::special_test", config); | ||
81 | assert.equal(specialTestEnv["DATA"], "special_test"); | ||
82 | }); | ||
83 | |||
84 | test('exact test name works', () => { | ||
85 | const config = [ | ||
86 | { | ||
87 | env: { DATA: "data" } | ||
88 | }, | ||
89 | { | ||
90 | mask: "some::mod::test_name", | ||
91 | env: { DATA: "test special" } | ||
92 | } | ||
93 | ]; | ||
94 | const testEnv = fakePrepareEnv("test some::mod::test_name", config); | ||
95 | assert.equal(testEnv["DATA"], "test special"); | ||
96 | |||
97 | const specialTestEnv = fakePrepareEnv("test some::mod::another_test", config); | ||
98 | assert.equal(specialTestEnv["DATA"], "data"); | ||
99 | }); | ||
100 | |||
101 | test('test mod name works', () => { | ||
102 | const config = [ | ||
103 | { | ||
104 | env: { DATA: "data" } | ||
105 | }, | ||
106 | { | ||
107 | mask: "some::mod", | ||
108 | env: { DATA: "mod special" } | ||
109 | } | ||
110 | ]; | ||
111 | const testEnv = fakePrepareEnv("test some::mod::test_name", config); | ||
112 | assert.equal(testEnv["DATA"], "mod special"); | ||
113 | |||
114 | const specialTestEnv = fakePrepareEnv("test some::mod::another_test", config); | ||
115 | assert.equal(specialTestEnv["DATA"], "mod special"); | ||
116 | }); | ||
117 | |||
118 | }); | ||