1
1
mirror of https://github.com/nmattia/snack.git synced 2024-09-11 11:55:36 +03:00

Add test for non-Nix-friendly paths

This commit is contained in:
Nicolas Mattia 2018-07-29 19:36:20 +02:00
parent 296834e52d
commit 5f905d15da
6 changed files with 74 additions and 0 deletions

View File

@ -109,6 +109,11 @@ pushd tests/readme
./test
popd
banner "Test that paths can be non-nix-friendly"
pushd tests/any-paths
./test
popd
banner "Test this file's formatting"
list=$(shfmt -i 2 -l script/test)
if [[ -n "$list" ]]; then

View File

@ -0,0 +1,6 @@
module Main where
import Lib
main :: IO ()
main = topReddit >>= print

View File

@ -0,0 +1,17 @@
name: snack-readme
dependencies:
- lens
- wreq
library:
source-dirs: ./src
executable:
main: Main.hs
source-dirs: ./app
dependencies:
- snack-readme
default-extensions:
- OverloadedStrings

12
tests/any-paths/snack.nix Normal file
View File

@ -0,0 +1,12 @@
let
lib =
{ src = ./src;
dependencies = [ "wreq" "lens" ];
extensions = [ "OverloadedStrings"];
};
in
{ main = "Main";
src = ./app;
packages = [ lib ];
dependencies = [ "wreq" "lens" ];
}

View File

@ -0,0 +1,22 @@
module Lib where
import Control.Lens
import Network.Wreq
import Data.Aeson.Lens
import Data.Text (Text)
topReddit :: IO Text
topReddit =
getWith opts url
<&> (^. responseBody
. key "data"
. key "children"
. nth 0
. key "data"
. key "title"
. _String)
where
url = "https://www.reddit.com/r/haskell/top.json"
opts = defaults
& param "limit" .~ ["1"]
& param "t" .~ ["all"]

12
tests/any-paths/test Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
# vim: ft=sh sw=2 et
set -euo pipefail
test() {
echo | $SNACK ghci
$SNACK run
}
SNACK="snack -s snack.nix" test
SNACK="snack --package-yaml package.yaml" test