Merge pull request #151237 from wchresta/master

idris2: add package tests

authored by Marek Fajkus and committed by GitHub de64ca62 37e968f8

+71
+4
pkgs/development/compilers/idris2/default.nix
··· 6 6 , chez 7 7 , gmp 8 8 , zsh 9 + , callPackage 9 10 }: 10 11 11 12 # NOTICE: An `idris2WithPackages` is available at: https://github.com/claymager/idris2-pkgs ··· 81 82 --suffix IDRIS2_PATH ':' "${additionalIdris2Paths}" \ 82 83 --suffix ${if stdenv.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH"} ':' "$out/${name}/lib" 83 84 ''; 85 + 86 + # Run package tests 87 + passthru.tests = callPackage ./tests.nix { inherit pname; }; 84 88 85 89 meta = { 86 90 description = "A purely functional programming language with first class types";
+67
pkgs/development/compilers/idris2/tests.nix
··· 1 + { stdenv, lib, pname, idris2, zsh }: 2 + 3 + let 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.optional 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 + }; 37 + in { 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 + code = '' 54 + module Main 55 + 56 + import Data.Vect 57 + import Data.Vect.Sort -- from contrib 58 + 59 + vect : Vect 3 Int 60 + vect = 3 :: 1 :: 5 :: Nil 61 + 62 + main : IO () 63 + main = putStrLn $ show (sort vect) 64 + ''; 65 + want = "[1, 3, 5]"; 66 + }; 67 + }