Skip to content

Commit 7d003a3

Browse files
committed
ok got some failing tests for bs, which isnt awesome
1 parent 24212e6 commit 7d003a3

File tree

4 files changed

+47
-24
lines changed

4 files changed

+47
-24
lines changed

src/analyze/BuildSystem.re

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,24 @@ let getBsbExecutable = rootPath =>
120120
|?>> (path => path /+ ".bin" /+ "bsb")
121121
);
122122

123-
let getCompilerVersion = executable => {
124-
let cmd = executable ++ " -version";
125-
let (output, success) = Commands.execSync(cmd);
126-
success ? switch output {
127-
| [line] => switch (Utils.split_on_char('.', String.trim(line))) {
123+
let parseOCamlVersion = versionString =>switch (Utils.split_on_char('.', String.trim(versionString))) {
128124
| ["4", "02", _] => Ok(V402)
129125
| ["4", "06", _] => Ok(V406)
130126
| ["4", "07", _] => Ok(V407)
131127
| ["4", "08", _] => Ok(V408)
132-
| _ => Error("Unsupported OCaml version: " ++ line)
128+
| _ => Error("Unsupported OCaml version: " ++ versionString)
133129
}
130+
131+
let getCompilerVersion = executable => {
132+
let cmd = executable ++ " -version";
133+
let (output, success) = Commands.execSync(cmd);
134+
success ? switch output {
135+
| [line] when Str.string_match(Str.regexp_string("BuckleScript "), line, 0) =>
136+
switch (Str.split(Str.regexp_string("(Using OCaml"), String.trim(line))) {
137+
| [_, version] => parseOCamlVersion(version)
138+
| _ => Error("Cannot detect OCaml version from BuckleScript version string: " ++ line)
139+
}
140+
| [line] => parseOCamlVersion(line)
134141
| _ => Error("Unable to determine compiler version (ran " ++ cmd ++ "). Output: " ++ String.concat("\n", output))
135142
} : Error("Could not run compiler (ran " ++ cmd ++ "). Output: " ++ String.concat("\n", output));
136143
};
@@ -162,6 +169,21 @@ let detect = (rootPath, bsconfig) => {
162169
}) : Bsb(bsbVersion);
163170
};
164171

172+
let detectFull = projectDir => {
173+
let bsConfig = Filename.concat(projectDir, "bsconfig.json");
174+
if (Files.exists(bsConfig)) {
175+
let%try raw = Files.readFileResult(bsConfig);
176+
let config = Json.parse(raw);
177+
detect(projectDir, config);
178+
} else {
179+
let esy = getLine("esy --version", ~pwd=projectDir);
180+
switch (esy) {
181+
| Ok(v) => Ok(Dune(Esy(v)))
182+
| Error(err) => Error("Couldn't get esy version")
183+
};
184+
};
185+
};
186+
165187
let getEsyCompiledBase = () => {
166188
let env = Unix.environment()->Array.to_list;
167189

src/analyze_example_tests/ExamplesTests.re

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ open TestFramework;
33

44
open Analyze;
55

6-
let checkExampleProject = (rootPath, sourcePaths) => {
6+
let checkExampleProject = (name, rootPath, sourcePaths) => {
77

8-
let {describe, describeSkip, describeOnly} =
8+
let {describe} =
99
describeConfig
1010
|> withLifecycle(testLifecycle =>
1111
testLifecycle
@@ -25,7 +25,7 @@ let checkExampleProject = (rootPath, sourcePaths) => {
2525
Files.collect(path, FindFiles.isSourceFile)
2626
})->Belt.List.toArray->Belt.List.concatMany;
2727

28-
describe(rootPath, ({test}) => {
28+
describe("Examples Test " ++ name, ({test}) => {
2929
files->Belt.List.forEach(path => {
3030
let uri = Utils.toUri(path);
3131
test(uri, ({expect, env: state}) => {
@@ -77,12 +77,12 @@ let projects = (Sys.os_type == "Unix" ? esyProjects : []) @ [
7777
// let main = (baseDir, _verbose, args) => {
7878
// print_endline("Checking each example project to make sure we can analyze each source file...");
7979
let baseDir = Sys.getcwd();
80-
projects->Belt.List.forEach(((root, sourcePaths, prepareCommand)) => {
80+
projects->Belt.List.forEach(((rootName, sourcePaths, prepareCommand)) => {
8181
// if (args == [] || List.mem(root, args)) {
82-
describe(root, ({test}) => {
83-
let root = Filename.concat(baseDir, Filename.concat("examples", root));
82+
describe("ExamplesTests " ++ rootName, ({test}) => {
83+
let root = Filename.concat(baseDir, Filename.concat("examples", rootName));
8484

85-
let {describe, describeSkip, describeOnly} =
85+
let {describe} =
8686
describeConfig
8787
|> withLifecycle(testLifecycle =>
8888
testLifecycle
@@ -107,7 +107,7 @@ let baseDir = Sys.getcwd();
107107
// sourcePaths->Belt.List.forEach(sourcePath => {
108108
// describe(sourcePath, ({test}) => checkExampleProject(root, sourcePath))
109109
// })
110-
checkExampleProject(root, sourcePaths)
110+
checkExampleProject(rootName, root, sourcePaths)
111111
// }
112112
})
113113
// } else {

src/analyze_fixture_tests/AnalyzeFixtureTests.re

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ Printexc.record_backtrace(true);
3030
// Log.spamError := true;
3131
// };
3232

33-
let projectDirs = ["./examples/bs-3.1.5", "./examples/dune", "./examples/example-react"];
33+
let projectDirs = [
34+
"./examples/bs-3.1.5",
35+
"./examples/dune",
36+
"./examples/example-react",
37+
"."
38+
];
3439

40+
let baseDir = Sys.getcwd();
3541
projectDirs->Belt.List.forEach(projectDir => {
3642
// describe(projectDir, ({describe}) => {
3743
tests->Belt.List.forEach(m => {
@@ -48,7 +54,7 @@ projectDirs->Belt.List.forEach(projectDir => {
4854
->Belt.List.forEach(item => {
4955
test(item.name, ({expect}) => {
5056
expect.string(
51-
M.getOutput(~projectDir, item.otherFiles, item.mainContent)
57+
M.getOutput(~projectDir=Filename.concat(baseDir, projectDir), item.otherFiles, item.mainContent)
5258
->String.trim,
5359
).
5460
toEqual(

src/analyze_fixture_tests/lib/TestUtils.re

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ open Analyze;
22
let tmp = "/tmp/.lsp-test";
33
Files.mkdirp(tmp);
44

5-
let getBuildSystem = (projectDir) => {
6-
let esy = BuildSystem.getLine("esy --version", ~pwd=projectDir);
7-
switch (esy) {
8-
| Ok(v) => Ok(BuildSystem.Dune(Esy(v)));
9-
| Error(err) => Error("Couldn't get esy version")
10-
};
11-
};
5+
// let getBuildSystem = (projectDir) => {
6+
// };
127

138
let compilerForProjectDir = (projectDir) => {
14-
let%try buildSystem = getBuildSystem(projectDir);
9+
let%try buildSystem = BuildSystem.detectFull(projectDir);
1510
let%try compilerPath = BuildSystem.getCompiler(projectDir, buildSystem);
1611
let%try_wrap compilerVersion = BuildSystem.getCompilerVersion(compilerPath);
1712
(buildSystem, compilerPath, compilerVersion)

0 commit comments

Comments
 (0)