Skip to content

A peer-to-peer stack for code collaboration

Add RADPATH. (#397)

Julian Arnib7d8039e98f5
diff --git a/bin/rad-issues b/bin/rad-issues
index 041839b..94cf881 100755
--- a/bin/rad-issues
+++ b/bin/rad-issues
@@ -1,9 +1,9 @@
#!/usr/bin/env radicle
-(load! "rad/prelude.rad")
-(load! "rad/monadic/issues.rad")
-(load! "rad/prelude/io-utils.rad")
-(load! "rad/prelude/cmd-parsing.rad")
+(load! (find-module-file! "prelude.rad"))
+(load! (find-module-file! "monadic/issues.rad"))
+(load! (find-module-file! "prelude/io-utils.rad"))
+(load! (find-module-file! "prelude/cmd-parsing.rad"))
(import prelude/validation :as 'validation)
@@ -105,7 +105,7 @@
(fn [chain options]
(def chain-ref (make-chain-ref chain))
- (load! "rad/monadic/names.rad")
+ (load! (find-module-file! "rad/monadic/names.rad"))
(def names (ref (chain/load-chain! name-base)))
(def add-username
(fn [d]
diff --git a/cloudbuild.yaml b/cloudbuild.yaml
index f542174..e4ad6e7 100644
--- a/cloudbuild.yaml
+++ b/cloudbuild.yaml
@@ -67,7 +67,7 @@ steps:
stack test :doctest
stack test :spec
- stack exec -- radicle test/all.rad
+ RADPATH="$(pwd)/rad" stack exec -- radicle test/all.rad
- id: "Lint (weeder)"
waitFor: ["Build"]
@@ -87,7 +87,7 @@ steps:
set -euxo pipefail
mv docs/source/reference.rst oldref
- stack exec radicle-ref-doc
+ RADPATH="$(pwd)/rad" stack exec radicle-ref-doc
if ! (diff oldref docs/source/reference.rst); then
echo "Reference docs are not checked in"
exit 1
@@ -104,7 +104,7 @@ steps:
- |
set -euxo pipefail
- stack exec radicle-doc docs/source/guide/Basics.lrad
+ RADPATH="$(pwd)/rad" stack exec radicle-doc docs/source/guide/Basics.lrad
- id: "Build radicle-server image"
waitFor:
@@ -171,6 +171,7 @@ steps:
- |
set -euxo pipefail
export RAD_IPFS_API_URL=http://ipfs-test-network:5001
+ export RADPATH="$(pwd)/rad"
stack test :e2e
stack exec -- radicle test/machine-backends.rad radicle-server
diff --git a/docs/source/guide/Issues.lrad b/docs/source/guide/Issues.lrad
index f750798..4382742 100644
--- a/docs/source/guide/Issues.lrad
+++ b/docs/source/guide/Issues.lrad
@@ -11,10 +11,10 @@ exec doc -- docs/source/guide/Issues.lrad`.
First we load the prelude:
- (load! "rad/prelude.rad")
+ (load! (find-module-file! "prelude.rad"))
We'll use a ref to store the issues, as a dictionary from issue IDs to issues.
-
+
(def issues (ref {}))
To update the state of our issues we'll use `modify-ref`, a function which takes
@@ -27,7 +27,7 @@ create a function for that:
Next we'll define a function for creating a new issue. An issue is a dict which
looks like:
-
+
{ :id "ab12-xy23"
:author "user-id-here"
:title "I want pattern matching"
@@ -90,7 +90,7 @@ leave such an `update` command with no restrictions; we'll talk about that
later.
(load! "rad/chain.rad")
-
+
(def eval
(updatable-eval
(fn [expr state]
@@ -103,7 +103,7 @@ function at the REPL.
:author "james"
:title "Pattern matching"
:body "Pleeease"})
-
+
(create {:id "a37e56bd-b66a-4f3f-af06-9eaeb4afdae9"
:author "julian"
:title "Better numbers"
@@ -145,7 +145,7 @@ to issues.
(modify-map issue-id
(fn [i]
(modify-map :comments
- (fn [cs] (add-right comment cs))
+ (fn [cs] (add-right comment cs))
i))
is))))))
diff --git a/docs/source/guide/Modules.lrad b/docs/source/guide/Modules.lrad
index 8b91b5d..45a525e 100644
--- a/docs/source/guide/Modules.lrad
+++ b/docs/source/guide/Modules.lrad
@@ -43,7 +43,7 @@ And then we could use this module with different values of `VAT`:
(import (make-taxes 2/10))
;; We also need to import `prelude/io` to be able to use `print!`
- (import (file-module! "rad/prelude/io.rad") :unqualified)
+ (import (file-module! "prelude/io.rad") :unqualified)
(print! (string-append "100 EUR + VAT is: " (show (taxes/add-VAT 100))))
diff --git a/docs/source/guide/PatternMatching.lrad b/docs/source/guide/PatternMatching.lrad
index b69995c..7d60555 100644
--- a/docs/source/guide/PatternMatching.lrad
+++ b/docs/source/guide/PatternMatching.lrad
@@ -9,7 +9,7 @@ used in `match` expressions.
Pattern matching is invoked as follows:
;; Just getting an import out of the way
- (import (file-module! "rad/prelude/io.rad") :unqualified)
+ (import (file-module! "prelude/io.rad") :unqualified)
(match 42
'x (print! (string-append "x was: " (show x))))
@@ -17,9 +17,9 @@ Pattern matching is invoked as follows:
That's not very interesting, but it's all we can do before we import some more
patterns:
- (import (file-module! "rad/prelude/test.rad") :unqualified)
- (file-module! "rad/prelude/basic.rad")
- (import (file-module! "rad/prelude/patterns.rad") :unqualified)
+ (import (file-module! "prelude/test.rad") :unqualified)
+ (file-module! "prelude/basic.rad")
+ (import (file-module! "prelude/patterns.rad") :unqualified)
Now we can pattern match on vectors, numbers, dicts, etc. For example,
evaluating:
@@ -69,7 +69,7 @@ These are the patterns that come included in the prelude:
- The pattern `(/as x p)`, where `x` is an atom and `p` is a pattern, matches
any values that `p` matches while also binding this value to `x` in the
branch.
-
+
## Binding variables
Variables used in patterns must be quoted because patterns are themselves
@@ -77,12 +77,12 @@ evaluated. This means that if `x` is already bound to a value then it can be
used in a pattern. For example:
(def x 1)
-
+
(print!
(match [2 2]
[x 'y] (+ y y)
[(+ x 1) 'y] (+ x y)))
-
+
will print the number `3`, that is, evaluate the second branch. This is because
`(+ x 1)` evaluates to `2`, and so this matches the first `2` of the value `[2
2]`.
@@ -179,5 +179,5 @@ Will print `"DANGER! powerful player Alice Smith with spell radius 134 is
approaching!"`, but calling:
(nearby bob)
-
+
will print `"A weak elf with only 55 health is nearby! Attack!"`.
diff --git a/docs/source/guide/index.rst b/docs/source/guide/index.rst
index de6f537..483c430 100644
--- a/docs/source/guide/index.rst
+++ b/docs/source/guide/index.rst
@@ -2,7 +2,7 @@ The radicle guide
==================
radicle is a language for building and interacting with chains of the Open
-Source Network. What these chains do--how they behave--is entirely up to you.
+Source Network. What these chains do--how they behave--is entirely up to you.
This guide provides an introduction to radicle--as a language, as a tool for
building chains, and as a means of interacting with existing chains.
@@ -14,24 +14,24 @@ An example
As a running example, we'll create a chain for managing the issues of a
repository. We'll see how to define the format of issues that can be created;
how to define rights and permissions for certain types of interaction; and
-how to allow for future changes to the chain.
+how to allow for future changes to the chain.
.. code-block:: radicle
- (load! "rad/prelude.rad")
+ (load! (find-module-file! "prelude.rad"))
(def issues (ref { :open nil :closed nil }))
(def system (ref {}))
(def new-feature-request
- (fn [author description test-case]
+ (fn [author description test-case]
...))
(def new-bug-report
- (fn [author description test-case]
+ (fn [author description test-case]
...))
(def new-question
- (fn [author description]
+ (fn [author description]
...))
(def close-issue ...)
@@ -48,7 +48,7 @@ how to allow for future changes to the chain.
})
- (def handle-input
+ (def handle-input
(fn [expr]
...))
diff --git a/docs/source/reference.rst b/docs/source/reference.rst
index 59b33c9..71d02d2 100644
--- a/docs/source/reference.rst
+++ b/docs/source/reference.rst
@@ -357,6 +357,14 @@ Given a file whose code starts with module metadata, creates the module.
That is, the file is evaluated as if the code was wrapped in
``(module ...)``.
+``find-module-file!``
+~~~~~~~~~~~~~~~~~~~~~
+
+Find a file according to radicle search path rules. These are: 1) If
+RADPATH is set, first search there; 2) If RADPATH is not set, search in
+the distribution directory 3) If the file is still not found, search in
+the current directory.
+
``import``
~~~~~~~~~~
diff --git a/exe/Doc.hs b/exe/Doc.hs
index e0a9a00..2109033 100644
--- a/exe/Doc.hs
+++ b/exe/Doc.hs
@@ -25,7 +25,7 @@ run f = do
txt <- readFile f
let extensions = def { readerExtensions = githubMarkdownExtensions }
pand <- runIOorExplode $ readMarkdown extensions txt
- let code = T.append "(load! \"rad/prelude.rad\")" (getCode pand)
+ let code = T.append "(load! (find-module-file! \"prelude.rad\"))" (getCode pand)
res <- runLang (replBindings []) $ interpretMany (toS f) $ code
case res of
(Left err, _) -> die . toS $ "Error: " ++ show err
diff --git a/exe/ReferenceDoc.hs b/exe/ReferenceDoc.hs
index 8ef3197..5b7d7cc 100644
--- a/exe/ReferenceDoc.hs
+++ b/exe/ReferenceDoc.hs
@@ -35,8 +35,8 @@ main = do
res_ <- interpret
"reference-doc"
( "(do"
- <> "(file-module! \"rad/prelude/test-eval.rad\") (import prelude/test-eval '[eval tests] :unqualified)"
- <> foldMap (\m -> "(file-module! \"rad/" <> m <> ".rad\")") (modules content)
+ <> "(file-module! \"prelude/test-eval.rad\") (import prelude/test-eval '[eval tests] :unqualified)"
+ <> foldMap (\m -> "(file-module! \"" <> m <> ".rad\")") (modules content)
<> "(get-current-state))")
(replBindings [])
let res = res_ `lPanic` "Error running the prelude."
diff --git a/nix/shell.nix b/nix/shell.nix
index da12324..16668fc 100644
--- a/nix/shell.nix
+++ b/nix/shell.nix
@@ -13,7 +13,7 @@ in
stdenv.mkDerivation {
name = "radicle-dev";
- buildInputs = [ ghc zlib glibcLocales python3 wget stack postgresql moreutils fzf]
+ buildInputs = [ ghc zlib glibcLocales python3 wget stack postgresql moreutils fzf docker_compose]
++ (if doc then [docstuffs postgresql] else [])
++ (if extras then [ vimPlugins.stylish-haskell haskellPackages.apply-refact hlint ] else []);
LANG = "en_US.UTF-8";
diff --git a/rad/examples/counter.rad b/rad/examples/counter.rad
index 14d20e4..7cf0f3c 100644
--- a/rad/examples/counter.rad
+++ b/rad/examples/counter.rad
@@ -9,7 +9,7 @@
;; (counter/get-value "my-chain-id") ;; => 1
;;
-(load! "rad/prelude.rad")
+(load! (find-module-file! "prelude.rad"))
(import prelude/test '[assert-equal] :unqualified)
diff --git a/rad/monadic/issues-upgrade.rad b/rad/monadic/issues-upgrade.rad
index c89fad3..5e7c866 100644
--- a/rad/monadic/issues-upgrade.rad
+++ b/rad/monadic/issues-upgrade.rad
@@ -1,4 +1,4 @@
-(load! "rad/monadic/issues.rad")
+(load! (find-module-file! "monadic/issues.rad"))
(import prelude/chain :unqualified)
diff --git a/rad/monadic/issues.rad b/rad/monadic/issues.rad
index 6e2d11b..2887263 100644
--- a/rad/monadic/issues.rad
+++ b/rad/monadic/issues.rad
@@ -3,9 +3,12 @@
;; Create a remote issue chain. Returns a ref for the chain that you
;; can assign to a variable.
+{:module 'monadic/issues
+ :doc "Functions for interacting with issues RSM"
+ :exports '[create-issues-chain!]}
(import prelude/lens :unqualified)
-(import prelude/chain '[send-code! ]:unqualified)
+(import prelude/chain '[send-code!] :unqualified)
(import prelude/time '[install-fake-clock] :unqualified)
(import prelude/io :as 'io)
@@ -17,7 +20,7 @@
"Create a remote issue chain with the given url."
(fn [url]
(chain/send-prelude! url)
- (send-code! url "rad/monadic/issue-remote.rad")))
+ (send-code! url (find-module-file! "monadic/issue-remote.rad"))))
(def sign-entity!
"Assumes a key pair is stored at `my-keys.rad`. Using that key pair, will sign a
diff --git a/rad/monadic/names-upgrade.rad b/rad/monadic/names-upgrade.rad
index 22c95f8..45d84ea 100644
--- a/rad/monadic/names-upgrade.rad
+++ b/rad/monadic/names-upgrade.rad
@@ -1,4 +1,4 @@
-(load! "rad/monadic/names.rad")
+(load! (find-module-file! "monadic/names.rad"))
(import prelude/chain :unqualified)
diff --git a/rad/monadic/names.rad b/rad/monadic/names.rad
index 744631a..0448d59 100644
--- a/rad/monadic/names.rad
+++ b/rad/monadic/names.rad
@@ -1,7 +1,7 @@
(def create-name-chain!
(fn [url]
(chain/send-prelude! url)
- (chain/send-code! url "rad/monadic/names-remote.rad")))
+ (chain/send-code! url (find-module-file! "rad/monadic/names-remote.rad"))))
(def lookup-key
(fn [chain-ref key]
diff --git a/rad/prelude.rad b/rad/prelude.rad
index 304f1ea..64774b8 100644
--- a/rad/prelude.rad
+++ b/rad/prelude.rad
@@ -1,25 +1,25 @@
-(file-module! "rad/prelude/test-eval.rad")
+(file-module! "prelude/test-eval.rad")
(import prelude/test-eval '[eval tests] :unqualified)
-(file-module! "rad/prelude/basic.rad")
-(file-module! "rad/prelude/patterns.rad")
-(file-module! "rad/prelude/strings.rad")
-(file-module! "rad/prelude/dict.rad")
-(file-module! "rad/prelude/io.rad")
-(file-module! "rad/prelude/bool.rad")
-(file-module! "rad/prelude/maybe.rad")
-(file-module! "rad/prelude/exception.rad")
-(file-module! "rad/prelude/seq.rad")
-(file-module! "rad/prelude/list.rad")
-(file-module! "rad/prelude/set.rad")
-(file-module! "rad/prelude/ref.rad")
-(file-module! "rad/prelude/lens.rad")
-(file-module! "rad/prelude/chain.rad")
-(file-module! "rad/prelude/state-machine.rad")
-(file-module! "rad/prelude/validation.rad")
-(file-module! "rad/prelude/util.rad")
-(file-module! "rad/prelude/time.rad")
-(file-module! "rad/prelude/test.rad")
+(file-module! "prelude/basic.rad")
+(file-module! "prelude/patterns.rad")
+(file-module! "prelude/strings.rad")
+(file-module! "prelude/dict.rad")
+(file-module! "prelude/io.rad")
+(file-module! "prelude/bool.rad")
+(file-module! "prelude/maybe.rad")
+(file-module! "prelude/exception.rad")
+(file-module! "prelude/seq.rad")
+(file-module! "prelude/list.rad")
+(file-module! "prelude/set.rad")
+(file-module! "prelude/ref.rad")
+(file-module! "prelude/lens.rad")
+(file-module! "prelude/chain.rad")
+(file-module! "prelude/state-machine.rad")
+(file-module! "prelude/validation.rad")
+(file-module! "prelude/util.rad")
+(file-module! "prelude/time.rad")
+(file-module! "prelude/test.rad")
(import prelude/basic :unqualified)
(import prelude/patterns :unqualified)
diff --git a/rad/prelude/chain.rad b/rad/prelude/chain.rad
index 966af7d..49abdb1 100644
--- a/rad/prelude/chain.rad
+++ b/rad/prelude/chain.rad
@@ -245,19 +245,20 @@
(def pure-prelude-files
"List of files which together define the pure prelude."
- ["rad/prelude/basic.rad"
- "rad/prelude/patterns.rad"
- "rad/prelude/strings.rad"
- "rad/prelude/dict.rad"
- "rad/prelude/bool.rad"
- "rad/prelude/maybe.rad"
- "rad/prelude/list.rad"
- "rad/prelude/set.rad"
- "rad/prelude/ref.rad"
- "rad/prelude/lens.rad"
- "rad/prelude/state-machine.rad"
- "rad/prelude/validation.rad"
- "rad/prelude/util.rad"])
+ (map find-module-file!
+ ["prelude/basic.rad"
+ "prelude/patterns.rad"
+ "prelude/strings.rad"
+ "prelude/dict.rad"
+ "prelude/bool.rad"
+ "prelude/maybe.rad"
+ "prelude/list.rad"
+ "prelude/set.rad"
+ "prelude/ref.rad"
+ "prelude/lens.rad"
+ "prelude/state-machine.rad"
+ "prelude/validation.rad"
+ "prelude/util.rad"]))
(def file-to-module
"Make the text of a file into code for a module."
@@ -266,7 +267,7 @@
(def pure-prelude-code
"Code for the pure prelude. Useful as the first inputs to a new chain."
- (<> [(file-to-module "rad/prelude/test-eval.rad")
+ (<> [(file-to-module (find-module-file! "prelude/test-eval.rad"))
'(import prelude/test-eval '[eval tests] :unqualified)]
(map file-to-module pure-prelude-files)))
diff --git a/rad/repl.rad b/rad/repl.rad
index e39f0d5..c5861d5 100644
--- a/rad/repl.rad
+++ b/rad/repl.rad
@@ -1,4 +1,4 @@
-(load! "rad/prelude.rad")
+(load! (find-module-file! "prelude.rad"))
(import prelude/chain '[eval] :unqualified)
(def help
diff --git a/reference-doc.yaml b/reference-doc.yaml
index 75e7d5e..91d6c4a 100644
--- a/reference-doc.yaml
+++ b/reference-doc.yaml
@@ -81,6 +81,7 @@ primFns:
- dict?
# Modules
- file-module!
+- find-module-file!
- import
# State and Environment
- pure-state
diff --git a/src/Radicle/Internal/Effects.hs b/src/Radicle/Internal/Effects.hs
index 3c1c678..5600c8d 100644
--- a/src/Radicle/Internal/Effects.hs
+++ b/src/Radicle/Internal/Effects.hs
@@ -38,7 +38,8 @@ type ReplM m =
, ReadFile (Lang m)
, System m
, GetEnv (Lang m) Value
- , SetEnv (Lang m) Value )
+ , SetEnv (Lang m) Value
+ , FileModule (Lang m))
instance MonadRandom (InputT IO) where
getRandomBytes = liftIO . getRandomBytes
@@ -322,12 +323,29 @@ replPrimFns sysArgs = fromList $ allDocs $
\ That is, the file is evaluated as if the code was wrapped in `(module ...)`."
, oneArg "file-module!" $ \case
String filename -> do
- t_ <- fmap ignoreShebang <$> readFileS filename
+ ef <- fileModuleS filename
+ file <- case ef of
+ Nothing -> throwError . toLangError . OtherError $ "File not found in RADPATH: " <> filename
+ Just f -> pure f
+ t_ <- fmap ignoreShebang <$> readFileS file
t <- hoistEither . first (toLangError . OtherError) $ t_
vs <- readValues filename t
createModule vs
v -> throwErrorHere $ TypeError "file-module!" 0 TString v
)
+ , ( "find-module-file!"
+ , "Find a file according to radicle search path rules. These are: \
+ \ 1) If RADPATH is set, first search there; \
+ \ 2) If RADPATH is not set, search in the distribution directory \
+ \ 3) If the file is still not found, search in the current directory."
+ , oneArg "find-module-file!" $ \case
+ String filename -> do
+ t_ <- fileModuleS filename
+ case t_ of
+ Nothing -> throwError . toLangError . OtherError $ "File not found in RADPATH: " <> filename
+ Just t -> pure $ String t
+ v -> throwErrorHere $ TypeError "find-module-file!" 0 TString v
+ )
]
-- | Since `#` is not a comment in radicle, we need to explictly remove shebang
diff --git a/src/Radicle/Internal/Effects/Capabilities.hs b/src/Radicle/Internal/Effects/Capabilities.hs
index 8d600ff..5cc90c4 100644
--- a/src/Radicle/Internal/Effects/Capabilities.hs
+++ b/src/Radicle/Internal/Effects/Capabilities.hs
@@ -2,7 +2,6 @@
--
-- The intent is that any set of primops may wear on their sleaves (i.e.
-- constraints) what effects they do.
-{-# LANGUAGE CPP #-}
module Radicle.Internal.Effects.Capabilities where
import Protolude
@@ -10,9 +9,13 @@ import Protolude
import qualified Data.ByteString as BS
import Data.Text.Prettyprint.Doc (PageWidth)
import Data.Time
+import Paths_radicle
import System.Console.ANSI (hSupportsANSI)
import System.Console.Haskeline hiding (catch)
+import System.Directory (doesFileExist)
+import System.Environment (lookupEnv)
import System.Exit (ExitCode)
+import System.FilePath (splitSearchPath, (</>))
import System.IO
( BufferMode(LineBuffering)
, hClose
@@ -137,8 +140,42 @@ instance ReadFile IO where
instance {-# OVERLAPPABLE #-} ReadFile m => ReadFile (Lang m) where
readFileS = lift . readFileS
+class (Monad m) => FileModule m where
+ fileModuleS :: Text -> m (Maybe Text)
+instance FileModule IO where
+ fileModuleS file = do
+ x <- findModule $ toS file
+ case x of
+ Nothing -> pure Nothing
+ Just f -> pure . Just $ toS f
+instance FileModule (InputT IO) where
+ fileModuleS = lift . fileModuleS
+instance {-# OVERLAPPABLE #-} FileModule m => FileModule (Lang m) where
+ fileModuleS = lift . fileModuleS
+
putStrLnS :: (Stdout m) => Text -> m ()
putStrLnS t = putStrS t >> putStrS "\n"
modifyEnvS :: (GetEnv m r, SetEnv m r) => (Env r -> Env r) -> m ()
modifyEnvS f = getEnvS >>= setEnvS . f
+
+-- | Importing works as follows:
+--
+-- (1) If the RADPATH environment variable exists, search there
+-- (2) Otherwise search in data-dir
+-- (3) Finally we search in the current directory.
+--
+-- RADPATH should be a colon-separated list of directories (just like PATH).
+findModule :: FilePath -> IO (Maybe FilePath)
+findModule file = do
+ mrp <- lookupEnv "RADPATH"
+ radPathDirs <- case mrp of
+ Nothing -> (\x -> [x </> "rad"]) <$> getDataDir
+ Just rp -> pure $ splitSearchPath rp
+ let searchPath = radPathDirs ++ ["."]
+ let doFind xs = case xs of
+ [] -> pure Nothing
+ x:xs' -> do
+ exists <- doesFileExist (x </> file)
+ if exists then pure (Just $ x </> file) else doFind xs'
+ doFind searchPath
diff --git a/test/all.rad b/test/all.rad
index e90878c..297de59 100755
--- a/test/all.rad
+++ b/test/all.rad
@@ -3,10 +3,10 @@
;; Run all tests defined in the prelude and print their results with
;; TAP. Exit with status code 1 if any of the tests fail.
-(load! "rad/tests/stub-primitives.rad")
-(load! "rad/prelude.rad")
-(load! "rad/monadic/issues.rad")
-(load! "rad/monadic/names.rad")
+(load! (find-module-file! "tests/stub-primitives.rad"))
+(load! (find-module-file! "prelude.rad"))
+(load! (find-module-file! "monadic/issues.rad"))
+(load! (find-module-file! "monadic/names.rad"))
(import prelude/test)
diff --git a/test/spec/Radicle/Internal/TestCapabilities.hs b/test/spec/Radicle/Internal/TestCapabilities.hs
index 2522940..14592dd 100644
--- a/test/spec/Radicle/Internal/TestCapabilities.hs
+++ b/test/spec/Radicle/Internal/TestCapabilities.hs
@@ -92,7 +92,7 @@ sourceFiles = do
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
+ let path = drop (length dir + 5) absPath
pure (toS path, contents)
pure $ Map.fromList filesWithContent
@@ -142,6 +142,11 @@ instance {-# OVERLAPPING #-} ReadFile TestLang where
Just f -> pure $ Right f
Nothing -> throwErrorHere . OtherError $ "File not found: " <> fn
+instance {-# OVERLAPPING #-} FileModule TestLang where
+ fileModuleS fn = do
+ fs <- lift $ gets worldStateFiles
+ pure $ if Map.member fn fs then Just fn else Nothing
+
instance Monad m => MonadRandom (StateT WorldState m) where
getRandomBytes i = do
drg <- gets worldStateDRG
diff --git a/test/spec/Radicle/Tests.hs b/test/spec/Radicle/Tests.hs
index 3cc68a6..c8dd87b 100644
--- a/test/spec/Radicle/Tests.hs
+++ b/test/spec/Radicle/Tests.hs
@@ -874,7 +874,7 @@ 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
- (result, output) <- runCodeWithInput input "(load! \"rad/repl.rad\")"
+ (result, output) <- runCodeWithInput input "(load! (find-module-file! \"repl.rad\"))"
case result of
Left err -> assertFailure $ "Error thrown in Repl: " <> toS (renderPrettyDef err)
Right _ -> pure ()