forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathciTest.js
213 lines (188 loc) · 5.35 KB
/
ciTest.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
//@ts-check
var cp = require("child_process");
var path = require("path");
var installGlobal = false;
var ounitTest = false;
var mochaTest = false;
var themeTest = false;
var bsbTest = false;
var all = false;
if (process.argv.includes("-install-global")) {
installGlobal = true;
}
if (process.argv.includes("-ounit")) {
ounitTest = true;
}
if (process.argv.includes("-mocha")) {
mochaTest = true;
}
if (process.argv.includes("-theme")) {
themeTest = true;
}
if (process.argv.includes("-bsb")) {
bsbTest = true;
}
if (process.argv.includes("-all")) {
all = true;
}
if (all) {
installGlobal = true;
ounitTest = true;
mochaTest = true;
themeTest = true;
bsbTest = true;
}
var fs = require("fs");
function init() {
var vendorOCamlPath = path.join(
__dirname,
"..",
"native",
require("./buildocaml.js").getVersionPrefix(),
"bin"
);
process.env["PATH"] = vendorOCamlPath + path.delimiter + process.env["PATH"];
var ninjaPath = path.join(__dirname, "..", process.platform, "ninja.exe");
if (!fs.existsSync(ninjaPath)) {
throw new Error("ninja could not be configured");
}
}
function main() {
init();
// when binary was prebuilt, there can be no ocaml installation
// var output =
// cp.execSync('which ocaml', { encoding: 'ascii' })
// console.log('OCaml:', output)
var binDir = path.join(__dirname, "..", "jscomp", "bin");
if (ounitTest) {
cp.execSync(
`ocamlc.opt -I . -c js_refmt_compiler.mli js_refmt_compiler.ml`,
{
cwd: path.join(__dirname, "..", "lib", "4.06.1", "unstable"),
stdio: [0, 1, 2],
}
);
// running tests for native code
fs.copyFileSync(
path.join(
__dirname,
"..",
"lib",
"4.06.1",
"unstable",
"all_ounit_tests.ml"
),
path.join(binDir, "all_ounit_tests.ml")
);
cp.execSync(
`ocamlopt.opt -g -w -40-30 ../stubs/ext_basic_hash_stubs.c -I +compiler-libs ocamlcommon.cmxa unix.cmxa str.cmxa all_ounit_tests.ml -o test.exe`,
{
cwd: binDir,
stdio: [0, 1, 2],
}
);
cp.execSync(`./test.exe`, { cwd: binDir, stdio: [0, 1, 2] });
}
// running generated js tests
if (mochaTest) {
cp.execSync(`mocha jscomp/test/**/*test.js`, {
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
});
}
// set up global directory properly using
// npm config set prefix '~/.npm-global'
if (installGlobal) {
console.log("install bucklescript globally");
cp.execSync("sudo npm i -g --unsafe-perm . && bsc -bs-internal-check", {
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
});
}
var bsbDir = cp
.execSync(`bsb -where`, {
cwd: path.join(__dirname, ".."),
encoding: "utf8",
})
.trim();
console.log("BSBDIR:", bsbDir);
if (themeTest) {
console.log("Doing theme tests");
var themeOutput = cp.execSync(`bsb -themes`, { encoding: "ascii" });
var themes = themeOutput
.split("\n")
.slice(1)
.map((x) => x.trim())
.filter((x) => x);
var themesDir = path.join(__dirname, "..", "themes");
if (fs.existsSync(themesDir)) {
// fs.rmdirSync(themesDir,{recursive : true})
cp.execSync(`rm -rf ${themesDir}`, { stdio: [0, 1, 2] });
// we dont remove post-installation
// since it is useful for debugging
}
fs.mkdirSync(themesDir);
themes.forEach(function (theme) {
cp.exec(
`bsb -theme ${theme} -init ${theme}`,
{ cwd: themesDir, encoding: "utf8" },
function (error, stdout, stderr) {
console.log(stdout);
console.log(stderr);
if (error !== null) {
throw new Error(`init theme ${theme} failed`);
}
let config = {
cwd: path.join(themesDir, theme),
encoding: "utf8",
};
var output;
try {
output = cp.execSync(`npm link bs-platform`, config);
output = cp.execSync(`npm install`, config);
output = cp.execSync(`npm run clean`, config);
output = cp.execSync(`npm run build`, config);
} catch (err) {
console.error(`failed in theme ${theme}`);
console.log(output + "");
console.log(err + "");
}
}
);
});
}
if (bsbTest) {
console.log("Doing build_tests");
var buildTestDir = path.join(__dirname, "..", "jscomp", "build_tests");
cp.execSync(`npm link bs-platform`, {
cwd: buildTestDir,
stdio: [0, 1, 2],
encoding: "utf8",
});
var files = fs.readdirSync(buildTestDir);
files.forEach(function (file) {
var testDir = path.join(buildTestDir, file);
if (file === "node_modules" || !fs.lstatSync(testDir).isDirectory()) {
return;
}
if (!fs.existsSync(path.join(testDir, "input.js"))) {
console.warn(`input.js does not exist in ${testDir}`);
} else {
// note existsSync test already ensure that it is a directory
cp.exec(`node input.js`, { cwd: testDir, encoding: "utf8" }, function (
error,
stdout,
stderr
) {
console.log(stdout);
if (error !== null) {
console.log(stderr);
throw new Error(`working in ${testDir} Error: \n${error} `);
}
console.log("success in ", file);
});
}
});
}
}
main();