aboutsummaryrefslogtreecommitdiff
path: root/editors/code/tests/unit
diff options
context:
space:
mode:
authorvsrs <[email protected]>2020-07-02 19:33:26 +0100
committervsrs <[email protected]>2020-07-03 12:23:51 +0100
commit271abb7bc43f11c9b9e9c1353b162d9d267b1d21 (patch)
tree5bf0cbdcbfa09535dca9db7cc02cbc4d6153889a /editors/code/tests/unit
parent7b79d24ad5b251c0806a07aa7769e824f3c37fec (diff)
Add tests
Diffstat (limited to 'editors/code/tests/unit')
-rw-r--r--editors/code/tests/unit/runnable_env.test.ts118
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..979d497dd
--- /dev/null
+++ b/editors/code/tests/unit/runnable_env.test.ts
@@ -0,0 +1,118 @@
1import * as assert from 'assert';
2import { prepareEnv } from '../../src/run';
3import { RunnableEnvCfg } from '../../src/config';
4import * as ra from '../../src/lsp_ext';
5
6function make_runnable(label: string): ra.Runnable {
7 return {
8 label,
9 kind: "cargo",
10 args: {
11 cargoArgs: [],
12 executableArgs: []
13 }
14 }
15}
16
17function fakePrepareEnv(runnable_name: string, config: RunnableEnvCfg) : Record<string, string> {
18 const runnable = make_runnable(runnable_name);
19 return prepareEnv(runnable, config);
20}
21
22suite('Runnable env', () => {
23 test('Global config works', () => {
24 const bin_env = fakePrepareEnv("run project_name", {"GLOBAL": "g"});
25 assert.equal(bin_env["GLOBAL"], "g");
26
27 const test_env = fakePrepareEnv("test some::mod::test_name", {"GLOBAL": "g"});
28 assert.equal(test_env["GLOBAL"], "g");
29 });
30
31 test('null mask works', () => {
32 const config = [
33 {
34 env: { DATA: "data" }
35 }
36 ];
37 const bin_env = fakePrepareEnv("run project_name", config);
38 assert.equal(bin_env["DATA"], "data");
39
40 const test_env = fakePrepareEnv("test some::mod::test_name", config);
41 assert.equal(test_env["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 bin_env = fakePrepareEnv("run project_name", config);
54 assert.equal(bin_env["DATA"], "newdata");
55
56 const test_env = fakePrepareEnv("test some::mod::test_name", config);
57 assert.equal(test_env["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 bin_env = fakePrepareEnv("run project_name", config);
75 assert.equal(bin_env["DATA"], "rundata");
76
77 const test_env = fakePrepareEnv("test some::mod::test_name", config);
78 assert.equal(test_env["DATA"], "data");
79
80 const special_test_env = fakePrepareEnv("test some::mod::special_test", config);
81 assert.equal(special_test_env["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 test_env = fakePrepareEnv("test some::mod::test_name", config);
95 assert.equal(test_env["DATA"], "test special");
96
97 const special_test_env = fakePrepareEnv("test some::mod::another_test", config);
98 assert.equal(special_test_env["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 test_env = fakePrepareEnv("test some::mod::test_name", config);
112 assert.equal(test_env["DATA"], "mod special");
113
114 const special_test_env = fakePrepareEnv("test some::mod::another_test", config);
115 assert.equal(special_test_env["DATA"], "mod special");
116 });
117
118});