From 3831af577bed5050eba7492a6e97a4f99dfe533b Mon Sep 17 00:00:00 2001 From: Lukasz Czajka Date: Mon, 4 Nov 2024 14:22:09 +0100 Subject: [PATCH 01/29] Revert "add test" This reverts commit 3b28dbd259789de3f185c52987770436cbab5eab. --- test/Compilation/Positive.hs | 7 +------ tests/Compilation/positive/out/test083.out | 1 - tests/Compilation/positive/test083.juvix | 13 ------------- 3 files changed, 1 insertion(+), 20 deletions(-) delete mode 100644 tests/Compilation/positive/out/test083.out delete mode 100644 tests/Compilation/positive/test083.juvix diff --git a/test/Compilation/Positive.hs b/test/Compilation/Positive.hs index b3cd1a9236..0885b6f9a6 100644 --- a/test/Compilation/Positive.hs +++ b/test/Compilation/Positive.hs @@ -485,10 +485,5 @@ tests = "Test082: Pattern matching with side conditions" $(mkRelDir ".") $(mkRelFile "test082.juvix") - $(mkRelFile "out/test082.out"), - posTest - "Test083: Record update" - $(mkRelDir ".") - $(mkRelFile "test083.juvix") - $(mkRelFile "out/test083.out") + $(mkRelFile "out/test082.out") ] diff --git a/tests/Compilation/positive/out/test083.out b/tests/Compilation/positive/out/test083.out deleted file mode 100644 index b1bd38b62a..0000000000 --- a/tests/Compilation/positive/out/test083.out +++ /dev/null @@ -1 +0,0 @@ -13 diff --git a/tests/Compilation/positive/test083.juvix b/tests/Compilation/positive/test083.juvix deleted file mode 100644 index 76bb0610cd..0000000000 --- a/tests/Compilation/positive/test083.juvix +++ /dev/null @@ -1,13 +0,0 @@ --- Record update -module test083; - -import Stdlib.Prelude open; - -type R := mkR@{ - x : Nat; - y : Nat; -}; - -f (r : R) : R := let x := 7 in r@R{x := R.x r + x; y := x}; - -main : Nat := case f (mkR 1 2) of mkR x y := x + 5; From 84786a247dfb3c1071d3bcb8ddc25ecd50aa49aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Czajka?= <62751+lukaszcz@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:31:30 +0100 Subject: [PATCH 02/29] Non-recursive definitions (#3138) * Closes #2968 * Implements detection of function-like definitions, which either: - have some arguments on the left of `:`, or - have at least one clause. * Only function-like definitions are recursive. * Non-recursive definitions are not mutually recursive either, and can be used only after their definition. This necessitates rearranging some definitions in existing Juvix code. * Changes the scoping of identifiers in record updates. Now field names on the right side don't refer to the old values of the record fields but to identifiers in scope defined outside the record update. To refer to old values, one needs to explicitly use record projections, e.g. ``` r@Rec{x := Rec.x r} ``` --- test/Compilation/Positive.hs | 7 ++++++- tests/Compilation/positive/out/test083.out | 1 + tests/Compilation/positive/test083.juvix | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/Compilation/positive/out/test083.out create mode 100644 tests/Compilation/positive/test083.juvix diff --git a/test/Compilation/Positive.hs b/test/Compilation/Positive.hs index 0885b6f9a6..b3cd1a9236 100644 --- a/test/Compilation/Positive.hs +++ b/test/Compilation/Positive.hs @@ -485,5 +485,10 @@ tests = "Test082: Pattern matching with side conditions" $(mkRelDir ".") $(mkRelFile "test082.juvix") - $(mkRelFile "out/test082.out") + $(mkRelFile "out/test082.out"), + posTest + "Test083: Record update" + $(mkRelDir ".") + $(mkRelFile "test083.juvix") + $(mkRelFile "out/test083.out") ] diff --git a/tests/Compilation/positive/out/test083.out b/tests/Compilation/positive/out/test083.out new file mode 100644 index 0000000000..b1bd38b62a --- /dev/null +++ b/tests/Compilation/positive/out/test083.out @@ -0,0 +1 @@ +13 diff --git a/tests/Compilation/positive/test083.juvix b/tests/Compilation/positive/test083.juvix new file mode 100644 index 0000000000..76bb0610cd --- /dev/null +++ b/tests/Compilation/positive/test083.juvix @@ -0,0 +1,13 @@ +-- Record update +module test083; + +import Stdlib.Prelude open; + +type R := mkR@{ + x : Nat; + y : Nat; +}; + +f (r : R) : R := let x := 7 in r@R{x := R.x r + x; y := x}; + +main : Nat := case f (mkR 1 2) of mkR x y := x + 5; From 88f3675060de693d089540981337698767c9e465 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Tue, 29 Oct 2024 16:23:18 +0100 Subject: [PATCH 03/29] anoma node tests --- src/Anoma/Effect/Base.hs | 36 +- src/Juvix/Data/Error/GenericError.hs | 7 + src/Juvix/Prelude/Base/Foundation.hs | 4 + test/Anoma/Compilation/Positive.hs | 1502 +++++++++++++++----------- test/Base.hs | 20 +- test/Nockma/Compile/Tree/Positive.hs | 10 +- test/Nockma/Eval/Positive.hs | 7 +- 7 files changed, 929 insertions(+), 657 deletions(-) diff --git a/src/Anoma/Effect/Base.hs b/src/Anoma/Effect/Base.hs index f35781c1f6..33fd9abe4e 100644 --- a/src/Anoma/Effect/Base.hs +++ b/src/Anoma/Effect/Base.hs @@ -7,8 +7,12 @@ module Anoma.Effect.Base noHalt, anomaRpc, AnomaPath (..), + AnomaProcesses (..), + anomaNodeHandle, + anomaClientHandle, anomaPath, runAnoma, + runAnomaTest, module Anoma.Rpc.Base, module Juvix.Compiler.Nockma.Translation.FromTree, ) @@ -23,13 +27,19 @@ import Juvix.Extra.Paths (anomaStartExs) import Juvix.Prelude import Juvix.Prelude.Aeson (Value, eitherDecodeStrict, encode) +data AnomaProcesses = AnomaProcesses + { _anomaNodeHandle :: ProcessHandle, + _anomaClientHandle :: ProcessHandle + } + data Anoma :: Effect where -- | Keep the node and client running - NoHalt :: Anoma m ExitCode + NoHalt :: Anoma m AnomaProcesses -- | grpc call AnomaRpc :: GrpcMethodUrl -> Value -> Anoma m Value makeSem ''Anoma +makeLenses ''AnomaProcesses newtype AnomaPath = AnomaPath {_anomaPath :: Path Abs Dir} @@ -106,7 +116,11 @@ withSpawnAnomaNode body = withSystemTempFile "start.exs" $ \fp tmpHandle -> do cwd = Just (toFilePath anomapath) } -anomaRpc' :: (Members '[Reader AnomaPath, Process, EmbedIO, Error SimpleError] r) => GrpcMethodUrl -> Value -> Sem r Value +anomaRpc' :: + (Members '[Reader AnomaPath, Process, EmbedIO, Error SimpleError] r) => + GrpcMethodUrl -> + Value -> + Sem r Value anomaRpc' method payload = do cproc <- grpcCliProcess method withCreateProcess cproc $ \mstdin mstdout _stderr _procHandle -> do @@ -141,11 +155,23 @@ grpcCliProcess method = do std_out = CreatePipe } +-- | Assumes the node and client are already running +runAnomaTest :: forall r a. (Members '[Logger, EmbedIO, Error SimpleError] r) => AnomaPath -> Sem (Anoma ': r) a -> Sem r a +runAnomaTest anomapath body = runReader anomapath . runProcess $ + (`interpret` inject body) $ \case + NoHalt -> error "unsupported" + AnomaRpc method i -> anomaRpc' method i + runAnoma :: forall r a. (Members '[Logger, EmbedIO, Error SimpleError] r) => AnomaPath -> Sem (Anoma ': r) a -> Sem r a -runAnoma anomapath body = runReader anomapath . runConcurrent . runProcess $ +runAnoma anomapath body = runReader anomapath . runProcess $ withSpawnAnomaNode $ \grpcport _nodeOut nodeH -> runReader (GrpcPort grpcport) $ - withSpawnAnomaClient $ \_clientH -> do + withSpawnAnomaClient $ \clientH -> do (`interpret` inject body) $ \case - NoHalt -> waitForProcess nodeH + NoHalt -> + waitForProcess nodeH + $> AnomaProcesses + { _anomaNodeHandle = nodeH, + _anomaClientHandle = clientH + } AnomaRpc method i -> anomaRpc' method i diff --git a/src/Juvix/Data/Error/GenericError.hs b/src/Juvix/Data/Error/GenericError.hs index 7dac8376e9..5dcfd19a79 100644 --- a/src/Juvix/Data/Error/GenericError.hs +++ b/src/Juvix/Data/Error/GenericError.hs @@ -120,3 +120,10 @@ runErrorIO' :: Sem (Error a ': r) b -> Sem r b runErrorIO' = runReader defaultGenericOptions . runErrorIO . raiseUnder + +runSimpleErrorIO :: (Members '[EmbedIO] r) => Sem (Error SimpleError ': r) a -> Sem r a +runSimpleErrorIO m = do + res <- runError m + case res of + Left (SimpleError msg) -> renderIO True msg >> exitFailure + Right r -> return r diff --git a/src/Juvix/Prelude/Base/Foundation.hs b/src/Juvix/Prelude/Base/Foundation.hs index 2698916a26..37d0fbf0dc 100644 --- a/src/Juvix/Prelude/Base/Foundation.hs +++ b/src/Juvix/Prelude/Base/Foundation.hs @@ -146,6 +146,7 @@ import Data.Int import Data.IntMap.Strict (IntMap) import Data.IntMap.Strict qualified as IntMap import Data.IntSet (IntSet) +import Data.IntSet qualified as IntSet import Data.Kind qualified as GHC import Data.List.Extra hiding (allSame, foldr1, groupSortOn, head, last, mconcatMap, replicate, unzip) import Data.List.Extra qualified as List @@ -729,6 +730,9 @@ uncurryF g input_ = uncurry g <$> input_ intMapToList :: IntMap a -> [Indexed a] intMapToList = map (uncurry Indexed) . IntMap.toList +intSet :: (Foldable f) => f (Int) -> IntSet +intSet = IntSet.fromList . toList + intMap :: (Foldable f) => f (Int, a) -> IntMap a intMap = IntMap.fromList . toList diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index 7e8aaca619..7375f51abc 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -1,7 +1,9 @@ -module Anoma.Compilation.Positive where +module Anoma.Compilation.Positive (allTests) where +import Anoma.Effect.Base +import Anoma.Effect.RunNockma import Base -import Data.HashMap.Strict qualified as HashMap +import Data.IntSet qualified as IntSet import Juvix.Compiler.Backend (Target (TargetAnoma)) import Juvix.Compiler.Nockma.Anoma import Juvix.Compiler.Nockma.Evaluator @@ -9,42 +11,116 @@ import Juvix.Compiler.Nockma.Language import Juvix.Compiler.Nockma.Translation.FromSource.QQ import Juvix.Compiler.Nockma.Translation.FromTree import Juvix.Prelude qualified as Prelude -import Nockma.Eval.Positive +import Nockma.Eval.Positive (Check, Test (..), eqNock, eqTraces) +import Nockma.Eval.Positive qualified as NockmaEval + +data AnomaTest = AnomaTest + { _anomaEnableDebug :: Bool, + _anomaProgramStorage :: Storage Natural, + _anomaTestNum :: Int, + _anomaTestTag :: Text, + _anomaRelRoot :: Prelude.Path Rel Dir, + _anomaMainFile :: Prelude.Path Rel File, + _anomaArgs :: [Term Natural], + _anomaCheck :: Check () + } root :: Prelude.Path Abs Dir root = relToProject $(mkRelDir "tests/Anoma/Compilation/positive") -mkAnomaCallTest' :: Bool -> Storage Natural -> Text -> Prelude.Path Rel Dir -> Prelude.Path Rel File -> [Term Natural] -> Check () -> TestTree -mkAnomaCallTest' enableDebug _testProgramStorage _testName relRoot mainFile args _testCheck = - testCase (unpack _testName) (mkTestIO >>= mkNockmaAssertion) +anomaTestName :: AnomaTest -> Text +anomaTestName AnomaTest {..} = numberedTestName _anomaTestNum _anomaTestTag + +fromAnomaTest :: AnomaTest -> TestTree +fromAnomaTest a@AnomaTest {..} = + testCase testname (mkTestIO >>= NockmaEval.mkNockmaAssertion) where + testname :: Text + testname = anomaTestName a + mkTestIO :: IO Test mkTestIO = do - anomaRes <- withRootCopy compileMain - let _testProgramFormula = anomaCall args + anomaRes <- withRootCopy (compileMain _anomaEnableDebug _anomaRelRoot _anomaMainFile) + let _testProgramFormula = anomaCall _anomaArgs _testProgramSubject = anomaRes ^. anomaClosure _testEvalOptions = defaultEvalOptions _testAssertEvalError :: Maybe (NockEvalError Natural -> Assertion) = Nothing - return Test {..} + return + Test + { _testName = testname, + _testCheck = _anomaCheck, + _testProgramStorage = _anomaProgramStorage, + .. + } - withRootCopy :: (Prelude.Path Abs Dir -> IO a) -> IO a - withRootCopy action = withSystemTempDir "test" $ \tmpRootDir -> do - copyDirRecur root tmpRootDir - action tmpRootDir +mkAnomaTest' :: + Bool -> + Storage Natural -> + Int -> + Text -> + Prelude.Path Rel Dir -> + Prelude.Path Rel File -> + [Term Natural] -> + Check () -> + AnomaTest +mkAnomaTest' _anomaEnableDebug _anomaProgramStorage _anomaTestNum _anomaTestTag _anomaRelRoot _anomaMainFile _anomaArgs _anomaCheck = + AnomaTest + { .. + } - compileMain :: Prelude.Path Abs Dir -> IO AnomaResult - compileMain rootCopyDir = do - let testRootDir = rootCopyDir relRoot - entryPoint <- - set entryPointTarget (Just TargetAnoma) . set entryPointDebug enableDebug - <$> testDefaultEntryPointIO testRootDir (testRootDir mainFile) - (^. pipelineResult) . snd <$> testRunIO entryPoint upToAnoma +testAnomaPath :: AnomaPath +testAnomaPath = AnomaPath $(mkAbsDir "/home/jan/anoma") -mkAnomaCallTestNoDebug :: Text -> Prelude.Path Rel Dir -> Prelude.Path Rel File -> [Term Natural] -> Check () -> TestTree -mkAnomaCallTestNoDebug = mkAnomaCallTest' False emptyStorage +mkAnomaNodeTest :: AnomaTest -> TestTree +mkAnomaNodeTest a@AnomaTest {..} = + testCase (anomaTestName a) assertion + where + assertion :: Assertion + assertion = do + program :: Term Natural <- (^. anomaClosure) <$> withRootCopy (compileMain False _anomaRelRoot _anomaMainFile) + runM + . ignoreLogger + . runSimpleErrorIO + . runAnomaTest testAnomaPath + $ do + out <- runNockma program _anomaArgs + runM + . runReader out + . runReader [] + $ _anomaCheck -mkAnomaCallTest :: Text -> Prelude.Path Rel Dir -> Prelude.Path Rel File -> [Term Natural] -> Check () -> TestTree -mkAnomaCallTest = mkAnomaCallTest' True emptyStorage +withRootCopy :: (Prelude.Path Abs Dir -> IO a) -> IO a +withRootCopy action = withSystemTempDir "test" $ \tmpRootDir -> do + copyDirRecur root tmpRootDir + action tmpRootDir + +compileMain :: Bool -> Prelude.Path Rel Dir -> Prelude.Path Rel File -> Prelude.Path Abs Dir -> IO AnomaResult +compileMain enableDebug relRoot mainFile rootCopyDir = do + let testRootDir = rootCopyDir relRoot + entryPoint <- + set entryPointTarget (Just TargetAnoma) . set entryPointDebug enableDebug + <$> testDefaultEntryPointIO testRootDir (testRootDir mainFile) + (^. pipelineResult) . snd <$> testRunIO entryPoint upToAnoma + +mkAnomaTestNoDebug :: + Int -> + Text -> + Prelude.Path Rel Dir -> + Prelude.Path Rel File -> + [Term Natural] -> + Check () -> + AnomaTest +mkAnomaTestNoDebug = mkAnomaTest' False emptyStorage + +mkAnomaTest :: + Int -> + Text -> + Prelude.Path Rel Dir -> + Prelude.Path Rel File -> + [Term Natural] -> + Check () -> + AnomaTest +mkAnomaTest = mkAnomaTest' True emptyStorage checkNatOutput :: [Natural] -> Check () checkNatOutput = checkOutput . fmap toNock @@ -56,627 +132,773 @@ checkOutput expected = case unsnoc expected of eqTraces xs eqNock x +anomaNodeValid :: IntSet +anomaNodeValid = + intSet + [ 1, + 2, + 5, + 8, + 10, + 16, + 17, + 18, + 19, + 24, + 26, + 31, + 36, + 37, + 38, + 40, + 41, + 45, + 46, + 47, + 50, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 62, + 64, + 65 + ] + allTests :: TestTree allTests = testGroup "Anoma positive tests" - [ mkAnomaCallTest - "Test001: Arithmetic operators" - $(mkRelDir ".") - $(mkRelFile "test001.juvix") - [nockNatLiteral 5] - (checkNatOutput [11]), - mkAnomaCallTest - "Test002: Arithmetic operators inside lambdas" - $(mkRelDir ".") - $(mkRelFile "test002.juvix") - [nockNatLiteral 2] - (checkNatOutput [11]), - mkAnomaCallTest - "Test003: Integer arithmetic" - $(mkRelDir ".") - $(mkRelFile "test003.juvix") - [] - (checkNatOutput [1, 4, 2, 4, 0]), - mkAnomaCallTestNoDebug - "Test003: Integer arithmetic - no debug" - $(mkRelDir ".") - $(mkRelFile "test003.juvix") - [] - (checkNatOutput [1, 4, 2, 4, 0]), - mkAnomaCallTest - "Test005: Higher-order functions" - $(mkRelDir ".") - $(mkRelFile "test005.juvix") - [nockNatLiteral 1] - (checkNatOutput [6]), - mkAnomaCallTest - "Test006: If-then-else and lazy boolean operators" - $(mkRelDir ".") - $(mkRelFile "test006.juvix") - [] - (checkOutput [[nock| 2 |], [nock| true |], [nock| false |]]), - mkAnomaCallTest - "Test007: Pattern matching and lambda-case" - $(mkRelDir ".") - $(mkRelFile "test007.juvix") - [] - $ do - let l :: Term Natural = [nock| [1 2 nil] |] - checkOutput [[nock| false |], [nock| true |], [nock| 0 |], [nock| [1 nil] |], [nock| 1 |], l, l], - mkAnomaCallTest - "Test008: Recursion" - $(mkRelDir ".") - $(mkRelFile "test008.juvix") - [nockNatLiteral 1000] - (eqNock [nock| 500500 |]), - mkAnomaCallTest - "Test009: Tail recursion" - $(mkRelDir ".") - $(mkRelFile "test009.juvix") - [nockNatLiteral 1000] - $ checkNatOutput [500500, 120, 3628800, 479001600], - mkAnomaCallTest - "Test010: Let" - $(mkRelDir ".") - $(mkRelFile "test010.juvix") - [] - (checkNatOutput [32]), - mkAnomaCallTest - "Test011: Tail recursion: Fibonacci numbers in linear time" - $(mkRelDir ".") - $(mkRelFile "test011.juvix") - [] - $ do - let fib10 :: Natural = 55 - fib100 :: Natural = 354224848179261915075 - fib1000 :: Natural = 43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875 - checkNatOutput [fib10, fib100, fib1000], - mkAnomaCallTest - "Test012: Trees" - $(mkRelDir ".") - $(mkRelFile "test012.juvix") - [nockNatLiteral 1000] - $ checkNatOutput - [ 13200200200, - 21320020020013200200200, - 3213200200200132002002002132002002001320020020021320020020013200200200, - 13213200200200132002002002132002002001320020020021320020020013200200200, - 21321320020020013200200200213200200200132002002002132002002001320020020013213200200200132002002002132002002001320020020021320020020013200200200 - ], - mkAnomaCallTest - "Test013: Functions returning functions with variable capture" - $(mkRelDir ".") - $(mkRelFile "test013.juvix") - [] - $ checkNatOutput [1, 0, 2, 5], - mkAnomaCallTest - "Test014: Arithmetic" - $(mkRelDir ".") - $(mkRelFile "test014.juvix") - [] - $ checkNatOutput [7, 17, 37, 31], - mkAnomaCallTest - "Test015: Local functions with free variables" - $(mkRelDir ".") - $(mkRelFile "test015.juvix") - [] - $ checkNatOutput [600, 25, 30, 45, 55, 16], - mkAnomaCallTest - "Test016: Recursion through higher-order functions" - $(mkRelDir ".") - $(mkRelFile "test016.juvix") - [] - $ checkNatOutput [55], - mkAnomaCallTest - "Test017: Tail recursion through higher-order functions" - $(mkRelDir ".") - $(mkRelFile "test017.juvix") - [nockNatLiteral 1000] - $ checkNatOutput [500500], - mkAnomaCallTest - "Test018: Higher-order functions and recursion" - $(mkRelDir ".") - $(mkRelFile "test018.juvix") - [] - $ checkNatOutput [11], - mkAnomaCallTest - "Test019: Self-application" - $(mkRelDir ".") - $(mkRelFile "test019.juvix") - [] - $ checkNatOutput [7], - mkAnomaCallTest - "Test020: Recursive functions: McCarthy's 91 function, subtraction by increments" - $(mkRelDir ".") - $(mkRelFile "test020.juvix") - [] - $ checkNatOutput [91, 91, 91, 91, 100, 6, 6, 400, 4000], - mkAnomaCallTest - "Test021: Fast exponentiation" - $(mkRelDir ".") - $(mkRelFile "test021.juvix") - [] - $ checkNatOutput [8, 2187, 48828125], - mkAnomaCallTest - "Test022: Lists" - $(mkRelDir ".") - $(mkRelFile "test022.juvix") - [nockNatLiteral 1000] - $ checkOutput - [ [nock| [10 9 8 7 6 5 4 3 2 1 nil] |], - [nock| [1 2 3 4 5 6 7 8 9 10 nil] |], - [nock| [10 9 8 7 6 nil] |], - [nock| [0 1 2 3 4 5 6 7 8 9 nil] |], - [nock| 500500 |], - [nock| 500500 |] - ], - mkAnomaCallTest - "Test023: Mutual recursion" - $(mkRelDir ".") - $(mkRelFile "test023.juvix") - [] - $ checkNatOutput [32, 869, 6385109], - mkAnomaCallTest - "Test024: Nested binders with variable capture" - $(mkRelDir ".") - $(mkRelFile "test024.juvix") - [] - $ checkNatOutput [6688], - mkAnomaCallTest - "Test025: Euclid's algorithm" - $(mkRelDir ".") - $(mkRelFile "test025.juvix") - [] - $ checkNatOutput [14, 70, 1, 1, 1], - mkAnomaCallTest - "Test026: Functional queues" - $(mkRelDir ".") - $(mkRelFile "test026.juvix") - [] - $ checkOutput [makeList (toNock @Natural <$> [1 .. 100])], - -- TODO allow lambda branches of different number of patterns - -- mkAnomaCallTest - -- "Test027: Church numerals" - -- $(mkRelDir ".") - -- $(mkRelFile "test027.juvix") - -- [] - -- $ checkNatOutput [7, 10, 21], - mkAnomaCallTest - "Test028: Streams without memoization" - $(mkRelDir ".") - $(mkRelFile "test028.juvix") - [nockNatLiteral 10, nockNatLiteral 50] - $ checkNatOutput [31, 233], - mkAnomaCallTest - "Test029: Ackermann function" - $(mkRelDir ".") - $(mkRelFile "test029.juvix") - [] - $ checkNatOutput [8, 9, 15, 17, 29], - mkAnomaCallTest - "Test030: Ackermann function (higher-order definition)" - $(mkRelDir ".") - $(mkRelFile "test030.juvix") - [] - $ checkNatOutput [10, 21, 2187, 15], - mkAnomaCallTest - "Test031: Nested lists" - $(mkRelDir ".") - $(mkRelFile "test031.juvix") - [] - $ checkOutput [[nock| [4 3 2 1 3 2 1 2 1 1 nil ] |]], - mkAnomaCallTest - "Test032: Merge sort" - $(mkRelDir ".") - $(mkRelFile "test032.juvix") - [] - $ do - let l = makeList (toNock @Natural <$> [2 .. 11]) - checkOutput [l, l, l], - mkAnomaCallTest - "Test033: Eta-expansion of builtins and constructors" - $(mkRelDir ".") - $(mkRelFile "test033.juvix") - [] - $ checkOutput - [ [nock| 9 |], - [nock| [7 2] |], - [nock| 5 |], - [nock| [3 2] |], - [nock| [1 2] |] - ], - mkAnomaCallTest - "Test034: Recursive let" - $(mkRelDir ".") - $(mkRelFile "test034.juvix") - [] - $ checkNatOutput [500500, 32, 869, 41, 85], - mkAnomaCallTest - "Test035: Pattern matching" - $(mkRelDir ".") - $(mkRelFile "test035.juvix") - [] - $ checkOutput - [ [nock| [9 7 5 3 1 nil] |], - [nock| 300 |], - [nock| 4160 |], - [nock| 2336 |], - [nock| 1 |], - [nock| 0 |] - ], - mkAnomaCallTest - "Test036: Eta-expansion" - $(mkRelDir ".") - $(mkRelFile "test036.juvix") - [] - $ checkNatOutput [18], - mkAnomaCallTest - "Test037: Applications with lets and cases in function position" - $(mkRelDir ".") - $(mkRelFile "test037.juvix") - [] - $ checkNatOutput [9], - mkAnomaCallTest - "Test038: Simple case expression" - $(mkRelDir ".") - $(mkRelFile "test038.juvix") - [] - $ checkNatOutput [1], - mkAnomaCallTest - "Test039: Mutually recursive let expression" - $(mkRelDir ".") - $(mkRelFile "test039.juvix") - [] - $ checkOutput [[nock| false |], [nock| true |]], - mkAnomaCallTest - "Test040: Pattern matching nullary constructor" - $(mkRelDir ".") - $(mkRelFile "test040.juvix") - [] - $ checkOutput [[nock| true |]], - mkAnomaCallTest - "Test041: Use a builtin inductive in an inductive constructor" - $(mkRelDir ".") - $(mkRelFile "test041.juvix") - [] - $ checkNatOutput [6], - mkAnomaCallTest - "Test043: Builtin trace" - $(mkRelDir ".") - $(mkRelFile "test043.juvix") - [] - $ checkNatOutput [0, 1], - mkAnomaCallTest - "Test046: Polymorphic type arguments" - $(mkRelDir ".") - $(mkRelFile "test046.juvix") - [] - $ checkNatOutput [7], - mkAnomaCallTest - "Test047: Local Modules" - $(mkRelDir ".") - $(mkRelFile "test047.juvix") - [] - $ checkNatOutput [660], - mkAnomaCallTest - "Test049: Builtin Int" - $(mkRelDir ".") - $(mkRelFile "test049.juvix") - [] - $ checkOutput - [ [nock| 1 |], - [nock| 1 |], - [nock| 0 |], - [nock| 1|], - [nock| 1 |], - [nock| false |], - [nock| 1|], - [nock| 1 |], - [nock| 4 |], - [nock| true |], - [nock| false |], - [nock| false |], - [nock| true |], - [nock| true |], - [nock| true |], - [nock| 1|], - [nock| 2|] - ], - mkAnomaCallTest - "Test050: Pattern matching with integers" - $(mkRelDir ".") - $(mkRelFile "test050.juvix") - [] - $ checkNatOutput [11], - mkAnomaCallTest - "Test052: Simple lambda calculus" - $(mkRelDir ".") - $(mkRelFile "test052.juvix") - [] - $ checkOutput [[nock| [15 nil] |]], - mkAnomaCallTest - "Test053: Inlining" - $(mkRelDir ".") - $(mkRelFile "test053.juvix") - [] - $ checkNatOutput [21], - mkAnomaCallTest - "Test054: Iterators" - $(mkRelDir ".") - $(mkRelFile "test054.juvix") - [] - $ checkNatOutput [189], - mkAnomaCallTest - "Test055: Constructor printing" - $(mkRelDir ".") - $(mkRelFile "test055.juvix") - [] - $ checkOutput - [[nock| [[[[1 2] 3] [[2 3] 4] nil] [1 2] [2 3] nil] |]], - mkAnomaCallTest - "Test056: Argument specialization" - $(mkRelDir ".") - $(mkRelFile "test056.juvix") - [] - $ checkNatOutput [69], - mkAnomaCallTest - "Test057: Case folding" - $(mkRelDir ".") - $(mkRelFile "test057.juvix") - [] - $ checkNatOutput [8], - mkAnomaCallTest - "Test058: Ranges" - $(mkRelDir ".") - $(mkRelFile "test058.juvix") - [] - $ checkNatOutput [7550], - mkAnomaCallTest - "Test059: Builtin list" - $(mkRelDir ".") - $(mkRelFile "test059.juvix") - [] - $ checkNatOutput [11], - mkAnomaCallTest - "Test060: Record update" - $(mkRelDir ".") - $(mkRelFile "test060.juvix") - [] - $ checkOutput [[nock| [30 10 2] |]], - mkAnomaCallTest - "Test061: Traits" - $(mkRelDir ".") - $(mkRelFile "test061.juvix") - [] - $ checkNatOutput [1, 0, 3, 5, 1, 6, 5, 3, 1, 1, 6, 1, 3], - mkAnomaCallTest - "Test062: Overapplication" - $(mkRelDir ".") - $(mkRelFile "test062.juvix") - [] - $ checkNatOutput [1], - mkAnomaCallTest - "Test063: Coercions" - $(mkRelDir ".") - $(mkRelFile "test063.juvix") - [] - $ checkNatOutput [0, 1, 2, 300, 4, 5, 6, 7], - mkAnomaCallTest - "Test064: Constant folding" - $(mkRelDir ".") - $(mkRelFile "test064.juvix") - [] - $ checkNatOutput [37], - mkAnomaCallTest - "Test065: Arithmetic simplification" - $(mkRelDir ".") - $(mkRelFile "test065.juvix") - [] - $ checkNatOutput [42], - mkAnomaCallTest - "Test066: Import function with a function call in default argument" - $(mkRelDir "test066") - $(mkRelFile "M.juvix") - [] - $ checkNatOutput [0], - mkAnomaCallTest - "Test067: Dependent default values inserted during translation FromConcrete" - $(mkRelDir ".") - $(mkRelFile "test067.juvix") - [] - $ checkNatOutput [30], - mkAnomaCallTest - "Test068: Dependent default values inserted in the arity checker" - $(mkRelDir ".") - $(mkRelFile "test068.juvix") - [] - $ checkNatOutput [30], - mkAnomaCallTest - "Test069: Dependent default values for Ord trait" - $(mkRelDir ".") - $(mkRelFile "test069.juvix") - [] - $ checkOutput [[nock| true |]], - mkAnomaCallTest - "Test070: Nested default values and named arguments" - $(mkRelDir ".") - $(mkRelFile "test070.juvix") - [] - $ checkNatOutput [1463], - mkAnomaCallTest - "Test071: Named application (Ord instance with default cmp)" - $(mkRelDir ".") - $(mkRelFile "test071.juvix") - [] - $ checkNatOutput [1528], - mkAnomaCallTest - "Test072: Monad transformers (ReaderT + StateT + Identity)" - $(mkRelDir "test072") - $(mkRelFile "ReaderT.juvix") - [] - $ checkNatOutput [10], - mkAnomaCallTest - "Test073: Import and use a syntax alias" - $(mkRelDir "test073") - $(mkRelFile "test073.juvix") - [] - $ checkNatOutput [11], - let k1 :: Term Natural = [nock| 333 |] - v1 :: Term Natural = [nock| 222 |] - k2 :: Term Natural = [nock| [1 2 3 nil] |] - v2 :: Term Natural = [nock| [4 5 6 nil] |] - -- The keys of the storage are of the form [id key nil]. - -- The id is captured from the arguments tuple of the function. - sk1 :: Term Natural = [nock| [[333 1 2 3 nil] 333 nil] |] - sk2 :: Term Natural = [nock| [[333 1 2 3 nil] [1 2 3 nil] nil] |] - in mkAnomaCallTest' - True - ( Storage - ( HashMap.fromList - [ (StorageKey sk1, v1), - (StorageKey sk2, v2) - ] - ) - ) - "Test074: Builtin anomaGet" - $(mkRelDir ".") - $(mkRelFile "test074.juvix") - [OpQuote # k1, OpQuote # k2] - $ checkOutput [v1, v2], - mkAnomaCallTest - "Test075: Anoma encode" - $(mkRelDir ".") - $(mkRelFile "test075.juvix") - [] - $ checkNatOutput [2, 84081, 4657, 12], - mkAnomaCallTest - "Test076: Anoma decode" - $(mkRelDir ".") - $(mkRelFile "test076.juvix") - [] - $ checkOutput - [ [nock| 0 |], - [nock| [1 2 0] |], - [nock| [1 2] |], - [nock| false |] - ], - mkAnomaCallTest - "Test077: Anoma verify-detached" - $(mkRelDir ".") - $(mkRelFile "test077.juvix") - [] - $ checkOutput - [ [nock| 64 |], - [nock| true |] - ], - let toSignAndVerify :: Term Natural = [nock| [1 2 nil] |] - in mkAnomaCallTest - "Test078: Anoma sign and verify" - $(mkRelDir ".") - $(mkRelFile "test078.juvix") - [OpQuote # toSignAndVerify] - $ checkOutput - [toSignAndVerify], - let inputStr :: Term Natural = [nock| "Juvix!" |] - in mkAnomaCallTest - "Test079: Strings" - $(mkRelDir ".") - $(mkRelFile "test079.juvix") - [OpQuote # inputStr] - $ checkOutput [[nock| "Juvix! ✨ héllo world ✨" |]], - mkAnomaCallTest - "Test080: Maybe" - $(mkRelDir ".") - $(mkRelFile "test080.juvix") - [] - $ checkOutput - [ [nock| [nil 1] |], - [nock| 2 |], - [nock| 3 |], - [nock| nil |] - ], - mkAnomaCallTest - "Test081: UInt8" - $(mkRelDir ".") - $(mkRelFile "test081.juvix") - [] - $ checkOutput - [ [nock| 1 |], - [nock| 255 |], - [nock| 2 |], - [nock| true |], - [nock| true |], - [nock| false |], - [nock| 1 |], - [nock| 238 |], - [nock| 3 |], - [nock| 240 |], - [nock| [1 238 3 2 nil] |] - ], - mkAnomaCallTest - "Test082: ByteArray" - $(mkRelDir ".") - $(mkRelFile "test082.juvix") - [] - $ checkOutput - [ [nock| 0 |], - [nock| [0 0] |], - [nock| 3 |], - [nock| [3 0] |], - [nock| 4 |], - [nock| [4 1] |], - [nock| 2 |], - [nock| [2 258] |], - [nock| 1 |], - [nock| [1 0] |] - ], - mkAnomaCallTest - "Test083: Anoma ByteArray" - $(mkRelDir ".") - $(mkRelFile "test083.juvix") - [] - $ checkOutput - [ [nock| [[0 0] 0] |], - [nock| [[3 0] 0] |], - [nock| [[4 1] 1] |], - [nock| [[2 258] 258] |], - [nock| [[1 0] 0] |] - ], - mkAnomaCallTest - "Test084: Anoma Sha256" - $(mkRelDir ".") - $(mkRelFile "test084.juvix") - [] - $ checkOutput - [ [nock| 64 |], - [nock| + [ haskellNockmaTests, + anomaNodeTests + ] + where + anomaNodeTests :: TestTree + anomaNodeTests = + testGroup + "Anoma positive tests (Anoma node evaluator)" + (map mkAnomaNodeTest (filter isAnomaNodeValid anomaTests)) + where + isAnomaNodeValid :: AnomaTest -> Bool + isAnomaNodeValid AnomaTest {..} = IntSet.member _anomaTestNum anomaNodeValid + + haskellNockmaTests :: TestTree + haskellNockmaTests = + testGroup + "Anoma positive tests (Haskell evaluator)" + (map fromAnomaTest anomaTests) + + anomaTests :: [AnomaTest] + anomaTests = + [ mkAnomaTest + 1 + "Arithmetic operators" + $(mkRelDir ".") + $(mkRelFile "test001.juvix") + [nockNatLiteral 5] + (checkNatOutput [11]), + mkAnomaTest + 2 + "Arithmetic operators inside lambdas" + $(mkRelDir ".") + $(mkRelFile "test002.juvix") + [nockNatLiteral 2] + (checkNatOutput [11]), + mkAnomaTest + 3 + "Integer arithmetic" + $(mkRelDir ".") + $(mkRelFile "test003.juvix") + [] + (checkNatOutput [1, 4, 2, 4, 0]), + mkAnomaTestNoDebug + 3 + "Integer arithmetic - no debug" + $(mkRelDir ".") + $(mkRelFile "test003.juvix") + [] + (checkNatOutput [1, 4, 2, 4, 0]), + mkAnomaTest + 5 + "Higher-order functions" + $(mkRelDir ".") + $(mkRelFile "test005.juvix") + [nockNatLiteral 1] + (checkNatOutput [6]), + mkAnomaTest + 6 + "If-then-else and lazy boolean operators" + $(mkRelDir ".") + $(mkRelFile "test006.juvix") + [] + (checkOutput [[nock| 2 |], [nock| true |], [nock| false |]]), + mkAnomaTest + 7 + "Pattern matching and lambda-case" + $(mkRelDir ".") + $(mkRelFile "test007.juvix") + [] + $ do + let l :: Term Natural = [nock| [1 2 nil] |] + checkOutput [[nock| false |], [nock| true |], [nock| 0 |], [nock| [1 nil] |], [nock| 1 |], l, l], + mkAnomaTest + 8 + "Recursion" + $(mkRelDir ".") + $(mkRelFile "test008.juvix") + [nockNatLiteral 1000] + (eqNock [nock| 500500 |]), + mkAnomaTest + 9 + "Tail recursion" + $(mkRelDir ".") + $(mkRelFile "test009.juvix") + [nockNatLiteral 1000] + $ checkNatOutput [500500, 120, 3628800, 479001600], + mkAnomaTest + 10 + "Let" + $(mkRelDir ".") + $(mkRelFile "test010.juvix") + [] + (checkNatOutput [32]), + mkAnomaTest + 11 + "Tail recursion: Fibonacci numbers in linear time" + $(mkRelDir ".") + $(mkRelFile "test011.juvix") + [] + $ do + let fib10 :: Natural = 55 + fib100 :: Natural = 354224848179261915075 + fib1000 :: Natural = 43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875 + checkNatOutput [fib10, fib100, fib1000], + mkAnomaTest + 12 + "Trees" + $(mkRelDir ".") + $(mkRelFile "test012.juvix") + [nockNatLiteral 1000] + $ checkNatOutput + [ 13200200200, + 21320020020013200200200, + 3213200200200132002002002132002002001320020020021320020020013200200200, + 13213200200200132002002002132002002001320020020021320020020013200200200, + 21321320020020013200200200213200200200132002002002132002002001320020020013213200200200132002002002132002002001320020020021320020020013200200200 + ], + mkAnomaTest + 13 + "Functions returning functions with variable capture" + $(mkRelDir ".") + $(mkRelFile "test013.juvix") + [] + $ checkNatOutput [1, 0, 2, 5], + mkAnomaTest + 14 + "Arithmetic" + $(mkRelDir ".") + $(mkRelFile "test014.juvix") + [] + $ checkNatOutput [7, 17, 37, 31], + mkAnomaTest + 15 + "Local functions with free variables" + $(mkRelDir ".") + $(mkRelFile "test015.juvix") + [] + $ checkNatOutput [600, 25, 30, 45, 55, 16], + mkAnomaTest + 16 + "Recursion through higher-order functions" + $(mkRelDir ".") + $(mkRelFile "test016.juvix") + [] + $ checkNatOutput [55], + mkAnomaTest + 17 + "Tail recursion through higher-order functions" + $(mkRelDir ".") + $(mkRelFile "test017.juvix") + [nockNatLiteral 1000] + $ checkNatOutput [500500], + mkAnomaTest + 18 + "Higher-order functions and recursion" + $(mkRelDir ".") + $(mkRelFile "test018.juvix") + [] + $ checkNatOutput [11], + mkAnomaTest + 19 + "Self-application" + $(mkRelDir ".") + $(mkRelFile "test019.juvix") + [] + $ checkNatOutput [7], + mkAnomaTest + 20 + "Recursive functions: McCarthy's 91 function, subtraction by increments" + $(mkRelDir ".") + $(mkRelFile "test020.juvix") + [] + $ checkNatOutput [91, 91, 91, 91, 100, 6, 6, 400, 4000], + mkAnomaTest + 21 + "Fast exponentiation" + $(mkRelDir ".") + $(mkRelFile "test021.juvix") + [] + $ checkNatOutput [8, 2187, 48828125], + mkAnomaTest + 22 + "Lists" + $(mkRelDir ".") + $(mkRelFile "test022.juvix") + [nockNatLiteral 1000] + $ checkOutput + [ [nock| [10 9 8 7 6 5 4 3 2 1 nil] |], + [nock| [1 2 3 4 5 6 7 8 9 10 nil] |], + [nock| [10 9 8 7 6 nil] |], + [nock| [0 1 2 3 4 5 6 7 8 9 nil] |], + [nock| 500500 |], + [nock| 500500 |] + ], + mkAnomaTest + 23 + "Mutual recursion" + $(mkRelDir ".") + $(mkRelFile "test023.juvix") + [] + $ checkNatOutput [32, 869, 6385109], + mkAnomaTest + 24 + "Nested binders with variable capture" + $(mkRelDir ".") + $(mkRelFile "test024.juvix") + [] + $ checkNatOutput [6688], + mkAnomaTest + 25 + "Euclid's algorithm" + $(mkRelDir ".") + $(mkRelFile "test025.juvix") + [] + $ checkNatOutput [14, 70, 1, 1, 1], + mkAnomaTest + 26 + "Functional queues" + $(mkRelDir ".") + $(mkRelFile "test026.juvix") + [] + $ checkOutput [makeList (toNock @Natural <$> [1 .. 100])], + -- TODO allow lambda branches of different number of patterns + -- mkAnomaTest + -- "Test027: Church numerals" + -- $(mkRelDir ".") + -- $(mkRelFile "test027.juvix") + -- [] + -- $ checkNatOutput [7, 10, 21], + mkAnomaTest + 28 + "Streams without memoization" + $(mkRelDir ".") + $(mkRelFile "test028.juvix") + [nockNatLiteral 10, nockNatLiteral 50] + $ checkNatOutput [31, 233], + mkAnomaTest + 29 + "Ackermann function" + $(mkRelDir ".") + $(mkRelFile "test029.juvix") + [] + $ checkNatOutput [8, 9, 15, 17, 29], + mkAnomaTest + 30 + "Ackermann function (higher-order definition)" + $(mkRelDir ".") + $(mkRelFile "test030.juvix") + [] + $ checkNatOutput [10, 21, 2187, 15], + mkAnomaTest + 31 + "Nested lists" + $(mkRelDir ".") + $(mkRelFile "test031.juvix") + [] + $ checkOutput [[nock| [4 3 2 1 3 2 1 2 1 1 nil ] |]], + mkAnomaTest + 32 + "Merge sort" + $(mkRelDir ".") + $(mkRelFile "test032.juvix") + [] + $ do + let l = makeList (toNock @Natural <$> [2 .. 11]) + checkOutput [l, l, l], + mkAnomaTest + 33 + "Eta-expansion of builtins and constructors" + $(mkRelDir ".") + $(mkRelFile "test033.juvix") + [] + $ checkOutput + [ [nock| 9 |], + [nock| [7 2] |], + [nock| 5 |], + [nock| [3 2] |], + [nock| [1 2] |] + ], + mkAnomaTest + 34 + "Recursive let" + $(mkRelDir ".") + $(mkRelFile "test034.juvix") + [] + $ checkNatOutput [500500, 32, 869, 41, 85], + mkAnomaTest + 35 + "Pattern matching" + $(mkRelDir ".") + $(mkRelFile "test035.juvix") + [] + $ checkOutput + [ [nock| [9 7 5 3 1 nil] |], + [nock| 300 |], + [nock| 4160 |], + [nock| 2336 |], + [nock| 1 |], + [nock| 0 |] + ], + mkAnomaTest + 36 + "Eta-expansion" + $(mkRelDir ".") + $(mkRelFile "test036.juvix") + [] + $ checkNatOutput [18], + mkAnomaTest + 37 + "Applications with lets and cases in function position" + $(mkRelDir ".") + $(mkRelFile "test037.juvix") + [] + $ checkNatOutput [9], + mkAnomaTest + 38 + "Simple case expression" + $(mkRelDir ".") + $(mkRelFile "test038.juvix") + [] + $ checkNatOutput [1], + mkAnomaTest + 39 + "Mutually recursive let expression" + $(mkRelDir ".") + $(mkRelFile "test039.juvix") + [] + $ checkOutput [[nock| false |], [nock| true |]], + mkAnomaTest + 40 + "Pattern matching nullary constructor" + $(mkRelDir ".") + $(mkRelFile "test040.juvix") + [] + $ checkOutput [[nock| true |]], + mkAnomaTest + 41 + "Use a builtin inductive in an inductive constructor" + $(mkRelDir ".") + $(mkRelFile "test041.juvix") + [] + $ checkNatOutput [6], + mkAnomaTest + 43 + "Builtin trace" + $(mkRelDir ".") + $(mkRelFile "test043.juvix") + [] + $ checkNatOutput [0, 1], + mkAnomaTest + 45 + "Implicit builtin bool" + $(mkRelDir ".") + $(mkRelFile "test045.juvix") + [] + $ checkNatOutput [4], + mkAnomaTest + 46 + "Polymorphic type arguments" + $(mkRelDir ".") + $(mkRelFile "test046.juvix") + [] + $ checkNatOutput [7], + mkAnomaTest + 47 + "Local Modules" + $(mkRelDir ".") + $(mkRelFile "test047.juvix") + [] + $ checkNatOutput [660], + mkAnomaTest + 49 + "Builtin Int" + $(mkRelDir ".") + $(mkRelFile "test049.juvix") + [] + $ checkOutput + [ [nock| 1 |], + [nock| 1 |], + [nock| 0 |], + [nock| 1|], + [nock| 1 |], + [nock| false |], + [nock| 1|], + [nock| 1 |], + [nock| 4 |], + [nock| true |], + [nock| false |], + [nock| false |], + [nock| true |], + [nock| true |], + [nock| true |], + [nock| 1|], + [nock| 2|] + ], + mkAnomaTest + 50 + "Pattern matching with integers" + $(mkRelDir ".") + $(mkRelFile "test050.juvix") + [] + $ checkNatOutput [11], + mkAnomaTest + 52 + "Simple lambda calculus" + $(mkRelDir ".") + $(mkRelFile "test052.juvix") + [] + $ checkOutput [[nock| [15 nil] |]], + mkAnomaTest + 53 + "Inlining" + $(mkRelDir ".") + $(mkRelFile "test053.juvix") + [] + $ checkNatOutput [21], + mkAnomaTest + 54 + "Iterators" + $(mkRelDir ".") + $(mkRelFile "test054.juvix") + [] + $ checkNatOutput [189], + mkAnomaTest + 55 + "Constructor printing" + $(mkRelDir ".") + $(mkRelFile "test055.juvix") + [] + $ checkOutput + [[nock| [[[[1 2] 3] [[2 3] 4] nil] [1 2] [2 3] nil] |]], + mkAnomaTest + 56 + "Argument specialization" + $(mkRelDir ".") + $(mkRelFile "test056.juvix") + [] + $ checkNatOutput [69], + mkAnomaTest + 57 + "Case folding" + $(mkRelDir ".") + $(mkRelFile "test057.juvix") + [] + $ checkNatOutput [8], + mkAnomaTest + 58 + "Ranges" + $(mkRelDir ".") + $(mkRelFile "test058.juvix") + [] + $ checkNatOutput [7550], + mkAnomaTest + 59 + "Builtin list" + $(mkRelDir ".") + $(mkRelFile "test059.juvix") + [] + $ checkNatOutput [11], + mkAnomaTest + 60 + "Record update" + $(mkRelDir ".") + $(mkRelFile "test060.juvix") + [] + $ checkOutput [[nock| [30 10 2] |]], + mkAnomaTest + 61 + "Traits" + $(mkRelDir ".") + $(mkRelFile "test061.juvix") + [] + $ checkNatOutput [1, 0, 3, 5, 1, 6, 5, 3, 1, 1, 6, 1, 3], + mkAnomaTest + 62 + "Overapplication" + $(mkRelDir ".") + $(mkRelFile "test062.juvix") + [] + $ checkNatOutput [1], + mkAnomaTest + 63 + "Coercions" + $(mkRelDir ".") + $(mkRelFile "test063.juvix") + [] + $ checkNatOutput [0, 1, 2, 300, 4, 5, 6, 7], + mkAnomaTest + 64 + "Constant folding" + $(mkRelDir ".") + $(mkRelFile "test064.juvix") + [] + $ checkNatOutput [37], + mkAnomaTest + 65 + "Arithmetic simplification" + $(mkRelDir ".") + $(mkRelFile "test065.juvix") + [] + $ checkNatOutput [42], + mkAnomaTest + 66 + "Import function with a function call in default argument" + $(mkRelDir "test066") + $(mkRelFile "M.juvix") + [] + $ checkNatOutput [0], + mkAnomaTest + 67 + "Dependent default values inserted during translation FromConcrete" + $(mkRelDir ".") + $(mkRelFile "test067.juvix") + [] + $ checkNatOutput [30], + mkAnomaTest + 68 + "Dependent default values inserted in the arity checker" + $(mkRelDir ".") + $(mkRelFile "test068.juvix") + [] + $ checkNatOutput [30], + mkAnomaTest + 69 + "Dependent default values for Ord trait" + $(mkRelDir ".") + $(mkRelFile "test069.juvix") + [] + $ checkOutput [[nock| true |]], + mkAnomaTest + 70 + "Nested default values and named arguments" + $(mkRelDir ".") + $(mkRelFile "test070.juvix") + [] + $ checkNatOutput [1463], + mkAnomaTest + 71 + "Named application (Ord instance with default cmp)" + $(mkRelDir ".") + $(mkRelFile "test071.juvix") + [] + $ checkNatOutput [1528], + mkAnomaTest + 72 + "Monad transformers (ReaderT + StateT + Identity)" + $(mkRelDir "test072") + $(mkRelFile "ReaderT.juvix") + [] + $ checkNatOutput [10], + mkAnomaTest + 73 + "Import and use a syntax alias" + $(mkRelDir "test073") + $(mkRelFile "test073.juvix") + [] + $ checkNatOutput [11], + let k1 :: Term Natural = [nock| 333 |] + v1 :: Term Natural = [nock| 222 |] + k2 :: Term Natural = [nock| [1 2 3 nil] |] + v2 :: Term Natural = [nock| [4 5 6 nil] |] + -- The keys of the storage are of the form [id key nil]. + -- The id is captured from the arguments tuple of the function. + sk1 :: Term Natural = [nock| [[333 1 2 3 nil] 333 nil] |] + sk2 :: Term Natural = [nock| [[333 1 2 3 nil] [1 2 3 nil] nil] |] + in mkAnomaTest' + True + ( Storage + ( hashMap + [ (StorageKey sk1, v1), + (StorageKey sk2, v2) + ] + ) + ) + 74 + "Builtin anomaGet" + $(mkRelDir ".") + $(mkRelFile "test074.juvix") + [OpQuote # k1, OpQuote # k2] + $ checkOutput [v1, v2], + mkAnomaTest + 75 + "Anoma encode" + $(mkRelDir ".") + $(mkRelFile "test075.juvix") + [] + $ checkNatOutput [2, 84081, 4657, 12], + mkAnomaTest + 76 + "Anoma decode" + $(mkRelDir ".") + $(mkRelFile "test076.juvix") + [] + $ checkOutput + [ [nock| 0 |], + [nock| [1 2 0] |], + [nock| [1 2] |], + [nock| false |] + ], + mkAnomaTest + 77 + "Anoma verify-detached" + $(mkRelDir ".") + $(mkRelFile "test077.juvix") + [] + $ checkOutput + [ [nock| 64 |], + [nock| true |] + ], + let toSignAndVerify :: Term Natural = [nock| [1 2 nil] |] + in mkAnomaTest + 78 + "Anoma sign and verify" + $(mkRelDir ".") + $(mkRelFile "test078.juvix") + [OpQuote # toSignAndVerify] + $ checkOutput + [toSignAndVerify], + let inputStr :: Term Natural = [nock| "Juvix!" |] + in mkAnomaTest + 79 + "Strings" + $(mkRelDir ".") + $(mkRelFile "test079.juvix") + [OpQuote # inputStr] + $ checkOutput [[nock| "Juvix! ✨ héllo world ✨" |]], + mkAnomaTest + 80 + "Maybe" + $(mkRelDir ".") + $(mkRelFile "test080.juvix") + [] + $ checkOutput + [ [nock| [nil 1] |], + [nock| 2 |], + [nock| 3 |], + [nock| nil |] + ], + mkAnomaTest + 81 + "UInt8" + $(mkRelDir ".") + $(mkRelFile "test081.juvix") + [] + $ checkOutput + [ [nock| 1 |], + [nock| 255 |], + [nock| 2 |], + [nock| true |], + [nock| true |], + [nock| false |], + [nock| 1 |], + [nock| 238 |], + [nock| 3 |], + [nock| 240 |], + [nock| [1 238 3 2 nil] |] + ], + mkAnomaTest + 82 + "ByteArray" + $(mkRelDir ".") + $(mkRelFile "test082.juvix") + [] + $ checkOutput + [ [nock| 0 |], + [nock| [0 0] |], + [nock| 3 |], + [nock| [3 0] |], + [nock| 4 |], + [nock| [4 1] |], + [nock| 2 |], + [nock| [2 258] |], + [nock| 1 |], + [nock| [1 0] |] + ], + mkAnomaTest + 83 + "Anoma ByteArray" + $(mkRelDir ".") + $(mkRelFile "test083.juvix") + [] + $ checkOutput + [ [nock| [[0 0] 0] |], + [nock| [[3 0] 0] |], + [nock| [[4 1] 1] |], + [nock| [[2 258] 258] |], + [nock| [[1 0] 0] |] + ], + mkAnomaTest + 84 + "Anoma Sha256" + $(mkRelDir ".") + $(mkRelFile "test084.juvix") + [] + $ checkOutput + [ [nock| 64 |], + [nock| [ 64 5092006196359674779938793937035252249221936503860319648757996882954518215195609232852607160812968472040491493412050369557521935588220586883008001462395444 ] |] - ], - mkAnomaCallTest - "Test085: Anoma Resource Machine builtins" - $(mkRelDir ".") - $(mkRelFile "test085.juvix") - [] - $ checkOutput - [ [nock| [[[11 22] 110] 0] |], - [nock| [10 11] |], - [nock| 478793196187462788804451 |], - [nock| 418565088612 |], - [nock| 0 |] - ], - mkAnomaCallTest - "Test086: Anoma Random" - $(mkRelDir ".") - $(mkRelFile "test086.juvix") - [] - $ checkOutput - [ [nock| [2 30764] |], - [nock| [3 10689019] |], - [nock| [2 20159] |], - [nock| [4 4187579825] |] - ] - ] + ], + mkAnomaTest + 85 + "Anoma Resource Machine builtins" + $(mkRelDir ".") + $(mkRelFile "test085.juvix") + [] + $ checkOutput + [ [nock| [[[11 22] 110] 0] |], + [nock| [10 11] |], + [nock| 478793196187462788804451 |], + [nock| 418565088612 |], + [nock| 0 |] + ], + mkAnomaTest + 86 + "Anoma Random" + $(mkRelDir ".") + $(mkRelFile "test086.juvix") + [] + $ checkOutput + [ [nock| [2 30764] |], + [nock| [3 10689019] |], + [nock| [2 20159] |], + [nock| [4 4187579825] |] + ] + ] diff --git a/test/Base.hs b/test/Base.hs index 86c315a1f0..059eb54b8f 100644 --- a/test/Base.hs +++ b/test/Base.hs @@ -23,10 +23,10 @@ import Juvix.Data.Effect.TaggedLock import Juvix.Extra.Paths hiding (rootBuildDir) import Juvix.Prelude hiding (assert, readProcess) import Juvix.Prelude.Env -import Juvix.Prelude.Pretty (prettyString) +import Juvix.Prelude.Pretty import System.Process qualified as P import Test.Tasty -import Test.Tasty.HUnit hiding (assertFailure) +import Test.Tasty.HUnit hiding (assertFailure, testCase) import Test.Tasty.HUnit qualified as HUnit data AssertionDescr @@ -63,7 +63,7 @@ mkTest TestDescr {..} = case _testAssertion of withPrecondition :: Assertion -> IO TestTree -> IO TestTree withPrecondition assertion ifSuccess = do E.catch (assertion >> ifSuccess) $ \case - E.SomeException e -> return (testCase "Precondition failed" (assertFailure (show e))) + E.SomeException e -> return (testCase @String "Precondition failed" (assertFailure (show e))) assertEqDiffText :: String -> Text -> Text -> Assertion assertEqDiffText = assertEqDiff unpack @@ -190,3 +190,17 @@ readProcessCwd' menv mcwd cmd args stdinText = hClose hout return r ) + +to3DigitString :: Int -> Text +to3DigitString n + | n < 10 = "00" <> show n + | n < 100 = "0" <> show n + | n < 1000 = show n + | otherwise = error ("The given number has more than 3 digits. Given number = " <> prettyText n) + +-- | E.g. Test001: str +numberedTestName :: Int -> Text -> Text +numberedTestName i str = "Test" <> to3DigitString i <> ": " <> str + +testCase :: (HasTextBackend str) => str -> Assertion -> TestTree +testCase name = HUnit.testCase (toPlainString name) diff --git a/test/Nockma/Compile/Tree/Positive.hs b/test/Nockma/Compile/Tree/Positive.hs index dc72690406..f0559edac7 100644 --- a/test/Nockma/Compile/Tree/Positive.hs +++ b/test/Nockma/Compile/Tree/Positive.hs @@ -76,14 +76,8 @@ convertTest p = do go :: Base.Path Rel File -> Base.Path Rel File go = replaceExtensions' [".nockma", ".out"] - testNum :: String - testNum = take 3 (drop 4 (p ^. Tree.name)) - to3DigitString :: Int -> String - to3DigitString n - | n < 10 = "00" ++ show n - | n < 100 = "0" ++ show n - | n < 1000 = show n - | otherwise = impossible + testNum :: Text + testNum = pack (take 3 (drop 4 (p ^. Tree.name))) allTests :: TestTree allTests = diff --git a/test/Nockma/Eval/Positive.hs b/test/Nockma/Eval/Positive.hs index c1f283aeaf..d008fcecab 100644 --- a/test/Nockma/Eval/Positive.hs +++ b/test/Nockma/Eval/Positive.hs @@ -11,7 +11,12 @@ import Juvix.Compiler.Nockma.Pretty import Juvix.Compiler.Nockma.Translation.FromSource.QQ import Juvix.Compiler.Nockma.Translation.FromTree -type Check = Sem '[Reader [Term Natural], Reader (Term Natural), EmbedIO] +type Check = + Sem + '[ Reader [Term Natural], + Reader (Term Natural), + EmbedIO + ] data Test = Test { _testEvalOptions :: EvalOptions, From 1d408b7f380428cfed9e605ee56dcb451d601dcb Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 09:49:13 +0100 Subject: [PATCH 04/29] wip run anoma in tests --- app/Commands/Dev/Anoma/Node.hs | 3 +- src/Anoma/Effect/Base.hs | 12 ++--- src/Juvix/Data/Error/GenericError.hs | 2 +- test/Anoma/Compilation/Positive.hs | 69 ++++++++++++++++++++-------- test/Base.hs | 7 +++ test/Main.hs | 6 ++- 6 files changed, 71 insertions(+), 28 deletions(-) diff --git a/app/Commands/Dev/Anoma/Node.hs b/app/Commands/Dev/Anoma/Node.hs index f885c82967..e6a41e59ef 100644 --- a/app/Commands/Dev/Anoma/Node.hs +++ b/app/Commands/Dev/Anoma/Node.hs @@ -11,4 +11,5 @@ runCommand opts = runAppError @SimpleError $ do anomaDir :: AnomaPath <- AnomaPath <$> fromAppPathDir (opts ^. nodeAnomaPath) runAnoma anomaDir $ do - void noHalt + p <- getAnomaProcesses + void (waitForProcess (p ^. anomaNodeHandle)) diff --git a/src/Anoma/Effect/Base.hs b/src/Anoma/Effect/Base.hs index 33fd9abe4e..16a03b7a08 100644 --- a/src/Anoma/Effect/Base.hs +++ b/src/Anoma/Effect/Base.hs @@ -4,7 +4,7 @@ -- 2. grpcurl module Anoma.Effect.Base ( Anoma, - noHalt, + getAnomaProcesses, anomaRpc, AnomaPath (..), AnomaProcesses (..), @@ -34,7 +34,7 @@ data AnomaProcesses = AnomaProcesses data Anoma :: Effect where -- | Keep the node and client running - NoHalt :: Anoma m AnomaProcesses + GetAnomaProcesses :: Anoma m AnomaProcesses -- | grpc call AnomaRpc :: GrpcMethodUrl -> Value -> Anoma m Value @@ -159,7 +159,7 @@ grpcCliProcess method = do runAnomaTest :: forall r a. (Members '[Logger, EmbedIO, Error SimpleError] r) => AnomaPath -> Sem (Anoma ': r) a -> Sem r a runAnomaTest anomapath body = runReader anomapath . runProcess $ (`interpret` inject body) $ \case - NoHalt -> error "unsupported" + GetAnomaProcesses -> error "unsupported" AnomaRpc method i -> anomaRpc' method i runAnoma :: forall r a. (Members '[Logger, EmbedIO, Error SimpleError] r) => AnomaPath -> Sem (Anoma ': r) a -> Sem r a @@ -168,9 +168,9 @@ runAnoma anomapath body = runReader anomapath . runProcess $ runReader (GrpcPort grpcport) $ withSpawnAnomaClient $ \clientH -> do (`interpret` inject body) $ \case - NoHalt -> - waitForProcess nodeH - $> AnomaProcesses + GetAnomaProcesses -> + return + AnomaProcesses { _anomaNodeHandle = nodeH, _anomaClientHandle = clientH } diff --git a/src/Juvix/Data/Error/GenericError.hs b/src/Juvix/Data/Error/GenericError.hs index 5dcfd19a79..ef11cd05db 100644 --- a/src/Juvix/Data/Error/GenericError.hs +++ b/src/Juvix/Data/Error/GenericError.hs @@ -125,5 +125,5 @@ runSimpleErrorIO :: (Members '[EmbedIO] r) => Sem (Error SimpleError ': r) a -> runSimpleErrorIO m = do res <- runError m case res of - Left (SimpleError msg) -> renderIO True msg >> exitFailure + Left (SimpleError msg) -> hRenderIO True stderr msg >> exitFailure Right r -> return r diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index 7375f51abc..f26696d241 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -41,7 +41,7 @@ fromAnomaTest a@AnomaTest {..} = mkTestIO :: IO Test mkTestIO = do anomaRes <- withRootCopy (compileMain _anomaEnableDebug _anomaRelRoot _anomaMainFile) - let _testProgramFormula = anomaCall _anomaArgs + let _testProgramFormula = anomaCall (map (opQuote "Quote arg") _anomaArgs) _testProgramSubject = anomaRes ^. anomaClosure _testEvalOptions = defaultEvalOptions _testAssertEvalError :: Maybe (NockEvalError Natural -> Assertion) = Nothing @@ -78,12 +78,16 @@ mkAnomaNodeTest a@AnomaTest {..} = assertion :: Assertion assertion = do program :: Term Natural <- (^. anomaClosure) <$> withRootCopy (compileMain False _anomaRelRoot _anomaMainFile) + -- For some reason the evaluation fails if no args are given + let args' + | null _anomaArgs = [toNock (nockVoid @Natural)] + | otherwise = _anomaArgs runM . ignoreLogger - . runSimpleErrorIO - . runAnomaTest testAnomaPath + . runSimpleErrorHUnit + . runAnoma testAnomaPath $ do - out <- runNockma program _anomaArgs + out <- runNockma program args' runM . runReader out . runReader [] @@ -170,28 +174,57 @@ anomaNodeValid = 65 ] +anomaNodeBug :: IntSet +anomaNodeBug = + intSet + [ 24, + 41, + 52, + 54, + 56 + ] + allTests :: TestTree allTests = testGroup "Anoma positive tests" - [ haskellNockmaTests, + [ -- haskellNockmaTests, anomaNodeTests ] where anomaNodeTests :: TestTree anomaNodeTests = testGroup - "Anoma positive tests (Anoma node evaluator)" - (map mkAnomaNodeTest (filter isAnomaNodeValid anomaTests)) + "AnomaNode" + (map mkAnomaNodeTest (filter shouldRun anomaTests)) where - isAnomaNodeValid :: AnomaTest -> Bool - isAnomaNodeValid AnomaTest {..} = IntSet.member _anomaTestNum anomaNodeValid + shouldRun :: AnomaTest -> Bool + shouldRun AnomaTest {..} = + IntSet.member _anomaTestNum anomaNodeValid + && IntSet.notMember _anomaTestNum anomaNodeBug haskellNockmaTests :: TestTree haskellNockmaTests = + -- withResource initNode freeNode $ \_ -> testGroup "Anoma positive tests (Haskell evaluator)" (map fromAnomaTest anomaTests) + -- where + -- initNode :: IO AnomaProcesses + -- initNode = runM + -- . runSimpleErrorHUnit + -- . ignoreLogger + -- . runAnoma testAnomaPath + -- $ do + -- noHalt + + -- freeNode :: AnomaProcesses -> IO () + -- freeNode AnomaProcesses {..} = runM . runProcess $ do + -- terminateProcess _anomaClientHandle + -- terminateProcess _anomaNodeHandle + + natArg :: Natural -> Term Natural + natArg = toNock anomaTests :: [AnomaTest] anomaTests = @@ -200,14 +233,14 @@ allTests = "Arithmetic operators" $(mkRelDir ".") $(mkRelFile "test001.juvix") - [nockNatLiteral 5] + [natArg 5] (checkNatOutput [11]), mkAnomaTest 2 "Arithmetic operators inside lambdas" $(mkRelDir ".") $(mkRelFile "test002.juvix") - [nockNatLiteral 2] + [natArg 2] (checkNatOutput [11]), mkAnomaTest 3 @@ -228,7 +261,7 @@ allTests = "Higher-order functions" $(mkRelDir ".") $(mkRelFile "test005.juvix") - [nockNatLiteral 1] + [natArg 1] (checkNatOutput [6]), mkAnomaTest 6 @@ -251,14 +284,14 @@ allTests = "Recursion" $(mkRelDir ".") $(mkRelFile "test008.juvix") - [nockNatLiteral 1000] + [natArg 1000] (eqNock [nock| 500500 |]), mkAnomaTest 9 "Tail recursion" $(mkRelDir ".") $(mkRelFile "test009.juvix") - [nockNatLiteral 1000] + [natArg 1000] $ checkNatOutput [500500, 120, 3628800, 479001600], mkAnomaTest 10 @@ -283,7 +316,7 @@ allTests = "Trees" $(mkRelDir ".") $(mkRelFile "test012.juvix") - [nockNatLiteral 1000] + [natArg 1000] $ checkNatOutput [ 13200200200, 21320020020013200200200, @@ -324,7 +357,7 @@ allTests = "Tail recursion through higher-order functions" $(mkRelDir ".") $(mkRelFile "test017.juvix") - [nockNatLiteral 1000] + [natArg 1000] $ checkNatOutput [500500], mkAnomaTest 18 @@ -359,7 +392,7 @@ allTests = "Lists" $(mkRelDir ".") $(mkRelFile "test022.juvix") - [nockNatLiteral 1000] + [natArg 1000] $ checkOutput [ [nock| [10 9 8 7 6 5 4 3 2 1 nil] |], [nock| [1 2 3 4 5 6 7 8 9 10 nil] |], @@ -408,7 +441,7 @@ allTests = "Streams without memoization" $(mkRelDir ".") $(mkRelFile "test028.juvix") - [nockNatLiteral 10, nockNatLiteral 50] + [natArg 10, natArg 50] $ checkNatOutput [31, 233], mkAnomaTest 29 diff --git a/test/Base.hs b/test/Base.hs index 059eb54b8f..e4515e1fc0 100644 --- a/test/Base.hs +++ b/test/Base.hs @@ -132,6 +132,13 @@ testRunIOEitherTermination entry = assertFailure :: (MonadIO m) => String -> m a assertFailure = liftIO . HUnit.assertFailure +runSimpleErrorHUnit :: (Members '[EmbedIO] r) => Sem (Error SimpleError ': r) a -> Sem r a +runSimpleErrorHUnit m = do + res <- runError m + case res of + Left (SimpleError msg) -> assertFailure (toPlainString msg) + Right r -> return r + wantsError :: forall err b. (Generic err, GenericHasConstructor (GHC.Rep err)) => diff --git a/test/Main.hs b/test/Main.hs index 6f7dd375ab..67431506d0 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -1,6 +1,7 @@ module Main (main) where import Anoma qualified +import Anoma.Compilation.Positive qualified as AnomaPositive import Asm qualified import BackendMarkdown qualified import Base @@ -66,5 +67,6 @@ fastTests = main :: IO () main = do - tests <- sequence [fastTests, slowTests] - defaultMain (testGroup "Juvix tests" tests) + -- tests <- sequence [fastTests, slowTests] + -- defaultMain (testGroup "Juvix tests" tests) + defaultMain AnomaPositive.allTests From de4229bc55a4603dbf63560b05c88aec52e881d7 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 11:24:57 +0100 Subject: [PATCH 05/29] use ANOMA_PATH --- src/Juvix/Prelude/Env.hs | 8 +++++++- test/Anoma/Compilation/Positive.hs | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Juvix/Prelude/Env.hs b/src/Juvix/Prelude/Env.hs index 29927f39fc..e0b6968361 100644 --- a/src/Juvix/Prelude/Env.hs +++ b/src/Juvix/Prelude/Env.hs @@ -7,15 +7,18 @@ import System.Environment -- | Environment variables relevant to Juvix data EnvVar = EnvWasiSysrootPath + | EnvAnomaPath deriving stock (Show, Eq) envVarString :: EnvVar -> String envVarString = \case EnvWasiSysrootPath -> "WASI_SYSROOT_PATH" + EnvAnomaPath -> "ANOMA_PATH" envVarHint :: EnvVar -> Maybe String envVarHint = \case - EnvWasiSysrootPath -> Just "Set to the location of the wasi-clib sysroot" + EnvWasiSysrootPath -> Just "It should point to the location of the wasi-clib sysroot" + EnvAnomaPath -> Just "It should point to the location of the Anoma repository" getEnvVar :: (MonadIO m) => EnvVar -> m String getEnvVar var = fromMaybeM (error (pack msg)) (liftIO (lookupEnv (envVarString var))) @@ -23,6 +26,9 @@ getEnvVar var = fromMaybeM (error (pack msg)) (liftIO (lookupEnv (envVarString v msg :: String msg = "Missing environment variable " <> envVarString var <> maybe "" (". " <>) (envVarHint var) +getAnomaPathAbs :: (MonadIO m) => m (Path Abs Dir) +getAnomaPathAbs = absDir <$> getEnvVar EnvAnomaPath + getWasiSysrootPathStr :: (MonadIO m) => m String getWasiSysrootPathStr = getEnvVar EnvWasiSysrootPath diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index f26696d241..eb51bf2fb9 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -68,8 +68,8 @@ mkAnomaTest' _anomaEnableDebug _anomaProgramStorage _anomaTestNum _anomaTestTag { .. } -testAnomaPath :: AnomaPath -testAnomaPath = AnomaPath $(mkAbsDir "/home/jan/anoma") +envAnomaPath :: (MonadIO m) => m AnomaPath +envAnomaPath = AnomaPath <$> getAnomaPathAbs mkAnomaNodeTest :: AnomaTest -> TestTree mkAnomaNodeTest a@AnomaTest {..} = @@ -82,6 +82,7 @@ mkAnomaNodeTest a@AnomaTest {..} = let args' | null _anomaArgs = [toNock (nockVoid @Natural)] | otherwise = _anomaArgs + testAnomaPath <- envAnomaPath runM . ignoreLogger . runSimpleErrorHUnit From 646f3761c99e27ede9acd07f6b0da4429a4d10d2 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 11:55:39 +0100 Subject: [PATCH 06/29] ci --- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2142b9689..744bf59784 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -119,6 +119,38 @@ jobs: path: main submodules: true + - name: Set up Elixir + id: beam + uses: erlef/setup-beam@v1.18.2 + with: + elixir-version: '1.17.3' + otp-version: '27.1' + + - name: Cache anoma + id: cache-anoma + uses: actions/cache@v3 + with: + path: | + ${{ env.HOME }}/anoma + key: "${{ runner.os }}-anoma" + + - name: Install anoma + run: >- + cd $HOME + git clone https://github.com/anoma/anoma.git + cd anoma + git checkout 98e3660b91cd55f1d9424dcff9420425ae98f5f8 + mix deps.get + mix escript.install hex protobuf + mix compile + mix do --app anoma_client escript.build + with: + cached: "${{ steps.cache-llvm.outputs.cache-hit }}" + + - name: Install grpcurl + run: >- + curl -sSL "https://github.com/fullstorydev/grpcurl/releases/download/v1.9.1/grpcurl_1.9.1_linux_x86_64.tar.gz" | tar -xz -C ~/.local/bin --no-wildcards grpcurl + - name: Cache LLVM and Clang id: cache-llvm uses: actions/cache@v3 @@ -146,6 +178,10 @@ jobs: run: | echo "WASI_SYSROOT_PATH=$GITHUB_WORKSPACE/wasi-sysroot" >> $GITHUB_ENV + - name: Set ANOMA_PATH + run: | + echo "ANOMA_PATH=$HOME/anoma" >> $GITHUB_ENV + - name: Add ~/.local/bin to PATH run: | mkdir -p "$HOME/.local/bin" From 4fef05f55eeb263c69683e71b41559f52d9a42ec Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 15:56:55 +0100 Subject: [PATCH 07/29] typo --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 744bf59784..838ac46d67 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,7 +145,7 @@ jobs: mix compile mix do --app anoma_client escript.build with: - cached: "${{ steps.cache-llvm.outputs.cache-hit }}" + cached: "${{ steps.cache-anoma.outputs.cache-hit }}" - name: Install grpcurl run: >- From 56ba2dccc359d1ab64b0a849470d5175f1d1e3a9 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 15:57:50 +0100 Subject: [PATCH 08/29] revert ci --- .github/workflows/ci.yml | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 838ac46d67..f2142b9689 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -119,38 +119,6 @@ jobs: path: main submodules: true - - name: Set up Elixir - id: beam - uses: erlef/setup-beam@v1.18.2 - with: - elixir-version: '1.17.3' - otp-version: '27.1' - - - name: Cache anoma - id: cache-anoma - uses: actions/cache@v3 - with: - path: | - ${{ env.HOME }}/anoma - key: "${{ runner.os }}-anoma" - - - name: Install anoma - run: >- - cd $HOME - git clone https://github.com/anoma/anoma.git - cd anoma - git checkout 98e3660b91cd55f1d9424dcff9420425ae98f5f8 - mix deps.get - mix escript.install hex protobuf - mix compile - mix do --app anoma_client escript.build - with: - cached: "${{ steps.cache-anoma.outputs.cache-hit }}" - - - name: Install grpcurl - run: >- - curl -sSL "https://github.com/fullstorydev/grpcurl/releases/download/v1.9.1/grpcurl_1.9.1_linux_x86_64.tar.gz" | tar -xz -C ~/.local/bin --no-wildcards grpcurl - - name: Cache LLVM and Clang id: cache-llvm uses: actions/cache@v3 @@ -178,10 +146,6 @@ jobs: run: | echo "WASI_SYSROOT_PATH=$GITHUB_WORKSPACE/wasi-sysroot" >> $GITHUB_ENV - - name: Set ANOMA_PATH - run: | - echo "ANOMA_PATH=$HOME/anoma" >> $GITHUB_ENV - - name: Add ~/.local/bin to PATH run: | mkdir -p "$HOME/.local/bin" From 1eedafcbe119c053e92b0e266d8538b22a3a199a Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 16:32:28 +0100 Subject: [PATCH 09/29] try again --- .github/workflows/ci.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2142b9689..86cd7862f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -119,6 +119,36 @@ jobs: path: main submodules: true + - name: Set up Elixir + id: beam + uses: erlef/setup-beam@v1.18.2 + with: + elixir-version: "1.17.3" + otp-version: "27.1" + + - name: Cache anoma + id: cache-anoma + uses: actions/cache@v3 + with: + path: | + ${{ env.HOME }}/anoma + key: "${{ runner.os }}-anoma" + + - name: Install anoma + run: | + cd $HOME + git clone https://github.com/anoma/anoma.git + cd anoma + git checkout 98e3660b91cd55f1d9424dcff9420425ae98f5f8 + mix deps.get + mix escript.install hex protobuf + mix compile + mix do --app anoma_client escript.build + + - name: Install grpcurl + run: | + curl -sSL "https://github.com/fullstorydev/grpcurl/releases/download/v1.9.1/grpcurl_1.9.1_linux_x86_64.tar.gz" | tar -xz -C ~/.local/bin --no-wildcards grpcurl + - name: Cache LLVM and Clang id: cache-llvm uses: actions/cache@v3 @@ -146,6 +176,10 @@ jobs: run: | echo "WASI_SYSROOT_PATH=$GITHUB_WORKSPACE/wasi-sysroot" >> $GITHUB_ENV + - name: Set ANOMA_PATH + run: | + echo "ANOMA_PATH=$HOME/anoma" >> $GITHUB_ENV + - name: Add ~/.local/bin to PATH run: | mkdir -p "$HOME/.local/bin" From e0b0ff6161fa69e69375bafe79361c56a78073ae Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 16:53:30 +0100 Subject: [PATCH 10/29] install protoc --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86cd7862f6..e27dbfe711 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,6 +126,11 @@ jobs: elixir-version: "1.17.3" otp-version: "27.1" + - name: Install protoc + run: | + sudo apt install -y protobuf-compiler + protoc --version + - name: Cache anoma id: cache-anoma uses: actions/cache@v3 From b36310f10d9ce45b22947750c687827d304c209c Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 17:35:21 +0100 Subject: [PATCH 11/29] fix path --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e27dbfe711..be4719579d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -139,7 +139,11 @@ jobs: ${{ env.HOME }}/anoma key: "${{ runner.os }}-anoma" - - name: Install anoma + - name: add ~/.mix/escripts to PATH + run: | + echo "$HOME/.mix/escripts" >> $GITHUB_PATH + + - name: Build anoma run: | cd $HOME git clone https://github.com/anoma/anoma.git From 85c91673411e2268bf2a555ce92a2029a4bca7df Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 18:03:39 +0100 Subject: [PATCH 12/29] try again --- .github/workflows/ci.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be4719579d..351e84065c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -139,18 +139,16 @@ jobs: ${{ env.HOME }}/anoma key: "${{ runner.os }}-anoma" - - name: add ~/.mix/escripts to PATH - run: | - echo "$HOME/.mix/escripts" >> $GITHUB_PATH - - name: Build anoma run: | cd $HOME git clone https://github.com/anoma/anoma.git cd anoma git checkout 98e3660b91cd55f1d9424dcff9420425ae98f5f8 + mix local.hex --force + mix escript.install hex protobuf --force + echo "$HOME/.mix/escripts" >> $GITHUB_PATH mix deps.get - mix escript.install hex protobuf mix compile mix do --app anoma_client escript.build From 73d067401c902813f982c4549e29547760b51434 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 18:19:34 +0100 Subject: [PATCH 13/29] remove quote test074 --- test/Anoma/Compilation/Positive.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index eb51bf2fb9..3d739fa604 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -786,7 +786,7 @@ allTests = "Builtin anomaGet" $(mkRelDir ".") $(mkRelFile "test074.juvix") - [OpQuote # k1, OpQuote # k2] + [k1, k2] $ checkOutput [v1, v2], mkAnomaTest 75 From 51d7d745ed58bdf78840e7fde8776274f169cbc7 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 18:21:16 +0100 Subject: [PATCH 14/29] remove quote tests 078 079 --- test/Anoma/Compilation/Positive.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index 3d739fa604..98a89ea447 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -823,7 +823,7 @@ allTests = "Anoma sign and verify" $(mkRelDir ".") $(mkRelFile "test078.juvix") - [OpQuote # toSignAndVerify] + [toSignAndVerify] $ checkOutput [toSignAndVerify], let inputStr :: Term Natural = [nock| "Juvix!" |] @@ -832,7 +832,7 @@ allTests = "Strings" $(mkRelDir ".") $(mkRelFile "test079.juvix") - [OpQuote # inputStr] + [inputStr] $ checkOutput [[nock| "Juvix! ✨ héllo world ✨" |]], mkAnomaTest 80 From d25b2b3b75026f09f785aff7ea6597474798db75 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 18:22:30 +0100 Subject: [PATCH 15/29] add more tests --- test/Anoma/Compilation/Positive.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index 98a89ea447..df707b89f4 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -172,7 +172,14 @@ anomaNodeValid = 60, 62, 64, - 65 + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72 ] anomaNodeBug :: IntSet From 515dec3b85799bf8872ec0b2c879bfe449ac2119 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 18:24:26 +0100 Subject: [PATCH 16/29] move .local/bin up --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 351e84065c..516b4e74a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -119,6 +119,11 @@ jobs: path: main submodules: true + - name: Add ~/.local/bin to PATH + run: | + mkdir -p "$HOME/.local/bin" + echo "$HOME/.local/bin" >> $GITHUB_PATH + - name: Set up Elixir id: beam uses: erlef/setup-beam@v1.18.2 @@ -187,11 +192,6 @@ jobs: run: | echo "ANOMA_PATH=$HOME/anoma" >> $GITHUB_ENV - - name: Add ~/.local/bin to PATH - run: | - mkdir -p "$HOME/.local/bin" - echo "$HOME/.local/bin" >> $GITHUB_PATH - - run: echo "HOME=$HOME" >> $GITHUB_ENV shell: bash From 68ccf31b2f3dac4049937dc97194257cf21ce11a Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 18:50:26 +0100 Subject: [PATCH 17/29] enable all tests --- test/Anoma/Compilation/Positive.hs | 2 +- test/Main.hs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index df707b89f4..e988fdbf2a 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -196,7 +196,7 @@ allTests :: TestTree allTests = testGroup "Anoma positive tests" - [ -- haskellNockmaTests, + [ haskellNockmaTests, anomaNodeTests ] where diff --git a/test/Main.hs b/test/Main.hs index 67431506d0..f11f81bb71 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -1,7 +1,6 @@ module Main (main) where import Anoma qualified -import Anoma.Compilation.Positive qualified as AnomaPositive import Asm qualified import BackendMarkdown qualified import Base @@ -67,6 +66,7 @@ fastTests = main :: IO () main = do - -- tests <- sequence [fastTests, slowTests] - -- defaultMain (testGroup "Juvix tests" tests) - defaultMain AnomaPositive.allTests + tests <- sequence [fastTests, slowTests] + defaultMain (testGroup "Juvix tests" tests) + +-- defaultMain AnomaPositive.allTests From 5b53d0d4ae3bb9a32160b7c1116423f3ddde15e7 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 30 Oct 2024 18:52:14 +0100 Subject: [PATCH 18/29] anoma cache --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 516b4e74a4..8e59af4636 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,6 +145,7 @@ jobs: key: "${{ runner.os }}-anoma" - name: Build anoma + if: steps.cache-anoma.outputs.cache-hit != 'true' run: | cd $HOME git clone https://github.com/anoma/anoma.git From acc7c29e9593e9c4f48cd680201c469dcad07896 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 31 Oct 2024 11:20:05 +0100 Subject: [PATCH 19/29] run ci --- .github/workflows/ci.yml | 77 ++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e59af4636..7b7e6b3e6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,41 +75,41 @@ jobs: build-and-test-linux: runs-on: ubuntu-22.04 steps: - - name: Free disk space - run: | - df -h - echo "/usr/local" - du -hsc /usr/local/* - sudo rm -rf \ - /usr/local/aws-sam-cil \ - /usr/local/julia* || : - echo "end /usr/local" - echo "/usr/local/lib" - du -hsc /usr/local/lib/* - sudo rm -rf \ - /usr/local/lib/android \ - /usr/local/lib/heroku \ - /usr/local/lib/node_modules || : - echo "end /usr/local/lib" - echo "/usr/local/share" - du -hsc /usr/local/share/* - sudo rm -rf \ - /usr/local/share/chromium \ - /usr/local/share/powershell || : - echo "end /usr/local/share" - echo "/opt/hostedtoolcache/" - du -hsc /opt/hostedtoolcache/* - sudo rm -rf \ - /opt/hostedtoolcache/CodeQL \ - /opt/hostedtoolcache/go \ - /opt/hostedtoolcache/PyPy \ - /opt/hostedtoolcache/node || : - echo "end /opt/hostedtoolcache/*" - sudo apt purge -y \ - firefox \ - google-chrome-stable \ - microsoft-edge-stable - df -h + # - name: Free disk space + # run: | + # df -h + # echo "/usr/local" + # du -hsc /usr/local/* + # sudo rm -rf \ + # /usr/local/aws-sam-cil \ + # /usr/local/julia* || : + # echo "end /usr/local" + # echo "/usr/local/lib" + # du -hsc /usr/local/lib/* + # sudo rm -rf \ + # /usr/local/lib/android \ + # /usr/local/lib/heroku \ + # /usr/local/lib/node_modules || : + # echo "end /usr/local/lib" + # echo "/usr/local/share" + # du -hsc /usr/local/share/* + # sudo rm -rf \ + # /usr/local/share/chromium \ + # /usr/local/share/powershell || : + # echo "end /usr/local/share" + # echo "/opt/hostedtoolcache/" + # du -hsc /opt/hostedtoolcache/* + # sudo rm -rf \ + # /opt/hostedtoolcache/CodeQL \ + # /opt/hostedtoolcache/go \ + # /opt/hostedtoolcache/PyPy \ + # /opt/hostedtoolcache/node || : + # echo "end /opt/hostedtoolcache/*" + # sudo apt purge -y \ + # firefox \ + # google-chrome-stable \ + # microsoft-edge-stable + # df -h - uses: extractions/setup-just@v2 @@ -162,6 +162,13 @@ jobs: run: | curl -sSL "https://github.com/fullstorydev/grpcurl/releases/download/v1.9.1/grpcurl_1.9.1_linux_x86_64.tar.gz" | tar -xz -C ~/.local/bin --no-wildcards grpcurl + - name: Test Anoma (TMP) + run: | + cd $HOME/anoma + echo "IO.puts(Anoma.Node.Examples.ENode.start_node().grpc_port)" > start.exs + mix run start.exs + ./apps/anoma_client/anoma_client + - name: Cache LLVM and Clang id: cache-llvm uses: actions/cache@v3 From cd6634fb4874816faca04bcc5bac52c058cec859 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 31 Oct 2024 12:06:49 +0100 Subject: [PATCH 20/29] simplify --- .github/workflows/ci.yml | 74 +++++++++++----------- test/Main.hs | 130 ++++++++++++++++++++------------------- 2 files changed, 103 insertions(+), 101 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b7e6b3e6e..bb8935f437 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -220,49 +220,49 @@ jobs: path: ${{ env.HOME }}/.local/bin/juvix-cairo-vm key: ${{ runner.os }}-cairo-vm-${{ env.CAIRO_VM_VERSION }} - - name: Install Rust toolchain - if: steps.cache-cairo-vm.outputs.cache-hit != 'true' - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - cache-on-failure: false - - - name: Install RISC0 VM - shell: bash - run: | - cargo install cargo-binstall@1.6.9 --force - cargo binstall cargo-risczero@1.1.1 --no-confirm --force - cargo risczero install - - - name: Checkout CairoVM - uses: actions/checkout@v4 - if: steps.cache-cairo-vm.outputs.cache-hit != 'true' - with: - repository: anoma/juvix-cairo-vm - path: juvix-cairo-vm - ref: ${{ env.CAIRO_VM_VERSION }} - - - name: Install Cairo VM - if: steps.cache-cairo-vm.outputs.cache-hit != 'true' - shell: bash - run: | - cd juvix-cairo-vm - cargo build --release - cp target/release/juvix-cairo-vm $HOME/.local/bin/juvix-cairo-vm - - - name: Install run_cairo_vm.sh - shell: bash - run: | - cp main/scripts/run_cairo_vm.sh $HOME/.local/bin/run_cairo_vm.sh + # - name: Install Rust toolchain + # if: steps.cache-cairo-vm.outputs.cache-hit != 'true' + # uses: actions-rust-lang/setup-rust-toolchain@v1 + # with: + # cache-on-failure: false + + # - name: Install RISC0 VM + # shell: bash + # run: | + # cargo install cargo-binstall@1.6.9 --force + # cargo binstall cargo-risczero@1.1.1 --no-confirm --force + # cargo risczero install + + # - name: Checkout CairoVM + # uses: actions/checkout@v4 + # if: steps.cache-cairo-vm.outputs.cache-hit != 'true' + # with: + # repository: anoma/juvix-cairo-vm + # path: juvix-cairo-vm + # ref: ${{ env.CAIRO_VM_VERSION }} + + # - name: Install Cairo VM + # if: steps.cache-cairo-vm.outputs.cache-hit != 'true' + # shell: bash + # run: | + # cd juvix-cairo-vm + # cargo build --release + # cp target/release/juvix-cairo-vm $HOME/.local/bin/juvix-cairo-vm + + # - name: Install run_cairo_vm.sh + # shell: bash + # run: | + # cp main/scripts/run_cairo_vm.sh $HOME/.local/bin/run_cairo_vm.sh - name: Make runtime run: | cd main just ${{ env.JUST_ARGS }} build runtime - - name: Test Rust runtime - run: | - cd main/runtime/rust/juvix - cargo test --release + # - name: Test Rust runtime + # run: | + # cd main/runtime/rust/juvix + # cargo test --release # We use the options: # - -fhide-source-paths diff --git a/test/Main.hs b/test/Main.hs index f11f81bb71..b2461c96f6 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -1,72 +1,74 @@ module Main (main) where -import Anoma qualified -import Asm qualified -import BackendMarkdown qualified +-- import Anoma qualified +-- import Asm qualified +-- import BackendMarkdown qualified + +import Anoma.Compilation.Positive qualified as AnomaPositive import Base -import Casm qualified -import Compilation qualified -import Core qualified -import Examples qualified -import Format qualified -import Formatter qualified -import Internal qualified -import Isabelle qualified -import Juvix.Config qualified as Config -import Nockma qualified -import Package qualified -import Parsing qualified -import Reg qualified -import Repl qualified -import Resolver qualified -import Runtime qualified -import Rust qualified -import Scope qualified -import Termination qualified -import Tree qualified -import Typecheck qualified -slowTests :: IO TestTree -slowTests = - sequentialTestGroup - "Juvix slow tests" - AllFinish - <$> sequence - [ return Runtime.allTests, - return Reg.allTests, - return Asm.allTests, - return Tree.allTests, - return Core.allTests, - return Internal.allTests, - return Compilation.allTests, - return Examples.allTests, - Casm.allTests, - return Anoma.allTests, - return Repl.allTests - ] - <> sequence (if Config.config ^. Config.configRust then [Rust.allTests] else []) +-- import Casm qualified +-- import Compilation qualified +-- import Core qualified +-- import Examples qualified +-- import Format qualified +-- import Formatter qualified +-- import Internal qualified +-- import Isabelle qualified +-- import Juvix.Config qualified as Config +-- import Nockma qualified +-- import Package qualified +-- import Parsing qualified +-- import Reg qualified +-- import Repl qualified +-- import Resolver qualified +-- import Runtime qualified +-- import Rust qualified +-- import Scope qualified +-- import Termination qualified +-- import Tree qualified +-- import Typecheck qualified + +-- slowTests :: IO TestTree +-- slowTests = +-- sequentialTestGroup +-- "Juvix slow tests" +-- AllFinish +-- <$> sequence +-- [ return Runtime.allTests, +-- return Reg.allTests, +-- return Asm.allTests, +-- return Tree.allTests, +-- return Core.allTests, +-- return Internal.allTests, +-- return Compilation.allTests, +-- return Examples.allTests, +-- Casm.allTests, +-- return Anoma.allTests, +-- return Repl.allTests +-- ] +-- <> sequence (if Config.config ^. Config.configRust then [Rust.allTests] else []) -fastTests :: IO TestTree -fastTests = - return $ - testGroup - "Juvix fast tests" - [ Parsing.allTests, - Resolver.allTests, - Scope.allTests, - Termination.allTests, - Typecheck.allTests, - Format.allTests, - Formatter.allTests, - Package.allTests, - BackendMarkdown.allTests, - Isabelle.allTests, - Nockma.allTests - ] +-- fastTests :: IO TestTree +-- fastTests = +-- return $ +-- testGroup +-- "Juvix fast tests" +-- [ Parsing.allTests, +-- Resolver.allTests, +-- Scope.allTests, +-- Termination.allTests, +-- Typecheck.allTests, +-- Format.allTests, +-- Formatter.allTests, +-- Package.allTests, +-- BackendMarkdown.allTests, +-- Isabelle.allTests, +-- Nockma.allTests +-- ] main :: IO () main = do - tests <- sequence [fastTests, slowTests] - defaultMain (testGroup "Juvix tests" tests) - --- defaultMain AnomaPositive.allTests + -- tests <- sequence [fastTests, slowTests] + -- defaultMain (testGroup "Juvix tests" tests) + defaultMain AnomaPositive.allTests From bba5da2e13006d5f9e9f0b47eab2f306a002818f Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 31 Oct 2024 17:28:28 +0100 Subject: [PATCH 21/29] try --- .github/workflows/ci.yml | 6 ++- test/Anoma/Compilation/Positive.hs | 86 ++++++++++++++++-------------- 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb8935f437..519f601cd6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -166,8 +166,10 @@ jobs: run: | cd $HOME/anoma echo "IO.puts(Anoma.Node.Examples.ENode.start_node().grpc_port)" > start.exs - mix run start.exs - ./apps/anoma_client/anoma_client + result=$(timeout 20s mix run --no-halt start.exs | { read -r line; echo "$line"; } &) + echo "Node = $result" + timeout 20s ./apps/anoma_client/anoma_client --listen-port 50051 --node-host localhost --node-port $result + exit 0 - name: Cache LLVM and Clang id: cache-llvm diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index e988fdbf2a..188b8a2330 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -140,48 +140,54 @@ checkOutput expected = case unsnoc expected of anomaNodeValid :: IntSet anomaNodeValid = intSet - [ 1, - 2, - 5, - 8, - 10, - 16, - 17, - 18, - 19, - 24, - 26, - 31, - 36, - 37, - 38, - 40, - 41, - 45, - 46, - 47, - 50, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 59, - 60, - 62, - 64, - 65, - 66, - 67, - 68, - 69, - 70, - 71, - 72 + [ 1 ] +-- anomaNodeValid :: IntSet +-- anomaNodeValid = +-- intSet +-- [ 1, +-- 2, +-- 5, +-- 8, +-- 10, +-- 16, +-- 17, +-- 18, +-- 19, +-- 24, +-- 26, +-- 31, +-- 36, +-- 37, +-- 38, +-- 40, +-- 41, +-- 45, +-- 46, +-- 47, +-- 50, +-- 52, +-- 53, +-- 54, +-- 55, +-- 56, +-- 57, +-- 58, +-- 59, +-- 60, +-- 62, +-- 64, +-- 65, +-- 66, +-- 67, +-- 68, +-- 69, +-- 70, +-- 71, +-- 72 +-- ] + anomaNodeBug :: IntSet anomaNodeBug = intSet From f48ae18d493eb6ebd19c3fde7f65777e068fe2d8 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 31 Oct 2024 18:51:28 +0100 Subject: [PATCH 22/29] remove dummy --- .github/workflows/ci.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 519f601cd6..e3eb5472dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -162,15 +162,6 @@ jobs: run: | curl -sSL "https://github.com/fullstorydev/grpcurl/releases/download/v1.9.1/grpcurl_1.9.1_linux_x86_64.tar.gz" | tar -xz -C ~/.local/bin --no-wildcards grpcurl - - name: Test Anoma (TMP) - run: | - cd $HOME/anoma - echo "IO.puts(Anoma.Node.Examples.ENode.start_node().grpc_port)" > start.exs - result=$(timeout 20s mix run --no-halt start.exs | { read -r line; echo "$line"; } &) - echo "Node = $result" - timeout 20s ./apps/anoma_client/anoma_client --listen-port 50051 --node-host localhost --node-port $result - exit 0 - - name: Cache LLVM and Clang id: cache-llvm uses: actions/cache@v3 From b12cd943f2e26bdfdf449613ca488c9bae93ca35 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 31 Oct 2024 19:10:29 +0100 Subject: [PATCH 23/29] automatically get listenPort --- src/Anoma/Effect/Base.hs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Anoma/Effect/Base.hs b/src/Anoma/Effect/Base.hs index 16a03b7a08..e74e5f9b43 100644 --- a/src/Anoma/Effect/Base.hs +++ b/src/Anoma/Effect/Base.hs @@ -12,7 +12,7 @@ module Anoma.Effect.Base anomaClientHandle, anomaPath, runAnoma, - runAnomaTest, + -- runAnomaTest, module Anoma.Rpc.Base, module Juvix.Compiler.Nockma.Translation.FromTree, ) @@ -32,6 +32,8 @@ data AnomaProcesses = AnomaProcesses _anomaClientHandle :: ProcessHandle } +newtype ListenPort = ListenPort Int + data Anoma :: Effect where -- | Keep the node and client running GetAnomaProcesses :: Anoma m AnomaProcesses @@ -48,9 +50,6 @@ newtype GrpcPort = GrpcPort {_grpcPort :: Int} makeLenses ''AnomaPath makeLenses ''GrpcPort -listenPort :: Int -listenPort = 50051 - relativeToAnomaDir :: (Members '[Reader AnomaPath] r) => Path Rel x -> Sem r (Path Abs x) relativeToAnomaDir p = do anoma <- asks (^. anomaPath) @@ -58,18 +57,19 @@ relativeToAnomaDir p = do withSpawnAnomaClient :: (Members '[Process, Logger, EmbedIO, Reader AnomaPath, Reader GrpcPort, Error SimpleError] r) => - (ProcessHandle -> Sem r a) -> + (Int -> ProcessHandle -> Sem r a) -> Sem r a withSpawnAnomaClient body = do cprocess <- mkProcess withCreateProcess cprocess $ \_stdin mstdout _stderr procHandle -> do let out = fromJust mstdout txt <- hGetLine out - case takeWhile (/= '.') (unpack txt) of - "Connected to node" -> do + case span (/= '.') (unpack txt) of + ("Connected to node", rest) -> do + let port = readJust (last (nonEmpty' (words rest))) logInfo "Anoma client successfully started" - logInfo (mkAnsiText ("Listening on port " <> annotate AnnImportant (pretty listenPort))) - body procHandle + logInfo (mkAnsiText ("Listening on port " <> annotate AnnImportant (pretty port))) + body port procHandle _ -> throw (SimpleError (mkAnsiText @Text "Something went wrong when starting the anoma client")) where mkProcess :: (Members '[Reader AnomaPath, Reader GrpcPort] r') => Sem r' CreateProcess @@ -80,7 +80,7 @@ withSpawnAnomaClient body = do ( proc (toFilePath anomaClient) [ "--listen-port", - show listenPort, + "0", "--node-host", "localhost", "--node-port", @@ -117,7 +117,7 @@ withSpawnAnomaNode body = withSystemTempFile "start.exs" $ \fp tmpHandle -> do } anomaRpc' :: - (Members '[Reader AnomaPath, Process, EmbedIO, Error SimpleError] r) => + (Members '[Reader ListenPort, Reader AnomaPath, Process, EmbedIO, Error SimpleError] r) => GrpcMethodUrl -> Value -> Sem r Value @@ -134,9 +134,10 @@ anomaRpc' method payload = do Right r -> return r Left err -> throw (SimpleError (mkAnsiText err)) -grpcCliProcess :: (Members '[Reader AnomaPath] r) => GrpcMethodUrl -> Sem r CreateProcess +grpcCliProcess :: (Members '[Reader ListenPort, Reader AnomaPath] r) => GrpcMethodUrl -> Sem r CreateProcess grpcCliProcess method = do importPath <- relativeToAnomaDir relProtoDir + ListenPort listenPort <- ask return ( proc "grpcurl" @@ -156,17 +157,16 @@ grpcCliProcess method = do } -- | Assumes the node and client are already running -runAnomaTest :: forall r a. (Members '[Logger, EmbedIO, Error SimpleError] r) => AnomaPath -> Sem (Anoma ': r) a -> Sem r a -runAnomaTest anomapath body = runReader anomapath . runProcess $ - (`interpret` inject body) $ \case - GetAnomaProcesses -> error "unsupported" - AnomaRpc method i -> anomaRpc' method i - +-- runAnomaTest :: forall r a. (Members '[Reader ListenPort, Logger, EmbedIO, Error SimpleError] r) => AnomaPath -> Sem (Anoma ': r) a -> Sem r a +-- runAnomaTest anomapath body = runReader anomapath . runProcess $ +-- (`interpret` inject body) $ \case +-- GetAnomaProcesses -> error "unsupported" +-- AnomaRpc method i -> anomaRpc' method i runAnoma :: forall r a. (Members '[Logger, EmbedIO, Error SimpleError] r) => AnomaPath -> Sem (Anoma ': r) a -> Sem r a runAnoma anomapath body = runReader anomapath . runProcess $ withSpawnAnomaNode $ \grpcport _nodeOut nodeH -> runReader (GrpcPort grpcport) $ - withSpawnAnomaClient $ \clientH -> do + withSpawnAnomaClient $ \listenPort clientH -> runReader (ListenPort listenPort) $ do (`interpret` inject body) $ \case GetAnomaProcesses -> return From 43c9370229148f4531402e4960304c4f06dc293e Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 31 Oct 2024 19:51:02 +0100 Subject: [PATCH 24/29] restore tests --- .github/workflows/ci.yml | 144 ++++++++++++++--------------- test/Anoma/Compilation/Positive.hs | 86 ++++++++--------- test/Main.hs | 128 +++++++++++++------------ 3 files changed, 174 insertions(+), 184 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3eb5472dc..8e59af4636 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,41 +75,41 @@ jobs: build-and-test-linux: runs-on: ubuntu-22.04 steps: - # - name: Free disk space - # run: | - # df -h - # echo "/usr/local" - # du -hsc /usr/local/* - # sudo rm -rf \ - # /usr/local/aws-sam-cil \ - # /usr/local/julia* || : - # echo "end /usr/local" - # echo "/usr/local/lib" - # du -hsc /usr/local/lib/* - # sudo rm -rf \ - # /usr/local/lib/android \ - # /usr/local/lib/heroku \ - # /usr/local/lib/node_modules || : - # echo "end /usr/local/lib" - # echo "/usr/local/share" - # du -hsc /usr/local/share/* - # sudo rm -rf \ - # /usr/local/share/chromium \ - # /usr/local/share/powershell || : - # echo "end /usr/local/share" - # echo "/opt/hostedtoolcache/" - # du -hsc /opt/hostedtoolcache/* - # sudo rm -rf \ - # /opt/hostedtoolcache/CodeQL \ - # /opt/hostedtoolcache/go \ - # /opt/hostedtoolcache/PyPy \ - # /opt/hostedtoolcache/node || : - # echo "end /opt/hostedtoolcache/*" - # sudo apt purge -y \ - # firefox \ - # google-chrome-stable \ - # microsoft-edge-stable - # df -h + - name: Free disk space + run: | + df -h + echo "/usr/local" + du -hsc /usr/local/* + sudo rm -rf \ + /usr/local/aws-sam-cil \ + /usr/local/julia* || : + echo "end /usr/local" + echo "/usr/local/lib" + du -hsc /usr/local/lib/* + sudo rm -rf \ + /usr/local/lib/android \ + /usr/local/lib/heroku \ + /usr/local/lib/node_modules || : + echo "end /usr/local/lib" + echo "/usr/local/share" + du -hsc /usr/local/share/* + sudo rm -rf \ + /usr/local/share/chromium \ + /usr/local/share/powershell || : + echo "end /usr/local/share" + echo "/opt/hostedtoolcache/" + du -hsc /opt/hostedtoolcache/* + sudo rm -rf \ + /opt/hostedtoolcache/CodeQL \ + /opt/hostedtoolcache/go \ + /opt/hostedtoolcache/PyPy \ + /opt/hostedtoolcache/node || : + echo "end /opt/hostedtoolcache/*" + sudo apt purge -y \ + firefox \ + google-chrome-stable \ + microsoft-edge-stable + df -h - uses: extractions/setup-just@v2 @@ -213,49 +213,49 @@ jobs: path: ${{ env.HOME }}/.local/bin/juvix-cairo-vm key: ${{ runner.os }}-cairo-vm-${{ env.CAIRO_VM_VERSION }} - # - name: Install Rust toolchain - # if: steps.cache-cairo-vm.outputs.cache-hit != 'true' - # uses: actions-rust-lang/setup-rust-toolchain@v1 - # with: - # cache-on-failure: false - - # - name: Install RISC0 VM - # shell: bash - # run: | - # cargo install cargo-binstall@1.6.9 --force - # cargo binstall cargo-risczero@1.1.1 --no-confirm --force - # cargo risczero install - - # - name: Checkout CairoVM - # uses: actions/checkout@v4 - # if: steps.cache-cairo-vm.outputs.cache-hit != 'true' - # with: - # repository: anoma/juvix-cairo-vm - # path: juvix-cairo-vm - # ref: ${{ env.CAIRO_VM_VERSION }} - - # - name: Install Cairo VM - # if: steps.cache-cairo-vm.outputs.cache-hit != 'true' - # shell: bash - # run: | - # cd juvix-cairo-vm - # cargo build --release - # cp target/release/juvix-cairo-vm $HOME/.local/bin/juvix-cairo-vm - - # - name: Install run_cairo_vm.sh - # shell: bash - # run: | - # cp main/scripts/run_cairo_vm.sh $HOME/.local/bin/run_cairo_vm.sh + - name: Install Rust toolchain + if: steps.cache-cairo-vm.outputs.cache-hit != 'true' + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + cache-on-failure: false + + - name: Install RISC0 VM + shell: bash + run: | + cargo install cargo-binstall@1.6.9 --force + cargo binstall cargo-risczero@1.1.1 --no-confirm --force + cargo risczero install + + - name: Checkout CairoVM + uses: actions/checkout@v4 + if: steps.cache-cairo-vm.outputs.cache-hit != 'true' + with: + repository: anoma/juvix-cairo-vm + path: juvix-cairo-vm + ref: ${{ env.CAIRO_VM_VERSION }} + + - name: Install Cairo VM + if: steps.cache-cairo-vm.outputs.cache-hit != 'true' + shell: bash + run: | + cd juvix-cairo-vm + cargo build --release + cp target/release/juvix-cairo-vm $HOME/.local/bin/juvix-cairo-vm + + - name: Install run_cairo_vm.sh + shell: bash + run: | + cp main/scripts/run_cairo_vm.sh $HOME/.local/bin/run_cairo_vm.sh - name: Make runtime run: | cd main just ${{ env.JUST_ARGS }} build runtime - # - name: Test Rust runtime - # run: | - # cd main/runtime/rust/juvix - # cargo test --release + - name: Test Rust runtime + run: | + cd main/runtime/rust/juvix + cargo test --release # We use the options: # - -fhide-source-paths diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index 188b8a2330..e988fdbf2a 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -140,54 +140,48 @@ checkOutput expected = case unsnoc expected of anomaNodeValid :: IntSet anomaNodeValid = intSet - [ 1 + [ 1, + 2, + 5, + 8, + 10, + 16, + 17, + 18, + 19, + 24, + 26, + 31, + 36, + 37, + 38, + 40, + 41, + 45, + 46, + 47, + 50, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 62, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72 ] --- anomaNodeValid :: IntSet --- anomaNodeValid = --- intSet --- [ 1, --- 2, --- 5, --- 8, --- 10, --- 16, --- 17, --- 18, --- 19, --- 24, --- 26, --- 31, --- 36, --- 37, --- 38, --- 40, --- 41, --- 45, --- 46, --- 47, --- 50, --- 52, --- 53, --- 54, --- 55, --- 56, --- 57, --- 58, --- 59, --- 60, --- 62, --- 64, --- 65, --- 66, --- 67, --- 68, --- 69, --- 70, --- 71, --- 72 --- ] - anomaNodeBug :: IntSet anomaNodeBug = intSet diff --git a/test/Main.hs b/test/Main.hs index b2461c96f6..6f7dd375ab 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -1,74 +1,70 @@ module Main (main) where --- import Anoma qualified --- import Asm qualified --- import BackendMarkdown qualified - -import Anoma.Compilation.Positive qualified as AnomaPositive +import Anoma qualified +import Asm qualified +import BackendMarkdown qualified import Base +import Casm qualified +import Compilation qualified +import Core qualified +import Examples qualified +import Format qualified +import Formatter qualified +import Internal qualified +import Isabelle qualified +import Juvix.Config qualified as Config +import Nockma qualified +import Package qualified +import Parsing qualified +import Reg qualified +import Repl qualified +import Resolver qualified +import Runtime qualified +import Rust qualified +import Scope qualified +import Termination qualified +import Tree qualified +import Typecheck qualified --- import Casm qualified --- import Compilation qualified --- import Core qualified --- import Examples qualified --- import Format qualified --- import Formatter qualified --- import Internal qualified --- import Isabelle qualified --- import Juvix.Config qualified as Config --- import Nockma qualified --- import Package qualified --- import Parsing qualified --- import Reg qualified --- import Repl qualified --- import Resolver qualified --- import Runtime qualified --- import Rust qualified --- import Scope qualified --- import Termination qualified --- import Tree qualified --- import Typecheck qualified - --- slowTests :: IO TestTree --- slowTests = --- sequentialTestGroup --- "Juvix slow tests" --- AllFinish --- <$> sequence --- [ return Runtime.allTests, --- return Reg.allTests, --- return Asm.allTests, --- return Tree.allTests, --- return Core.allTests, --- return Internal.allTests, --- return Compilation.allTests, --- return Examples.allTests, --- Casm.allTests, --- return Anoma.allTests, --- return Repl.allTests --- ] --- <> sequence (if Config.config ^. Config.configRust then [Rust.allTests] else []) +slowTests :: IO TestTree +slowTests = + sequentialTestGroup + "Juvix slow tests" + AllFinish + <$> sequence + [ return Runtime.allTests, + return Reg.allTests, + return Asm.allTests, + return Tree.allTests, + return Core.allTests, + return Internal.allTests, + return Compilation.allTests, + return Examples.allTests, + Casm.allTests, + return Anoma.allTests, + return Repl.allTests + ] + <> sequence (if Config.config ^. Config.configRust then [Rust.allTests] else []) --- fastTests :: IO TestTree --- fastTests = --- return $ --- testGroup --- "Juvix fast tests" --- [ Parsing.allTests, --- Resolver.allTests, --- Scope.allTests, --- Termination.allTests, --- Typecheck.allTests, --- Format.allTests, --- Formatter.allTests, --- Package.allTests, --- BackendMarkdown.allTests, --- Isabelle.allTests, --- Nockma.allTests --- ] +fastTests :: IO TestTree +fastTests = + return $ + testGroup + "Juvix fast tests" + [ Parsing.allTests, + Resolver.allTests, + Scope.allTests, + Termination.allTests, + Typecheck.allTests, + Format.allTests, + Formatter.allTests, + Package.allTests, + BackendMarkdown.allTests, + Isabelle.allTests, + Nockma.allTests + ] main :: IO () main = do - -- tests <- sequence [fastTests, slowTests] - -- defaultMain (testGroup "Juvix tests" tests) - defaultMain AnomaPositive.allTests + tests <- sequence [fastTests, slowTests] + defaultMain (testGroup "Juvix tests" tests) From acb2e9508645ad8b5d01897fdc7581bdadba93ed Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Mon, 4 Nov 2024 16:32:38 +0100 Subject: [PATCH 25/29] classify tests --- test/Anoma/Compilation/Positive.hs | 158 ++++++++++++++++++----------- 1 file changed, 101 insertions(+), 57 deletions(-) diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index e988fdbf2a..8880d29e7c 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -3,7 +3,6 @@ module Anoma.Compilation.Positive (allTests) where import Anoma.Effect.Base import Anoma.Effect.RunNockma import Base -import Data.IntSet qualified as IntSet import Juvix.Compiler.Backend (Target (TargetAnoma)) import Juvix.Compiler.Nockma.Anoma import Juvix.Compiler.Nockma.Evaluator @@ -137,60 +136,107 @@ checkOutput expected = case unsnoc expected of eqTraces xs eqNock x -anomaNodeValid :: IntSet -anomaNodeValid = - intSet - [ 1, - 2, - 5, - 8, - 10, - 16, - 17, - 18, - 19, - 24, - 26, - 31, - 36, - 37, - 38, - 40, - 41, - 45, - 46, - 47, - 50, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 59, - 60, - 62, - 64, - 65, - 66, - 67, - 68, - 69, - 70, - 71, - 72 - ] +data TestClass + = ClassWorking + | -- | The test uses trace, so we need to wait until we update the anoma-node + -- and parse the traces from the response + ClassTrace + | -- | The anoma node returns a response with an error + ClassNodeError + | -- | The anoma node returns a value but it doesn't match the expected value + ClassWrong + | -- | We have no test with this number + ClassMissing + deriving stock (Eq, Show) -anomaNodeBug :: IntSet -anomaNodeBug = - intSet - [ 24, - 41, - 52, - 54, - 56 - ] +classify :: AnomaTest -> TestClass +classify AnomaTest {..} = case _anomaTestNum of + 1 -> ClassWorking + 2 -> ClassWorking + 3 -> ClassTrace + 4 -> ClassMissing + 5 -> ClassWorking + 6 -> ClassTrace + 7 -> ClassTrace + 8 -> ClassWorking + 9 -> ClassTrace + 10 -> ClassWorking + 11 -> ClassTrace + 12 -> ClassTrace + 13 -> ClassTrace + 14 -> ClassTrace + 15 -> ClassTrace + 16 -> ClassWorking + 17 -> ClassWorking + 18 -> ClassWorking + 19 -> ClassWorking + 20 -> ClassTrace + 21 -> ClassTrace + 22 -> ClassTrace + 23 -> ClassTrace + 24 -> ClassNodeError + 25 -> ClassTrace + 26 -> ClassWorking + 27 -> ClassMissing + 28 -> ClassTrace + 29 -> ClassTrace + 30 -> ClassTrace + 31 -> ClassWorking + 32 -> ClassTrace + 33 -> ClassTrace + 34 -> ClassTrace + 35 -> ClassTrace + 36 -> ClassWorking + 37 -> ClassWorking + 38 -> ClassWorking + 39 -> ClassTrace + 40 -> ClassWorking + 41 -> ClassWrong + 42 -> ClassMissing + 43 -> ClassTrace + 45 -> ClassWorking + 46 -> ClassWorking + 47 -> ClassWorking + 48 -> ClassMissing + 49 -> ClassTrace + 50 -> ClassWorking + 51 -> ClassMissing + 52 -> ClassWrong + 53 -> ClassWorking + 54 -> ClassNodeError + 55 -> ClassWorking + 56 -> ClassNodeError + 57 -> ClassWorking + 58 -> ClassWorking + 59 -> ClassWorking + 60 -> ClassNodeError + 61 -> ClassTrace + 62 -> ClassWorking + 63 -> ClassTrace + 64 -> ClassWorking + 65 -> ClassWorking + 66 -> ClassWorking + 67 -> ClassWorking + 68 -> ClassWorking + 69 -> ClassWorking + 70 -> ClassWorking + 71 -> ClassWorking + 72 -> ClassWorking + 73 -> ClassWorking + 74 -> ClassTrace + 75 -> ClassTrace + 76 -> ClassTrace + 77 -> ClassNodeError + 78 -> ClassNodeError + 79 -> ClassWorking + 80 -> ClassTrace + 81 -> ClassTrace + 82 -> ClassTrace + 83 -> ClassTrace + 84 -> ClassTrace + 85 -> ClassTrace + 86 -> ClassTrace + _ -> error "non-exhaustive test classification" allTests :: TestTree allTests = @@ -207,9 +253,7 @@ allTests = (map mkAnomaNodeTest (filter shouldRun anomaTests)) where shouldRun :: AnomaTest -> Bool - shouldRun AnomaTest {..} = - IntSet.member _anomaTestNum anomaNodeValid - && IntSet.notMember _anomaTestNum anomaNodeBug + shouldRun a = classify a == ClassWorking haskellNockmaTests :: TestTree haskellNockmaTests = From cc7585d6fd91191c2cb8479852ee51c69b40a340 Mon Sep 17 00:00:00 2001 From: Paul Cadman Date: Tue, 5 Nov 2024 11:42:06 +0000 Subject: [PATCH 26/29] Fix argsPath in nock stdlib call The argsPath in stdlib call should be unconditionally [R, L] i.e the 'arguments' slot of the stdlib function. --- src/Juvix/Compiler/Nockma/Translation/FromTree.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Juvix/Compiler/Nockma/Translation/FromTree.hs b/src/Juvix/Compiler/Nockma/Translation/FromTree.hs index c486dc99fd..ca00a4b988 100644 --- a/src/Juvix/Compiler/Nockma/Translation/FromTree.hs +++ b/src/Juvix/Compiler/Nockma/Translation/FromTree.hs @@ -885,9 +885,8 @@ callAnomaLib fun args = do let ref = AnomaLibFunction fun fPath = anomaLibPath ref getFunCode = opAddress "callStdlibFunCode" stdpath >># fPath - argsPath <- stackPath ArgsTuple let adjustArgs = case nonEmpty args of - Just args' -> opReplace "callStdlib-args" argsPath ((opAddress "stdlibR" [R]) >># foldTerms args') (opAddress "stdlibL" [L]) + Just args' -> opReplace "callStdlib-args" [R, L] ((opAddress "stdlibR" [R]) >># foldTerms args') (opAddress "stdlibL" [L]) Nothing -> opAddress "adjustArgsNothing" [L] callFn = opCall "callStdlib" (closurePath FunCode) adjustArgs meta = From fbe0b2e595504fbc5b7c8cf4af3aa0ee4dcb9b1d Mon Sep 17 00:00:00 2001 From: Paul Cadman Date: Tue, 5 Nov 2024 11:44:03 +0000 Subject: [PATCH 27/29] Mark nock tests which are now working --- test/Anoma/Compilation/Positive.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index 8880d29e7c..c98147e0ae 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -191,7 +191,7 @@ classify AnomaTest {..} = case _anomaTestNum of 38 -> ClassWorking 39 -> ClassTrace 40 -> ClassWorking - 41 -> ClassWrong + 41 -> ClassWorking 42 -> ClassMissing 43 -> ClassTrace 45 -> ClassWorking @@ -201,15 +201,15 @@ classify AnomaTest {..} = case _anomaTestNum of 49 -> ClassTrace 50 -> ClassWorking 51 -> ClassMissing - 52 -> ClassWrong + 52 -> ClassWorking 53 -> ClassWorking - 54 -> ClassNodeError + 54 -> ClassWorking 55 -> ClassWorking - 56 -> ClassNodeError + 56 -> ClassWorking 57 -> ClassWorking 58 -> ClassWorking 59 -> ClassWorking - 60 -> ClassNodeError + 60 -> ClassWorking 61 -> ClassTrace 62 -> ClassWorking 63 -> ClassTrace From b66b2f914f5ac44b4e1b65890bb6f40de54030f0 Mon Sep 17 00:00:00 2001 From: Paul Cadman Date: Tue, 5 Nov 2024 11:45:25 +0000 Subject: [PATCH 28/29] Remove commented out code --- src/Anoma/Effect/Base.hs | 1 - test/Anoma/Compilation/Positive.hs | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/src/Anoma/Effect/Base.hs b/src/Anoma/Effect/Base.hs index e74e5f9b43..bb1c5941fd 100644 --- a/src/Anoma/Effect/Base.hs +++ b/src/Anoma/Effect/Base.hs @@ -12,7 +12,6 @@ module Anoma.Effect.Base anomaClientHandle, anomaPath, runAnoma, - -- runAnomaTest, module Anoma.Rpc.Base, module Juvix.Compiler.Nockma.Translation.FromTree, ) diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index c98147e0ae..cdf64cb13c 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -257,23 +257,9 @@ allTests = haskellNockmaTests :: TestTree haskellNockmaTests = - -- withResource initNode freeNode $ \_ -> testGroup "Anoma positive tests (Haskell evaluator)" (map fromAnomaTest anomaTests) - -- where - -- initNode :: IO AnomaProcesses - -- initNode = runM - -- . runSimpleErrorHUnit - -- . ignoreLogger - -- . runAnoma testAnomaPath - -- $ do - -- noHalt - - -- freeNode :: AnomaProcesses -> IO () - -- freeNode AnomaProcesses {..} = runM . runProcess $ do - -- terminateProcess _anomaClientHandle - -- terminateProcess _anomaNodeHandle natArg :: Natural -> Term Natural natArg = toNock From 137756144f9cf3109b39a7fb94b910ef137a6db2 Mon Sep 17 00:00:00 2001 From: Paul Cadman Date: Tue, 5 Nov 2024 12:23:48 +0000 Subject: [PATCH 29/29] Nock test 24 works --- test/Anoma/Compilation/Positive.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index cdf64cb13c..00dff59858 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -174,7 +174,7 @@ classify AnomaTest {..} = case _anomaTestNum of 21 -> ClassTrace 22 -> ClassTrace 23 -> ClassTrace - 24 -> ClassNodeError + 24 -> ClassWorking 25 -> ClassTrace 26 -> ClassWorking 27 -> ClassMissing