From c11d97166802e3d01c02c472c018379e0d4b3459 Mon Sep 17 00:00:00 2001 From: Paul Cadman Date: Tue, 20 Feb 2024 08:19:32 +0000 Subject: [PATCH] Run each anoma compilation test in a separate temp dir --- test/Anoma/Compilation/Positive.hs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/test/Anoma/Compilation/Positive.hs b/test/Anoma/Compilation/Positive.hs index dfae003731..48b3868cdd 100644 --- a/test/Anoma/Compilation/Positive.hs +++ b/test/Anoma/Compilation/Positive.hs @@ -17,17 +17,26 @@ mkAnomaCallTest' :: Bool -> Text -> Prelude.Path Rel Dir -> Prelude.Path Rel Fil mkAnomaCallTest' enableDebug _testName relRoot mainFile args _testCheck = testCase (unpack _testName) (mkTestIO >>= mkNockmaAssertion) where - rootDir' :: Prelude.Path Abs Dir - rootDir' = root relRoot - mkTestIO :: IO Test mkTestIO = do - entryPoint <- set entryPointTarget TargetAnoma . set entryPointDebug enableDebug <$> testDefaultEntryPointIO rootDir' (rootDir' mainFile) - _testProgramSubject <- (^. pipelineResult) . snd <$> testRunIO entryPoint upToAnoma + _testProgramSubject <- withRootCopy compileMain let _testProgramFormula = anomaCall args _testEvalOptions = defaultEvalOptions return Test {..} + withRootCopy :: (Prelude.Path Abs Dir -> IO a) -> IO a + withRootCopy action = withSystemTempDir "test" $ \tmpRootDir -> do + copyDirRecur root tmpRootDir + action tmpRootDir + + compileMain :: Prelude.Path Abs Dir -> IO (Term Natural) + compileMain rootCopyDir = do + let testRootDir = rootCopyDir relRoot + entryPoint <- + set entryPointTarget TargetAnoma . set entryPointDebug enableDebug + <$> testDefaultEntryPointIO testRootDir (testRootDir mainFile) + (^. pipelineResult) . snd <$> testRunIO entryPoint upToAnoma + mkAnomaCallTestNoTrace :: Text -> Prelude.Path Rel Dir -> Prelude.Path Rel File -> [Term Natural] -> Check () -> TestTree mkAnomaCallTestNoTrace = mkAnomaCallTest' False