Skip to content

Commit 069f7d0

Browse files
zhujinxuannmattia
authored andcommitted
Add Ghci options (#163)
* Add Ghci options * Add ghci options test * Remove Build for test
1 parent 7e3b61e commit 069f7d0

File tree

7 files changed

+38
-4
lines changed

7 files changed

+38
-4
lines changed

bin/Snack.hs

+5-3
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ parseSnackConfig = SnackConfig <$> Opts.optional
234234
data Command
235235
= Build
236236
| Run [String] -- Run with extra args
237-
| Ghci
237+
| Ghci [String]
238238
| Test
239239
| Hoogle
240240

@@ -245,7 +245,9 @@ parseCommand =
245245
<> Opts.command "run" (Opts.info
246246
( Run <$> Opts.many (Opts.argument Opts.str (Opts.metavar "ARG"))
247247
) mempty)
248-
<> Opts.command "ghci" (Opts.info (pure Ghci) mempty)
248+
<> Opts.command "ghci" (Opts.info
249+
( Ghci <$> Opts.many (Opts.argument Opts.str (Opts.metavar "ARG"))
250+
) mempty)
249251
<> Opts.command "hoogle" (Opts.info (pure Hoogle) mempty)
250252
)
251253
<|> Opts.hsubparser
@@ -460,7 +462,7 @@ runCommand :: SnackConfig -> PackageFile -> Command -> IO ()
460462
runCommand snackCfg packageFile = \case
461463
Build -> S.shelly $ void $ snackBuild snackCfg packageFile
462464
Run args -> quiet (snackBuild snackCfg packageFile) >>= runBuildResult args
463-
Ghci -> flip runExe [] =<<
465+
Ghci args -> flip runExe args =<<
464466
ghciExePath <$> (quiet (snackGhci snackCfg packageFile))
465467
Test -> noTest
466468
Hoogle -> flip runExe [ "server", "--local" ] =<<

snack-lib/ghci.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ rec {
4848
done
4949
fi
5050
done
51-
${ghc}/bin/ghci ${lib.strings.escapeShellArgs ghciArgs}
51+
${ghc}/bin/ghci ${lib.strings.escapeShellArgs ghciArgs} $@
5252
'';
5353
}

tests/ghci-options/Main.hs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Main where
2+
3+
import Data.Text
4+
5+
main = putStrLn $ unpack "hello"

tests/ghci-options/golden

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello

tests/ghci-options/package.nix

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{ main = "Main";
2+
src = ./.;
3+
dependencies = [ "text" ];
4+
}

tests/ghci-options/package.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: snack-extensions-test
2+
dependencies:
3+
- text
4+
executable:
5+
main: Main.hs
6+
source-dirs: .

tests/ghci-options/test

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
# vim: ft=sh sw=2 et
3+
4+
set -euo pipefail
5+
6+
test() {
7+
TMP_FILE=$(mktemp)
8+
9+
capture_io "$TMP_FILE" main | $SNACK ghci -- -XOverloadedStrings
10+
11+
diff golden $TMP_FILE
12+
rm $TMP_FILE
13+
}
14+
15+
SNACK="snack --package-file ./package.nix" test
16+
SNACK="snack --package-file ./package.yaml" test

0 commit comments

Comments
 (0)