fixup testlib and add udp-tests.u to interpreter-tests.md

This commit is contained in:
Arya Irani 2024-04-02 01:15:21 -06:00
parent 1be5cf2d1d
commit 0f6246904e
3 changed files with 20 additions and 14 deletions

View File

@ -41,6 +41,11 @@ to `Tests.check` and `Tests.checkEqual`).
.> add
```
```ucm:hide
.> load unison-src/builtin-tests/udp-tests.u
.> add
```
```ucm:hide
.> load unison-src/builtin-tests/tls-chain-tests.u
.> add

View File

@ -1,18 +1,18 @@
unique ability Tests where
pass : Text -> ()
fail : Text -> Text -> ()
fail : Text -> Text -> ()
exception : Text -> Failure -> ()
Tests.check : Text -> '{g, Exception} Boolean ->{g, Tests} ()
Tests.check msg b =
match catch b with
Tests.check msg b =
match catch b with
Left e -> exception msg e
Right true -> pass msg
Right false -> fail msg ""
Tests.checkEqual : Text -> a -> a ->{Tests} ()
Tests.checkEqual msg a1 a2 =
Tests.checkEqual msg a1 a2 =
match catch '(a1 === a2) with
Left e -> exception msg e
Right true -> pass msg
@ -22,20 +22,20 @@ Tests.checkEqual msg a1 a2 =
Tests.main : '{IO,Exception,Tests} () -> '{IO,Exception} ()
Tests.main suite = do
if Tests.run suite then ()
else bug "test suite failed"
else bug "test suite failed"
Tests.run : '{IO,Exception,Tests} () ->{IO,Exception} Boolean
Tests.run suite =
use Nat +
h passed failed = cases
{ _ } -> (passed, failed)
{ pass msg -> k } ->
{ _ } -> (passed, failed)
{ pass msg -> k } ->
printLine (" ✅ " ++ msg)
handle !k with h (passed + 1) failed
{ fail msg reason -> k } ->
{ fail msg reason -> k } ->
printLine (" 🆘 " ++ msg ++ " " ++ reason)
handle !k with h passed (failed + 1)
{ exception msg failure@(Failure _ cause payload) -> k} ->
{ exception msg failure@(Failure _ cause payload) -> k} ->
printLine (" 💥 " ++ msg ++ " " ++ cause)
handle !k with h passed (failed + 1)
@ -43,16 +43,17 @@ Tests.run suite =
printLine "*** Test suite ***"
printLine ""
(passed, failed) = handle !suite with h 0 0
(passed, failed) = handle !suite with h 0 0
printLine ""
printLine ""
printLine "Summary of results:"
printLine ""
use Nat ==
if failed == 0 then
printLine (" ✅✅✅ " ++ Nat.toText passed ++ " PASSED")
else
printLine (" 🆘🆘🆘 " ++ Nat.toText failed ++ " FAILED, "
printLine (" 🆘🆘🆘 " ++ Nat.toText failed ++ " FAILED, "
++ Nat.toText passed ++ " passed")
failed == 0

View File

@ -41,7 +41,7 @@ testServerAndClient = do
setup = catchAll do
UDP.server goodIp goodPort
match setup with
Left e ->
Left e ->
Tests.fail "Unable to open a socket for UDP server" (Debug.evalToText e)
Right ssocket ->
serve = do
@ -52,7 +52,7 @@ testServerAndClient = do
serveResult = !Promise.new
_ = fork do Promise.write serveResult (catchAll serve)
data = catchAll do
csocket = UDP.client goodIp goodPort
send csocket (toUtf8 fromClientMsg)
@ -61,4 +61,4 @@ testServerAndClient = do
fromUtf8 d
checkEqual "Server received data" (Promise.read serveResult) (Right fromClientMsg)
checkEqual "Client received data" data (Right fromServerMsg)
checkEqual "Client received data" data (Right fromServerMsg)