Skip to content

Commit

Permalink
add test for ghc library in ghci
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed Oct 13, 2023
1 parent 0a2aee6 commit 1067133
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
5 changes: 5 additions & 0 deletions lib/doc/prose.nix
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,11 @@ in {
The Glorious Glasgow Haskell Compilation System, version 9.2.4
```
::: {.note}
If you depend on the GHC library package `ghc`, you'll have to set `ghci.args = ["-package ghc"];`.
Otherwise it won't be visible, due to a bug.
:::
## Services {#services}
Services use in environments and commands can be user-defined in a flake:
Expand Down
18 changes: 10 additions & 8 deletions test/ghci/root/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
library.enable = true;
executable.enable = true;
test.enable = true;
library.dependencies = ["path" "path-io" "core"];
# library.default-extensions = ["OverloadedStrings"];
library.dependencies = ["path" "path-io" "core" "ghc"];
};
};
ghci.run.print = ''putStrLn "print success"'';
ghci.run.cwd = ''putStrLn . toFilePath =<< getCurrentDir'';
ghci.setup.cwd = ''
import Path (toFilePath)
import Path.IO (getCurrentDir)
'';
ghci = {
run.print = ''putStrLn "print success"'';
run.cwd = ''putStrLn . toFilePath =<< getCurrentDir'';
setup.cwd = ''
import Path (toFilePath)
import Path.IO (getCurrentDir)
'';
args = ["-package ghc"];
};
commands.ghci-app = {
ghci = {
enable = true;
Expand Down
13 changes: 13 additions & 0 deletions test/ghci/root/pkg/lib/Root/LibGhc.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{-# language CPP #-}

module Root.LibGhc where

message :: String
#if MIN_VERSION_ghc(9,6,0)
message = "over"
#else
message = "under"
#endif

main :: IO ()
main = putStrLn message
2 changes: 2 additions & 0 deletions test/ghci/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
flake_update
nix run .#gen-cabal-quiet
ghci_match '.#ghci -- -p root -m Root.LibGhc' 'one module loaded' 'ghc library not visible'
ghci_match ".#ghci -- --root $PWD -c lib -m Root.Lib -r cwd" "$PWD/pkg/" 'ghci cwd with cd printed wrong directory'
ghci_match '.#ghci -- -c lib -m Root.Lib -r cwd -- --no-cd' "$PWD/" 'ghci cwd with no-cd printed wrong directory'
Expand Down

0 comments on commit 1067133

Please sign in to comment.