nixir/tests/integration/run.sh
NotAShelf 531855d91a
tests: cover flake refs and lexer/parser regressions
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I1b5f90bbb210262a9287a9b8eac02e9d6a6a6964
2026-04-24 23:13:24 +03:00

103 lines
3.2 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
echo ""
PLUGIN_PATH="$(pwd)/build/nix-ir-plugin.so"
TEST_DIR="$(pwd)/tests/integration"
if [ ! -f "$PLUGIN_PATH" ]; then
echo "ERROR: Plugin not found at $PLUGIN_PATH"
exit 1
fi
echo "Plugin path: $PLUGIN_PATH"
echo ""
echo "Test 1: Plugin Loading"
echo "----------------------"
if nix-instantiate --plugin-files "$PLUGIN_PATH" --eval "$TEST_DIR/simple_eval.nix" 2>&1 | grep -q "30"; then
echo "[PASS] Plugin loads and evaluates correctly"
else
echo "[FAIL] Plugin failed to load or evaluate"
exit 1
fi
echo ""
echo "Test 2: Normal Nix Evaluation (No Plugin)"
echo "------------------------------------------"
result=$(nix-instantiate --eval --strict --json "$TEST_DIR/regression_normal_nix.nix" 2>&1)
if echo "$result" | grep -q '"math":7'; then
echo "[PASS] Normal Nix evaluation works without plugin"
else
echo "[FAIL] Normal Nix evaluation broken"
echo "$result"
exit 1
fi
echo ""
echo "Test 3: Normal Nix Evaluation (With Plugin)"
echo "--------------------------------------------"
result=$(nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --strict --json "$TEST_DIR/regression_normal_nix.nix" 2>&1)
if echo "$result" | grep -q '"math":7'; then
echo "[PASS] Normal Nix evaluation works with plugin loaded"
else
echo "[FAIL] Plugin breaks normal Nix evaluation"
echo "$result"
exit 1
fi
echo ""
echo "Test 4: Import Builtin"
echo "----------------------"
cd "$TEST_DIR"
result=$(nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --strict --json import_test.nix 2>&1)
if echo "$result" | grep -q '"value":142'; then
echo "[PASS] Import builtin works correctly"
else
echo "[FAIL] Import builtin broken"
echo "$result"
exit 1
fi
cd - >/dev/null
echo ""
echo "Test 5: IR Builtins Available"
echo "------------------------------"
result=$(nix-instantiate --plugin-files "$PLUGIN_PATH" --eval "$TEST_DIR/ir_builtins_test.nix" 2>&1)
if echo "$result" | grep -q "info.*="; then
echo "[PASS] IR builtins (nixIR_info, nixIR_compile, nixIR_loadIR) available"
else
echo "[WARN] IR builtins may not be available (check plugin initialization)"
fi
echo ""
echo "Test 6: Flake Reference Compilation"
echo "-----------------------------------"
flake_ir=$(mktemp /tmp/nixir-flake-value-XXXXXX.nixir)
"$(pwd)/build/nix-irc" "$TEST_DIR/flake_ref#value" "$flake_ir"
result=$(nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --strict --json --expr "builtins.nixIR_loadIR \"$flake_ir\"" 2>&1)
if echo "$result" | grep -q '^42$'; then
echo "[PASS] Flake reference compiles and evaluates correctly"
else
echo "[FAIL] Flake reference compilation broken"
echo "$result"
exit 1
fi
echo ""
echo "Test 7: NixOS Configuration Attribute Path"
echo "------------------------------------------"
config_ir=$(mktemp /tmp/nixir-flake-config-XXXXXX.nixir)
"$(pwd)/build/nix-irc" "$TEST_DIR/flake_ref#nixosConfigurations.demo.config.networking.hostName" "$config_ir"
result=$(nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --strict --json --expr "builtins.nixIR_loadIR \"$config_ir\"" 2>&1)
if echo "$result" | grep -q '"nixir-demo"'; then
echo "[PASS] Nested flake attribute selection works for nixosConfigurations"
else
echo "[FAIL] NixOS configuration flake selection broken"
echo "$result"
exit 1
fi
echo ""
echo "Integration Tests Complete"