Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ again with the same simple `esy` command.

% esy

And test compiled executable (runs `scripts.tests` specified in
And run compiled executable (runs `scripts.run` specified in
`package.json`):

% esy run

You can test your code (runs `scripts.test` specified in
`package.json`):

% esy test
Expand Down
2 changes: 2 additions & 0 deletions lib/Util.re
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ let hello = () =>
"!"
</Pastel>
);

let add = (a, b) => a + b;
4 changes: 4 additions & 0 deletions lib/Util.rei
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
print_endline(hello());
]} */
let hello: unit => string;

/** A simple function to show how to write test.
*/
let add: (int, int) => int;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
}
},
"scripts": {
"test": "esy x Hello",
"test": "esy b dune exec ./test/TestRunner.exe #{self.root}",
"run": "esy x Hello",
"format": "esy dune build @fmt --auto-promote",
"doc": "esy dune build @doc"
},
Expand Down
1 change: 1 addition & 0 deletions test/TestRunner.re
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestLib.TestFramework.cli();
3 changes: 3 additions & 0 deletions test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name TestRunner)
(libraries testLib))
18 changes: 18 additions & 0 deletions test/lib/TestFramework.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// In package.json we pass #{self.root} as first argument
if (Array.length(Sys.argv) < 2)
failwith("pass the project root as first argument");
let projectDir = Sys.argv[1];

include Rely.Make({
let config =
Rely.TestFrameworkConfig.initialize({
snapshotDir:
Filename.(
projectDir
|> (dir => concat(dir, "test"))
|> (dir => concat(dir, "lib"))
|> (dir => Filename.concat(dir, "__snapshots__"))
),
projectDir,
});
});
9 changes: 9 additions & 0 deletions test/lib/UtilTest.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
open TestFramework;

open Lib;

describe("Util", ({test, _}) => {
test("add", ({expect, _}) => {
expect.int(Util.add(3, 3)).toBe(6)
})
});
Empty file added test/lib/__snapshots__/.gitkeep
Empty file.
8 changes: 8 additions & 0 deletions test/lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(library
(name testLib)
; the linkall flag ensures that all of our tests are compiled and the
; -g flag emits debugging information
(ocamlopt_flags -linkall -g)
; you will want to depend on the library you are testing as well, however for
; the purposes of this example we are only depending on the test runner itself
(libraries lib rely.lib))