diff options
Diffstat (limited to 'spec/cli')
| -rwxr-xr-x | spec/cli/test_execution.sh | 45 |
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 | |||
| 63 | assert_output_contains "First argument" "first" $YUE_BIN -e "$TMP_DIR/args_test.yue" first second | 63 | assert_output_contains "First argument" "first" $YUE_BIN -e "$TMP_DIR/args_test.yue" first second |
| 64 | assert_output_contains "Second argument" "second" $YUE_BIN -e "$TMP_DIR/args_test.yue" first second | 64 | assert_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 |
| 67 | echo "" | ||
| 68 | echo "Testing arg table layout..." | ||
| 69 | cat > "$TMP_DIR/arg_table.yue" << 'EOF' | ||
| 70 | import arg | ||
| 71 | print "main=" .. tostring arg[0] | ||
| 72 | print "first=" .. tostring arg[1] | ||
| 73 | print "exe=" .. tostring arg[-2] | ||
| 74 | print "option=" .. tostring arg[-1] | ||
| 75 | EOF | ||
| 76 | |||
| 77 | assert_output_contains "Yue arg[0]" "main=$TMP_DIR/arg_table.yue" $YUE_BIN -e "$TMP_DIR/arg_table.yue" alpha | ||
| 78 | assert_output_contains "Yue arg[1]" "first=alpha" $YUE_BIN -e "$TMP_DIR/arg_table.yue" alpha | ||
| 79 | assert_output_contains "Yue arg[-1]" "option=-e" $YUE_BIN -e "$TMP_DIR/arg_table.yue" alpha | ||
| 80 | assert_output_contains "Yue --execute arg[0]" "main=$TMP_DIR/arg_table.yue" $YUE_BIN --execute="$TMP_DIR/arg_table.yue" alpha | ||
| 81 | |||
| 82 | cat > "$TMP_DIR/arg_table.lua" << 'EOF' | ||
| 83 | print("main=" .. tostring(arg[0])) | ||
| 84 | print("first=" .. tostring(arg[1])) | ||
| 85 | print("exe=" .. tostring(arg[-2])) | ||
| 86 | print("option=" .. tostring(arg[-1])) | ||
| 87 | EOF | ||
| 88 | |||
| 89 | assert_output_contains "Lua arg[0]" "main=$TMP_DIR/arg_table.lua" $YUE_BIN -e "$TMP_DIR/arg_table.lua" alpha | ||
| 90 | assert_output_contains "Lua arg[1]" "first=alpha" $YUE_BIN -e "$TMP_DIR/arg_table.lua" alpha | ||
| 91 | assert_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 | ||
| 67 | echo "" | 94 | echo "" |
| 68 | echo "Testing compiler options in execute mode..." | 95 | echo "Testing compiler options in execute mode..." |
| 69 | cat > "$TMP_DIR/options_test.yue" << 'EOF' | 96 | cat > "$TMP_DIR/options_test.yue" << 'EOF' |
| @@ -72,12 +99,12 @@ EOF | |||
| 72 | 99 | ||
| 73 | assert_success "Execute with compiler option" $YUE_BIN -e "$TMP_DIR/options_test.yue" --reserve_line_number=true | 100 | assert_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 |
| 76 | echo "" | 103 | echo "" |
| 77 | echo "Testing table operations..." | 104 | echo "Testing table operations..." |
| 78 | assert_output_contains "Table operations" "3" $YUE_BIN -e 't = {1, 2, 3}; print #t' | 105 | assert_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 |
| 81 | echo "" | 108 | echo "" |
| 82 | echo "Testing function definition..." | 109 | echo "Testing function definition..." |
| 83 | cat > "$TMP_DIR/func_test.yue" << 'EOF' | 110 | cat > "$TMP_DIR/func_test.yue" << 'EOF' |
| @@ -87,7 +114,7 @@ EOF | |||
| 87 | 114 | ||
| 88 | assert_output_contains "Function execution" "10" $YUE_BIN -e "$TMP_DIR/func_test.yue" | 115 | assert_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 |
| 91 | echo "" | 118 | echo "" |
| 92 | echo "Testing class execution..." | 119 | echo "Testing class execution..." |
| 93 | cat > "$TMP_DIR/class_test.yue" << 'EOF' | 120 | cat > "$TMP_DIR/class_test.yue" << 'EOF' |
| @@ -103,7 +130,7 @@ EOF | |||
| 103 | 130 | ||
| 104 | assert_output_contains "Class method execution" "5" $YUE_BIN -e "$TMP_DIR/class_test.yue" | 131 | assert_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 |
| 107 | echo "" | 134 | echo "" |
| 108 | echo "Testing import in execute mode..." | 135 | echo "Testing import in execute mode..." |
| 109 | cat > "$TMP_DIR/import_test.yue" << 'EOF' | 136 | cat > "$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 |
| 114 | assert_success "Execute with import" $YUE_BIN -e "$TMP_DIR/import_test.yue" --path="$TMP_DIR" | 141 | assert_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 |
| 117 | echo "" | 144 | echo "" |
| 118 | echo "Testing error handling in executed code..." | 145 | echo "Testing error handling in executed code..." |
| 119 | cat > "$TMP_DIR/error_test.yue" << 'EOF' | 146 | cat > "$TMP_DIR/error_test.yue" << 'EOF' |
| @@ -126,7 +153,7 @@ EOF | |||
| 126 | 153 | ||
| 127 | assert_output_contains "Error handling" "caught:" $YUE_BIN -e "$TMP_DIR/error_test.yue" | 154 | assert_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 |
| 130 | echo "" | 157 | echo "" |
| 131 | echo "Testing export in execute mode..." | 158 | echo "Testing export in execute mode..." |
| 132 | cat > "$TMP_DIR/export_test.yue" << 'EOF' | 159 | cat > "$TMP_DIR/export_test.yue" << 'EOF' |
| @@ -136,7 +163,7 @@ EOF | |||
| 136 | 163 | ||
| 137 | assert_output_contains "Export value" "42" $YUE_BIN -e "$TMP_DIR/export_test.yue" | 164 | assert_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 |
| 140 | echo "" | 167 | echo "" |
| 141 | echo "Testing macro in execute mode..." | 168 | echo "Testing macro in execute mode..." |
| 142 | cat > "$TMP_DIR/macro_test.yue" << 'EOF' | 169 | cat > "$TMP_DIR/macro_test.yue" << 'EOF' |
| @@ -148,7 +175,7 @@ EOF | |||
| 148 | 175 | ||
| 149 | assert_output_contains "Macro execution" "42" $YUE_BIN -e "$TMP_DIR/macro_test.yue" | 176 | assert_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 |
| 152 | echo "" | 179 | echo "" |
| 153 | echo "Testing string literals..." | 180 | echo "Testing string literals..." |
| 154 | # Use grep without -F to match patterns with newlines | 181 | # Use grep without -F to match patterns with newlines |
