diff --git a/tests/integration/import_test.nix b/tests/integration/import_test.nix new file mode 100644 index 0000000..7914eea --- /dev/null +++ b/tests/integration/import_test.nix @@ -0,0 +1,7 @@ +# Test that import builtin still works +let + imported = import ./imported_module.nix; +in { + value = imported.foo + 100; + nested = imported.bar.baz; +} diff --git a/tests/integration/imported_module.nix b/tests/integration/imported_module.nix new file mode 100644 index 0000000..a9b969c --- /dev/null +++ b/tests/integration/imported_module.nix @@ -0,0 +1,7 @@ +# Module to be imported +{ + foo = 42; + bar = { + baz = "hello"; + }; +} diff --git a/tests/integration/ir_builtins_test.nix b/tests/integration/ir_builtins_test.nix new file mode 100644 index 0000000..4aa28e3 --- /dev/null +++ b/tests/integration/ir_builtins_test.nix @@ -0,0 +1,13 @@ +# Test our custom IR builtins +let + # Test nixIR_info + info = builtins.nixIR_info; + + # Test nixIR_compile + compiled = builtins.nixIR_compile "let x = 10; in x + 5"; + + # Test that normal builtins still work + list = builtins.map (x: x * 2) [1 2 3]; +in { + inherit info compiled list; +} diff --git a/tests/integration/regression_normal_nix.nix b/tests/integration/regression_normal_nix.nix new file mode 100644 index 0000000..2eb73f6 --- /dev/null +++ b/tests/integration/regression_normal_nix.nix @@ -0,0 +1,39 @@ +# Test that normal Nix evaluation is not broken +# This file should work identically with or without the plugin +let + # Basic arithmetic + math = 1 + 2 * 3; + + # String operations + str = "hello" + " " + "world"; + + # List operations + list = [1 2 3] ++ [4 5 6]; + + # Attrset operations + attrs = + { + a = 1; + b = 2; + } + // {c = 3;}; + + # Functions + double = x: x * 2; + result = double 21; + + # Conditionals + cond = + if true + then "yes" + else "no"; + + # Let bindings + nested = let + x = 10; + y = 20; + in + x + y; +in { + inherit math str list attrs result cond nested; +} diff --git a/tests/integration/run.sh b/tests/integration/run.sh new file mode 100755 index 0000000..8645388 --- /dev/null +++ b/tests/integration/run.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "=== Phase 6: Integration Testing ===" +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 "Integration Tests Complete" diff --git a/tests/integration/simple_eval.nix b/tests/integration/simple_eval.nix new file mode 100644 index 0000000..9dc2744 --- /dev/null +++ b/tests/integration/simple_eval.nix @@ -0,0 +1,6 @@ +# Simple expression to test plugin loading +let + x = 10; + y = 20; +in + x + y