A peer-to-peer stack for code collaboration
Improve usage of 'sourceFiles' in tests
Thomas Scholtes95fe8f5e5387
diff --git a/package.yaml b/package.yamlindex b19b6d9..f8d5be8 100644--- a/package.yaml+++ b/package.yaml@@ -56,6 +56,7 @@ tests:- radicle- containers- cryptonite+ - directory- filemanip- interpolate- megaparsecdiff --git a/test/spec/Radicle/Internal/TestCapabilities.hs b/test/spec/Radicle/Internal/TestCapabilities.hsindex 52a6c84..41f1be1 100644--- a/test/spec/Radicle/Internal/TestCapabilities.hs+++ b/test/spec/Radicle/Internal/TestCapabilities.hs@@ -15,6 +15,7 @@ import qualified Crypto.Random as CryptoRandimport qualified Data.Map.Strict as Mapimport qualified Data.Sequence as Seqimport qualified Data.Time as Time+import System.Directory (getCurrentDirectory)import qualified System.FilePath.Find as FPimport System.IO.Unsafe (unsafePerformIO)@@ -25,8 +26,6 @@ import Radicle.Internal.Effects.Capabilitiesimport Radicle.Internal.Storageimport qualified Radicle.Internal.UUID as UUID-import Paths_radicle-data WorldState = WorldState{ worldStateStdin :: [Text]@@ -82,12 +81,18 @@ runTest bnds prog = fst <$> runTestWith bnds [] progrunTest' :: Text -> Either (LangError Value) ValuerunTest' a = unsafePerformIO $ runTest pureEnv a--- | The radicle source files, along with their directory.-sourceFiles :: IO (FilePath, [FilePath])++-- | Loads the content for all radicle sources in the "./rad" folder.+-- Returns a map from files names to contents.+sourceFiles :: IO (Map Text Text)sourceFiles = do- dir <- getDataDir- allFiles <- FP.find FP.always (FP.extension FP.==? ".rad") dir- pure (dir <> "/", drop (length dir + 1) <$> allFiles)+ dir <- getCurrentDirectory+ absPaths <- FP.find FP.always (FP.extension FP.==? ".rad") dir+ filesWithContent <- forM absPaths $ \absPath -> do+ contents <- readFile absPath+ let path = drop (length dir + 1) absPath+ pure (toS path, contents)+ pure $ Map.fromList filesWithContent-- | Bindings with REPL and client stuff mocked, and with -- a 'test-env__'-- variable set to true.diff --git a/test/spec/Radicle/Tests.hs b/test/spec/Radicle/Tests.hsindex eaab92b..5454062 100644--- a/test/spec/Radicle/Tests.hs+++ b/test/spec/Radicle/Tests.hs@@ -788,17 +788,11 @@ test_source_files = dowheretestOne :: FilePath -> IO [TestTree]testOne file = do- (dir, files) <- sourceFiles- allFiles <- forM files $ \f -> do- contents <- readFile (dir <> f)- pure (toS f, contents)- contents <- readFile (dir <> file)keyPair :: Text <- runTest testBindings "(gen-key-pair! (default-ecc-curve))" >>= \caseRight kp -> pure $ renderCompactPretty kpLeft _ -> panic "Couldn't generate keypair file."- (r, out) <- runTestWithFiles testBindings []- (Map.insert "my-keys.rad" keyPair (fromList allFiles))- contents+ srcs <- Map.insert "my-keys.rad" keyPair <$> sourceFiles+ (r, out) <- runTestWithFiles testBindings [] srcs $ toS $ "(load! \"" <> file <> "\")"let makeTest line =let name = T.reverse $ T.drop 1 $ T.dropWhile (/= '\'')$ T.reverse $ T.drop 1 $ T.dropWhile (/= '\'') line@@ -853,9 +847,8 @@ prettyEither (Right v) = renderPrettyDef v-- that the last two lines of the actual output equal @[a, b]@.assertReplInteraction :: [Text] -> [Text] -> IO ()assertReplInteraction input expected = do- (dir, srcs) <- sourceFiles- srcMap <- forM srcs (\src -> (T.pack src ,) <$> readFile (dir <> src))- (result, output) <- runTestWithFiles testBindings input (Map.fromList srcMap) "(load! \"rad/repl.rad\")"+ srcs <- sourceFiles+ (result, output) <- runTestWithFiles testBindings input srcs "(load! \"rad/repl.rad\")"case result ofLeft err -> assertFailure $ "Error thrown in Repl: " <> toS (renderPrettyDef err)Right _ -> pure ()