mirror of
https://github.com/nmattia/snack.git
synced 2024-09-11 11:55:36 +03:00
Add GHCi test suite
This commit is contained in:
parent
9b12d90030
commit
bed01c7b75
@ -62,9 +62,6 @@ if [[ -z "$COMMAND" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "snack nix: $SNACK_NIX"
|
||||
echo "command: $COMMAND"
|
||||
|
||||
case $COMMAND in
|
||||
build)
|
||||
"$NIX_BUILD" --no-out-link -A build "$SNACK_NIX"
|
||||
@ -75,7 +72,6 @@ case $COMMAND in
|
||||
;;
|
||||
run)
|
||||
res=$("$NIX_BUILD" --no-out-link -A build "$SNACK_NIX")
|
||||
echo "running $res"
|
||||
"$res/out"
|
||||
;;
|
||||
esac
|
||||
|
@ -8,4 +8,3 @@
|
||||
["NIX_BUILD=${pkgs.nix}/bin/nix-build"]
|
||||
(builtins.readFile ./bin/snack));
|
||||
}
|
||||
|
||||
|
27
script/test
27
script/test
@ -11,9 +11,28 @@ set -euo pipefail
|
||||
## Functions
|
||||
|
||||
banner() {
|
||||
echo
|
||||
echo "--- $*"
|
||||
}
|
||||
|
||||
capture_io() {
|
||||
OUT_FILE="$1"
|
||||
|
||||
cat <<END_HEREDOC
|
||||
import GHC.IO.Handle
|
||||
import System.IO
|
||||
old_stdout <- hDuplicate stdout
|
||||
:{
|
||||
withFile "$OUT_FILE" WriteMode $ \\h -> do
|
||||
hDuplicateTo h stdout
|
||||
$2
|
||||
hDuplicateTo old_stdout stdout
|
||||
:}
|
||||
END_HEREDOC
|
||||
}
|
||||
|
||||
export -f capture_io
|
||||
|
||||
fail() {
|
||||
echo "ERROR: $*"
|
||||
exit 1
|
||||
@ -25,22 +44,22 @@ cd "$(dirname "$0")/.."
|
||||
|
||||
banner "Test packages"
|
||||
pushd tests/packages
|
||||
snack build
|
||||
./test
|
||||
popd
|
||||
|
||||
banner "Test Template Haskell"
|
||||
pushd tests/template-haskell
|
||||
snack build
|
||||
./test
|
||||
popd
|
||||
|
||||
banner "Test Template Haskell 2"
|
||||
pushd tests/template-haskell-2
|
||||
snack build -f code/snack.nix
|
||||
./test
|
||||
popd
|
||||
|
||||
banner "Test Template Haskell 3"
|
||||
pushd tests/template-haskell-3
|
||||
snack build
|
||||
./test
|
||||
popd
|
||||
|
||||
banner "Test stack-exe formatting"
|
||||
|
7
shell.nix
Normal file
7
shell.nix
Normal file
@ -0,0 +1,7 @@
|
||||
{ pkgs ? import ./nix {} }:
|
||||
let
|
||||
snack = (pkgs.callPackage ./. {}).snack-exe;
|
||||
in pkgs.mkShell
|
||||
{ name = "snack-shell";
|
||||
buildInputs = [ snack ];
|
||||
}
|
6
tests/packages/expected
Normal file
6
tests/packages/expected
Normal file
@ -0,0 +1,6 @@
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
Leaving GHCi.
|
5
tests/packages/golden
Normal file
5
tests/packages/golden
Normal file
@ -0,0 +1,5 @@
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
14
tests/packages/test
Executable file
14
tests/packages/test
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
# vim: ft=sh sw=2 et
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
snack build
|
||||
snack run | diff golden -
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
capture_io "$TMP_FILE" main | snack ghci
|
||||
|
||||
diff golden $TMP_FILE
|
||||
rm $TMP_FILE
|
2
tests/template-haskell-2/golden
Normal file
2
tests/template-haskell-2/golden
Normal file
@ -0,0 +1,2 @@
|
||||
Hello, World!
|
||||
|
14
tests/template-haskell-2/test
Executable file
14
tests/template-haskell-2/test
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
# vim: ft=sh sw=2 et
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
snack build -f code/snack.nix
|
||||
snack run -f code/snack.nix | diff golden -
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
capture_io "$TMP_FILE" main | snack -f code/snack.nix ghci
|
||||
|
||||
diff golden $TMP_FILE
|
||||
rm $TMP_FILE
|
2
tests/template-haskell-3/golden
Normal file
2
tests/template-haskell-3/golden
Normal file
@ -0,0 +1,2 @@
|
||||
Hello, World!
|
||||
|
14
tests/template-haskell-3/test
Executable file
14
tests/template-haskell-3/test
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
# vim: ft=sh sw=2 et
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
snack build
|
||||
snack run | diff golden -
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
capture_io "$TMP_FILE" main | snack ghci
|
||||
|
||||
diff golden $TMP_FILE
|
||||
rm $TMP_FILE
|
2
tests/template-haskell/golden
Normal file
2
tests/template-haskell/golden
Normal file
@ -0,0 +1,2 @@
|
||||
Hello, World!
|
||||
|
14
tests/template-haskell/test
Executable file
14
tests/template-haskell/test
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
# vim: ft=sh sw=2 et
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
snack build
|
||||
snack run | diff golden -
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
capture_io "$TMP_FILE" main | snack ghci
|
||||
|
||||
diff golden $TMP_FILE
|
||||
rm $TMP_FILE
|
Loading…
Reference in New Issue
Block a user