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 ; "${ + cleanSource ./. +}")')" +(cd $dir; find) | sort -f | diff -U10 - <(cat <&2 tests ok