at 22.05-pre 1.3 kB view raw
1#!/usr/bin/env bash 2set -euo pipefail 3 4# Use 5# || die 6die() { 7 echo >&2 "test case failed: " "$@" 8 exit 1 9} 10 11if test -n "${TEST_LIB:-}"; then 12 export NIX_PATH=nixpkgs="$(dirname "$TEST_LIB")" 13else 14 export NIX_PATH=nixpkgs="$(cd $(dirname ${BASH_SOURCE[0]})/../..; pwd)" 15fi 16 17work="$(mktemp -d)" 18clean_up() { 19 rm -rf "$work" 20} 21trap clean_up EXIT 22cd $work 23 24touch {README.md,module.o,foo.bar} 25 26# nix-instantiate doesn't write out the source, only computing the hash, so 27# this uses the experimental nix command instead. 28 29dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${ 30 cleanSource ./. 31}")')" 32(cd $dir; find) | sort -f | diff -U10 - <(cat <<EOF 33. 34./foo.bar 35./README.md 36EOF 37) || die "cleanSource 1" 38 39 40dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${ 41 cleanSourceWith { src = '"$work"'; filter = path: type: ! hasSuffix ".bar" path; } 42}")')" 43(cd $dir; find) | sort -f | diff -U10 - <(cat <<EOF 44. 45./module.o 46./README.md 47EOF 48) || die "cleanSourceWith 1" 49 50dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${ 51 cleanSourceWith { src = cleanSource '"$work"'; filter = path: type: ! hasSuffix ".bar" path; } 52}")')" 53(cd $dir; find) | sort -f | diff -U10 - <(cat <<EOF 54. 55./README.md 56EOF 57) || die "cleanSourceWith + cleanSource" 58 59echo >&2 tests ok