1 { stdenv, lib, pname, idris2, zsh }:
4 testCompileAndRun = {testName, code, want, packages ? []}: let
5 packageString = builtins.concatStringsSep " " (map (p: "--package " + p) packages);
6 in stdenv.mkDerivation {
7 name = "${pname}-${testName}";
10 # with idris2 compiled binaries assume zsh is available on darwin, but that
11 # is not the case with pure nix environments. Thus, we need to include zsh
12 # when we build for darwin in tests. While this is impure, this is also what
13 # we find in real darwin hosts.
14 nativeBuildInputs = lib.optionals stdenv.isDarwin [ zsh ];
19 cat > packageTest.idr <<HERE
23 ${idris2}/bin/idris2 ${packageString} -o packageTest packageTest.idr
25 GOT=$(./build/exec/packageTest)
27 if [ "$GOT" = "${want}" ]; then
28 echo "${testName} SUCCESS: '$GOT' = '${want}'"
30 >&2 echo "Got '$GOT', want: '${want}'"
38 # Simple hello world compiles, runs and outputs as expected
39 hello-world = testCompileAndRun {
40 testName = "hello-world";
45 main = putStrLn "Hello World!"
47 want = "Hello World!";
50 # Data.Vect.Sort is available via --package contrib
51 use-contrib = testCompileAndRun {
52 testName = "use-contrib";
53 packages = [ "contrib" ];
58 import Data.Vect.Sort -- from contrib
61 vect = 3 :: 1 :: 5 :: Nil
64 main = putStrLn $ show (sort vect)