Skip to content

Commit

Permalink
Release 0.17.0 (#16)
Browse files Browse the repository at this point in the history
* Update stdlib and remove @? syntax

* Format project
  • Loading branch information
paulcadman authored Dec 20, 2024
1 parent 91d6b4d commit e2eb37a
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 58 deletions.
35 changes: 18 additions & 17 deletions Example.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ import Test.JuvixUnit open;
headMay {A} : List A -> Maybe A := map just >> head nothing;

tests : List Test :=
[ testCase "1 == 1" (expectEqual 1 1)
; testCase "2 > 1" (expectGreater 2 1)
; testCase "2 >= 1" (expectGreaterEqual 2 1)
; testCase "1 >= 1" (expectGreaterEqual 1 1)
; testCase "1 < 2" (expectLess 1 2)
; testCase "1 <= 2" (expectLessEqual 1 2)
; testCase "1 <= 1" (expectLessEqual 1 1)
; testCase "[1] == [1]" (expectEqual [1] [1])
; testCase "[2] > [1]" (expectGreater [2] [1])
; testCase "[2] >= [1]" (expectGreaterEqual [2] [1])
; testCase "[1] >= [1]" (expectGreaterEqual [1] [1])
; testCase "[1] < [2]" (expectLess [1] [2])
; testCase "[1] <= [2]" (expectLessEqual [1] [2])
; testCase "[1] <= [1]" (expectLessEqual [1] [1])
; testCase "length [1] == 1" (expectTrue (length [1] == 1))
; testCase "headMay [] is nothing" (expectNothing (headMay {Nat} []))
; testCase "headMay [1] is just 1" (expectJust 1 (headMay [1]))
[
testCase "1 == 1" (expectEqual 1 1);
testCase "2 > 1" (expectGreater 2 1);
testCase "2 >= 1" (expectGreaterEqual 2 1);
testCase "1 >= 1" (expectGreaterEqual 1 1);
testCase "1 < 2" (expectLess 1 2);
testCase "1 <= 2" (expectLessEqual 1 2);
testCase "1 <= 1" (expectLessEqual 1 1);
testCase "[1] == [1]" (expectEqual [1] [1]);
testCase "[2] > [1]" (expectGreater [2] [1]);
testCase "[2] >= [1]" (expectGreaterEqual [2] [1]);
testCase "[1] >= [1]" (expectGreaterEqual [1] [1]);
testCase "[1] < [2]" (expectLess [1] [2]);
testCase "[1] <= [2]" (expectLessEqual [1] [2]);
testCase "[1] <= [1]" (expectLessEqual [1] [1]);
testCase "length [1] == 1" (expectTrue (length [1] == 1));
testCase "headMay [] is nothing" (expectNothing (headMay {Nat} []));
testCase "headMay [1] is just 1" (expectJust 1 (headMay [1]));
];

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

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "test";
version := mkVersion 0 16 0;
dependencies := [github "anoma" "juvix-stdlib" "v0.8.0"];
version := mkVersion 0 17 0;
dependencies :=
[
github
"anoma"
"juvix-stdlib"
"ff6d964320d24e3e8010733afcd886a62a56dd70";
];
};
61 changes: 41 additions & 20 deletions Test/JuvixUnit.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,41 @@ isFail : Assertion -> Bool
| (fail _) := true;

type Test :=
testCase {
testCase@{
name : String;
assertion : Assertion
assertion : Assertion;
};

type TestSuite :=
testSuite {
testSuite@{
name : String;
tests : List Test
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));
in foldr λ {t acc := runTest t >>> acc} (printString "");
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 "'")
>>> 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;

Expand All @@ -48,27 +56,36 @@ 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);

assertGreater {A} {{Ord A}} (msg : String) (a1 a2 : A) : Assertion := failUnless msg (a1 > a2);
assertGreater {A} {{Ord A}} (msg : String) (a1 a2 : A) : Assertion :=
failUnless msg (a1 > a2);

assertGreaterEqual {A} {{Ord A}} (msg : String) (a1 a2 : A) : Assertion :=
failUnless msg (a1 >= a2);

assertLess {A} {{Ord A}} (msg : String) (a1 a2 : A) : Assertion := failUnless msg (a1 < a2);
assertLess {A} {{Ord A}} (msg : String) (a1 a2 : A) : Assertion :=
failUnless msg (a1 < a2);

assertLessEqual {A} {{Ord A}} (msg : String) (a1 a2 : A) : Assertion := failUnless msg (a1 <= a2);
assertLessEqual {A} {{Ord A}} (msg : String) (a1 a2 : A) : Assertion :=
failUnless msg (a1 <= a2);

mkExpectMsg {A} {{Show A}} (actual : A) (msg : String) (expected : A) : String :=
mkExpectMsg
{A} {{Show A}} (actual : A) (msg : String) (expected : A) : String :=
"Expected " ++str Show.show actual ++str msg ++str Show.show expected;

expectTrue (actual : Bool) : Assertion := assertTrue (mkExpectMsg actual " to be " true) actual;
expectTrue (actual : Bool) : Assertion :=
assertTrue (mkExpectMsg actual " to be " true) actual;

expectFalse (actual : Bool) : Assertion := assertFalse (mkExpectMsg actual " to be " false) actual;
expectFalse (actual : Bool) : Assertion :=
assertFalse (mkExpectMsg actual " to be " false) actual;

expectEqual {A} {{Eq A}} {{Show A}} (expected actual : A) : Assertion :=
assertEqual (mkExpectMsg actual " == " expected) expected actual;
Expand All @@ -86,7 +103,11 @@ expectLessEqual {A} {{Ord A}} {{Show A}} (expected actual : A) : Assertion :=
assertLessEqual (mkExpectMsg actual " <= " expected) expected actual;

expectJust {A} {{Show A}} (expected : A) (actual : Maybe A) : Assertion :=
assertJust (mkExpectMsg "nothing" " to be " ("just " ++str Show.show expected)) actual;
assertJust
(mkExpectMsg "nothing" " to be " ("just " ++str Show.show expected))
actual;

expectNothing {A} {{Show A}} (actual : Maybe A) : Assertion :=
assertNothing λ {x := mkExpectMsg ("just " ++str Show.show x) " to be " "nothing"} actual;
assertNothing
λ{x := mkExpectMsg ("just " ++str Show.show x) " to be " "nothing"}
actual;
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.7.
# This file was autogenerated by Juvix version 0.6.8.
# Do not edit this file manually.

version: 2
checksum: 23a0f87e39f0f9ccd59b37ed7bbcae0aaccb570430cefb42bc543699546dbac8
checksum: ffa729ccad4b69b2b7673deabeeb8d738b8a71b6887fff53c4cb45f61d757d09
dependencies:
- git:
name: anoma_juvix-stdlib
ref: 0080b1183ab55e5180e69bfc3987e4cd6edbc230
ref: ff6d964320d24e3e8010733afcd886a62a56dd70
url: https://github.com/anoma/juvix-stdlib
dependencies: []
11 changes: 9 additions & 2 deletions tests/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "tests";
dependencies := [path "../"; github "anoma" "juvix-stdlib" "v0.6.0"]
dependencies :=
[
path "../";
github
"anoma"
"juvix-stdlib"
"ff6d964320d24e3e8010733afcd886a62a56dd70";
];
};
11 changes: 6 additions & 5 deletions tests/TestFail.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ 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
"TestFail"
[
testCase "2 == 1" (assertEqual "2 /= 1" 2 1);
testCase "1 == 1" (assertEqual "1 /= 1" 1 1);
]);
5 changes: 1 addition & 4 deletions tests/TestPass.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ import Test.JuvixUnit open;

main : IO :=
runTestSuite
testSuite@?{
name := "TestPass";
tests := [testCase "1 == 1" (assertEqual "1 /= 1" 1 1)]
};
(testSuite "TestPass" [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.5.
# This file was autogenerated by Juvix version 0.6.8.
# Do not edit this file manually.

version: 2
checksum: 90b72165433d68bfe79b7b6a61b2b06165f41afd61444e1aba5d8ed32cb56439
checksum: 307e5ef4b3124c659fdc9906f641cf6360ccde31cab68b934bf4a65b0ba83b9d
dependencies:
- path: ../
dependencies:
- git:
name: anoma_juvix-stdlib
ref: 17a82dd466010b51924677b16a3f09a6c4c86a80
ref: ff6d964320d24e3e8010733afcd886a62a56dd70
url: https://github.com/anoma/juvix-stdlib
dependencies: []
- git:
name: anoma_juvix-stdlib
ref: 17a82dd466010b51924677b16a3f09a6c4c86a80
ref: ff6d964320d24e3e8010733afcd886a62a56dd70
url: https://github.com/anoma/juvix-stdlib
dependencies: []

0 comments on commit e2eb37a

Please sign in to comment.