summary refs log tree commit diff
path: root/pkgs/test
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2017-09-02 23:48:55 +0200
committerDaiderd Jordan <daiderd@gmail.com>2017-09-10 22:49:47 +0200
commitb91307c2e1bfa8a32eb450cc00613f70af2ad1f6 (patch)
treecd34b672550a0e0649dfe0cb818a2c062e74e02a /pkgs/test
parent19c46733104c680267a0a0dd3a2e6be893bd52b4 (diff)
downloadnixpkgs-b91307c2e1bfa8a32eb450cc00613f70af2ad1f6.tar
nixpkgs-b91307c2e1bfa8a32eb450cc00613f70af2ad1f6.tar.gz
nixpkgs-b91307c2e1bfa8a32eb450cc00613f70af2ad1f6.tar.bz2
nixpkgs-b91307c2e1bfa8a32eb450cc00613f70af2ad1f6.tar.lz
nixpkgs-b91307c2e1bfa8a32eb450cc00613f70af2ad1f6.tar.xz
nixpkgs-b91307c2e1bfa8a32eb450cc00613f70af2ad1f6.tar.zst
nixpkgs-b91307c2e1bfa8a32eb450cc00613f70af2ad1f6.zip
nixpkgs-tests: add basic test for buildInputs
Diffstat (limited to 'pkgs/test')
-rw-r--r--pkgs/test/stdenv-inputs/bar.c3
-rw-r--r--pkgs/test/stdenv-inputs/cc-main.c7
-rw-r--r--pkgs/test/stdenv-inputs/default.nix64
-rw-r--r--pkgs/test/stdenv-inputs/foo.c3
-rw-r--r--pkgs/test/stdenv-inputs/include-main.c13
-rw-r--r--pkgs/test/stdenv-inputs/lib-main.c14
6 files changed, 104 insertions, 0 deletions
diff --git a/pkgs/test/stdenv-inputs/bar.c b/pkgs/test/stdenv-inputs/bar.c
new file mode 100644
index 00000000000..2d7299c2d46
--- /dev/null
+++ b/pkgs/test/stdenv-inputs/bar.c
@@ -0,0 +1,3 @@
+unsigned int bar(void) {
+  return 42;
+}
diff --git a/pkgs/test/stdenv-inputs/cc-main.c b/pkgs/test/stdenv-inputs/cc-main.c
new file mode 100644
index 00000000000..06f28bc33c6
--- /dev/null
+++ b/pkgs/test/stdenv-inputs/cc-main.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+  fprintf(stderr, "ok\n");
+  return 0;
+}
diff --git a/pkgs/test/stdenv-inputs/default.nix b/pkgs/test/stdenv-inputs/default.nix
new file mode 100644
index 00000000000..d1eb8b9bfe2
--- /dev/null
+++ b/pkgs/test/stdenv-inputs/default.nix
@@ -0,0 +1,64 @@
+{ stdenv }:
+
+let
+  shlib = if stdenv.isDarwin then "dylib" else "so";
+
+  foo = stdenv.mkDerivation {
+    name = "foo-test";
+
+    unpackPhase = ":";
+
+    installPhase = ''
+      mkdir -p $out/bin $out/include $out/lib
+      $CC -o $out/bin/foo ${./cc-main.c}
+      chmod +x $out/bin/foo
+      cp ${./foo.c} $out/include/foo.h
+      $CC -shared ${stdenv.lib.optionalString stdenv.isDarwin "-Wl,-install_name,$out/lib/libfoo.dylib"} -o $out/lib/libfoo.${shlib} ${./foo.c}
+    '';
+  };
+
+  bar = stdenv.mkDerivation {
+    name = "bar-test";
+    outputs = [ "out" "dev" ];
+
+    unpackPhase = ":";
+
+    installPhase = ''
+      mkdir -p $out/bin $dev/include $dev/lib
+      $CC -o $out/bin/bar ${./cc-main.c}
+      chmod +x $out/bin/bar
+      cp ${./bar.c} $dev/include/bar.h
+      $CC -shared ${stdenv.lib.optionalString stdenv.isDarwin "-Wl,-install_name,$dev/lib/libbar.dylib"} -o $dev/lib/libbar.${shlib} ${./bar.c}
+    '';
+  };
+in
+
+stdenv.mkDerivation {
+  name = "stdenv-inputs-test";
+  phases = [ "buildPhase" ];
+
+  buildInputs = [ foo bar ];
+
+  buildPhase = ''
+    env
+
+    printf "checking whether binaries are available... " >&2
+    foo && bar
+
+    printf "checking whether compiler can find headers... " >&2
+    $CC -o include-check ${./include-main.c}
+    ./include-check
+
+    printf "checking whether compiler can find headers... " >&2
+    $CC -o include-check ${./include-main.c}
+    ./include-check
+
+    printf "checking whether compiler can find libraries... " >&2
+    $CC -lfoo -lbar -o lib-check ${./lib-main.c}
+    ./lib-check
+
+    touch $out
+  '';
+
+  meta.platforms = stdenv.lib.platforms.all;
+}
diff --git a/pkgs/test/stdenv-inputs/foo.c b/pkgs/test/stdenv-inputs/foo.c
new file mode 100644
index 00000000000..0253a26d5d2
--- /dev/null
+++ b/pkgs/test/stdenv-inputs/foo.c
@@ -0,0 +1,3 @@
+unsigned int foo(void) {
+  return 42;
+}
diff --git a/pkgs/test/stdenv-inputs/include-main.c b/pkgs/test/stdenv-inputs/include-main.c
new file mode 100644
index 00000000000..35e5ee0d90f
--- /dev/null
+++ b/pkgs/test/stdenv-inputs/include-main.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include <foo.h>
+#include <bar.h>
+
+int main(int argc, char **argv)
+{
+  if (foo() != 42)
+    return 1;
+  if (bar() != 42)
+    return 1;
+  fprintf(stderr, "ok\n");
+  return 0;
+}
diff --git a/pkgs/test/stdenv-inputs/lib-main.c b/pkgs/test/stdenv-inputs/lib-main.c
new file mode 100644
index 00000000000..c9488fe43e5
--- /dev/null
+++ b/pkgs/test/stdenv-inputs/lib-main.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+extern unsigned int foo(void);
+extern unsigned int bar(void);
+
+int main(int argc, char **argv)
+{
+  if (foo() != 42)
+    return 1;
+  if (bar() != 42)
+    return 1;
+  fprintf(stderr, "ok\n");
+  return 0;
+}