aboutsummaryrefslogtreecommitdiff
path: root/spec/cli/test_execution.sh
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-07-03 09:49:00 +0800
committerLi Jin <dragon-fly@qq.com>2026-07-03 09:49:00 +0800
commitc9f3a486cfdad6e134ec88b1e43717508e066796 (patch)
treebf1ad02d9a590d438a552b481bc924715496ac97 /spec/cli/test_execution.sh
parent7bb66616ff5a6d3f6f3b35c68fa9a908af034884 (diff)
downloadyuescript-0.34.1.tar.gz
yuescript-0.34.1.tar.bz2
yuescript-0.34.1.zip
Fix execute arg table layoutv0.34.1
Diffstat (limited to '')
-rwxr-xr-xspec/cli/test_execution.sh45
1 files changed, 36 insertions, 9 deletions
diff --git a/spec/cli/test_execution.sh b/spec/cli/test_execution.sh
index fedfbea..6572e2e 100755
--- a/spec/cli/test_execution.sh
+++ b/spec/cli/test_execution.sh
@@ -63,7 +63,34 @@ EOF
63assert_output_contains "First argument" "first" $YUE_BIN -e "$TMP_DIR/args_test.yue" first second 63assert_output_contains "First argument" "first" $YUE_BIN -e "$TMP_DIR/args_test.yue" first second
64assert_output_contains "Second argument" "second" $YUE_BIN -e "$TMP_DIR/args_test.yue" first second 64assert_output_contains "Second argument" "second" $YUE_BIN -e "$TMP_DIR/args_test.yue" first second
65 65
66# Test 7: Test with compiler options via --key=value 66# Test 7: Test arg table layout for executed scripts
67echo ""
68echo "Testing arg table layout..."
69cat > "$TMP_DIR/arg_table.yue" << 'EOF'
70import arg
71print "main=" .. tostring arg[0]
72print "first=" .. tostring arg[1]
73print "exe=" .. tostring arg[-2]
74print "option=" .. tostring arg[-1]
75EOF
76
77assert_output_contains "Yue arg[0]" "main=$TMP_DIR/arg_table.yue" $YUE_BIN -e "$TMP_DIR/arg_table.yue" alpha
78assert_output_contains "Yue arg[1]" "first=alpha" $YUE_BIN -e "$TMP_DIR/arg_table.yue" alpha
79assert_output_contains "Yue arg[-1]" "option=-e" $YUE_BIN -e "$TMP_DIR/arg_table.yue" alpha
80assert_output_contains "Yue --execute arg[0]" "main=$TMP_DIR/arg_table.yue" $YUE_BIN --execute="$TMP_DIR/arg_table.yue" alpha
81
82cat > "$TMP_DIR/arg_table.lua" << 'EOF'
83print("main=" .. tostring(arg[0]))
84print("first=" .. tostring(arg[1]))
85print("exe=" .. tostring(arg[-2]))
86print("option=" .. tostring(arg[-1]))
87EOF
88
89assert_output_contains "Lua arg[0]" "main=$TMP_DIR/arg_table.lua" $YUE_BIN -e "$TMP_DIR/arg_table.lua" alpha
90assert_output_contains "Lua arg[1]" "first=alpha" $YUE_BIN -e "$TMP_DIR/arg_table.lua" alpha
91assert_output_contains "Lua arg[-1]" "option=-e" $YUE_BIN -e "$TMP_DIR/arg_table.lua" alpha
92
93# Test 8: Test with compiler options via --key=value
67echo "" 94echo ""
68echo "Testing compiler options in execute mode..." 95echo "Testing compiler options in execute mode..."
69cat > "$TMP_DIR/options_test.yue" << 'EOF' 96cat > "$TMP_DIR/options_test.yue" << 'EOF'
@@ -72,12 +99,12 @@ EOF
72 99
73assert_success "Execute with compiler option" $YUE_BIN -e "$TMP_DIR/options_test.yue" --reserve_line_number=true 100assert_success "Execute with compiler option" $YUE_BIN -e "$TMP_DIR/options_test.yue" --reserve_line_number=true
74 101
75# Test 8: Execute code with table operations 102# Test 9: Execute code with table operations
76echo "" 103echo ""
77echo "Testing table operations..." 104echo "Testing table operations..."
78assert_output_contains "Table operations" "3" $YUE_BIN -e 't = {1, 2, 3}; print #t' 105assert_output_contains "Table operations" "3" $YUE_BIN -e 't = {1, 2, 3}; print #t'
79 106
80# Test 9: Execute code with function definition 107# Test 10: Execute code with function definition
81echo "" 108echo ""
82echo "Testing function definition..." 109echo "Testing function definition..."
83cat > "$TMP_DIR/func_test.yue" << 'EOF' 110cat > "$TMP_DIR/func_test.yue" << 'EOF'
@@ -87,7 +114,7 @@ EOF
87 114
88assert_output_contains "Function execution" "10" $YUE_BIN -e "$TMP_DIR/func_test.yue" 115assert_output_contains "Function execution" "10" $YUE_BIN -e "$TMP_DIR/func_test.yue"
89 116
90# Test 10: Execute code with class 117# Test 11: Execute code with class
91echo "" 118echo ""
92echo "Testing class execution..." 119echo "Testing class execution..."
93cat > "$TMP_DIR/class_test.yue" << 'EOF' 120cat > "$TMP_DIR/class_test.yue" << 'EOF'
@@ -103,7 +130,7 @@ EOF
103 130
104assert_output_contains "Class method execution" "5" $YUE_BIN -e "$TMP_DIR/class_test.yue" 131assert_output_contains "Class method execution" "5" $YUE_BIN -e "$TMP_DIR/class_test.yue"
105 132
106# Test 11: Execute with import 133# Test 12: Execute with import
107echo "" 134echo ""
108echo "Testing import in execute mode..." 135echo "Testing import in execute mode..."
109cat > "$TMP_DIR/import_test.yue" << 'EOF' 136cat > "$TMP_DIR/import_test.yue" << 'EOF'
@@ -113,7 +140,7 @@ EOF
113# Note: This test depends on how imports are set up 140# Note: This test depends on how imports are set up
114assert_success "Execute with import" $YUE_BIN -e "$TMP_DIR/import_test.yue" --path="$TMP_DIR" 141assert_success "Execute with import" $YUE_BIN -e "$TMP_DIR/import_test.yue" --path="$TMP_DIR"
115 142
116# Test 12: Execute code with error handling 143# Test 13: Execute code with error handling
117echo "" 144echo ""
118echo "Testing error handling in executed code..." 145echo "Testing error handling in executed code..."
119cat > "$TMP_DIR/error_test.yue" << 'EOF' 146cat > "$TMP_DIR/error_test.yue" << 'EOF'
@@ -126,7 +153,7 @@ EOF
126 153
127assert_output_contains "Error handling" "caught:" $YUE_BIN -e "$TMP_DIR/error_test.yue" 154assert_output_contains "Error handling" "caught:" $YUE_BIN -e "$TMP_DIR/error_test.yue"
128 155
129# Test 13: Execute with export statement 156# Test 14: Execute with export statement
130echo "" 157echo ""
131echo "Testing export in execute mode..." 158echo "Testing export in execute mode..."
132cat > "$TMP_DIR/export_test.yue" << 'EOF' 159cat > "$TMP_DIR/export_test.yue" << 'EOF'
@@ -136,7 +163,7 @@ EOF
136 163
137assert_output_contains "Export value" "42" $YUE_BIN -e "$TMP_DIR/export_test.yue" 164assert_output_contains "Export value" "42" $YUE_BIN -e "$TMP_DIR/export_test.yue"
138 165
139# Test 14: Execute with macro 166# Test 15: Execute with macro
140echo "" 167echo ""
141echo "Testing macro in execute mode..." 168echo "Testing macro in execute mode..."
142cat > "$TMP_DIR/macro_test.yue" << 'EOF' 169cat > "$TMP_DIR/macro_test.yue" << 'EOF'
@@ -148,7 +175,7 @@ EOF
148 175
149assert_output_contains "Macro execution" "42" $YUE_BIN -e "$TMP_DIR/macro_test.yue" 176assert_output_contains "Macro execution" "42" $YUE_BIN -e "$TMP_DIR/macro_test.yue"
150 177
151# Test 15: Execute with string literal 178# Test 16: Execute with string literal
152echo "" 179echo ""
153echo "Testing string literals..." 180echo "Testing string literals..."
154# Use grep without -F to match patterns with newlines 181# Use grep without -F to match patterns with newlines