Skip to content

Commit 02f4467

Browse files
committed
remove prepareCompiler
1 parent 02f60b8 commit 02f4467

File tree

2 files changed

+2
-161
lines changed

2 files changed

+2
-161
lines changed

tests/docstrings_examples/DocTest.res

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -62,89 +62,8 @@ open Node
6262

6363
module Docgen = RescriptTools.Docgen
6464

65-
@val @scope(("import", "meta")) external url: string = "url"
66-
67-
let dirname =
68-
url
69-
->URL.fileURLToPath
70-
->Path.dirname
71-
72-
let compilerDir = Path.join([dirname, "..", ".examples-tests"])
73-
74-
let rescriptBin = Path.join([compilerDir, "node_modules", ".bin", "rescript"])
75-
7665
let bscBin = Path.join(["cli", "bsc"])
7766

78-
let rescriptCoreCompiled = Path.join([
79-
compilerDir,
80-
"node_modules",
81-
"@rescript",
82-
"core",
83-
"lib",
84-
"ocaml",
85-
])
86-
87-
let makePackageJson = coreVersion =>
88-
`{
89-
"name": "test-compiler-examples",
90-
"version": "1.0.0",
91-
"dependencies": {
92-
"@rescript/core": "file:rescript-core-${coreVersion}.tgz",
93-
"rescript": "11.1.4"
94-
}
95-
}
96-
`
97-
98-
let rescriptJson = `{
99-
"name": "dummy",
100-
"sources": {
101-
"dir": "dummy",
102-
"subdirs": true
103-
},
104-
"bs-dependencies": [
105-
"@rescript/core"
106-
],
107-
"bsc-flags": [
108-
"-open RescriptCore"
109-
]
110-
}`
111-
112-
let prepareCompiler = () => {
113-
let corePath = Path.join([compilerDir, ".."])
114-
115-
if !Fs.existsSync(compilerDir) {
116-
Fs.mkdirSync(compilerDir)->ignore
117-
}
118-
119-
ChildProcess.execFileSync("npm", ["pack", corePath], {cwd: compilerDir, stdio: "ignore"})->ignore
120-
121-
let currentCoreVersion = switch Path.join2(corePath, "package.json")
122-
->Fs.readFileSync
123-
->JSON.parseExn {
124-
| Object(dict) =>
125-
switch dict->Dict.getUnsafe("version") {
126-
| String(s) => s
127-
| _ => assert(false)
128-
}
129-
| _ => assert(false)
130-
}
131-
132-
Path.join2(compilerDir, "package.json")->Fs.writeFileSync(makePackageJson(currentCoreVersion))
133-
Path.join2(compilerDir, "rescript.json")->Fs.writeFileSync(rescriptJson)
134-
135-
let dummyFolder = Path.join2(compilerDir, "dummy")
136-
137-
if !Fs.existsSync(dummyFolder) {
138-
Fs.mkdirSync(dummyFolder)->ignore
139-
}
140-
141-
ChildProcess.execFileSync("npm", ["install"], {cwd: compilerDir})->ignore
142-
143-
ChildProcess.execFileSync(rescriptBin, ["build"], {cwd: compilerDir})->ignore
144-
}
145-
146-
// prepareCompiler()
147-
14867
type example = {
14968
id: string,
15069
kind: string,
@@ -160,7 +79,7 @@ let testCode = async (~id, ~code) => {
16079

16180
let () = await Fs.writeFile(tempFileName ++ ".res", code)
16281

163-
let args = [tempFileName ++ ".res", "-I", rescriptCoreCompiled, "-w", "-3-109"]
82+
let args = [tempFileName ++ ".res", "-w", "-3-109"]
16483

16584
let promise = await Promise.make((resolve, _reject) => {
16685
let spawn = ChildProcess.spawn(bscBin, args)

tests/docstrings_examples/DocTest.res.mjs

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import * as Fs from "fs";
44
import * as Os from "os";
5-
import * as Url from "url";
65
import * as List from "rescript/lib/es6/List.js";
76
import * as Path from "path";
87
import * as $$Array from "rescript/lib/es6/Array.js";
@@ -37,76 +36,8 @@ let Node = {
3736
OS: OS
3837
};
3938

40-
let dirname = Path.dirname(Url.fileURLToPath(import.meta.url));
41-
42-
let compilerDir = Path.join(dirname, "..", ".examples-tests");
43-
44-
let rescriptBin = Path.join(compilerDir, "node_modules", ".bin", "rescript");
45-
4639
let bscBin = Path.join("cli", "bsc");
4740

48-
let rescriptCoreCompiled = Path.join(compilerDir, "node_modules", "@rescript", "core", "lib", "ocaml");
49-
50-
function makePackageJson(coreVersion) {
51-
return "{\n \"name\": \"test-compiler-examples\",\n \"version\": \"1.0.0\",\n \"dependencies\": {\n \"@rescript/core\": \"file:rescript-core-" + coreVersion + ".tgz\",\n \"rescript\": \"11.1.4\"\n }\n}\n";
52-
}
53-
54-
let rescriptJson = "{\n \"name\": \"dummy\",\n \"sources\": {\n \"dir\": \"dummy\",\n \"subdirs\": true\n },\n \"bs-dependencies\": [\n \"@rescript/core\"\n ],\n \"bsc-flags\": [\n \"-open RescriptCore\"\n ]\n}";
55-
56-
function prepareCompiler() {
57-
let corePath = Path.join(compilerDir, "..");
58-
if (!Fs.existsSync(compilerDir)) {
59-
Fs.mkdirSync(compilerDir);
60-
}
61-
Child_process.execFileSync("npm", [
62-
"pack",
63-
corePath
64-
], {
65-
stdio: "ignore",
66-
cwd: compilerDir
67-
});
68-
let dict = JSON.parse(Fs.readFileSync(Path.join(corePath, "package.json")));
69-
let currentCoreVersion;
70-
if (typeof dict === "object" && !Array.isArray(dict)) {
71-
let s = dict["version"];
72-
if (typeof s === "string") {
73-
currentCoreVersion = s;
74-
} else {
75-
throw {
76-
RE_EXN_ID: "Assert_failure",
77-
_1: [
78-
"DocTest.res",
79-
127,
80-
11
81-
],
82-
Error: new Error()
83-
};
84-
}
85-
} else {
86-
throw {
87-
RE_EXN_ID: "Assert_failure",
88-
_1: [
89-
"DocTest.res",
90-
129,
91-
9
92-
],
93-
Error: new Error()
94-
};
95-
}
96-
Fs.writeFileSync(Path.join(compilerDir, "package.json"), makePackageJson(currentCoreVersion));
97-
Fs.writeFileSync(Path.join(compilerDir, "rescript.json"), rescriptJson);
98-
let dummyFolder = Path.join(compilerDir, "dummy");
99-
if (!Fs.existsSync(dummyFolder)) {
100-
Fs.mkdirSync(dummyFolder);
101-
}
102-
Child_process.execFileSync("npm", ["install"], {
103-
cwd: compilerDir
104-
});
105-
Child_process.execFileSync(rescriptBin, ["build"], {
106-
cwd: compilerDir
107-
});
108-
}
109-
11041
function createFileInTempDir(id) {
11142
return Path.join(Os.tmpdir(), id);
11243
}
@@ -117,8 +48,6 @@ async function testCode(id, code) {
11748
await Promises.writeFile(tempFileName + ".res", code);
11849
let args = [
11950
tempFileName + ".res",
120-
"-I",
121-
rescriptCoreCompiled,
12251
"-w",
12352
"-3-109"
12453
];
@@ -342,14 +271,7 @@ let Docgen;
342271
export {
343272
Node,
344273
Docgen,
345-
dirname,
346-
compilerDir,
347-
rescriptBin,
348274
bscBin,
349-
rescriptCoreCompiled,
350-
makePackageJson,
351-
rescriptJson,
352-
prepareCompiler,
353275
createFileInTempDir,
354276
testCode,
355277
extractDocFromFile,
@@ -358,4 +280,4 @@ export {
358280
main,
359281
exitCode,
360282
}
361-
/* dirname Not a pure module */
283+
/* bscBin Not a pure module */

0 commit comments

Comments
 (0)