Skip to content

Commit

Permalink
Update to latest stdlib and format (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman authored Jul 19, 2024
1 parent 4254b60 commit f7e8229
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 66 deletions.
12 changes: 3 additions & 9 deletions Example.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@ headMay {A} : List A -> Maybe A := map just >> head nothing;
tests : List Test :=
[ testCase "1 == 1" (assertEqual "1 /= 1" 1 1)
; testCase "[1] == [1]" (assertEqual "[1] /= [1]" [1] [1])
; testCase
"length [1] == 1"
(assertTrue "length [1] /= 1" (length [1] == 1))
; testCase "length [1] == 1" (assertTrue "length [1] /= 1" (length [1] == 1))
; testCase
"headMay [] is nothing"
(assertNothing
λ {xs := "expected nothing, got: " ++str Show.show xs}
(headMay {Nat} []))
; testCase
"headMay [1] is just"
(assertJust "expected just, got nothing" (headMay [1]))
(assertNothing λ {xs := "expected nothing, got: " ++str Show.show xs} (headMay {Nat} []))
; testCase "headMay [1] is just" (assertJust "expected just, got nothing" (headMay [1]))
];

main : IO := runTestSuite (testSuite "Example" tests);
13 changes: 5 additions & 8 deletions Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage
{name := "test";
version := mkVersion 0 11 0;
dependencies := [ github
"anoma"
"juvix-stdlib"
"v0.4.0"
]};
defaultPackage@?{
name := "test";
version := mkVersion 0 12 0;
dependencies := [github "anoma" "juvix-stdlib" "v0.5.0"]
};
36 changes: 10 additions & 26 deletions Test/JuvixUnit.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,33 @@ type TestSuite :=
tests : List Test
};

anyFail (suite : TestSuite) : Bool :=
any (Test.assertion >> isFail) (TestSuite.tests suite);
anyFail (suite : TestSuite) : Bool := any (Test.assertion >> isFail) (TestSuite.tests suite);

runTests : List Test -> IO :=
let
showAssertion : Assertion -> String
| pass := "OK"
| (fail msg) := "FAIL: " ++str msg;
runTest (t : Test) : IO :=
printStringLn
(Test.name t
++str "\t\t"
++str showAssertion (Test.assertion t));
printStringLn (Test.name t ++str "\t\t" ++str showAssertion (Test.assertion t));
in foldr λ {t acc := runTest t >>> acc} (printString "");

runTestSuite (suite : TestSuite) : IO :=
printStringLn
("Test suite '" ++str TestSuite.name suite ++str "'")
printStringLn ("Test suite '" ++str TestSuite.name suite ++str "'")
>>> runTests (TestSuite.tests suite)
>>> printStringLn
("All tests from test suite '"
++str TestSuite.name suite
++str "' complete")
>>> ite
(anyFail suite)
(Fail.failwith "Suite failed")
(printStringLn "Suite passed");
>>> printStringLn ("All tests from test suite '" ++str TestSuite.name suite ++str "' complete")
>>> ite (anyFail suite) (Fail.failwith "Suite failed") (printStringLn "Suite passed");

failWhen (msg : String) (b : Bool) : Assertion :=
ite b (fail msg) pass;
failWhen (msg : String) (b : Bool) : Assertion := ite b (fail msg) pass;

failUnless (msg : String) (b : Bool) : Assertion :=
failWhen msg (not b);
failUnless (msg : String) (b : Bool) : Assertion := failWhen msg (not b);

assertTrue : String -> Bool -> Assertion := failUnless;

assertFalse : String -> Bool -> Assertion := failWhen;

assertJust {A} (msg : String) : Maybe A -> Assertion :=
maybe (fail msg) (const pass);
assertJust {A} (msg : String) : Maybe A -> Assertion := maybe (fail msg) (const pass);

assertNothing {A} (mkMsg : A -> String)
: Maybe A -> Assertion := maybe pass (mkMsg >> fail);
assertNothing {A} (mkMsg : A -> String) : Maybe A -> Assertion := maybe pass (mkMsg >> fail);

assertEqual {A} {{Eq A}} (msg : String) (a1 a2 : A)
: Assertion := failUnless msg (a1 == a2);
assertEqual {A} {{Eq A}} (msg : String) (a1 a2 : A) : Assertion := failUnless msg (a1 == a2);
6 changes: 3 additions & 3 deletions juvix.lock.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This file was autogenerated by Juvix version 0.6.3.
# This file was autogenerated by Juvix version 0.6.4.
# Do not edit this file manually.

version: 2
checksum: 792ac5870f4193fd7a2ce6336e1cc664e91872f3984be33ee8f5981de39df018
checksum: ccfae54b08216f345ed4d42cf26fa111a95ae51d1171c611b86352af409ee561
dependencies:
- git:
name: anoma_juvix-stdlib
ref: 89a5960fb8a29291e9271986b98ca7b1edf4031b
ref: 16211500dc59a944f851fbaeeef703fdd09163fa
url: https://github.com/anoma/juvix-stdlib
dependencies: []
12 changes: 4 additions & 8 deletions tests/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage
{name := "tests";
dependencies := [ path "../"
; github
"anoma"
"juvix-stdlib"
"v0.4.0"
]};
defaultPackage@?{
name := "tests";
dependencies := [path "../"; github "anoma" "juvix-stdlib" "v0.5.0"]
};
10 changes: 5 additions & 5 deletions tests/TestFail.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Test.JuvixUnit open;

main : IO :=
runTestSuite
(testSuite
(name := "TestFail";
tests := [ testCase "2 == 1" (assertEqual "2 /= 1" 2 1)
; testCase "1 == 1" (assertEqual "1 /= 1" 1 1)
]));
testSuite@?{
name := "TestFail";
tests :=
[testCase "2 == 1" (assertEqual "2 /= 1" 2 1); testCase "1 == 1" (assertEqual "1 /= 1" 1 1)]
};
7 changes: 4 additions & 3 deletions tests/TestPass.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Test.JuvixUnit open;

main : IO :=
runTestSuite
(testSuite
(name := "TestPass";
tests := [testCase "1 == 1" (assertEqual "1 /= 1" 1 1)]));
testSuite@?{
name := "TestPass";
tests := [testCase "1 == 1" (assertEqual "1 /= 1" 1 1)]
};
8 changes: 4 additions & 4 deletions tests/juvix.lock.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# This file was autogenerated by Juvix version 0.6.3.
# This file was autogenerated by Juvix version 0.6.4.
# Do not edit this file manually.

version: 2
checksum: 217a59a792323e680e3389cb3ab31f3534004fbbc7f695d3d81f66be6d7e7c41
checksum: c18d1a5878618cd758cd7a371c641facc945dc4c4d4ea7831135a01fa84bf6be
dependencies:
- path: ../
dependencies:
- git:
name: anoma_juvix-stdlib
ref: 89a5960fb8a29291e9271986b98ca7b1edf4031b
ref: 16211500dc59a944f851fbaeeef703fdd09163fa
url: https://github.com/anoma/juvix-stdlib
dependencies: []
- git:
name: anoma_juvix-stdlib
ref: 89a5960fb8a29291e9271986b98ca7b1edf4031b
ref: 16211500dc59a944f851fbaeeef703fdd09163fa
url: https://github.com/anoma/juvix-stdlib
dependencies: []

0 comments on commit f7e8229

Please sign in to comment.