Skip to content

Commit cb56e44

Browse files
committed
test(error): test panic
1 parent 8c06a60 commit cb56e44

File tree

5 files changed

+89
-4
lines changed

5 files changed

+89
-4
lines changed

Diff for: package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
"clean": "rescript clean",
66
"build": "rescript",
77
"watch": "rescript build -w",
8-
"test": "node test/PromiseTest.mjs && node test/TempTests.mjs"
8+
"test": "node test/TestSuite.mjs && node test/TempTests.mjs"
99
},
10-
"keywords": [
11-
"rescript"
12-
],
10+
"keywords": ["rescript"],
1311
"homepage": "https://github.com/rescript-association/rescript-core",
1412
"author": "ReScript Team",
1513
"license": "MIT",

Diff for: test/ErrorTests.mjs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
import * as Test from "./Test.mjs";
4+
import * as Js_exn from "rescript/lib/es6/js_exn.js";
5+
import * as RescriptCore from "../src/RescriptCore.mjs";
6+
import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
7+
8+
function panicTest(param) {
9+
var caught;
10+
try {
11+
caught = RescriptCore.panic("uh oh");
12+
}
13+
catch (raw_err){
14+
var err = Caml_js_exceptions.internalToOCamlException(raw_err);
15+
if (err.RE_EXN_ID === Js_exn.$$Error) {
16+
caught = err._1.message;
17+
} else {
18+
throw err;
19+
}
20+
}
21+
Test.run([
22+
[
23+
"ErrorTests.res",
24+
8,
25+
22,
26+
43
27+
],
28+
"Should resolve test"
29+
], caught, (function (prim0, prim1) {
30+
return prim0 === prim1;
31+
}), "Panic! uh oh");
32+
}
33+
34+
panicTest(undefined);
35+
36+
export {
37+
panicTest ,
38+
}
39+
/* Not a pure module */

Diff for: test/ErrorTests.res

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
open RescriptCore
2+
3+
let panicTest = () => {
4+
let caught = try panic("uh oh") catch {
5+
| Exn.Error(err) => Error.message(err)
6+
}
7+
8+
Test.run(__POS_OF__("Should resolve test"), caught, \"==", Some("Panic! uh oh"))
9+
}
10+
11+
panicTest()

Diff for: test/TestSuite.mjs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
import * as ErrorTests from "./ErrorTests.mjs";
4+
import * as PromiseTest from "./PromiseTest.mjs";
5+
6+
var TestError = PromiseTest.TestError;
7+
8+
var fail = PromiseTest.fail;
9+
10+
var equal = PromiseTest.equal;
11+
12+
var Creation = PromiseTest.Creation;
13+
14+
var ThenChaining = PromiseTest.ThenChaining;
15+
16+
var Rejection = PromiseTest.Rejection;
17+
18+
var Catching = PromiseTest.Catching;
19+
20+
var Concurrently = PromiseTest.Concurrently;
21+
22+
var panicTest = ErrorTests.panicTest;
23+
24+
export {
25+
TestError ,
26+
fail ,
27+
equal ,
28+
Creation ,
29+
ThenChaining ,
30+
Rejection ,
31+
Catching ,
32+
Concurrently ,
33+
panicTest ,
34+
}
35+
/* ErrorTests Not a pure module */

Diff for: test/TestSuite.res

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include PromiseTest
2+
include ErrorTests

0 commit comments

Comments
 (0)