test(joinir): Phase 130 post-if add fixture + smokes
This commit is contained in:
41
apps/tests/phase130_if_only_post_if_add_min.hako
Normal file
41
apps/tests/phase130_if_only_post_if_add_min.hako
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Phase 130: if-only post-if with add computation (Normalized post_k)
|
||||||
|
// Pattern: x=1/2 (conditionally); x = x + 3; return x
|
||||||
|
// Expected: Case A (flag=1) → 5, Case B (flag=0) → 4
|
||||||
|
//
|
||||||
|
// This tests that post_k can execute computation statements:
|
||||||
|
// - if branches: update x (then: x=2, else: x=1)
|
||||||
|
// - join_k: merge env
|
||||||
|
// - post_k: x = x + 3; return x
|
||||||
|
// - Case A: 2 + 3 = 5
|
||||||
|
// - Case B: 1 + 3 = 4
|
||||||
|
|
||||||
|
static box Main {
|
||||||
|
main() {
|
||||||
|
local x
|
||||||
|
local flag
|
||||||
|
|
||||||
|
// Case A: flag=1 → x=2 → x=x+3 → 5
|
||||||
|
x = 2
|
||||||
|
flag = 1
|
||||||
|
if flag == 1 {
|
||||||
|
x = 2
|
||||||
|
} else {
|
||||||
|
x = 1
|
||||||
|
}
|
||||||
|
x = x + 3
|
||||||
|
print(x)
|
||||||
|
|
||||||
|
// Case B: flag=0 → x=1 → x=x+3 → 4
|
||||||
|
x = 1
|
||||||
|
flag = 0
|
||||||
|
if flag == 1 {
|
||||||
|
x = 2
|
||||||
|
} else {
|
||||||
|
x = 1
|
||||||
|
}
|
||||||
|
x = x + 3
|
||||||
|
print(x)
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Phase 130: if-only post-if add (LLVM EXE parity)
|
||||||
|
# Pattern: x = x + 3 computation after if merge via post_k
|
||||||
|
|
||||||
|
source "$(dirname "$0")/../../../lib/test_runner.sh"
|
||||||
|
source "$(dirname "$0")/../../../lib/llvm_exe_runner.sh"
|
||||||
|
export SMOKES_USE_PYVM=0
|
||||||
|
require_env || exit 2
|
||||||
|
|
||||||
|
llvm_exe_preflight_or_skip || exit 0
|
||||||
|
|
||||||
|
# Phase 97/98/100 SSOT: plugin dlopen check → build only if needed → dlopen recheck.
|
||||||
|
FILEBOX_SO="$NYASH_ROOT/plugins/nyash-filebox-plugin/libnyash_filebox_plugin.so"
|
||||||
|
MAPBOX_SO="$NYASH_ROOT/plugins/nyash-map-plugin/libnyash_map_plugin.so"
|
||||||
|
STRINGBOX_SO="$NYASH_ROOT/plugins/nyash-string-plugin/libnyash_string_plugin.so"
|
||||||
|
CONSOLEBOX_SO="$NYASH_ROOT/plugins/nyash-console-plugin/libnyash_console_plugin.so"
|
||||||
|
INTEGERBOX_SO="$NYASH_ROOT/plugins/nyash-integer-plugin/libnyash_integer_plugin.so"
|
||||||
|
|
||||||
|
LLVM_REQUIRED_PLUGINS=(
|
||||||
|
"FileBox|$FILEBOX_SO|nyash-filebox-plugin"
|
||||||
|
"MapBox|$MAPBOX_SO|nyash-map-plugin"
|
||||||
|
"StringBox|$STRINGBOX_SO|nyash-string-plugin"
|
||||||
|
"ConsoleBox|$CONSOLEBOX_SO|nyash-console-plugin"
|
||||||
|
"IntegerBox|$INTEGERBOX_SO|nyash-integer-plugin"
|
||||||
|
)
|
||||||
|
LLVM_PLUGIN_BUILD_LOG="/tmp/phase130_if_only_post_if_add_plugin_build.log"
|
||||||
|
llvm_exe_ensure_plugins_or_fail || exit 1
|
||||||
|
|
||||||
|
INPUT_HAKO="$NYASH_ROOT/apps/tests/phase130_if_only_post_if_add_min.hako"
|
||||||
|
OUTPUT_EXE="$NYASH_ROOT/tmp/phase130_if_only_post_if_add_llvm_exe"
|
||||||
|
|
||||||
|
EXPECTED=$'5\n4'
|
||||||
|
EXPECTED_LINES=2
|
||||||
|
LLVM_BUILD_LOG="/tmp/phase130_if_only_post_if_add_build.log"
|
||||||
|
if llvm_exe_build_and_run_numeric_smoke; then
|
||||||
|
test_pass "phase130_if_only_post_if_add_llvm_exe: output matches expected (5\\n4)"
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Phase 130: If-only Post-If Add (Normalized post_k with computation, VM)
|
||||||
|
#
|
||||||
|
# Verifies that post_k can execute computation statements after if:
|
||||||
|
# - Case A: flag=1 → x=2 → x=x+3 → 5
|
||||||
|
# - Case B: flag=0 → x=1 → x=x+3 → 4
|
||||||
|
# - Dev-only: NYASH_JOINIR_DEV=1 HAKO_JOINIR_STRICT=1
|
||||||
|
|
||||||
|
source "$(dirname "$0")/../../../lib/test_runner.sh"
|
||||||
|
source "$(dirname "$0")/../../../lib/output_validator.sh"
|
||||||
|
export SMOKES_USE_PYVM=0
|
||||||
|
require_env || exit 2
|
||||||
|
|
||||||
|
PASS_COUNT=0
|
||||||
|
FAIL_COUNT=0
|
||||||
|
RUN_TIMEOUT_SECS=${RUN_TIMEOUT_SECS:-10}
|
||||||
|
|
||||||
|
echo "[INFO] Phase 130: If-only Post-If Add (Normalized post_k with computation, VM)"
|
||||||
|
|
||||||
|
# Test 1: phase130_if_only_post_if_add_min.hako
|
||||||
|
echo "[INFO] Test 1: phase130_if_only_post_if_add_min.hako"
|
||||||
|
INPUT="$NYASH_ROOT/apps/tests/phase130_if_only_post_if_add_min.hako"
|
||||||
|
|
||||||
|
set +e
|
||||||
|
OUTPUT=$(timeout "$RUN_TIMEOUT_SECS" env \
|
||||||
|
NYASH_DISABLE_PLUGINS=1 \
|
||||||
|
HAKO_JOINIR_STRICT=1 \
|
||||||
|
NYASH_JOINIR_DEV=1 \
|
||||||
|
"$NYASH_BIN" --backend vm "$INPUT" 2>&1)
|
||||||
|
EXIT_CODE=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ "$EXIT_CODE" -eq 124 ]; then
|
||||||
|
echo "[FAIL] hakorune timed out (>${RUN_TIMEOUT_SECS}s)"
|
||||||
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
||||||
|
elif [ "$EXIT_CODE" -eq 0 ]; then
|
||||||
|
# Phase 130: expect 5\n4 (Case A: 2+3=5, Case B: 1+3=4)
|
||||||
|
EXPECTED=$'5\n4'
|
||||||
|
if validate_numeric_output 2 "$EXPECTED" "$OUTPUT"; then
|
||||||
|
echo "[PASS] Output verified: 5\\n4 (exit code: $EXIT_CODE)"
|
||||||
|
PASS_COUNT=$((PASS_COUNT + 1))
|
||||||
|
else
|
||||||
|
echo "[INFO] output (tail):"
|
||||||
|
echo "$OUTPUT" | tail -n 50 || true
|
||||||
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "[FAIL] hakorune failed with exit code $EXIT_CODE"
|
||||||
|
echo "[INFO] output (tail):"
|
||||||
|
echo "$OUTPUT" | tail -n 50 || true
|
||||||
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[INFO] PASS: $PASS_COUNT, FAIL: $FAIL_COUNT"
|
||||||
|
|
||||||
|
if [ "$FAIL_COUNT" -eq 0 ]; then
|
||||||
|
test_pass "phase130_if_only_post_if_add_vm: All tests passed"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
test_fail "phase130_if_only_post_if_add_vm: $FAIL_COUNT test(s) failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user