mirror of
https://github.com/nmattia/niv.git
synced 2024-09-18 19:07:19 +03:00
Refactor eval tests
This commit is contained in:
parent
e82eb322ea
commit
7abb350a10
@ -1,45 +1,63 @@
|
||||
{ pkgs ? import <nixpkgs> {}
|
||||
}:
|
||||
|
||||
pkgs.runCommand "foobar" { nativeBuildInputs = [ pkgs.jq pkgs.nix pkgs.moreutils ]; }
|
||||
|
||||
let
|
||||
mkTest = name: text:
|
||||
{
|
||||
${name} =
|
||||
pkgs.runCommand name { nativeBuildInputs = [ pkgs.jq pkgs.nix pkgs.moreutils ]; }
|
||||
''
|
||||
# for nix to run smoothly in multi-user install
|
||||
# https://github.com/NixOS/nix/issues/3258
|
||||
# https://github.com/cachix/install-nix-action/issues/16
|
||||
export NIX_STATE_DIR="$TMPDIR"
|
||||
export NIX_LOG_DIR="$TMPDIR"
|
||||
|
||||
cp ${ ../../nix/sources.nix} sources.nix
|
||||
echo '{}' > sources.json
|
||||
|
||||
update_sources() {
|
||||
cat sources.json | jq -cMe "$@" | sponge sources.json
|
||||
}
|
||||
|
||||
eval_outPath() {
|
||||
nix eval --raw '(let sources = import ./sources.nix; in sources.'"$1"'.outPath)'
|
||||
}
|
||||
|
||||
eq() {
|
||||
if ! [ "$1" == "$2" ]; then
|
||||
echo "expected"
|
||||
echo " '$1' == '$2'"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
${text}
|
||||
|
||||
touch "$out"
|
||||
'';
|
||||
};
|
||||
in
|
||||
|
||||
mkTest "simple-eval" ''
|
||||
|
||||
update_sources '.foo = { type: "tarball", url: "foo", sha256: "whocares" }'
|
||||
update_sources '."ba-r" = { type: "tarball", url: "foo", sha256: "whocares" }'
|
||||
update_sources '."ba z" = { type: "tarball", url: "foo", sha256: "whocares" }'
|
||||
|
||||
res="$(NIV_OVERRIDE_foo="hello" eval_outPath "foo")"
|
||||
eq "$res" "hello"
|
||||
|
||||
res="$(NIV_OVERRIDE_ba_r="hello" eval_outPath "ba-r")"
|
||||
eq "$res" "hello"
|
||||
|
||||
res="$(NIV_OVERRIDE_ba_z="hello" eval_outPath '"ba z"')"
|
||||
eq "$res" "hello"
|
||||
|
||||
'' // mkTest "sources-json-elsewhere"
|
||||
''
|
||||
# for nix to run smoothly in multi-user install
|
||||
# https://github.com/NixOS/nix/issues/3258
|
||||
# https://github.com/cachix/install-nix-action/issues/16
|
||||
export NIX_STATE_DIR="$TMPDIR"
|
||||
export NIX_LOG_DIR="$TMPDIR"
|
||||
|
||||
cp ${ ../../nix/sources.nix} sources.nix
|
||||
echo '{}' > sources.json
|
||||
|
||||
update_sources() {
|
||||
cat sources.json | jq -cMe "$1" | sponge sources.json
|
||||
}
|
||||
|
||||
update_sources '.foo = { type: "tarball", url: "foo", sha256: "whocares" }'
|
||||
update_sources '."ba-r" = { type: "tarball", url: "foo", sha256: "whocares" }'
|
||||
update_sources '."ba z" = { type: "tarball", url: "foo", sha256: "whocares" }'
|
||||
|
||||
eval_outPath() {
|
||||
nix eval --raw '(let sources = import ./sources.nix; in sources.'"$1"'.outPath)'
|
||||
}
|
||||
|
||||
eq() {
|
||||
if ! [ "$1" == "$2" ]; then
|
||||
echo "expected"
|
||||
echo " '$1' == '$2'"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
res="$(NIV_OVERRIDE_foo="hello" eval_outPath "foo")"
|
||||
eq "$res" "hello"
|
||||
|
||||
res="$(NIV_OVERRIDE_ba_r="hello" eval_outPath "ba-r")"
|
||||
eq "$res" "hello"
|
||||
|
||||
res="$(NIV_OVERRIDE_ba_z="hello" eval_outPath '"ba z"')"
|
||||
eq "$res" "hello"
|
||||
|
||||
mkdir other
|
||||
mv sources.json other
|
||||
@ -52,6 +70,4 @@ pkgs.runCommand "foobar" { nativeBuildInputs = [ pkgs.jq pkgs.nix pkgs.moreutils
|
||||
|
||||
res="$(NIV_OVERRIDE_foo="hello" eval_outPath "foo")"
|
||||
eq "$res" "hello"
|
||||
|
||||
touch "$out"
|
||||
''
|
||||
|
Loading…
Reference in New Issue
Block a user