From 971fcf8413b46d6576969603d9b0537cc75932b0 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 6 May 2024 08:59:07 -0700 Subject: [PATCH 01/10] Port `equal` over to not requiring a description --- src/Zora.res | 2 +- tests/assertions.test.mjs | 59 +++++++++++++++++--------------- tests/assertions.test.res | 53 ++++++++++++++++++++-------- tests/multiple_blocking.test.res | 2 +- tests/parallel.test.res | 12 +++---- tests/simple.res | 2 +- tests/standaloneParallel.res | 4 +-- 7 files changed, 81 insertions(+), 53 deletions(-) diff --git a/src/Zora.res b/src/Zora.res index 1d0e1c5..9e9f0a7 100644 --- a/src/Zora.res +++ b/src/Zora.res @@ -17,7 +17,7 @@ type testMessage = string @send external blockSkip: (t, testTitle, zoraTestBlock) => unit = "skip" @send external blockOnly: (t, testTitle, zoraTestBlock) => unit = "only" -@send external equal: (t, 't, 't, testMessage) => unit = "equal" +@send external equal: (t, 't, 't, ~msg: testMessage=?) => unit = "equal" @send external notEqual: (t, 't, 't, testMessage) => unit = "notEqual" @send external is: (t, 't, 't, testMessage) => unit = "is" @send external isNot: (t, 't, 't, testMessage) => unit = "isNot" diff --git a/tests/assertions.test.mjs b/tests/assertions.test.mjs index 4e98540..783c653 100644 --- a/tests/assertions.test.mjs +++ b/tests/assertions.test.mjs @@ -5,34 +5,39 @@ import * as Zora$1 from "zora"; import * as Caml_option from "rescript/lib/es6/caml_option.js"; Zora$1.test("Test assertions", (async function (t) { - t.equal(42, 42, "Numbers are equal"); - t.notEqual(42, 43, "Numbers are not equal"); - var x = { - hello: "world" - }; - var z = { - hello: "world" - }; - t.is(x, x, "object is object"); - t.is(x, x, "object is object"); - t.isNot(x, z, "object is not object with same values"); - t.equal(x, z, "Object is deep equal"); - t.ok(true, "boolean is ok"); - t.notOk(false, "boolean is not ok"); - Zora.optionNone(t, undefined, "None is None"); - Zora.optionSome(t, Caml_option.some(x), (function (t, n) { - t.equal(n.hello, "world", "option should be hello world"); + t.test("With descriptions", (async function (t) { + t.equal(42, 42, "Numbers are equal"); + t.notEqual(42, 43, "Numbers are not equal"); + var x = { + hello: "world" + }; + var z = { + hello: "world" + }; + t.is(x, x, "object is object"); + t.is(x, x, "object is object"); + t.isNot(x, z, "object is not object with same values"); + t.equal(x, z, "Object is deep equal"); + t.ok(true, "boolean is ok"); + t.notOk(false, "boolean is not ok"); + Zora.optionNone(t, undefined, "None is None"); + Zora.optionSome(t, Caml_option.some(x), (function (t, n) { + t.equal(n.hello, "world", "option should be hello world"); + })); + Zora.resultError(t, { + TAG: "Error", + _0: x + }, "Is Error Result"); + return Zora.resultOk(t, { + TAG: "Ok", + _0: x + }, (function (t, n) { + t.equal(n.hello, "world", "Is Ok Result"); + })); + })); + t.test("Without descriptions", (async function (t) { + t.equal(42, 42); })); - Zora.resultError(t, { - TAG: "Error", - _0: x - }, "Is Error Result"); - return Zora.resultOk(t, { - TAG: "Ok", - _0: x - }, (function (t, n) { - t.equal(n.hello, "world", "Is Ok Result"); - })); })); export { diff --git a/tests/assertions.test.res b/tests/assertions.test.res index 3dece21..97d9ac9 100644 --- a/tests/assertions.test.res +++ b/tests/assertions.test.res @@ -1,19 +1,42 @@ open Zora zora("Test assertions", async t => { - t->equal(42, 42, "Numbers are equal") - t->notEqual(42, 43, "Numbers are not equal") - let x = {"hello": "world"} - let y = x - let z = {"hello": "world"} - t->is(x, x, "object is object") - t->is(x, y, "object is object") - t->isNot(x, z, "object is not object with same values") - t->equal(x, z, "Object is deep equal") - t->ok(true, "boolean is ok") - t->notOk(false, "boolean is not ok") - t->optionNone(None, "None is None") - t->optionSome(Some(x), (t, n) => t->equal(n["hello"], "world", "option should be hello world")) - t->resultError(Belt.Result.Error(x), "Is Error Result") - t->resultOk(Belt.Result.Ok(x), (t, n) => t->equal(n["hello"], "world", "Is Ok Result")) + t->test("With descriptions", async t => { + t->equal(42, 42, ~msg="Numbers are equal") + t->notEqual(42, 43, "Numbers are not equal") + let x = {"hello": "world"} + let y = x + let z = {"hello": "world"} + t->is(x, x, "object is object") + t->is(x, y, "object is object") + t->isNot(x, z, "object is not object with same values") + t->equal(x, z, ~msg="Object is deep equal") + t->ok(true, "boolean is ok") + t->notOk(false, "boolean is not ok") + t->optionNone(None, "None is None") + t->optionSome( + Some(x), + (t, n) => t->equal(n["hello"], "world", ~msg="option should be hello world"), + ) + t->resultError(Belt.Result.Error(x), "Is Error Result") + t->resultOk(Belt.Result.Ok(x), (t, n) => t->equal(n["hello"], "world", ~msg="Is Ok Result")) + }) + + t->test("Without descriptions", async t => { + t->equal(42, 42) + // t->notEqual(42, 43) + // let x = {"hello": "world"} + // let y = x + // let z = {"hello": "world"} + // t->is(x, x) + // t->is(x, y) + // t->isNot(x, z) + // t->equal(x, z) + // t->ok(true) + // t->notOk(false) + // t->optionNone(None) + // t->optionSome(Some(x), (t, n) => t->equal(n["hello"], "world")) + // t->resultError(Belt.Result.Error(x)) + // t->resultOk(Belt.Result.Ok(x), (t, n) => t->equal(n["hello"], "world")) + }) }) diff --git a/tests/multiple_blocking.test.res b/tests/multiple_blocking.test.res index b2acfbf..178f6cb 100644 --- a/tests/multiple_blocking.test.res +++ b/tests/multiple_blocking.test.res @@ -7,6 +7,6 @@ zoraBlock("Should run some simple blocking tests", t => { t->block("should answer question", t => { let answer = 42 - t->equal(answer, 42, "should be 42") + t->equal(answer, 42, ~msg="should be 42") }) }) diff --git a/tests/parallel.test.res b/tests/parallel.test.res index adc7849..5dd7743 100644 --- a/tests/parallel.test.res +++ b/tests/parallel.test.res @@ -14,21 +14,21 @@ zora("Some Parallel Tests", async t => { t->test("parallel 1", async t => { {await wait(10)}->ignore - t->equal(state.contents, 1, "parallel 2 should have incremented by now") + t->equal(state.contents, 1, ~msg="parallel 2 should have incremented by now") state.contents = state.contents + 1 - t->equal(state.contents, 2, "parallel 1 should increment") + t->equal(state.contents, 2, ~msg="parallel 1 should increment") }) t->test("parallel 2", async t => { - t->equal(state.contents, 0, "parallel 2 should be the first to increment") + t->equal(state.contents, 0, ~msg="parallel 2 should be the first to increment") state.contents = state.contents + 1 - t->equal(state.contents, 1, "parallel 2 should increment") + t->equal(state.contents, 1, ~msg="parallel 2 should increment") }) t->test("parallel 3", async t => { {await wait(20)}->ignore - t->equal(state.contents, 2, "parallel 1 and 2 should have incremented by now") + t->equal(state.contents, 2, ~msg="parallel 1 and 2 should have incremented by now") state.contents = state.contents + 1 - t->equal(state.contents, 3, "parallel 3 should increment last") + t->equal(state.contents, 3, ~msg="parallel 3 should increment last") }) }) diff --git a/tests/simple.res b/tests/simple.res index e32cf26..8793242 100644 --- a/tests/simple.res +++ b/tests/simple.res @@ -2,5 +2,5 @@ open Zora zoraBlock("should run a test synchronously", t => { let answer = 3.14 - t->equal(answer, 3.14, "Should be a tasty dessert") + t->equal(answer, 3.14, ~msg="Should be a tasty dessert") }) diff --git a/tests/standaloneParallel.res b/tests/standaloneParallel.res index 1e030ba..de91908 100644 --- a/tests/standaloneParallel.res +++ b/tests/standaloneParallel.res @@ -2,10 +2,10 @@ open Zora zora("should run a test asynchronously", async t => { let answer = 42 - t->equal(answer, 42, "Should answer the question") + t->equal(answer, 42, ~msg="Should answer the question") }) zora("should run a second test at the same time", async t => { let answer = 3.14 - t->equal(answer, 3.14, "Should be a tasty dessert") + t->equal(answer, 3.14, ~msg="Should be a tasty dessert") }) From 7b2933a481cdcc91c1e00710aeca0aa5a055986c Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 6 May 2024 12:22:44 -0700 Subject: [PATCH 02/10] Port `notEqual` --- src/Zora.res | 2 +- tests/assertions.test.mjs | 1 + tests/assertions.test.res | 6 ++---- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Zora.res b/src/Zora.res index 9e9f0a7..6778bee 100644 --- a/src/Zora.res +++ b/src/Zora.res @@ -18,7 +18,7 @@ type testMessage = string @send external blockOnly: (t, testTitle, zoraTestBlock) => unit = "only" @send external equal: (t, 't, 't, ~msg: testMessage=?) => unit = "equal" -@send external notEqual: (t, 't, 't, testMessage) => unit = "notEqual" +@send external notEqual: (t, 't, 't, ~msg: testMessage=?) => unit = "notEqual" @send external is: (t, 't, 't, testMessage) => unit = "is" @send external isNot: (t, 't, 't, testMessage) => unit = "isNot" @send external ok: (t, bool, testMessage) => unit = "ok" diff --git a/tests/assertions.test.mjs b/tests/assertions.test.mjs index 783c653..8a9b94f 100644 --- a/tests/assertions.test.mjs +++ b/tests/assertions.test.mjs @@ -37,6 +37,7 @@ Zora$1.test("Test assertions", (async function (t) { })); t.test("Without descriptions", (async function (t) { t.equal(42, 42); + t.notEqual(42, 43); })); })); diff --git a/tests/assertions.test.res b/tests/assertions.test.res index 97d9ac9..38abe09 100644 --- a/tests/assertions.test.res +++ b/tests/assertions.test.res @@ -3,7 +3,7 @@ open Zora zora("Test assertions", async t => { t->test("With descriptions", async t => { t->equal(42, 42, ~msg="Numbers are equal") - t->notEqual(42, 43, "Numbers are not equal") + t->notEqual(42, 43, ~msg="Numbers are not equal") let x = {"hello": "world"} let y = x let z = {"hello": "world"} @@ -24,12 +24,10 @@ zora("Test assertions", async t => { t->test("Without descriptions", async t => { t->equal(42, 42) - // t->notEqual(42, 43) + t->notEqual(42, 43) // let x = {"hello": "world"} - // let y = x // let z = {"hello": "world"} // t->is(x, x) - // t->is(x, y) // t->isNot(x, z) // t->equal(x, z) // t->ok(true) From 8940171bc2b4903fc4cee02381454c2849aef846 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 6 May 2024 12:25:26 -0700 Subject: [PATCH 03/10] Port `is` --- src/Zora.res | 2 +- tests/assertions.test.mjs | 4 ++++ tests/assertions.test.res | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Zora.res b/src/Zora.res index 6778bee..13ab34e 100644 --- a/src/Zora.res +++ b/src/Zora.res @@ -19,7 +19,7 @@ type testMessage = string @send external equal: (t, 't, 't, ~msg: testMessage=?) => unit = "equal" @send external notEqual: (t, 't, 't, ~msg: testMessage=?) => unit = "notEqual" -@send external is: (t, 't, 't, testMessage) => unit = "is" +@send external is: (t, 't, 't, ~msg: testMessage=?) => unit = "is" @send external isNot: (t, 't, 't, testMessage) => unit = "isNot" @send external ok: (t, bool, testMessage) => unit = "ok" @send external notOk: (t, bool, testMessage) => unit = "notOk" diff --git a/tests/assertions.test.mjs b/tests/assertions.test.mjs index 8a9b94f..b33944b 100644 --- a/tests/assertions.test.mjs +++ b/tests/assertions.test.mjs @@ -38,6 +38,10 @@ Zora$1.test("Test assertions", (async function (t) { t.test("Without descriptions", (async function (t) { t.equal(42, 42); t.notEqual(42, 43); + var x = { + hello: "world" + }; + t.is(x, x); })); })); diff --git a/tests/assertions.test.res b/tests/assertions.test.res index 38abe09..032b6c6 100644 --- a/tests/assertions.test.res +++ b/tests/assertions.test.res @@ -7,8 +7,8 @@ zora("Test assertions", async t => { let x = {"hello": "world"} let y = x let z = {"hello": "world"} - t->is(x, x, "object is object") - t->is(x, y, "object is object") + t->is(x, x, ~msg="object is object") + t->is(x, y, ~msg="object is object") t->isNot(x, z, "object is not object with same values") t->equal(x, z, ~msg="Object is deep equal") t->ok(true, "boolean is ok") @@ -25,9 +25,9 @@ zora("Test assertions", async t => { t->test("Without descriptions", async t => { t->equal(42, 42) t->notEqual(42, 43) - // let x = {"hello": "world"} + let x = {"hello": "world"} // let z = {"hello": "world"} - // t->is(x, x) + t->is(x, x) // t->isNot(x, z) // t->equal(x, z) // t->ok(true) From ec4b755175aa7b2857e956df9453c1850f56d6b5 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 6 May 2024 12:26:50 -0700 Subject: [PATCH 04/10] Port `isNot` --- src/Zora.res | 2 +- tests/assertions.test.mjs | 4 ++++ tests/assertions.test.res | 7 +++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Zora.res b/src/Zora.res index 13ab34e..66634b2 100644 --- a/src/Zora.res +++ b/src/Zora.res @@ -20,7 +20,7 @@ type testMessage = string @send external equal: (t, 't, 't, ~msg: testMessage=?) => unit = "equal" @send external notEqual: (t, 't, 't, ~msg: testMessage=?) => unit = "notEqual" @send external is: (t, 't, 't, ~msg: testMessage=?) => unit = "is" -@send external isNot: (t, 't, 't, testMessage) => unit = "isNot" +@send external isNot: (t, 't, 't, ~msg: testMessage=?) => unit = "isNot" @send external ok: (t, bool, testMessage) => unit = "ok" @send external notOk: (t, bool, testMessage) => unit = "notOk" @send external fail: (t, testMessage) => unit = "fail" diff --git a/tests/assertions.test.mjs b/tests/assertions.test.mjs index b33944b..08eb609 100644 --- a/tests/assertions.test.mjs +++ b/tests/assertions.test.mjs @@ -41,7 +41,11 @@ Zora$1.test("Test assertions", (async function (t) { var x = { hello: "world" }; + var z = { + hello: "world" + }; t.is(x, x); + t.isNot(x, z); })); })); diff --git a/tests/assertions.test.res b/tests/assertions.test.res index 032b6c6..61385a6 100644 --- a/tests/assertions.test.res +++ b/tests/assertions.test.res @@ -9,7 +9,7 @@ zora("Test assertions", async t => { let z = {"hello": "world"} t->is(x, x, ~msg="object is object") t->is(x, y, ~msg="object is object") - t->isNot(x, z, "object is not object with same values") + t->isNot(x, z, ~msg="object is not object with same values") t->equal(x, z, ~msg="Object is deep equal") t->ok(true, "boolean is ok") t->notOk(false, "boolean is not ok") @@ -26,10 +26,9 @@ zora("Test assertions", async t => { t->equal(42, 42) t->notEqual(42, 43) let x = {"hello": "world"} - // let z = {"hello": "world"} + let z = {"hello": "world"} t->is(x, x) - // t->isNot(x, z) - // t->equal(x, z) + t->isNot(x, z) // t->ok(true) // t->notOk(false) // t->optionNone(None) From 263079847b048479899a9834d9586ad721021c91 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 6 May 2024 12:27:51 -0700 Subject: [PATCH 05/10] Port `ok` --- src/Zora.res | 6 +++--- tests/assertions.test.mjs | 1 + tests/assertions.test.res | 4 ++-- tests/multiple_blocking.test.res | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Zora.res b/src/Zora.res index 66634b2..9262bc3 100644 --- a/src/Zora.res +++ b/src/Zora.res @@ -21,12 +21,12 @@ type testMessage = string @send external notEqual: (t, 't, 't, ~msg: testMessage=?) => unit = "notEqual" @send external is: (t, 't, 't, ~msg: testMessage=?) => unit = "is" @send external isNot: (t, 't, 't, ~msg: testMessage=?) => unit = "isNot" -@send external ok: (t, bool, testMessage) => unit = "ok" +@send external ok: (t, bool, ~msg: testMessage=?) => unit = "ok" @send external notOk: (t, bool, testMessage) => unit = "notOk" @send external fail: (t, testMessage) => unit = "fail" let optionNone = (zora: t, actual: option<'a>, message: testMessage) => { - zora->ok(actual->Belt.Option.isNone, message) + zora->ok(actual->Belt.Option.isNone, ~msg=message) } let optionSome = (zora: t, actual: option<'a>, check: (t, 'a) => unit) => { switch actual { @@ -36,7 +36,7 @@ let optionSome = (zora: t, actual: option<'a>, check: (t, 'a) => unit) => { } let resultError = (zora: t, actual: Belt.Result.t<'a, 'b>, message: testMessage) => { - zora->ok(actual->Belt.Result.isError, message) + zora->ok(actual->Belt.Result.isError, ~msg=message) } let resultOk = (zora: t, actual: Belt.Result.t<'a, 'b>, check: (t, 'a) => unit) => { switch actual { diff --git a/tests/assertions.test.mjs b/tests/assertions.test.mjs index 08eb609..c92c044 100644 --- a/tests/assertions.test.mjs +++ b/tests/assertions.test.mjs @@ -46,6 +46,7 @@ Zora$1.test("Test assertions", (async function (t) { }; t.is(x, x); t.isNot(x, z); + t.ok(true); })); })); diff --git a/tests/assertions.test.res b/tests/assertions.test.res index 61385a6..90795c4 100644 --- a/tests/assertions.test.res +++ b/tests/assertions.test.res @@ -11,7 +11,7 @@ zora("Test assertions", async t => { t->is(x, y, ~msg="object is object") t->isNot(x, z, ~msg="object is not object with same values") t->equal(x, z, ~msg="Object is deep equal") - t->ok(true, "boolean is ok") + t->ok(true, ~msg="boolean is ok") t->notOk(false, "boolean is not ok") t->optionNone(None, "None is None") t->optionSome( @@ -29,7 +29,7 @@ zora("Test assertions", async t => { let z = {"hello": "world"} t->is(x, x) t->isNot(x, z) - // t->ok(true) + t->ok(true) // t->notOk(false) // t->optionNone(None) // t->optionSome(Some(x), (t, n) => t->equal(n["hello"], "world")) diff --git a/tests/multiple_blocking.test.res b/tests/multiple_blocking.test.res index 178f6cb..d01c591 100644 --- a/tests/multiple_blocking.test.res +++ b/tests/multiple_blocking.test.res @@ -2,7 +2,7 @@ open Zora zoraBlock("Should run some simple blocking tests", t => { t->block("should greet", t => { - t->ok(true, "hello world") + t->ok(true, ~msg="hello world") }) t->block("should answer question", t => { From 49f036c3ddff1a5c9ca6be42222556d7e7469239 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 6 May 2024 12:28:44 -0700 Subject: [PATCH 06/10] Port `notOk` --- src/Zora.res | 2 +- tests/assertions.test.mjs | 1 + tests/assertions.test.res | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Zora.res b/src/Zora.res index 9262bc3..309718d 100644 --- a/src/Zora.res +++ b/src/Zora.res @@ -22,7 +22,7 @@ type testMessage = string @send external is: (t, 't, 't, ~msg: testMessage=?) => unit = "is" @send external isNot: (t, 't, 't, ~msg: testMessage=?) => unit = "isNot" @send external ok: (t, bool, ~msg: testMessage=?) => unit = "ok" -@send external notOk: (t, bool, testMessage) => unit = "notOk" +@send external notOk: (t, bool, ~msg: testMessage=?) => unit = "notOk" @send external fail: (t, testMessage) => unit = "fail" let optionNone = (zora: t, actual: option<'a>, message: testMessage) => { diff --git a/tests/assertions.test.mjs b/tests/assertions.test.mjs index c92c044..7b23ff8 100644 --- a/tests/assertions.test.mjs +++ b/tests/assertions.test.mjs @@ -47,6 +47,7 @@ Zora$1.test("Test assertions", (async function (t) { t.is(x, x); t.isNot(x, z); t.ok(true); + t.notOk(false); })); })); diff --git a/tests/assertions.test.res b/tests/assertions.test.res index 90795c4..572b9b4 100644 --- a/tests/assertions.test.res +++ b/tests/assertions.test.res @@ -12,7 +12,7 @@ zora("Test assertions", async t => { t->isNot(x, z, ~msg="object is not object with same values") t->equal(x, z, ~msg="Object is deep equal") t->ok(true, ~msg="boolean is ok") - t->notOk(false, "boolean is not ok") + t->notOk(false, ~msg="boolean is not ok") t->optionNone(None, "None is None") t->optionSome( Some(x), @@ -30,7 +30,7 @@ zora("Test assertions", async t => { t->is(x, x) t->isNot(x, z) t->ok(true) - // t->notOk(false) + t->notOk(false) // t->optionNone(None) // t->optionSome(Some(x), (t, n) => t->equal(n["hello"], "world")) // t->resultError(Belt.Result.Error(x)) From 5d5d3fc289e001f80d3343dd5688a0f589e1ee79 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 6 May 2024 12:29:40 -0700 Subject: [PATCH 07/10] Port `fail` --- src/Zora.res | 6 +++--- tests/skip.test.res | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Zora.res b/src/Zora.res index 309718d..b1d971c 100644 --- a/src/Zora.res +++ b/src/Zora.res @@ -23,14 +23,14 @@ type testMessage = string @send external isNot: (t, 't, 't, ~msg: testMessage=?) => unit = "isNot" @send external ok: (t, bool, ~msg: testMessage=?) => unit = "ok" @send external notOk: (t, bool, ~msg: testMessage=?) => unit = "notOk" -@send external fail: (t, testMessage) => unit = "fail" +@send external fail: (t, ~msg: testMessage=?) => unit = "fail" let optionNone = (zora: t, actual: option<'a>, message: testMessage) => { zora->ok(actual->Belt.Option.isNone, ~msg=message) } let optionSome = (zora: t, actual: option<'a>, check: (t, 'a) => unit) => { switch actual { - | None => zora->fail("Expected Some value, got None") + | None => zora->fail(~msg="Expected Some value, got None") | Some(value) => zora->check(value) } } @@ -40,7 +40,7 @@ let resultError = (zora: t, actual: Belt.Result.t<'a, 'b>, message: testMessage) } let resultOk = (zora: t, actual: Belt.Result.t<'a, 'b>, check: (t, 'a) => unit) => { switch actual { - | Belt.Result.Error(_) => zora->fail("Expected ok value, got error") + | Belt.Result.Error(_) => zora->fail(~msg="Expected ok value, got error") | Belt.Result.Ok(value) => zora->check(value) } } diff --git a/tests/skip.test.res b/tests/skip.test.res index ec6c2ec..e1cadfe 100644 --- a/tests/skip.test.res +++ b/tests/skip.test.res @@ -2,10 +2,10 @@ open Zora zora("should skip some tests", async t => { t->skip("broken test", async t => { - t->fail("Test is broken") + t->fail(~msg="Test is broken") }) t->blockSkip("also broken", t => { - t->fail("Test is broken, too") + t->fail(~msg="Test is broken, too") }) }) From 823d947541c31c89c27b27e086b693bb42be08e1 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 6 May 2024 12:45:25 -0700 Subject: [PATCH 08/10] Port `optionNone` Along the way, move off of `Belt` and over to `Core`. --- README.md | 6 +++--- rescript.json | 4 +++- src/Zora.mjs | 14 +++++++++----- src/Zora.res | 17 ++++++++++------- tests/assertions.test.mjs | 1 + tests/assertions.test.res | 12 ++++++------ 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index e551986..ea0a945 100644 --- a/README.md +++ b/README.md @@ -320,7 +320,7 @@ for CI: This library models all the default assertions provided by Zora except for those dealing with raising exceptions, which don't map neatly to ReScript exceptions. There are additional bindings for checking if a ReScript `option` -is `Some()` or `None` or if a `Belt.Result` is `Ok()` or `Error()` and asserting +is `Some()` or `None` or if a `Result` is `Ok()` or `Error()` and asserting on the value therein. In the interest of avoiding bloat, I do not intend to add a lot of other @@ -344,8 +344,8 @@ zora("Test assertions", t => { t->notOk(false, "boolean is not ok") t->optionNone(None, "None is None") t->optionSome(Some(x), (t, n) => t->equal(n["hello"], "world", "option should be hello world")) - t->resultError(Belt.Result.Error(x), "Is Error Result") - t->resultOk(Belt.Result.Ok(x), (t, n) => t->equal(n["hello"], "world", "Is Ok Result")) + t->resultError(Error(x), "Is Error Result") + t->resultOk(Ok(x), (t, n) => t->equal(n["hello"], "world", "Is Ok Result")) }) ``` diff --git a/rescript.json b/rescript.json index 85878a6..bb46430 100644 --- a/rescript.json +++ b/rescript.json @@ -12,5 +12,7 @@ "package-specs": { "module": "esmodule", "in-source": true - } + }, + "bs-dependencies": ["@rescript/core"], + "bsc-flags": ["-open RescriptCore"] } diff --git a/src/Zora.mjs b/src/Zora.mjs index da90690..430557c 100644 --- a/src/Zora.mjs +++ b/src/Zora.mjs @@ -1,11 +1,15 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Belt_Option from "rescript/lib/es6/belt_Option.js"; -import * as Belt_Result from "rescript/lib/es6/belt_Result.js"; import * as Caml_option from "rescript/lib/es6/caml_option.js"; +import * as Core__Option from "@rescript/core/src/Core__Option.mjs"; +import * as Core__Result from "@rescript/core/src/Core__Result.mjs"; -function optionNone(zora, actual, message) { - zora.ok(Belt_Option.isNone(actual), message); +function optionNone(zora, actual, msg) { + if (msg !== undefined) { + zora.ok(Core__Option.isNone(actual), msg); + } else { + zora.ok(Core__Option.isNone(actual)); + } } function optionSome(zora, actual, check) { @@ -18,7 +22,7 @@ function optionSome(zora, actual, check) { } function resultError(zora, actual, message) { - zora.ok(Belt_Result.isError(actual), message); + zora.ok(Core__Result.isError(actual), message); } function resultOk(zora, actual, check) { diff --git a/src/Zora.res b/src/Zora.res index b1d971c..b6a1d56 100644 --- a/src/Zora.res +++ b/src/Zora.res @@ -25,8 +25,11 @@ type testMessage = string @send external notOk: (t, bool, ~msg: testMessage=?) => unit = "notOk" @send external fail: (t, ~msg: testMessage=?) => unit = "fail" -let optionNone = (zora: t, actual: option<'a>, message: testMessage) => { - zora->ok(actual->Belt.Option.isNone, ~msg=message) +let optionNone = (zora: t, actual: option<'a>, ~msg: option=?) => { + switch msg { + | Some(description) => zora->ok(actual->Option.isNone, ~msg=description) + | None => zora->ok(actual->Option.isNone) + } } let optionSome = (zora: t, actual: option<'a>, check: (t, 'a) => unit) => { switch actual { @@ -35,12 +38,12 @@ let optionSome = (zora: t, actual: option<'a>, check: (t, 'a) => unit) => { } } -let resultError = (zora: t, actual: Belt.Result.t<'a, 'b>, message: testMessage) => { - zora->ok(actual->Belt.Result.isError, ~msg=message) +let resultError = (zora: t, actual: result<'a, 'b>, message: testMessage) => { + zora->ok(actual->Result.isError, ~msg=message) } -let resultOk = (zora: t, actual: Belt.Result.t<'a, 'b>, check: (t, 'a) => unit) => { +let resultOk = (zora: t, actual: result<'a, 'b>, check: (t, 'a) => unit) => { switch actual { - | Belt.Result.Error(_) => zora->fail(~msg="Expected ok value, got error") - | Belt.Result.Ok(value) => zora->check(value) + | Error(_) => zora->fail(~msg="Expected ok value, got error") + | Ok(value) => zora->check(value) } } diff --git a/tests/assertions.test.mjs b/tests/assertions.test.mjs index 7b23ff8..f6c1f85 100644 --- a/tests/assertions.test.mjs +++ b/tests/assertions.test.mjs @@ -48,6 +48,7 @@ Zora$1.test("Test assertions", (async function (t) { t.isNot(x, z); t.ok(true); t.notOk(false); + return Zora.optionNone(t, undefined, undefined); })); })); diff --git a/tests/assertions.test.res b/tests/assertions.test.res index 572b9b4..a786ed8 100644 --- a/tests/assertions.test.res +++ b/tests/assertions.test.res @@ -13,13 +13,13 @@ zora("Test assertions", async t => { t->equal(x, z, ~msg="Object is deep equal") t->ok(true, ~msg="boolean is ok") t->notOk(false, ~msg="boolean is not ok") - t->optionNone(None, "None is None") + t->optionNone(None, ~msg="None is None") t->optionSome( Some(x), (t, n) => t->equal(n["hello"], "world", ~msg="option should be hello world"), ) - t->resultError(Belt.Result.Error(x), "Is Error Result") - t->resultOk(Belt.Result.Ok(x), (t, n) => t->equal(n["hello"], "world", ~msg="Is Ok Result")) + t->resultError(Error(x), "Is Error Result") + t->resultOk(Ok(x), (t, n) => t->equal(n["hello"], "world", ~msg="Is Ok Result")) }) t->test("Without descriptions", async t => { @@ -31,9 +31,9 @@ zora("Test assertions", async t => { t->isNot(x, z) t->ok(true) t->notOk(false) - // t->optionNone(None) + t->optionNone(None) // t->optionSome(Some(x), (t, n) => t->equal(n["hello"], "world")) - // t->resultError(Belt.Result.Error(x)) - // t->resultOk(Belt.Result.Ok(x), (t, n) => t->equal(n["hello"], "world")) + // t->resultError(Error(x)) + // t->resultOk(Ok(x), (t, n) => t->equal(n["hello"], "world")) }) }) From 56f5ac0bcd8f51a7322fdd08fee571a2f6340980 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 6 May 2024 12:51:28 -0700 Subject: [PATCH 09/10] Port `resultError` --- src/Zora.mjs | 8 ++++++-- src/Zora.res | 7 +++++-- tests/assertions.test.mjs | 6 +++++- tests/assertions.test.res | 8 ++++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Zora.mjs b/src/Zora.mjs index 430557c..b636f93 100644 --- a/src/Zora.mjs +++ b/src/Zora.mjs @@ -21,8 +21,12 @@ function optionSome(zora, actual, check) { } } -function resultError(zora, actual, message) { - zora.ok(Core__Result.isError(actual), message); +function resultError(zora, actual, msg) { + if (msg !== undefined) { + zora.ok(Core__Result.isError(actual), msg); + } else { + zora.ok(Core__Result.isError(actual)); + } } function resultOk(zora, actual, check) { diff --git a/src/Zora.res b/src/Zora.res index b6a1d56..3dfe37d 100644 --- a/src/Zora.res +++ b/src/Zora.res @@ -38,8 +38,11 @@ let optionSome = (zora: t, actual: option<'a>, check: (t, 'a) => unit) => { } } -let resultError = (zora: t, actual: result<'a, 'b>, message: testMessage) => { - zora->ok(actual->Result.isError, ~msg=message) +let resultError = (zora: t, actual: result<'a, 'b>, ~msg: option=?) => { + switch msg { + | Some(description) => zora->ok(actual->Result.isError, ~msg=description) + | None => zora->ok(actual->Result.isError) + } } let resultOk = (zora: t, actual: result<'a, 'b>, check: (t, 'a) => unit) => { switch actual { diff --git a/tests/assertions.test.mjs b/tests/assertions.test.mjs index f6c1f85..95e4e43 100644 --- a/tests/assertions.test.mjs +++ b/tests/assertions.test.mjs @@ -48,7 +48,11 @@ Zora$1.test("Test assertions", (async function (t) { t.isNot(x, z); t.ok(true); t.notOk(false); - return Zora.optionNone(t, undefined, undefined); + Zora.optionNone(t, undefined, undefined); + return Zora.resultError(t, { + TAG: "Error", + _0: x + }, undefined); })); })); diff --git a/tests/assertions.test.res b/tests/assertions.test.res index a786ed8..48f6ab5 100644 --- a/tests/assertions.test.res +++ b/tests/assertions.test.res @@ -18,7 +18,7 @@ zora("Test assertions", async t => { Some(x), (t, n) => t->equal(n["hello"], "world", ~msg="option should be hello world"), ) - t->resultError(Error(x), "Is Error Result") + t->resultError(Error(x), ~msg="Is Error Result") t->resultOk(Ok(x), (t, n) => t->equal(n["hello"], "world", ~msg="Is Ok Result")) }) @@ -32,8 +32,8 @@ zora("Test assertions", async t => { t->ok(true) t->notOk(false) t->optionNone(None) - // t->optionSome(Some(x), (t, n) => t->equal(n["hello"], "world")) - // t->resultError(Error(x)) - // t->resultOk(Ok(x), (t, n) => t->equal(n["hello"], "world")) + // optionSome has no ~msg. + t->resultError(Error(x)) + // resultOk has no ~msg. }) }) From b4110771470d63bb8cc1acfac1648bf77c0fed6a Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 6 May 2024 12:54:50 -0700 Subject: [PATCH 10/10] Normalize capitalization of types in failure message of `resultOk` as compared to `optionSome`. --- src/Zora.mjs | 2 +- src/Zora.res | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Zora.mjs b/src/Zora.mjs index b636f93..2b6e91b 100644 --- a/src/Zora.mjs +++ b/src/Zora.mjs @@ -33,7 +33,7 @@ function resultOk(zora, actual, check) { if (actual.TAG === "Ok") { return check(zora, actual._0); } - zora.fail("Expected ok value, got error"); + zora.fail("Expected Ok value, got Error"); } export { diff --git a/src/Zora.res b/src/Zora.res index 3dfe37d..d1181e1 100644 --- a/src/Zora.res +++ b/src/Zora.res @@ -46,7 +46,7 @@ let resultError = (zora: t, actual: result<'a, 'b>, ~msg: option=?) } let resultOk = (zora: t, actual: result<'a, 'b>, check: (t, 'a) => unit) => { switch actual { - | Error(_) => zora->fail(~msg="Expected ok value, got error") + | Error(_) => zora->fail(~msg="Expected Ok value, got Error") | Ok(value) => zora->check(value) } }