Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit 4d91cd9

Browse files
authored
Proper makefile test setup (#144)
* Proper makefile test setup This now: - Automatically installs the tests/ npm dependencies if not found. - Automatically builds the tests artifacts if not found. - Run the tests through `make test`. No more one-off npm script. - Does all that incrementally to avoid hassle.
1 parent 49808ce commit 4d91cd9

File tree

10 files changed

+60
-44
lines changed

10 files changed

+60
-44
lines changed

.github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ jobs:
4141
# - run: opam pin add rescript-editor-support.dev . --no-action
4242
# - run: opam install . --deps-only --with-doc --with-test
4343

44-
- run: eval $(opam env) && make
44+
- run: eval $(opam env) && make test
4545
if: matrix.os != 'windows-latest'
46+
# CI windows running the binary somehow stucks. Not sure why. Disable for now.
4647
- run: "& $env:CYGWIN_ROOT\\bin\\ocaml-env exec -- make"
4748
if: matrix.os == 'windows-latest'
4849

Makefile

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ build-native: lib/rescript-editor-support.exe depend
3030
dce: build-native
3131
node_modules/.bin/reanalyze -dce-cmt src -suppress src/vendor
3232

33+
tests/node_modules/.bin/rescript:
34+
@cd tests && npm install
35+
36+
tests/lib/.compiler.log: tests/node_modules/.bin/rescript
37+
@cd tests && node_modules/.bin/rescript build -with-deps
38+
39+
test: dce tests/lib/.compiler.log
40+
./test.sh
41+
3342
clean:
3443
git clean -dfx src
3544

3645
.DEFAULT_GOAL := build-native
3746

38-
.PHONY: depend clean build-native dce
47+
.PHONY: depend clean build-native dce test

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"name": "rescript-editor-support",
33
"version": "1.0.0",
4-
"scripts": {
5-
"test": "cd tests && ./test.sh"
6-
},
74
"keywords": [
85
"rescript",
96
"lsp",

test.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function exp {
2+
echo "$(dirname $1)/expected/$(basename $1).txt"
3+
}
4+
5+
for file in tests/src/*.res; do
6+
lib/rescript-editor-support.exe test $file &> $(exp $file)
7+
done
8+
9+
warningYellow='\033[0;33m'
10+
successGreen='\033[0;32m'
11+
reset='\033[0m'
12+
13+
diff=$(git ls-files --modified tests/src/expected)
14+
if [[ $diff = "" ]]; then
15+
printf "${successGreen}✅ No unstaged tests difference.${reset}\n"
16+
else
17+
printf "${warningYellow}⚠️ There are unstaged differences in tests/! Did you break a test?\n${diff}\n${reset}"
18+
exit 1
19+
fi

tests/src/expected/Auto.res.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Hover src/Auto.res 2:13
1+
Hover tests/src/Auto.res 2:13
22
{"contents": "```rescript\n(Belt.List.t<'a>, 'a => 'b) => Belt.List.t<'b>\n```\n\n`map xs f`\n\nreturn the list obtained by applying `f` to each element of `xs`\n\n```ml\nmap [1;2] (fun x-> x + 1) = [3;4]\n```\n"}
33

tests/src/expected/Complete.res.txt

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Complete src/Complete.res 0:2
1+
Complete tests/src/Complete.res 0:2
22
[{
33
"label": "mapReverse",
44
"kind": 12,
@@ -67,7 +67,7 @@ Complete src/Complete.res 0:2
6767
"documentation": {"kind": "markdown", "value": "\nbelt_List.mli:298"}
6868
}]
6969

70-
Complete src/Complete.res 1:2
70+
Complete tests/src/Complete.res 1:2
7171
[{
7272
"label": "Floatarray",
7373
"kind": 9,
@@ -286,7 +286,7 @@ Complete src/Complete.res 1:2
286286
"documentation": {"kind": "markdown", "value": "`Array.blit v1 o1 v2 o2 len` copies `len` elements from array `v1`, starting at element number `o1`, to array `v2`, starting at element number `o2`. It works correctly even if `v1` and `v2` are the same array, and the source and destination chunks overlap.\n\nRaise `Invalid_argument \"Array.blit\"` if `o1` and `len` do not designate a valid subarray of `v1`, or if `o2` and `len` do not designate a valid subarray of `v2`.\n\n\n\n\narray.mli:118"}
287287
}]
288288

289-
Complete src/Complete.res 2:2
289+
Complete tests/src/Complete.res 2:2
290290
[{
291291
"label": "mapi",
292292
"kind": 12,
@@ -337,7 +337,7 @@ Complete src/Complete.res 2:2
337337
"documentation": {"kind": "markdown", "value": "`mem a l` is true if and only if `a` is equal to an element of `l`.\n\nSince: 4.03.0\n\n\narray.mli:203"}
338338
}]
339339

340-
Complete src/Complete.res 12:2
340+
Complete tests/src/Complete.res 12:2
341341
[{
342342
"label": "customDouble",
343343
"kind": 12,
@@ -346,7 +346,7 @@ Complete src/Complete.res 12:2
346346
"documentation": {"kind": "markdown", "value": "Deprecated: Use customDouble instead\n\nSome doc comment\n\n\nComplete.res:1"}
347347
}]
348348

349-
Complete src/Complete.res 19:2
349+
Complete tests/src/Complete.res 19:2
350350
[{
351351
"label": "age",
352352
"kind": 4,
@@ -361,7 +361,7 @@ Complete src/Complete.res 19:2
361361
"documentation": {"kind": "markdown", "value": "\nComplete.res:20"}
362362
}]
363363

364-
Complete src/Complete.res 21:2
364+
Complete tests/src/Complete.res 21:2
365365
[{
366366
"label": "Js.Array2.mapi",
367367
"kind": 12,
@@ -376,7 +376,7 @@ Complete src/Complete.res 21:2
376376
"documentation": {"kind": "markdown", "value": "\njs_array2.ml:126"}
377377
}]
378378

379-
Complete src/Complete.res 23:2
379+
Complete tests/src/Complete.res 23:2
380380
[{
381381
"label": "Js.String2.toUpperCase",
382382
"kind": 12,
@@ -385,7 +385,7 @@ Complete src/Complete.res 23:2
385385
"documentation": {"kind": "markdown", "value": "`toUpperCase str` converts `str` to upper case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can expand the number of letters in the result; for example the German `\195\159` capitalizes to two `S`es in a row.\n\n```ml\ntoUpperCase \"abc\" = \"ABC\";;\ntoUpperCase {js|Stra\195\159e|js} = {js|STRASSE|js};;\ntoLowerCase {js|\207\128\207\130|js} = {js|\206\160\206\163|js};;\n```\n\n\n\njs_string2.ml:601"}
386386
}]
387387

388-
Complete src/Complete.res 27:2
388+
Complete tests/src/Complete.res 27:2
389389
[{
390390
"label": "Belt.Option.eqU",
391391
"kind": 12,
@@ -400,7 +400,7 @@ Complete src/Complete.res 27:2
400400
"documentation": {"kind": "markdown", "value": "`eq optValue1 optvalue2 predicate`\n\nEvaluates two optional values for equality with respect to a predicate function.\n\nIf both `optValue1` and `optValue2` are `None`, returns `true`.\n\nIf one of the arguments is `Some value` and the other is `None`, returns `false`\n\nIf arguments are `Some value1` and `Some value2`, returns the result of `predicate value1 value2`; the `predicate` function must return a `bool`\n\n```ml\nlet clockEqual = (fun a b -> a mod 12 = b mod 12);;\neq (Some 3) (Some 15) clockEqual = true;;\neq (Some 3) None clockEqual = false;;\neq None (Some 3) clockEqual = false;;\neq None None clockEqual = true;;\n```\n\n\n\nbelt_Option.mli:159"}
401401
}]
402402

403-
Complete src/Complete.res 36:2
403+
Complete tests/src/Complete.res 36:2
404404
[{
405405
"label": "ForAuto.abc",
406406
"kind": 12,
@@ -415,7 +415,7 @@ Complete src/Complete.res 36:2
415415
"documentation": {"kind": "markdown", "value": "\nComplete.res:34"}
416416
}]
417417

418-
Complete src/Complete.res 38:2
418+
Complete tests/src/Complete.res 38:2
419419
[{
420420
"label": "unsafeGet",
421421
"kind": 12,
@@ -430,7 +430,7 @@ Complete src/Complete.res 38:2
430430
"documentation": {"kind": "markdown", "value": "Experimental internal function\n\n\n\n\njs_dict.mli:63"}
431431
}]
432432

433-
Complete src/Complete.res 50:2
433+
Complete tests/src/Complete.res 50:2
434434
[{
435435
"label": "zzz",
436436
"kind": 12,
@@ -439,7 +439,7 @@ Complete src/Complete.res 50:2
439439
"documentation": {"kind": "markdown", "value": "\nComplete.res:50"}
440440
}]
441441

442-
Complete src/Complete.res 52:2
442+
Complete tests/src/Complete.res 52:2
443443
[{
444444
"label": "key",
445445
"kind": 4,

tests/src/expected/Definition.res.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
Definition src/Definition.res 2:8
1+
Definition tests/src/Definition.res 2:8
22
{"uri": "Definition.res", "range": "{"start": "{"line": "0", "character": "4"}", "end": "{"line": "0", "character": "6"}"}"}
33

4-
Definition src/Definition.res 10:23
4+
Definition tests/src/Definition.res 10:23
55
{"uri": "Definition.res", "range": "{"start": "{"line": "6", "character": "7"}", "end": "{"line": "6", "character": "13"}"}"}
66

7-
Hover src/Definition.res 14:14
7+
Hover tests/src/Definition.res 14:14
88
{"contents": "```rescript\n('a => 'b, list<'a>) => list<'b>\n```\n\n`List.map f [a1; ...; an]` applies function `f` to `a1, ..., an`, and builds the list `[f a1; ...; f an]` with the results returned by `f`. Not tail-recursive.\n\n"}
99

10-
Hover src/Definition.res 18:14
10+
Hover tests/src/Definition.res 18:14
1111
{"contents": "```rescript\n(Belt.List.t<'a>, 'a => 'b) => Belt.List.t<'b>\n```\n\n`map xs f`\n\nreturn the list obtained by applying `f` to each element of `xs`\n\n```ml\nmap [1;2] (fun x-> x + 1) = [3;4]\n```\n"}
1212

tests/src/expected/Hover.res.txt

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
Hover src/Hover.res 0:4
1+
Hover tests/src/Hover.res 0:4
22
{"contents": "```rescript\nint\n```"}
33

4-
Hover src/Hover.res 3:5
4+
Hover tests/src/Hover.res 3:5
55
{"contents": "```rescript\ntype t = (int, float)\n```"}
66

7-
Hover src/Hover.res 6:7
7+
Hover tests/src/Hover.res 6:7
88
{"contents": "```rescript\nmodule Id = {\n type x = int\n}\n```"}
99

10-
Hover src/Hover.res 19:11
10+
Hover tests/src/Hover.res 19:11
1111
{"contents": "\nThis module is commented\n```rescript\nmodule Dep = {\n let customDouble: int => int\n}\n```"}
1212

13-
Hover src/Hover.res 22:11
13+
Hover tests/src/Hover.res 22:11
1414
{"contents": "```rescript\nint => int\n```\n\nSome doc comment"}
1515

16-
Hover src/Hover.res 26:6
16+
Hover tests/src/Hover.res 26:6
1717
{"contents": "```rescript\nint\n```"}
1818

19-
Hover src/Hover.res 33:4
19+
Hover tests/src/Hover.res 33:4
2020
{"contents": "```rescript\nunit => int\n```\n\nDoc comment for functionWithTypeAnnotation"}
2121

22-
Hover src/Hover.res 37:13
22+
Hover tests/src/Hover.res 37:13
2323
{"contents": "```rescript\nstring\n```"}
2424

25-
Hover src/Hover.res 41:13
25+
Hover tests/src/Hover.res 41:13
2626
{"contents": "```rescript\nstring\n```"}
2727

tests/src/expected/Jsx.res.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
Definition src/Jsx.res 5:9
1+
Definition tests/src/Jsx.res 5:9
22
{"uri": "Jsx.res", "range": "{"start": "{"line": "2", "character": "6"}", "end": "{"line": "2", "character": "10"}"}"}
33

4-
Complete src/Jsx.res 7:2
4+
Complete tests/src/Jsx.res 7:2
55
[]
66

7-
Complete src/Jsx.res 10:2
7+
Complete tests/src/Jsx.res 10:2
88
[{
99
"label": "key",
1010
"kind": 4,

tests/test.sh

-10
This file was deleted.

0 commit comments

Comments
 (0)