summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2021-02-06 00:15:33 +0100
committerRobert Hensing <robert@roberthensing.nl>2021-05-29 14:32:56 +0200
commitd14be76615299c55e8f239cd1ec95c8107f41b33 (patch)
tree42b6963960f80295145810f65bf7fb2f7841350b /lib
parentdfd2b1bd9002c3cbe38e2cac8014d8b2723c4137 (diff)
downloadnixpkgs-d14be76615299c55e8f239cd1ec95c8107f41b33.tar
nixpkgs-d14be76615299c55e8f239cd1ec95c8107f41b33.tar.gz
nixpkgs-d14be76615299c55e8f239cd1ec95c8107f41b33.tar.bz2
nixpkgs-d14be76615299c55e8f239cd1ec95c8107f41b33.tar.lz
nixpkgs-d14be76615299c55e8f239cd1ec95c8107f41b33.tar.xz
nixpkgs-d14be76615299c55e8f239cd1ec95c8107f41b33.tar.zst
nixpkgs-d14be76615299c55e8f239cd1ec95c8107f41b33.zip
lib/tests/sources.sh: init
Diffstat (limited to 'lib')
-rw-r--r--lib/sources.nix1
-rw-r--r--lib/tests/release.nix4
-rwxr-xr-xlib/tests/sources.sh59
3 files changed, 64 insertions, 0 deletions
diff --git a/lib/sources.nix b/lib/sources.nix
index cad3c5b1a14..c7a0c000de6 100644
--- a/lib/sources.nix
+++ b/lib/sources.nix
@@ -1,6 +1,7 @@
 # Functions for copying sources to the Nix store.
 { lib }:
 
+# Tested in lib/tests/sources.sh
 let
   inherit (builtins)
     hasContext
diff --git a/lib/tests/release.nix b/lib/tests/release.nix
index 800d8a65c14..c3b05251f70 100644
--- a/lib/tests/release.nix
+++ b/lib/tests/release.nix
@@ -26,7 +26,11 @@ pkgs.runCommandNoCC "nixpkgs-lib-tests" {
     nix-store --init
 
     cp -r ${../.} lib
+    echo "Running lib/tests/modules.sh"
     bash lib/tests/modules.sh
 
+    echo "Running lib/tests/sources.sh"
+    TEST_LIB=$PWD/lib bash lib/tests/sources.sh
+
     touch $out
 ''
diff --git a/lib/tests/sources.sh b/lib/tests/sources.sh
new file mode 100755
index 00000000000..71fee719cb2
--- /dev/null
+++ b/lib/tests/sources.sh
@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+# Use
+#     || die
+die() {
+  echo >&2 "test case failed: " "$@"
+  exit 1
+}
+
+if test -n "${TEST_LIB:-}"; then
+  export NIX_PATH=nixpkgs="$(dirname "$TEST_LIB")"
+else
+  export NIX_PATH=nixpkgs="$(cd $(dirname ${BASH_SOURCE[0]})/../..; pwd)"
+fi
+
+work="$(mktemp -d)"
+clean_up() {
+  rm -rf "$work"
+}
+trap clean_up EXIT
+cd $work
+
+touch {README.md,module.o,foo.bar}
+
+# nix-instantiate doesn't write out the source, only computing the hash, so
+# this uses the experimental nix command instead.
+
+dir="$(nix eval --raw '(with import <nixpkgs/lib>; "${
+  cleanSource ./.
+}")')"
+(cd $dir; find) | sort -f | diff -U10 - <(cat <<EOF
+.
+./foo.bar
+./README.md
+EOF
+) || die "cleanSource 1"
+
+
+dir="$(nix eval --raw '(with import <nixpkgs/lib>; "${
+  cleanSourceWith { src = '"$work"'; filter = path: type: ! hasSuffix ".bar" path; }
+}")')"
+(cd $dir; find) | sort -f | diff -U10 - <(cat <<EOF
+.
+./module.o
+./README.md
+EOF
+) || die "cleanSourceWith 1"
+
+dir="$(nix eval --raw '(with import <nixpkgs/lib>; "${
+  cleanSourceWith { src = cleanSource '"$work"'; filter = path: type: ! hasSuffix ".bar" path; }
+}")')"
+(cd $dir; find) | sort -f | diff -U10 - <(cat <<EOF
+.
+./README.md
+EOF
+) || die "cleanSourceWith + cleanSource"
+
+echo >&2 tests ok