@@ -0,0 +1,56 @@
1+# Test a package set
2+{ stdenv, util, haskell-nix }:
3+
4+with stdenv.lib;
5+
6+let
7+ project = haskell-nix.cabalProject' {
8+ name = "exe-only";
9+ src = ./.;
10+ };
11+
12+ packages = project.hsPkgs;
13+
14+in
15+ stdenv.mkDerivation {
16+ name = "exe-only-test";
17+
18+ buildCommand = ''
19+ exe="${packages.exe-only.components.exes.exe-only}/bin/exe-only"
20+
21+ size=$(command stat --format '%s' "$exe")
22+ printf "size of executable $exe is $size. \n" >& 2
23+
24+ # fixme: run on target platform when cross-compiled
25+ printf "checking whether executable runs... " >& 2
26+ $exe
27+ '' + (if stdenv.hostPlatform.isMusl then ''
28+ printf "checking that executable is statically linked... " >& 2
29+ (ldd $exe 2>&1 || true) | grep -i "not a"
30+ '' else ''
31+ printf "checking that executable is dynamically linked to system libraries... " >& 2
32+ '' + optionalString stdenv.isLinux ''
33+ ldd $exe | grep libpthread
34+ '' + optionalString stdenv.isDarwin ''
35+ otool -L $exe |grep .dylib
36+ '') + ''
37+
38+ printf "Checking that \"all\" component has the programs... " >& 2
39+ all_exe="${packages.exe-only.components.all}/bin/exe-only"
40+ test -f "$all_exe"
41+ echo "$all_exe" >& 2
42+
43+ touch $out
44+ '';
45+
46+ meta.platforms = platforms.all;
47+
48+ passthru = {
49+ # Used for debugging with nix repl
50+ inherit pkgSet packages;
51+
52+ # Used for testing externally with nix-shell (../tests.sh).
53+ # This just adds cabal-install to the existing shells.
54+ test-shell = util.addCabalInstall packages.exe-only.components.all;
55+ };
56+}