summary refs log tree commit diff
path: root/third_party/bazel/rules_nixpkgs/tests
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/bazel/rules_nixpkgs/tests')
-rw-r--r--third_party/bazel/rules_nixpkgs/tests/BUILD58
-rw-r--r--third_party/bazel/rules_nixpkgs/tests/cc-test.cc1
-rw-r--r--third_party/bazel/rules_nixpkgs/tests/hello.nix3
-rw-r--r--third_party/bazel/rules_nixpkgs/tests/nixpkgs.nix1
-rw-r--r--third_party/bazel/rules_nixpkgs/tests/output.nix13
-rw-r--r--third_party/bazel/rules_nixpkgs/tests/pkgname.nix1
-rwxr-xr-xthird_party/bazel/rules_nixpkgs/tests/test_bin.sh4
-rwxr-xr-xthird_party/bazel/rules_nixpkgs/tests/test_output.sh15
8 files changed, 96 insertions, 0 deletions
diff --git a/third_party/bazel/rules_nixpkgs/tests/BUILD b/third_party/bazel/rules_nixpkgs/tests/BUILD
new file mode 100644
index 000000000000..68e4f4c58079
--- /dev/null
+++ b/third_party/bazel/rules_nixpkgs/tests/BUILD
@@ -0,0 +1,58 @@
+package(default_testonly = 1)
+
+[
+    # All of these tests use the "hello" binary to see
+    # whether different invocations of `nixpkgs_package`
+    # produce a valid bazel repository.
+    sh_test(
+        name = "run-{0}".format(test),
+        timeout = "short",
+        srcs = ["test_bin.sh"],
+        args = ["$(location @{0}//:bin)".format(test)],
+        data = ["@{0}//:bin".format(test)],
+    )
+    for test in [
+        "hello",
+        "expr-test",
+        "attribute-test",
+        "expr-attribute-test",
+        "nix-file-test",
+        "nix-file-deps-test",
+        "nixpkgs-git-repository-test",
+    ]
+] + [
+    # These tests use the nix package generated by ./output.nix
+
+    # Checks whether the `:include` filegroup of `nixpkgs_package`
+    # repositories works as intended
+    # (that the expected number of files are inside the target)
+    sh_test(
+        name = "run-test-include",
+        timeout = "short",
+        srcs = ["test_output.sh"],
+        args = [
+            "2",
+            "$(locations @output-filegroup-test//:include)",
+        ],
+        data = ["@output-filegroup-test//:include"],
+    ),
+
+    # Checks whether specifying a manual filegroup in the
+    # `nixpkgs_package` BUILD file works as well.
+    sh_test(
+        name = "run-test-manual-filegroup",
+        timeout = "short",
+        srcs = ["test_output.sh"],
+        args = [
+            "3",
+            "$(locations @output-filegroup-manual-test//:manual-filegroup)",
+        ],
+        data = ["@output-filegroup-manual-test//:manual-filegroup"],
+    ),
+]
+
+# Test nixpkgs_cc_configure() by building some CC code.
+cc_binary(
+    name = "cc-test",
+    srcs = ["cc-test.cc"],
+)
diff --git a/third_party/bazel/rules_nixpkgs/tests/cc-test.cc b/third_party/bazel/rules_nixpkgs/tests/cc-test.cc
new file mode 100644
index 000000000000..76e8197013aa
--- /dev/null
+++ b/third_party/bazel/rules_nixpkgs/tests/cc-test.cc
@@ -0,0 +1 @@
+int main() { return 0; }
diff --git a/third_party/bazel/rules_nixpkgs/tests/hello.nix b/third_party/bazel/rules_nixpkgs/tests/hello.nix
new file mode 100644
index 000000000000..285e93f7e803
--- /dev/null
+++ b/third_party/bazel/rules_nixpkgs/tests/hello.nix
@@ -0,0 +1,3 @@
+with import ./pkgname.nix;
+let pkgs = import <nixpkgs> {}; in builtins.getAttr pkgname pkgs
+
diff --git a/third_party/bazel/rules_nixpkgs/tests/nixpkgs.nix b/third_party/bazel/rules_nixpkgs/tests/nixpkgs.nix
new file mode 100644
index 000000000000..cdd1f58f0ea5
--- /dev/null
+++ b/third_party/bazel/rules_nixpkgs/tests/nixpkgs.nix
@@ -0,0 +1 @@
+import <nixpkgs> {}
diff --git a/third_party/bazel/rules_nixpkgs/tests/output.nix b/third_party/bazel/rules_nixpkgs/tests/output.nix
new file mode 100644
index 000000000000..a0269adb6679
--- /dev/null
+++ b/third_party/bazel/rules_nixpkgs/tests/output.nix
@@ -0,0 +1,13 @@
+with import <nixpkgs> {};
+
+runCommand "some-output" {
+  preferLocalBuild = true;
+  allowSubstitutes = false;
+} ''
+  mkdir -p $out/{bin,include/mylib}
+  touch $out/hi-i-exist
+  touch $out/hi-i-exist-too
+  touch $out/bin/im-a-binary
+  touch $out/include/mylib/im-a-header.h
+  touch $out/include/mylib/im-also-a-header.h
+''
diff --git a/third_party/bazel/rules_nixpkgs/tests/pkgname.nix b/third_party/bazel/rules_nixpkgs/tests/pkgname.nix
new file mode 100644
index 000000000000..9a4e13899786
--- /dev/null
+++ b/third_party/bazel/rules_nixpkgs/tests/pkgname.nix
@@ -0,0 +1 @@
+{ pkgname = "hello"; }
diff --git a/third_party/bazel/rules_nixpkgs/tests/test_bin.sh b/third_party/bazel/rules_nixpkgs/tests/test_bin.sh
new file mode 100755
index 000000000000..f4df0931b987
--- /dev/null
+++ b/third_party/bazel/rules_nixpkgs/tests/test_bin.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+echo "Executing: " $@
+$@
diff --git a/third_party/bazel/rules_nixpkgs/tests/test_output.sh b/third_party/bazel/rules_nixpkgs/tests/test_output.sh
new file mode 100755
index 000000000000..29f2735cf4ca
--- /dev/null
+++ b/third_party/bazel/rules_nixpkgs/tests/test_output.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# first param is the expected number of files given by `locations`
+expected_length="$1"
+
+# rest of the arguments are files
+shift
+no_of_files=$#
+
+if [ "$no_of_files" -ne "$expected_length" ]; then
+    echo "Should have received $expected_length files, but got $no_of_files:"
+    for f in "$@"; do
+        echo "$f"
+    done
+    exit 1
+fi