1
1
mirror of https://github.com/nmattia/snack.git synced 2024-11-24 04:04:35 +03:00

Add Ghci options (#163)

* Add Ghci options

* Add ghci options test

* Remove Build for test
This commit is contained in:
Jinxuan Zhu 2019-11-20 14:52:15 -05:00 committed by Nicolas Mattia
parent 7e3b61e4fc
commit 069f7d01fb
7 changed files with 38 additions and 4 deletions

View File

@ -234,7 +234,7 @@ parseSnackConfig = SnackConfig <$> Opts.optional
data Command
= Build
| Run [String] -- Run with extra args
| Ghci
| Ghci [String]
| Test
| Hoogle
@ -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
@ -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" ] =<<

View File

@ -48,6 +48,6 @@ rec {
done
fi
done
${ghc}/bin/ghci ${lib.strings.escapeShellArgs ghciArgs}
${ghc}/bin/ghci ${lib.strings.escapeShellArgs ghciArgs} $@
'';
}

View File

@ -0,0 +1,5 @@
module Main where
import Data.Text
main = putStrLn $ unpack "hello"

View File

@ -0,0 +1 @@
hello

View File

@ -0,0 +1,4 @@
{ main = "Main";
src = ./.;
dependencies = [ "text" ];
}

View File

@ -0,0 +1,6 @@
name: snack-extensions-test
dependencies:
- text
executable:
main: Main.hs
source-dirs: .

16
tests/ghci-options/test Executable file
View File

@ -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