forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
187 lines (155 loc) · 4.74 KB
/
test.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//@ts-check
const cp = require("child_process");
const path = require("path");
const fs = require("fs");
const { rescript_exe } = require("#cli/bin_path");
const duneBinDir = require("./dune").duneBinDir;
const { exec } = require("../tests/build_tests/utils.js");
let ounitTest = false;
let mochaTest = false;
let bsbTest = false;
let formatTest = false;
let runtimeDocstrings = false;
if (process.argv.includes("-ounit")) {
ounitTest = true;
}
if (process.argv.includes("-mocha")) {
mochaTest = true;
}
if (process.argv.includes("-bsb")) {
bsbTest = true;
}
if (process.argv.includes("-format")) {
formatTest = true;
}
if (process.argv.includes("-docstrings")) {
runtimeDocstrings = true;
}
if (process.argv.includes("-all")) {
ounitTest = true;
mochaTest = true;
bsbTest = true;
formatTest = true;
runtimeDocstrings = true;
}
async function runTests() {
if (formatTest) {
cp.execSync("npm run checkFormat", {
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
});
cp.execSync("bash scripts/format_check.sh", {
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
});
}
if (ounitTest) {
if (process.platform === "win32") {
console.log("Skipping OUnit tests on Windows");
} else {
cp.execSync(path.join(duneBinDir, "ounit_tests"), {
stdio: [0, 1, 2],
});
}
}
if (mochaTest) {
cp.execSync(`${rescript_exe} clean`, {
cwd: path.join(__dirname, "..", "tests/tests"),
stdio: [0, 1, 2],
});
cp.execSync(`${rescript_exe} build`, {
cwd: path.join(__dirname, "..", "tests/tests"),
stdio: [0, 1, 2],
});
cp.execSync("npx mocha -t 10000 tests/tests/**/*_test.mjs", {
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
});
cp.execSync("node tests/tests/src/core/Core_TestSuite.mjs", {
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
});
cp.execSync("node tests/tests/src/core/Core_TempTests.mjs", {
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
});
}
if (bsbTest) {
console.log("Doing build_tests");
const buildTestDir = path.join(__dirname, "..", "tests", "build_tests");
const files = fs.readdirSync(buildTestDir);
let hasError = false;
for (const file of files) {
const testDir = path.join(buildTestDir, file);
if (file === "node_modules" || !fs.lstatSync(testDir).isDirectory()) {
continue;
}
if (!fs.existsSync(path.join(testDir, "input.js"))) {
console.warn(`input.js does not exist in ${testDir}`);
} else {
console.log(`testing ${file}`);
// note existsSync test already ensure that it is a directory
const out = await exec(`node`, ["input.js"], { cwd: testDir });
console.log(out.stdout);
if (out.status === 0) {
console.log("✅ success in", file);
} else {
console.log(`❌ error in ${file} with stderr:\n`, out.stderr);
hasError = true;
}
}
}
if (hasError) {
process.exit(1);
}
}
if (runtimeDocstrings) {
if (process.platform === "win32") {
console.log(`Skipping docstrings tests on ${process.platform}`);
} else {
console.log("Running runtime docstrings tests");
const generated_mocha_test_res = path.join(
"tests",
"docstring_tests",
"generated_mocha_test.res",
);
// Remove `generated_mocha_test.res` if file exists
if (fs.existsSync(generated_mocha_test_res)) {
console.log(`Removing ${generated_mocha_test_res}`);
fs.unlinkSync(generated_mocha_test_res);
}
cp.execSync(`${rescript_exe} build`, {
cwd: path.join(__dirname, "..", "tests/docstring_tests"),
stdio: [0, 1, 2],
});
// Generate rescript file with all tests `generated_mocha_test.res`
cp.execSync(
`node ${path.join("tests", "docstring_tests", "DocTest.res.mjs")}`,
{
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
},
);
// Build again to check if generated_mocha_test.res has syntax or type erros
cp.execSync(`${rescript_exe} build`, {
cwd: path.join(__dirname, "..", "tests/docstring_tests"),
stdio: [0, 1, 2],
});
// Format generated_mocha_test.res
console.log("Formatting generated_mocha_test.res");
cp.execSync(`./cli/rescript format ${generated_mocha_test_res}`, {
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
});
console.log("Run mocha test");
cp.execSync(
`npx mocha ${path.join("tests", "docstring_tests", "generated_mocha_test.res.mjs")}`,
{
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
},
);
}
}
}
runTests();