nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
fork

Configure Feed

Select the types of activity you want to include in your feed.

at fix-function-merge 68 lines 1.8 kB view raw
1{ stdenv, lib, pname, idris2, zsh }: 2 3let 4 testCompileAndRun = {testName, code, want, packages ? []}: let 5 packageString = builtins.concatStringsSep " " (map (p: "--package " + p) packages); 6 in stdenv.mkDerivation { 7 name = "${pname}-${testName}"; 8 meta.timeout = 60; 9 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 ]; 15 16 buildCommand = '' 17 set -eo pipefail 18 19 cat > packageTest.idr <<HERE 20 ${code} 21 HERE 22 23 ${idris2}/bin/idris2 ${packageString} -o packageTest packageTest.idr 24 25 GOT=$(./build/exec/packageTest) 26 27 if [ "$GOT" = "${want}" ]; then 28 echo "${testName} SUCCESS: '$GOT' = '${want}'" 29 else 30 >&2 echo "Got '$GOT', want: '${want}'" 31 exit 1 32 fi 33 34 touch $out 35 ''; 36 }; 37in { 38 # Simple hello world compiles, runs and outputs as expected 39 hello-world = testCompileAndRun { 40 testName = "hello-world"; 41 code = '' 42 module Main 43 44 main : IO () 45 main = putStrLn "Hello World!" 46 ''; 47 want = "Hello World!"; 48 }; 49 50 # Data.Vect.Sort is available via --package contrib 51 use-contrib = testCompileAndRun { 52 testName = "use-contrib"; 53 packages = [ "contrib" ]; 54 code = '' 55 module Main 56 57 import Data.Vect 58 import Data.Vect.Sort -- from contrib 59 60 vect : Vect 3 Int 61 vect = 3 :: 1 :: 5 :: Nil 62 63 main : IO () 64 main = putStrLn $ show (sort vect) 65 ''; 66 want = "[1, 3, 5]"; 67 }; 68}