diff --git a/bin/Snack.hs b/bin/Snack.hs index a2b5c1c..4e84128 100644 --- a/bin/Snack.hs +++ b/bin/Snack.hs @@ -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" ] =<< diff --git a/snack-lib/ghci.nix b/snack-lib/ghci.nix index 741496d..925b966 100644 --- a/snack-lib/ghci.nix +++ b/snack-lib/ghci.nix @@ -48,6 +48,6 @@ rec { done fi done - ${ghc}/bin/ghci ${lib.strings.escapeShellArgs ghciArgs} + ${ghc}/bin/ghci ${lib.strings.escapeShellArgs ghciArgs} $@ ''; } diff --git a/tests/ghci-options/Main.hs b/tests/ghci-options/Main.hs new file mode 100644 index 0000000..429ce83 --- /dev/null +++ b/tests/ghci-options/Main.hs @@ -0,0 +1,5 @@ +module Main where + +import Data.Text + +main = putStrLn $ unpack "hello" diff --git a/tests/ghci-options/golden b/tests/ghci-options/golden new file mode 100644 index 0000000..ce01362 --- /dev/null +++ b/tests/ghci-options/golden @@ -0,0 +1 @@ +hello diff --git a/tests/ghci-options/package.nix b/tests/ghci-options/package.nix new file mode 100644 index 0000000..2777631 --- /dev/null +++ b/tests/ghci-options/package.nix @@ -0,0 +1,4 @@ +{ main = "Main"; + src = ./.; + dependencies = [ "text" ]; +} diff --git a/tests/ghci-options/package.yaml b/tests/ghci-options/package.yaml new file mode 100644 index 0000000..82ba30b --- /dev/null +++ b/tests/ghci-options/package.yaml @@ -0,0 +1,6 @@ +name: snack-extensions-test +dependencies: + - text +executable: + main: Main.hs + source-dirs: . diff --git a/tests/ghci-options/test b/tests/ghci-options/test new file mode 100755 index 0000000..3755a4e --- /dev/null +++ b/tests/ghci-options/test @@ -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