diff options
author | Alyssa Ross <hi@alyssa.is> | 2021-08-04 10:43:07 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2021-08-04 10:43:07 +0000 |
commit | 62614cbef7da005c1eda8c9400160f6bcd6546b8 (patch) | |
tree | c2630f69080637987b68acb1ee8676d2681fe304 /lib/tests/sources.sh | |
parent | d9c82ed3044c72cecf01c6ea042489d30914577c (diff) | |
parent | e24069138dfec3ef94f211f1da005bb5395adc11 (diff) | |
download | nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.gz nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.bz2 nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.lz nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.xz nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.zst nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.zip |
Merge branch 'nixpkgs-update' into master
Diffstat (limited to 'lib/tests/sources.sh')
-rwxr-xr-x | lib/tests/sources.sh | 59 |
1 files changed, 59 insertions, 0 deletions
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 |