2021-07-15 16:17:18 +00:00
|
|
|
source common.sh
|
|
|
|
|
2022-04-18 17:21:47 +00:00
|
|
|
testDir="$PWD"
|
|
|
|
cd "$TEST_ROOT"
|
|
|
|
|
2021-07-15 16:17:18 +00:00
|
|
|
replCmds="
|
2021-12-09 15:35:27 +00:00
|
|
|
simple = 1
|
2022-04-18 17:21:47 +00:00
|
|
|
simple = import $testDir/simple.nix
|
|
|
|
:bl simple
|
2021-11-26 15:03:07 +00:00
|
|
|
:log simple
|
|
|
|
"
|
|
|
|
|
|
|
|
replFailingCmds="
|
2022-04-18 17:21:47 +00:00
|
|
|
failing = import $testDir/simple-failing.nix
|
2021-11-26 15:03:07 +00:00
|
|
|
:b failing
|
|
|
|
:log failing
|
2021-07-15 16:17:18 +00:00
|
|
|
"
|
|
|
|
|
2021-12-28 12:54:46 +00:00
|
|
|
replUndefinedVariable="
|
2022-04-18 17:21:47 +00:00
|
|
|
import $testDir/undefined-variable.nix
|
2021-12-28 12:54:46 +00:00
|
|
|
"
|
|
|
|
|
2021-07-15 16:17:18 +00:00
|
|
|
testRepl () {
|
|
|
|
local nixArgs=("$@")
|
2022-04-18 17:21:47 +00:00
|
|
|
rm -rf repl-result-out || true # cleanup from other runs backed by a foreign nix store
|
2021-11-03 09:54:17 +00:00
|
|
|
local replOutput="$(nix repl "${nixArgs[@]}" <<< "$replCmds")"
|
|
|
|
echo "$replOutput"
|
|
|
|
local outPath=$(echo "$replOutput" |&
|
2021-07-15 16:17:18 +00:00
|
|
|
grep -o -E "$NIX_STORE_DIR/\w*-simple")
|
|
|
|
nix path-info "${nixArgs[@]}" "$outPath"
|
2022-04-18 17:21:47 +00:00
|
|
|
[ "$(realpath ./repl-result-out)" == "$outPath" ] || fail "nix repl :bl doesn't make a symlink"
|
|
|
|
# run it again without checking the output to ensure the previously created symlink gets overwritten
|
|
|
|
nix repl "${nixArgs[@]}" <<< "$replCmds" || fail "nix repl does not work twice with the same inputs"
|
|
|
|
|
2021-11-26 15:03:07 +00:00
|
|
|
# simple.nix prints a PATH during build
|
|
|
|
echo "$replOutput" | grep -qs 'PATH=' || fail "nix repl :log doesn't output logs"
|
2021-12-28 12:54:46 +00:00
|
|
|
local replOutput="$(nix repl "${nixArgs[@]}" <<< "$replFailingCmds" 2>&1)"
|
2021-11-26 15:03:07 +00:00
|
|
|
echo "$replOutput"
|
|
|
|
echo "$replOutput" | grep -qs 'This should fail' \
|
|
|
|
|| fail "nix repl :log doesn't output logs for a failed derivation"
|
2021-12-28 12:54:46 +00:00
|
|
|
local replOutput="$(nix repl --show-trace "${nixArgs[@]}" <<< "$replUndefinedVariable" 2>&1)"
|
|
|
|
echo "$replOutput"
|
|
|
|
echo "$replOutput" | grep -qs "while evaluating the file" \
|
|
|
|
|| fail "nix repl --show-trace doesn't show the trace"
|
2021-07-15 16:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Simple test, try building a drv
|
|
|
|
testRepl
|
|
|
|
# Same thing (kind-of), but with a remote store.
|
|
|
|
testRepl --store "$TEST_ROOT/store?real=$NIX_STORE_DIR"
|
2022-02-04 06:36:56 +00:00
|
|
|
|
|
|
|
testReplResponse () {
|
|
|
|
local response="$(nix repl <<< "$1")"
|
|
|
|
echo "$response" | grep -qs "$2" \
|
|
|
|
|| fail "repl command set:
|
|
|
|
|
|
|
|
$1
|
|
|
|
|
|
|
|
does not respond with:
|
|
|
|
|
|
|
|
$2
|
|
|
|
|
|
|
|
but with:
|
|
|
|
|
|
|
|
$response"
|
|
|
|
}
|
|
|
|
|
|
|
|
# :a uses the newest version of a symbol
|
|
|
|
testReplResponse '
|
|
|
|
:a { a = "1"; }
|
|
|
|
:a { a = "2"; }
|
|
|
|
"result: ${a}"
|
|
|
|
' "result: 2"
|