brewery
notashelf /
bfbcef9c284c54772e80b5a7f33efe9f9bcf75fa

nixir

public

Import-resolving Nix IR plugin

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/nixir.git
tests/integration/run.shBash103 lines3.2 KB
1
#!/usr/bin/env bash
2
set -euo pipefail
3
4
echo ""
5
6
PLUGIN_PATH="$(pwd)/build/nix-ir-plugin.so"
7
TEST_DIR="$(pwd)/tests/integration"
8
9
if [ ! -f "$PLUGIN_PATH" ]; then
10
	echo "ERROR: Plugin not found at $PLUGIN_PATH"
11
	exit 1
12
fi
13
14
echo "Plugin path: $PLUGIN_PATH"
15
echo ""
16
17
echo "Test 1: Plugin Loading"
18
echo "----------------------"
19
if nix-instantiate --plugin-files "$PLUGIN_PATH" --eval "$TEST_DIR/simple_eval.nix" 2>&1 | grep -q "30"; then
20
	echo "[PASS] Plugin loads and evaluates correctly"
21
else
22
	echo "[FAIL] Plugin failed to load or evaluate"
23
	exit 1
24
fi
25
echo ""
26
27
echo "Test 2: Normal Nix Evaluation (No Plugin)"
28
echo "------------------------------------------"
29
result=$(nix-instantiate --eval --strict --json "$TEST_DIR/regression_normal_nix.nix" 2>&1)
30
if echo "$result" | grep -q '"math":7'; then
31
	echo "[PASS] Normal Nix evaluation works without plugin"
32
else
33
	echo "[FAIL] Normal Nix evaluation broken"
34
	echo "$result"
35
	exit 1
36
fi
37
echo ""
38
39
echo "Test 3: Normal Nix Evaluation (With Plugin)"
40
echo "--------------------------------------------"
41
result=$(nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --strict --json "$TEST_DIR/regression_normal_nix.nix" 2>&1)
42
if echo "$result" | grep -q '"math":7'; then
43
	echo "[PASS] Normal Nix evaluation works with plugin loaded"
44
else
45
	echo "[FAIL] Plugin breaks normal Nix evaluation"
46
	echo "$result"
47
	exit 1
48
fi
49
echo ""
50
51
echo "Test 4: Import Builtin"
52
echo "----------------------"
53
cd "$TEST_DIR"
54
result=$(nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --strict --json import_test.nix 2>&1)
55
if echo "$result" | grep -q '"value":142'; then
56
	echo "[PASS] Import builtin works correctly"
57
else
58
	echo "[FAIL] Import builtin broken"
59
	echo "$result"
60
	exit 1
61
fi
62
cd - >/dev/null
63
echo ""
64
65
echo "Test 5: IR Builtins Available"
66
echo "------------------------------"
67
result=$(nix-instantiate --plugin-files "$PLUGIN_PATH" --eval "$TEST_DIR/ir_builtins_test.nix" 2>&1)
68
if echo "$result" | grep -q "info.*="; then
69
	echo "[PASS] IR builtins (nixIR_info, nixIR_compile, nixIR_loadIR) available"
70
else
71
	echo "[WARN] IR builtins may not be available (check plugin initialization)"
72
fi
73
echo ""
74
75
echo "Test 6: Flake Reference Compilation"
76
echo "-----------------------------------"
77
flake_ir=$(mktemp /tmp/nixir-flake-value-XXXXXX.nixir)
78
"$(pwd)/build/nix-irc" "$TEST_DIR/flake_ref#value" "$flake_ir"
79
result=$(nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --strict --json --expr "builtins.nixIR_loadIR \"$flake_ir\"" 2>&1)
80
if echo "$result" | grep -q '^42$'; then
81
	echo "[PASS] Flake reference compiles and evaluates correctly"
82
else
83
	echo "[FAIL] Flake reference compilation broken"
84
	echo "$result"
85
	exit 1
86
fi
87
echo ""
88
89
echo "Test 7: NixOS Configuration Attribute Path"
90
echo "------------------------------------------"
91
config_ir=$(mktemp /tmp/nixir-flake-config-XXXXXX.nixir)
92
"$(pwd)/build/nix-irc" "$TEST_DIR/flake_ref#nixosConfigurations.demo.config.networking.hostName" "$config_ir"
93
result=$(nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --strict --json --expr "builtins.nixIR_loadIR \"$config_ir\"" 2>&1)
94
if echo "$result" | grep -q '"nixir-demo"'; then
95
	echo "[PASS] Nested flake attribute selection works for nixosConfigurations"
96
else
97
	echo "[FAIL] NixOS configuration flake selection broken"
98
	echo "$result"
99
	exit 1
100
fi
101
echo ""
102
103
echo "Integration Tests Complete"