Skip to content

Commit

Permalink
Add Ghci options (#163)
Browse files Browse the repository at this point in the history
* Add Ghci options

* Add ghci options test

* Remove Build for test
  • Loading branch information
zhujinxuan authored and nmattia committed Nov 20, 2019
1 parent 7e3b61e commit 069f7d0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
8 changes: 5 additions & 3 deletions bin/Snack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ parseSnackConfig = SnackConfig <$> Opts.optional
data Command
= Build
| Run [String] -- Run with extra args
| Ghci
| Ghci [String]
| Test
| Hoogle

Expand All @@ -245,7 +245,9 @@ parseCommand =
<> Opts.command "run" (Opts.info
( Run <$> Opts.many (Opts.argument Opts.str (Opts.metavar "ARG"))
) mempty)
<> Opts.command "ghci" (Opts.info (pure Ghci) mempty)
<> Opts.command "ghci" (Opts.info
( Ghci <$> Opts.many (Opts.argument Opts.str (Opts.metavar "ARG"))
) mempty)
<> Opts.command "hoogle" (Opts.info (pure Hoogle) mempty)
)
<|> Opts.hsubparser
Expand Down Expand Up @@ -460,7 +462,7 @@ runCommand :: SnackConfig -> PackageFile -> Command -> IO ()
runCommand snackCfg packageFile = \case
Build -> S.shelly $ void $ snackBuild snackCfg packageFile
Run args -> quiet (snackBuild snackCfg packageFile) >>= runBuildResult args
Ghci -> flip runExe [] =<<
Ghci args -> flip runExe args =<<
ghciExePath <$> (quiet (snackGhci snackCfg packageFile))
Test -> noTest
Hoogle -> flip runExe [ "server", "--local" ] =<<
Expand Down
2 changes: 1 addition & 1 deletion snack-lib/ghci.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ rec {
done
fi
done
${ghc}/bin/ghci ${lib.strings.escapeShellArgs ghciArgs}
${ghc}/bin/ghci ${lib.strings.escapeShellArgs ghciArgs} $@
'';
}
5 changes: 5 additions & 0 deletions tests/ghci-options/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Main where

import Data.Text

main = putStrLn $ unpack "hello"
1 change: 1 addition & 0 deletions tests/ghci-options/golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
4 changes: 4 additions & 0 deletions tests/ghci-options/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ main = "Main";
src = ./.;
dependencies = [ "text" ];
}
6 changes: 6 additions & 0 deletions tests/ghci-options/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: snack-extensions-test
dependencies:
- text
executable:
main: Main.hs
source-dirs: .
16 changes: 16 additions & 0 deletions tests/ghci-options/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# vim: ft=sh sw=2 et

set -euo pipefail

test() {
TMP_FILE=$(mktemp)

capture_io "$TMP_FILE" main | $SNACK ghci -- -XOverloadedStrings

diff golden $TMP_FILE
rm $TMP_FILE
}

SNACK="snack --package-file ./package.nix" test
SNACK="snack --package-file ./package.yaml" test

0 comments on commit 069f7d0

Please sign in to comment.