tests: initial integration tests
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I09ed2eea568edfaecdb800197bc36c416a6a6964
This commit is contained in:
parent
347175bb86
commit
8bce6c27b5
6 changed files with 148 additions and 0 deletions
7
tests/integration/import_test.nix
Normal file
7
tests/integration/import_test.nix
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
7
tests/integration/imported_module.nix
Normal file
7
tests/integration/imported_module.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
# Module to be imported
|
||||||
|
{
|
||||||
|
foo = 42;
|
||||||
|
bar = {
|
||||||
|
baz = "hello";
|
||||||
|
};
|
||||||
|
}
|
||||||
13
tests/integration/ir_builtins_test.nix
Normal file
13
tests/integration/ir_builtins_test.nix
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
39
tests/integration/regression_normal_nix.nix
Normal file
39
tests/integration/regression_normal_nix.nix
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
76
tests/integration/run.sh
Executable file
76
tests/integration/run.sh
Executable file
|
|
@ -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"
|
||||||
6
tests/integration/simple_eval.nix
Normal file
6
tests/integration/simple_eval.nix
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
# Simple expression to test plugin loading
|
||||||
|
let
|
||||||
|
x = 10;
|
||||||
|
y = 20;
|
||||||
|
in
|
||||||
|
x + y
|
||||||
Loading…
Add table
Add a link
Reference in a new issue