diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-06 06:18:58 +0000 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-06 06:18:58 +0000 |
| commit | aacf6dd9ebdb4d55b432ea1d4213093fe35e0ad1 (patch) | |
| tree | 25926b10c10bc36133cfd1a337190dd003088e2e | |
| parent | 1f83d504bc344ffd3c8b4120b3865fd6c11a9e2d (diff) | |
| download | yuescript-aacf6dd9ebdb4d55b432ea1d4213093fe35e0ad1.tar.gz yuescript-aacf6dd9ebdb4d55b432ea1d4213093fe35e0ad1.tar.bz2 yuescript-aacf6dd9ebdb4d55b432ea1d4213093fe35e0ad1.zip | |
test: add comprehensive CLI test suite
Add 56 test cases across 4 test suites to verify the yue command line
tool functionality:
- Basic options test: -h, --help, -v, --version flags
- Compilation test: file/directory compilation with various options
- Error handling test: syntax errors, file not found, edge cases
- Execution test: -e option, script arguments, macros
The test framework includes helper functions for assertions and test
environment setup. All tests can be run via `bash spec/cli/run_all_tests.sh`.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
| -rw-r--r-- | makefile | 6 | ||||
| -rw-r--r-- | spec/cli/README.md | 147 | ||||
| -rwxr-xr-x | spec/cli/cli_test_helper.sh | 183 | ||||
| -rwxr-xr-x | spec/cli/run_all_tests.sh | 77 | ||||
| -rwxr-xr-x | spec/cli/test_basic_options.sh | 38 | ||||
| -rwxr-xr-x | spec/cli/test_compilation.sh | 148 | ||||
| -rwxr-xr-x | spec/cli/test_error_handling.sh | 169 | ||||
| -rwxr-xr-x | spec/cli/test_execution.sh | 159 |
8 files changed, 927 insertions, 0 deletions
| @@ -447,6 +447,12 @@ test: debug | |||
| 447 | @busted | 447 | @busted |
| 448 | @echo "Done!" | 448 | @echo "Done!" |
| 449 | 449 | ||
| 450 | # Test CLI tool functionality | ||
| 451 | .PHONY: test-cli | ||
| 452 | test-cli: debug | ||
| 453 | @echo "Running CLI tests..." | ||
| 454 | @bash spec/cli/run_all_tests.sh | ||
| 455 | |||
| 450 | # Test Yuescript compiler | 456 | # Test Yuescript compiler |
| 451 | .PHONY: gen | 457 | .PHONY: gen |
| 452 | gen: release | 458 | gen: release |
diff --git a/spec/cli/README.md b/spec/cli/README.md new file mode 100644 index 0000000..ea14e72 --- /dev/null +++ b/spec/cli/README.md | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | # YueScript CLI Tests | ||
| 2 | |||
| 3 | 测试 YueScript 命令行工具的功能。 | ||
| 4 | |||
| 5 | ## 测试结构 | ||
| 6 | |||
| 7 | ``` | ||
| 8 | spec/cli/ | ||
| 9 | ├── cli_test_helper.sh # 测试辅助函数库 | ||
| 10 | ├── test_basic_options.sh # 基本选项测试 | ||
| 11 | ├── test_compilation.sh # 编译功能测试 | ||
| 12 | ├── test_error_handling.sh # 错误处理测试 | ||
| 13 | ├── test_execution.sh # 代码执行测试 | ||
| 14 | ├── run_all_tests.sh # 运行所有测试 | ||
| 15 | └── README.md # 本文件 | ||
| 16 | ``` | ||
| 17 | |||
| 18 | ## 运行测试 | ||
| 19 | |||
| 20 | ### 前置要求 | ||
| 21 | |||
| 22 | 确保已编译 yue 二进制文件: | ||
| 23 | |||
| 24 | ```bash | ||
| 25 | make debug | ||
| 26 | ``` | ||
| 27 | |||
| 28 | ### 运行所有测试 | ||
| 29 | |||
| 30 | ```bash | ||
| 31 | cd spec/cli | ||
| 32 | bash run_all_tests.sh | ||
| 33 | ``` | ||
| 34 | |||
| 35 | ### 运行单个测试套件 | ||
| 36 | |||
| 37 | ```bash | ||
| 38 | # 测试基本选项 | ||
| 39 | bash test_basic_options.sh | ||
| 40 | |||
| 41 | # 测试编译功能 | ||
| 42 | bash test_compilation.sh | ||
| 43 | |||
| 44 | # 测试错误处理 | ||
| 45 | bash test_error_handling.sh | ||
| 46 | |||
| 47 | # 测试代码执行 | ||
| 48 | bash test_execution.sh | ||
| 49 | ``` | ||
| 50 | |||
| 51 | ### 指定 yue 二进制文件路径 | ||
| 52 | |||
| 53 | 如果二进制文件不在默认位置 (`./bin/debug/yue`),可以设置环境变量: | ||
| 54 | |||
| 55 | ```bash | ||
| 56 | YUE_BIN=/path/to/yue bash run_all_tests.sh | ||
| 57 | ``` | ||
| 58 | |||
| 59 | ## 测试覆盖范围 | ||
| 60 | |||
| 61 | ### 1. 基本选项测试 (test_basic_options.sh) | ||
| 62 | |||
| 63 | - `-h, --help`: 帮助信息 | ||
| 64 | - `-v, --version`: 版本信息 | ||
| 65 | - 无效选项的错误处理 | ||
| 66 | |||
| 67 | ### 2. 编译功能测试 (test_compilation.sh) | ||
| 68 | |||
| 69 | - 单文件编译到标准输出 (`-p`) | ||
| 70 | - 单文件编译到磁盘 | ||
| 71 | - 自定义输出文件 (`-o`) | ||
| 72 | - 目标目录编译 (`-t`) | ||
| 73 | - 目录递归编译 | ||
| 74 | - 保留行号 (`-l`) | ||
| 75 | - 使用空格代替制表符 (`-s`) | ||
| 76 | - 代码压缩 (`-m`) | ||
| 77 | - 标准输入/输出编译 | ||
| 78 | - 全局变量转储 (`-g`) | ||
| 79 | - 编译性能测试 (`-b`) | ||
| 80 | - 目标 Lua 版本 (`--target`) | ||
| 81 | |||
| 82 | ### 3. 错误处理测试 (test_error_handling.sh) | ||
| 83 | |||
| 84 | - 文件不存在错误 | ||
| 85 | - 语法错误 | ||
| 86 | - 无效选项组合 | ||
| 87 | - 空文件处理 | ||
| 88 | - 仅注释文件 | ||
| 89 | - 无效的目标版本 | ||
| 90 | - 复杂的合法代码 | ||
| 91 | - Unicode 处理 | ||
| 92 | - 超长行处理 | ||
| 93 | - 深层嵌套代码 | ||
| 94 | - 宏错误处理 | ||
| 95 | |||
| 96 | ### 4. 代码执行测试 (test_execution.sh) | ||
| 97 | |||
| 98 | - 内联代码执行 (`-e`) | ||
| 99 | - 计算表达式 | ||
| 100 | - 字符串插值 | ||
| 101 | - YueScript 文件执行 | ||
| 102 | - Lua 文件执行 | ||
| 103 | - 脚本参数传递 | ||
| 104 | - 编译器选项传递 | ||
| 105 | - 表操作 | ||
| 106 | - 函数定义与调用 | ||
| 107 | - 类与对象 | ||
| 108 | - 导入语句 | ||
| 109 | - 错误处理 | ||
| 110 | - 导出语句 | ||
| 111 | - 宏展开 | ||
| 112 | |||
| 113 | ## 测试辅助函数 | ||
| 114 | |||
| 115 | `cli_test_helper.sh` 提供以下函数: | ||
| 116 | |||
| 117 | - `check_yue_binary`: 检查 yue 二进制文件是否存在 | ||
| 118 | - `assert_success`: 断言命令成功 | ||
| 119 | - `assert_failure`: 断言命令失败 | ||
| 120 | - `assert_output_contains`: 断言输出包含指定字符串 | ||
| 121 | - `assert_output_equals`: 断言输出等于指定字符串 | ||
| 122 | - `assert_file_exists`: 断言文件存在 | ||
| 123 | - `print_summary`: 打印测试摘要 | ||
| 124 | - `setup_test_env`: 设置测试环境 | ||
| 125 | - `create_test_file`: 创建测试文件 | ||
| 126 | |||
| 127 | ## 添加新测试 | ||
| 128 | |||
| 129 | 1. 在对应的测试文件中添加新的测试用例 | ||
| 130 | 2. 使用提供的辅助函数来断言结果 | ||
| 131 | 3. 确保测试描述清晰明了 | ||
| 132 | 4. 运行测试验证功能 | ||
| 133 | |||
| 134 | 示例: | ||
| 135 | |||
| 136 | ```bash | ||
| 137 | echo "Testing new feature..." | ||
| 138 | cat > "$TMP_DIR/new_test.yue" << 'EOF' | ||
| 139 | -- test code here | ||
| 140 | EOF | ||
| 141 | |||
| 142 | assert_output_contains "New feature should work" "expected output" $YUE_BIN "$TMP_DIR/new_test.yue" | ||
| 143 | ``` | ||
| 144 | |||
| 145 | ## 持续集成 | ||
| 146 | |||
| 147 | 这些测试可以集成到 CI/CD 流程中,确保每次代码变更都不会破坏命令行工具的功能。 | ||
diff --git a/spec/cli/cli_test_helper.sh b/spec/cli/cli_test_helper.sh new file mode 100755 index 0000000..ade1546 --- /dev/null +++ b/spec/cli/cli_test_helper.sh | |||
| @@ -0,0 +1,183 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # CLI Test Helper for YueScript | ||
| 3 | # Provides utility functions for testing the yue command line tool | ||
| 4 | |||
| 5 | # Colors for output | ||
| 6 | RED='\033[0;31m' | ||
| 7 | GREEN='\033[0;32m' | ||
| 8 | YELLOW='\033[1;33m' | ||
| 9 | NC='\033[0m' # No Color | ||
| 10 | |||
| 11 | # Test counters | ||
| 12 | TESTS_RUN=0 | ||
| 13 | TESTS_PASSED=0 | ||
| 14 | TESTS_FAILED=0 | ||
| 15 | |||
| 16 | # Get the yue binary path | ||
| 17 | YUE_BIN="${YUE_BIN:-./bin/debug/yue}" | ||
| 18 | |||
| 19 | # Check if yue binary exists | ||
| 20 | check_yue_binary() { | ||
| 21 | if [ ! -f "$YUE_BIN" ]; then | ||
| 22 | echo -e "${RED}Error: yue binary not found at $YUE_BIN${NC}" | ||
| 23 | echo "Please build the project first or set YUE_BIN environment variable" | ||
| 24 | exit 1 | ||
| 25 | fi | ||
| 26 | if [ ! -x "$YUE_BIN" ]; then | ||
| 27 | echo -e "${RED}Error: yue binary is not executable${NC}" | ||
| 28 | exit 1 | ||
| 29 | fi | ||
| 30 | } | ||
| 31 | |||
| 32 | # Assert that a command succeeds | ||
| 33 | assert_success() { | ||
| 34 | local description="$1" | ||
| 35 | shift | ||
| 36 | TESTS_RUN=$((TESTS_RUN + 1)) | ||
| 37 | |||
| 38 | if "$@" > /tmp/test_stdout.txt 2> /tmp/test_stderr.txt; then | ||
| 39 | echo -e "${GREEN}✓${NC} $description" | ||
| 40 | TESTS_PASSED=$((TESTS_PASSED + 1)) | ||
| 41 | return 0 | ||
| 42 | else | ||
| 43 | echo -e "${RED}✗${NC} $description" | ||
| 44 | echo -e " ${YELLOW}Exit code: $?${NC}" | ||
| 45 | echo -e " ${YELLOW}STDOUT:$(cat /tmp/test_stdout.txt)${NC}" | ||
| 46 | echo -e " ${YELLOW}STDERR:$(cat /tmp/test_stderr.txt)${NC}" | ||
| 47 | TESTS_FAILED=$((TESTS_FAILED + 1)) | ||
| 48 | return 1 | ||
| 49 | fi | ||
| 50 | } | ||
| 51 | |||
| 52 | # Assert that a command fails | ||
| 53 | assert_failure() { | ||
| 54 | local description="$1" | ||
| 55 | shift | ||
| 56 | TESTS_RUN=$((TESTS_RUN + 1)) | ||
| 57 | |||
| 58 | if "$@" > /tmp/test_stdout.txt 2> /tmp/test_stderr.txt; then | ||
| 59 | echo -e "${RED}✗${NC} $description (expected failure but succeeded)" | ||
| 60 | echo -e " ${YELLOW}STDOUT:$(cat /tmp/test_stdout.txt)${NC}" | ||
| 61 | echo -e " ${YELLOW}STDERR:$(cat /tmp/test_stderr.txt)${NC}" | ||
| 62 | TESTS_FAILED=$((TESTS_FAILED + 1)) | ||
| 63 | return 1 | ||
| 64 | else | ||
| 65 | echo -e "${GREEN}✓${NC} $description" | ||
| 66 | TESTS_PASSED=$((TESTS_PASSED + 1)) | ||
| 67 | return 0 | ||
| 68 | fi | ||
| 69 | } | ||
| 70 | |||
| 71 | # Assert that output contains expected string | ||
| 72 | assert_output_contains() { | ||
| 73 | local description="$1" | ||
| 74 | local expected="$2" | ||
| 75 | shift 2 | ||
| 76 | TESTS_RUN=$((TESTS_RUN + 1)) | ||
| 77 | |||
| 78 | if "$@" > /tmp/test_stdout.txt 2> /tmp/test_stderr.txt; then | ||
| 79 | if grep -qF -- "$expected" /tmp/test_stdout.txt || grep -qF -- "$expected" /tmp/test_stderr.txt; then | ||
| 80 | echo -e "${GREEN}✓${NC} $description" | ||
| 81 | TESTS_PASSED=$((TESTS_PASSED + 1)) | ||
| 82 | return 0 | ||
| 83 | else | ||
| 84 | echo -e "${RED}✗${NC} $description (output doesn't contain '$expected')" | ||
| 85 | echo -e " ${YELLOW}STDOUT:$(cat /tmp/test_stdout.txt)${NC}" | ||
| 86 | echo -e " ${YELLOW}STDERR:$(cat /tmp/test_stderr.txt)${NC}" | ||
| 87 | TESTS_FAILED=$((TESTS_FAILED + 1)) | ||
| 88 | return 1 | ||
| 89 | fi | ||
| 90 | else | ||
| 91 | echo -e "${RED}✗${NC} $description (command failed)" | ||
| 92 | echo -e " ${YELLOW}Exit code: $?${NC}" | ||
| 93 | TESTS_FAILED=$((TESTS_FAILED + 1)) | ||
| 94 | return 1 | ||
| 95 | fi | ||
| 96 | } | ||
| 97 | |||
| 98 | # Assert that output equals expected string | ||
| 99 | assert_output_equals() { | ||
| 100 | local description="$1" | ||
| 101 | local expected="$2" | ||
| 102 | shift 2 | ||
| 103 | TESTS_RUN=$((TESTS_RUN + 1)) | ||
| 104 | |||
| 105 | if "$@" > /tmp/test_stdout.txt 2> /tmp/test_stderr.txt; then | ||
| 106 | local actual=$(cat /tmp/test_stdout.txt) | ||
| 107 | if [ "$actual" = "$expected" ]; then | ||
| 108 | echo -e "${GREEN}✓${NC} $description" | ||
| 109 | TESTS_PASSED=$((TESTS_PASSED + 1)) | ||
| 110 | return 0 | ||
| 111 | else | ||
| 112 | echo -e "${RED}✗${NC} $description (output mismatch)" | ||
| 113 | echo -e " ${YELLOW}Expected: '$expected'${NC}" | ||
| 114 | echo -e " ${YELLOW}Actual: '$actual'${NC}" | ||
| 115 | TESTS_FAILED=$((TESTS_FAILED + 1)) | ||
| 116 | return 1 | ||
| 117 | fi | ||
| 118 | else | ||
| 119 | echo -e "${RED}✗${NC} $description (command failed)" | ||
| 120 | echo -e " ${YELLOW}Exit code: $?${NC}" | ||
| 121 | TESTS_FAILED=$((TESTS_FAILED + 1)) | ||
| 122 | return 1 | ||
| 123 | fi | ||
| 124 | } | ||
| 125 | |||
| 126 | # Assert file exists | ||
| 127 | assert_file_exists() { | ||
| 128 | local description="$1" | ||
| 129 | local filepath="$2" | ||
| 130 | TESTS_RUN=$((TESTS_RUN + 1)) | ||
| 131 | |||
| 132 | if [ -f "$filepath" ]; then | ||
| 133 | echo -e "${GREEN}✓${NC} $description" | ||
| 134 | TESTS_PASSED=$((TESTS_PASSED + 1)) | ||
| 135 | return 0 | ||
| 136 | else | ||
| 137 | echo -e "${RED}✗${NC} $description (file not found: $filepath)" | ||
| 138 | TESTS_FAILED=$((TESTS_FAILED + 1)) | ||
| 139 | return 1 | ||
| 140 | fi | ||
| 141 | } | ||
| 142 | |||
| 143 | # Print test summary | ||
| 144 | print_summary() { | ||
| 145 | echo "" | ||
| 146 | echo "======================================" | ||
| 147 | echo "Test Summary" | ||
| 148 | echo "======================================" | ||
| 149 | echo "Total tests: $TESTS_RUN" | ||
| 150 | echo -e "Passed: ${GREEN}$TESTS_PASSED${NC}" | ||
| 151 | echo -e "Failed: ${RED}$TESTS_FAILED${NC}" | ||
| 152 | echo "======================================" | ||
| 153 | |||
| 154 | if [ $TESTS_FAILED -eq 0 ]; then | ||
| 155 | echo -e "${GREEN}All tests passed!${NC}" | ||
| 156 | return 0 | ||
| 157 | else | ||
| 158 | echo -e "${RED}Some tests failed!${NC}" | ||
| 159 | return 1 | ||
| 160 | fi | ||
| 161 | } | ||
| 162 | |||
| 163 | # Setup test environment | ||
| 164 | setup_test_env() { | ||
| 165 | # Create temporary directory for test files | ||
| 166 | TEST_TMP_DIR=$(mktemp -d) | ||
| 167 | export TEST_TMP_DIR | ||
| 168 | trap "rm -rf $TEST_TMP_DIR" EXIT | ||
| 169 | echo "Test directory: $TEST_TMP_DIR" | ||
| 170 | } | ||
| 171 | |||
| 172 | # Get test tmp dir | ||
| 173 | get_test_tmp_dir() { | ||
| 174 | echo "$TEST_TMP_DIR" | ||
| 175 | } | ||
| 176 | |||
| 177 | # Create a test yue file | ||
| 178 | create_test_file() { | ||
| 179 | local filepath="$1" | ||
| 180 | local content="$2" | ||
| 181 | mkdir -p "$(dirname "$filepath")" | ||
| 182 | echo "$content" > "$filepath" | ||
| 183 | } | ||
diff --git a/spec/cli/run_all_tests.sh b/spec/cli/run_all_tests.sh new file mode 100755 index 0000000..0067bba --- /dev/null +++ b/spec/cli/run_all_tests.sh | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # Main test runner for YueScript CLI | ||
| 3 | # Runs all CLI test suites | ||
| 4 | |||
| 5 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| 6 | |||
| 7 | # Colors | ||
| 8 | RED='\033[0;31m' | ||
| 9 | GREEN='\033[0;32m' | ||
| 10 | YELLOW='\033[1;33m' | ||
| 11 | BLUE='\033[0;34m' | ||
| 12 | NC='\033[0m' # No Color | ||
| 13 | |||
| 14 | echo -e "${BLUE}======================================" | ||
| 15 | echo "YueScript CLI Test Suite" | ||
| 16 | echo "======================================${NC}" | ||
| 17 | echo "" | ||
| 18 | |||
| 19 | # Check if yue binary exists | ||
| 20 | YUE_BIN="${YUE_BIN:-./bin/debug/yue}" | ||
| 21 | if [ ! -f "$YUE_BIN" ]; then | ||
| 22 | echo -e "${RED}Error: yue binary not found at $YUE_BIN${NC}" | ||
| 23 | echo "Please build the project first:" | ||
| 24 | echo " make debug" | ||
| 25 | echo "Or set YUE_BIN environment variable" | ||
| 26 | exit 1 | ||
| 27 | fi | ||
| 28 | |||
| 29 | # Track overall results | ||
| 30 | TOTAL_SUITES=0 | ||
| 31 | PASSED_SUITES=0 | ||
| 32 | FAILED_SUITES=0 | ||
| 33 | |||
| 34 | # Function to run a test suite | ||
| 35 | run_test_suite() { | ||
| 36 | local suite_name="$1" | ||
| 37 | local suite_file="$2" | ||
| 38 | |||
| 39 | TOTAL_SUITES=$((TOTAL_SUITES + 1)) | ||
| 40 | echo "" | ||
| 41 | echo -e "${BLUE}Running: $suite_name${NC}" | ||
| 42 | echo "======================================" | ||
| 43 | |||
| 44 | if bash "$suite_file"; then | ||
| 45 | echo -e "${GREEN}✓ $suite_name PASSED${NC}" | ||
| 46 | PASSED_SUITES=$((PASSED_SUITES + 1)) | ||
| 47 | return 0 | ||
| 48 | else | ||
| 49 | echo -e "${RED}✗ $suite_name FAILED${NC}" | ||
| 50 | FAILED_SUITES=$((FAILED_SUITES + 1)) | ||
| 51 | return 1 | ||
| 52 | fi | ||
| 53 | } | ||
| 54 | |||
| 55 | # Run all test suites | ||
| 56 | run_test_suite "Basic Options Test" "$SCRIPT_DIR/test_basic_options.sh" | ||
| 57 | run_test_suite "Compilation Test" "$SCRIPT_DIR/test_compilation.sh" | ||
| 58 | run_test_suite "Error Handling Test" "$SCRIPT_DIR/test_error_handling.sh" | ||
| 59 | run_test_suite "Execution Test" "$SCRIPT_DIR/test_execution.sh" | ||
| 60 | |||
| 61 | # Print final summary | ||
| 62 | echo "" | ||
| 63 | echo -e "${BLUE}======================================" | ||
| 64 | echo "Final Test Suite Summary" | ||
| 65 | echo "======================================${NC}" | ||
| 66 | echo "Total test suites: $TOTAL_SUITES" | ||
| 67 | echo -e "Passed: ${GREEN}$PASSED_SUITES${NC}" | ||
| 68 | echo -e "Failed: ${RED}$FAILED_SUITES${NC}" | ||
| 69 | echo "======================================" | ||
| 70 | |||
| 71 | if [ $FAILED_SUITES -eq 0 ]; then | ||
| 72 | echo -e "${GREEN}All test suites passed!${NC}" | ||
| 73 | exit 0 | ||
| 74 | else | ||
| 75 | echo -e "${RED}Some test suites failed!${NC}" | ||
| 76 | exit 1 | ||
| 77 | fi | ||
diff --git a/spec/cli/test_basic_options.sh b/spec/cli/test_basic_options.sh new file mode 100755 index 0000000..81cfaf7 --- /dev/null +++ b/spec/cli/test_basic_options.sh | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # Test Basic Options for YueScript CLI | ||
| 3 | # Tests: -h, --help, -v, --version | ||
| 4 | |||
| 5 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| 6 | source "$SCRIPT_DIR/cli_test_helper.sh" | ||
| 7 | |||
| 8 | # Check binary | ||
| 9 | check_yue_binary | ||
| 10 | |||
| 11 | echo "========================================" | ||
| 12 | echo "Testing Basic Options" | ||
| 13 | echo "========================================" | ||
| 14 | echo "" | ||
| 15 | |||
| 16 | # Test 1: Help flag -h | ||
| 17 | echo "Testing -h flag..." | ||
| 18 | assert_output_contains "Help flag -h should show usage" "Usage: yue" $YUE_BIN -h | ||
| 19 | |||
| 20 | # Test 2: Help flag --help | ||
| 21 | assert_output_contains "Help flag --help should show usage" "Usage: yue" $YUE_BIN --help | ||
| 22 | |||
| 23 | # Test 3: Version flag -v | ||
| 24 | assert_output_contains "Version flag -v should show version" "Yuescript version:" $YUE_BIN -v | ||
| 25 | |||
| 26 | # Test 4: Version flag --version | ||
| 27 | assert_output_contains "Version flag --version should show version" "Yuescript version:" $YUE_BIN --version | ||
| 28 | |||
| 29 | # Test 5: Verify help contains expected sections | ||
| 30 | echo "" | ||
| 31 | echo "Testing help content..." | ||
| 32 | # Use grep -F to search for fixed strings without interpreting special characters | ||
| 33 | assert_output_contains "Help should show compile options" "output-to" $YUE_BIN --help | ||
| 34 | assert_output_contains "Help should show minify option" "minify" $YUE_BIN --help | ||
| 35 | assert_output_contains "Help should show execute option" "execute" $YUE_BIN --help | ||
| 36 | |||
| 37 | echo "" | ||
| 38 | print_summary | ||
diff --git a/spec/cli/test_compilation.sh b/spec/cli/test_compilation.sh new file mode 100755 index 0000000..4ddde5a --- /dev/null +++ b/spec/cli/test_compilation.sh | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # Test Compilation Functionality for YueScript CLI | ||
| 3 | # Tests: File compilation, directory compilation, output options | ||
| 4 | |||
| 5 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| 6 | source "$SCRIPT_DIR/cli_test_helper.sh" | ||
| 7 | |||
| 8 | # Check binary | ||
| 9 | check_yue_binary | ||
| 10 | |||
| 11 | # Setup test environment | ||
| 12 | setup_test_env | ||
| 13 | TMP_DIR=$(get_test_tmp_dir) | ||
| 14 | |||
| 15 | echo "========================================" | ||
| 16 | echo "Testing Compilation Functionality" | ||
| 17 | echo "========================================" | ||
| 18 | echo "" | ||
| 19 | |||
| 20 | # Test 1: Compile a simple file to stdout | ||
| 21 | echo "Testing simple file compilation to stdout..." | ||
| 22 | cat > "$TMP_DIR/simple.yue" << 'EOF' | ||
| 23 | print "Hello, World!" | ||
| 24 | EOF | ||
| 25 | |||
| 26 | assert_output_contains "Compile simple file to stdout" "print" $YUE_BIN -p "$TMP_DIR/simple.yue" | ||
| 27 | |||
| 28 | # Test 2: Compile a simple file to disk | ||
| 29 | echo "" | ||
| 30 | echo "Testing file compilation to disk..." | ||
| 31 | cat > "$TMP_DIR/test1.yue" << 'EOF' | ||
| 32 | x = 1 + 2 | ||
| 33 | print x | ||
| 34 | EOF | ||
| 35 | |||
| 36 | assert_success "Compile test1.yue to disk" $YUE_BIN "$TMP_DIR/test1.yue" | ||
| 37 | assert_file_exists "Output file test1.lua should exist" "$TMP_DIR/test1.lua" | ||
| 38 | |||
| 39 | # Test 3: Compile with -o option | ||
| 40 | echo "" | ||
| 41 | echo "Testing compilation with -o option..." | ||
| 42 | cat > "$TMP_DIR/test2.yue" << 'EOF' | ||
| 43 | x = 10 | ||
| 44 | print x | ||
| 45 | EOF | ||
| 46 | |||
| 47 | assert_success "Compile with -o option" $YUE_BIN -o "$TMP_DIR/output.lua" "$TMP_DIR/test2.yue" | ||
| 48 | assert_file_exists "Custom output file should exist" "$TMP_DIR/output.lua" | ||
| 49 | |||
| 50 | # Test 4: Compile directory with -t option (target directory) | ||
| 51 | echo "" | ||
| 52 | echo "Testing compilation with -t option..." | ||
| 53 | mkdir -p "$TMP_DIR/src" | ||
| 54 | mkdir -p "$TMP_DIR/build" | ||
| 55 | cat > "$TMP_DIR/src/test3.yue" << 'EOF' | ||
| 56 | print "test" | ||
| 57 | EOF | ||
| 58 | |||
| 59 | assert_success "Compile directory with -t option" $YUE_BIN "$TMP_DIR/src" -t "$TMP_DIR/build" | ||
| 60 | assert_file_exists "Output should be in target directory" "$TMP_DIR/build/test3.lua" | ||
| 61 | |||
| 62 | # Test 5: Compile directory recursively | ||
| 63 | echo "" | ||
| 64 | echo "Testing directory compilation..." | ||
| 65 | mkdir -p "$TMP_DIR/project/src" | ||
| 66 | mkdir -p "$TMP_DIR/project/build" | ||
| 67 | |||
| 68 | cat > "$TMP_DIR/project/src/file1.yue" << 'EOF' | ||
| 69 | print "file1" | ||
| 70 | EOF | ||
| 71 | |||
| 72 | cat > "$TMP_DIR/project/src/file2.yue" << 'EOF' | ||
| 73 | print "file2" | ||
| 74 | EOF | ||
| 75 | |||
| 76 | assert_success "Compile entire directory" $YUE_BIN "$TMP_DIR/project/src" -t "$TMP_DIR/project/build" | ||
| 77 | # Files are compiled directly in target directory, not preserving src subdir | ||
| 78 | assert_file_exists "file1.lua should exist" "$TMP_DIR/project/build/file1.lua" | ||
| 79 | assert_file_exists "file2.lua should exist" "$TMP_DIR/project/build/file2.lua" | ||
| 80 | |||
| 81 | # Test 6: Compile with line numbers (-l) | ||
| 82 | echo "" | ||
| 83 | echo "Testing compilation with line numbers..." | ||
| 84 | cat > "$TMP_DIR/test_line.yue" << 'EOF' | ||
| 85 | print "line test" | ||
| 86 | EOF | ||
| 87 | |||
| 88 | assert_success "Compile with line numbers" $YUE_BIN -l "$TMP_DIR/test_line.yue" -o "$TMP_DIR/test_line.lua" | ||
| 89 | assert_output_contains "Compiled file should have line comment" "yue" cat "$TMP_DIR/test_line.lua" | ||
| 90 | |||
| 91 | # Test 7: Compile with spaces instead of tabs (-s) | ||
| 92 | echo "" | ||
| 93 | echo "Testing compilation with spaces..." | ||
| 94 | cat > "$TMP_DIR/test_spaces.yue" << 'EOF' | ||
| 95 | x = 1 | ||
| 96 | EOF | ||
| 97 | |||
| 98 | assert_success "Compile with spaces option" $YUE_BIN -s "$TMP_DIR/test_spaces.yue" -o "$TMP_DIR/test_spaces.lua" | ||
| 99 | |||
| 100 | # Test 8: Compile with minify (-m) | ||
| 101 | echo "" | ||
| 102 | echo "Testing compilation with minify..." | ||
| 103 | cat > "$TMP_DIR/test_minify.yue" << 'EOF' | ||
| 104 | -- this is a comment | ||
| 105 | x = 1 + 2 | ||
| 106 | print x | ||
| 107 | EOF | ||
| 108 | |||
| 109 | assert_success "Compile with minify option" $YUE_BIN -m "$TMP_DIR/test_minify.yue" -o "$TMP_DIR/test_minify.lua" | ||
| 110 | assert_file_exists "Minified file should exist" "$TMP_DIR/test_minify.lua" | ||
| 111 | |||
| 112 | # Test 9: Stdin/stdout compilation | ||
| 113 | echo "" | ||
| 114 | echo "Testing stdin/stdout compilation..." | ||
| 115 | echo 'print "stdin test"' | assert_output_contains "Compile from stdin" "print" $YUE_BIN - | ||
| 116 | |||
| 117 | # Test 10: Glob variable dumping (-g) | ||
| 118 | echo "" | ||
| 119 | echo "Testing global variable dumping..." | ||
| 120 | cat > "$TMP_DIR/test_globals.yue" << 'EOF' | ||
| 121 | local x = 1 | ||
| 122 | print unknown_global | ||
| 123 | EOF | ||
| 124 | |||
| 125 | # -g dumps globals in format: NAME LINE COLUMN | ||
| 126 | assert_output_contains "Dump global variables" "unknown_global" $YUE_BIN -g "$TMP_DIR/test_globals.yue" | ||
| 127 | |||
| 128 | # Test 11: Benchmark compilation (-b) | ||
| 129 | echo "" | ||
| 130 | echo "Testing benchmark compilation..." | ||
| 131 | cat > "$TMP_DIR/test_bench.yue" << 'EOF' | ||
| 132 | print "benchmark" | ||
| 133 | EOF | ||
| 134 | |||
| 135 | assert_output_contains "Benchmark should show compile time" "Compile time:" $YUE_BIN -b "$TMP_DIR/test_bench.yue" | ||
| 136 | |||
| 137 | # Test 12: Target version option | ||
| 138 | echo "" | ||
| 139 | echo "Testing target version option..." | ||
| 140 | cat > "$TMP_DIR/test_target.yue" << 'EOF' | ||
| 141 | print "target test" | ||
| 142 | EOF | ||
| 143 | |||
| 144 | assert_success "Compile with target 5.1" $YUE_BIN "$TMP_DIR/test_target.yue" -o "$TMP_DIR/test_target.lua" --target 5.1 | ||
| 145 | assert_file_exists "Target version compilation should succeed" "$TMP_DIR/test_target.lua" | ||
| 146 | |||
| 147 | echo "" | ||
| 148 | print_summary | ||
diff --git a/spec/cli/test_error_handling.sh b/spec/cli/test_error_handling.sh new file mode 100755 index 0000000..1ff1642 --- /dev/null +++ b/spec/cli/test_error_handling.sh | |||
| @@ -0,0 +1,169 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # Test Error Handling for YueScript CLI | ||
| 3 | # Tests: Syntax errors, file not found, invalid options | ||
| 4 | |||
| 5 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| 6 | source "$SCRIPT_DIR/cli_test_helper.sh" | ||
| 7 | |||
| 8 | # Check binary | ||
| 9 | check_yue_binary | ||
| 10 | |||
| 11 | # Setup test environment | ||
| 12 | setup_test_env | ||
| 13 | TMP_DIR=$(get_test_tmp_dir) | ||
| 14 | |||
| 15 | echo "========================================" | ||
| 16 | echo "Testing Error Handling" | ||
| 17 | echo "========================================" | ||
| 18 | echo "" | ||
| 19 | |||
| 20 | # Test 1: Non-existent file | ||
| 21 | echo "Testing non-existent file..." | ||
| 22 | assert_failure "Compiling non-existent file should fail" $YUE_BIN "$TMP_DIR/nonexistent.yue" | ||
| 23 | |||
| 24 | # Test 2: Syntax error in YueScript code | ||
| 25 | echo "" | ||
| 26 | echo "Testing syntax error..." | ||
| 27 | cat > "$TMP_DIR/syntax_error.yue" << 'EOF' | ||
| 28 | print "unclosed string | ||
| 29 | EOF | ||
| 30 | |||
| 31 | assert_failure "Compiling file with syntax error should fail" $YUE_BIN "$TMP_DIR/syntax_error.yue" | ||
| 32 | |||
| 33 | # Test 3: Invalid option combination | ||
| 34 | echo "" | ||
| 35 | echo "Testing invalid option combinations..." | ||
| 36 | cat > "$TMP_DIR/test1.yue" << 'EOF' | ||
| 37 | print "test" | ||
| 38 | EOF | ||
| 39 | |||
| 40 | cat > "$TMP_DIR/test2.yue" << 'EOF' | ||
| 41 | print "test2" | ||
| 42 | EOF | ||
| 43 | |||
| 44 | # -o with multiple files should fail | ||
| 45 | assert_failure "-o with multiple input files should fail" $YUE_BIN -o output.lua "$TMP_DIR/test1.yue" "$TMP_DIR/test2.yue" 2>&1 || true | ||
| 46 | |||
| 47 | # Test 4: Empty file | ||
| 48 | echo "" | ||
| 49 | echo "Testing empty file..." | ||
| 50 | touch "$TMP_DIR/empty.yue" | ||
| 51 | assert_success "Compiling empty file should succeed" $YUE_BIN "$TMP_DIR/empty.yue" | ||
| 52 | |||
| 53 | # Test 5: File with only comments | ||
| 54 | echo "" | ||
| 55 | echo "Testing file with only comments..." | ||
| 56 | cat > "$TMP_DIR/only_comments.yue" << 'EOF' | ||
| 57 | -- This is a comment | ||
| 58 | -- Another comment | ||
| 59 | EOF | ||
| 60 | |||
| 61 | assert_success "Compiling file with only comments should succeed" $YUE_BIN "$TMP_DIR/only_comments.yue" | ||
| 62 | |||
| 63 | # Test 6: Invalid Lua target version | ||
| 64 | echo "" | ||
| 65 | echo "Testing invalid target version..." | ||
| 66 | cat > "$TMP_DIR/test_target.yue" << 'EOF' | ||
| 67 | print "test" | ||
| 68 | EOF | ||
| 69 | |||
| 70 | # Note: Invalid target versions may be silently accepted or ignored | ||
| 71 | assert_success "Invalid target version is accepted (may be ignored)" $YUE_BIN "$TMP_DIR/test_target.yue" --target 9.9 | ||
| 72 | |||
| 73 | # Test 7: Complex YueScript with various features | ||
| 74 | echo "" | ||
| 75 | echo "Testing complex valid YueScript..." | ||
| 76 | cat > "$TMP_DIR/complex.yue" << 'EOF' | ||
| 77 | -- Class definition | ||
| 78 | class MyClass | ||
| 79 | new: (@value) => | ||
| 80 | |||
| 81 | get_value: => | ||
| 82 | @value | ||
| 83 | |||
| 84 | set_value: (@value) => | ||
| 85 | |||
| 86 | -- Table comprehension | ||
| 87 | numbers = [1, 2, 3, 4, 5] | ||
| 88 | squared = [x * x for x in numbers] | ||
| 89 | |||
| 90 | -- String interpolation | ||
| 91 | name = "YueScript" | ||
| 92 | message = "Hello, #{name}!" | ||
| 93 | |||
| 94 | -- Export statement | ||
| 95 | export MyClass, squared, message | ||
| 96 | EOF | ||
| 97 | |||
| 98 | assert_success "Compiling complex YueScript should succeed" $YUE_BIN "$TMP_DIR/complex.yue" | ||
| 99 | |||
| 100 | # Test 8: Watch mode with file (should fail) | ||
| 101 | echo "" | ||
| 102 | echo "Testing watch mode restrictions..." | ||
| 103 | assert_failure "Watch mode with file input should fail" $YUE_BIN -w "$TMP_DIR/test1.yue" 2>&1 || true | ||
| 104 | |||
| 105 | # Test 9: Invalid use of stdin/stdout | ||
| 106 | echo "" | ||
| 107 | echo "Testing invalid stdin usage..." | ||
| 108 | assert_failure "Stdin with additional arguments should fail" $YUE_BIN - "$TMP_DIR/test1.yue" 2>&1 || true | ||
| 109 | |||
| 110 | # Test 10: Check for proper error messages | ||
| 111 | echo "" | ||
| 112 | echo "Testing error message quality..." | ||
| 113 | cat > "$TMP_DIR/error_msg.yue" << 'EOF' | ||
| 114 | undef_var = undefined_value | ||
| 115 | EOF | ||
| 116 | |||
| 117 | assert_output_contains "Error message should contain file name" "error_msg.yue" $YUE_BIN "$TMP_DIR/error_msg.yue" || true | ||
| 118 | |||
| 119 | # Test 11: Unicode handling | ||
| 120 | echo "" | ||
| 121 | echo "Testing Unicode in source files..." | ||
| 122 | cat > "$TMP_DIR/unicode.yue" << 'EOF' | ||
| 123 | -- Unicode characters | ||
| 124 | message = "你好世界 🌍" | ||
| 125 | print message | ||
| 126 | EOF | ||
| 127 | |||
| 128 | assert_success "Compiling file with Unicode should succeed" $YUE_BIN "$TMP_DIR/unicode.yue" | ||
| 129 | |||
| 130 | # Test 12: Very long line | ||
| 131 | echo "" | ||
| 132 | echo "Testing very long line..." | ||
| 133 | # Generate a long line using printf instead of python | ||
| 134 | LONG_LINE="x = " | ||
| 135 | for i in $(seq 1 100); do | ||
| 136 | LONG_LINE="${LONG_LINE}1 + " | ||
| 137 | done | ||
| 138 | LONG_LINE="${LONG_LINE}1" | ||
| 139 | echo "$LONG_LINE" > "$TMP_DIR/long_line.yue" | ||
| 140 | assert_success "Compiling file with very long line should succeed" $YUE_BIN "$TMP_DIR/long_line.yue" | ||
| 141 | |||
| 142 | # Test 13: Deep nesting | ||
| 143 | echo "" | ||
| 144 | echo "Testing deeply nested code..." | ||
| 145 | cat > "$TMP_DIR/deep_nested.yue" << 'EOF' | ||
| 146 | if true | ||
| 147 | if true | ||
| 148 | if true | ||
| 149 | if true | ||
| 150 | if true | ||
| 151 | print "deep" | ||
| 152 | EOF | ||
| 153 | |||
| 154 | assert_success "Compiling deeply nested code should succeed" $YUE_BIN "$TMP_DIR/deep_nested.yue" | ||
| 155 | |||
| 156 | # Test 14: Invalid syntax in macro | ||
| 157 | echo "" | ||
| 158 | echo "Testing macro error handling..." | ||
| 159 | cat > "$TMP_DIR/macro_error.yue" << 'EOF' | ||
| 160 | macro bad_macro | ||
| 161 | error: invalid syntax here | ||
| 162 | |||
| 163 | print "test" | ||
| 164 | EOF | ||
| 165 | |||
| 166 | assert_failure "Compiling file with invalid macro should fail" $YUE_BIN "$TMP_DIR/macro_error.yue" | ||
| 167 | |||
| 168 | echo "" | ||
| 169 | print_summary | ||
diff --git a/spec/cli/test_execution.sh b/spec/cli/test_execution.sh new file mode 100755 index 0000000..fedfbea --- /dev/null +++ b/spec/cli/test_execution.sh | |||
| @@ -0,0 +1,159 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # Test Code Execution for YueScript CLI | ||
| 3 | # Tests: -e option, executing files, script arguments | ||
| 4 | |||
| 5 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| 6 | source "$SCRIPT_DIR/cli_test_helper.sh" | ||
| 7 | |||
| 8 | # Check binary | ||
| 9 | check_yue_binary | ||
| 10 | |||
| 11 | # Setup test environment | ||
| 12 | setup_test_env | ||
| 13 | TMP_DIR=$(get_test_tmp_dir) | ||
| 14 | |||
| 15 | echo "========================================" | ||
| 16 | echo "Testing Code Execution" | ||
| 17 | echo "========================================" | ||
| 18 | echo "" | ||
| 19 | |||
| 20 | # Test 1: Execute inline code | ||
| 21 | echo "Testing inline code execution..." | ||
| 22 | assert_output_contains "Execute inline code" "123" $YUE_BIN -e 'print 123' | ||
| 23 | |||
| 24 | # Test 2: Execute inline code with calculations | ||
| 25 | echo "" | ||
| 26 | echo "Testing inline code with calculations..." | ||
| 27 | assert_output_contains "Execute calculation" "5" $YUE_BIN -e 'print 2 + 3' | ||
| 28 | |||
| 29 | # Test 3: Execute inline code with string interpolation | ||
| 30 | echo "" | ||
| 31 | echo "Testing string interpolation..." | ||
| 32 | assert_output_contains "String interpolation" "Hello, World" $YUE_BIN -e 'name = "World"; print "Hello, #{name}"' | ||
| 33 | |||
| 34 | # Test 4: Execute YueScript file with -e | ||
| 35 | echo "" | ||
| 36 | echo "Testing file execution with -e..." | ||
| 37 | cat > "$TMP_DIR/exec_test.yue" << 'EOF' | ||
| 38 | x = 10 | ||
| 39 | y = 20 | ||
| 40 | print x + y | ||
| 41 | EOF | ||
| 42 | |||
| 43 | assert_output_contains "Execute file" "30" $YUE_BIN -e "$TMP_DIR/exec_test.yue" | ||
| 44 | |||
| 45 | # Test 5: Execute Lua file | ||
| 46 | echo "" | ||
| 47 | echo "Testing Lua file execution..." | ||
| 48 | cat > "$TMP_DIR/test.lua" << 'EOF' | ||
| 49 | print("Lua execution") | ||
| 50 | EOF | ||
| 51 | |||
| 52 | assert_output_contains "Execute Lua file" "Lua execution" $YUE_BIN -e "$TMP_DIR/test.lua" | ||
| 53 | |||
| 54 | # Test 6: Test with script arguments | ||
| 55 | echo "" | ||
| 56 | echo "Testing script arguments..." | ||
| 57 | cat > "$TMP_DIR/args_test.yue" << 'EOF' | ||
| 58 | import arg | ||
| 59 | print arg[1] | ||
| 60 | print arg[2] | ||
| 61 | EOF | ||
| 62 | |||
| 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 | ||
| 65 | |||
| 66 | # Test 7: Test with compiler options via --key=value | ||
| 67 | echo "" | ||
| 68 | echo "Testing compiler options in execute mode..." | ||
| 69 | cat > "$TMP_DIR/options_test.yue" << 'EOF' | ||
| 70 | print "test" | ||
| 71 | EOF | ||
| 72 | |||
| 73 | assert_success "Execute with compiler option" $YUE_BIN -e "$TMP_DIR/options_test.yue" --reserve_line_number=true | ||
| 74 | |||
| 75 | # Test 8: Execute code with table operations | ||
| 76 | echo "" | ||
| 77 | echo "Testing table operations..." | ||
| 78 | assert_output_contains "Table operations" "3" $YUE_BIN -e 't = {1, 2, 3}; print #t' | ||
| 79 | |||
| 80 | # Test 9: Execute code with function definition | ||
| 81 | echo "" | ||
| 82 | echo "Testing function definition..." | ||
| 83 | cat > "$TMP_DIR/func_test.yue" << 'EOF' | ||
| 84 | double = (x) -> x * 2 | ||
| 85 | print double(5) | ||
| 86 | EOF | ||
| 87 | |||
| 88 | assert_output_contains "Function execution" "10" $YUE_BIN -e "$TMP_DIR/func_test.yue" | ||
| 89 | |||
| 90 | # Test 10: Execute code with class | ||
| 91 | echo "" | ||
| 92 | echo "Testing class execution..." | ||
| 93 | cat > "$TMP_DIR/class_test.yue" << 'EOF' | ||
| 94 | class Point | ||
| 95 | new: (@x, @y) => | ||
| 96 | |||
| 97 | distance: => | ||
| 98 | math.sqrt(@x * @x + @y * @y) | ||
| 99 | |||
| 100 | p = Point(3, 4) | ||
| 101 | print p\distance! | ||
| 102 | EOF | ||
| 103 | |||
| 104 | assert_output_contains "Class method execution" "5" $YUE_BIN -e "$TMP_DIR/class_test.yue" | ||
| 105 | |||
| 106 | # Test 11: Execute with import | ||
| 107 | echo "" | ||
| 108 | echo "Testing import in execute mode..." | ||
| 109 | cat > "$TMP_DIR/import_test.yue" << 'EOF' | ||
| 110 | print "test" | ||
| 111 | EOF | ||
| 112 | |||
| 113 | # 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" | ||
| 115 | |||
| 116 | # Test 12: Execute code with error handling | ||
| 117 | echo "" | ||
| 118 | echo "Testing error handling in executed code..." | ||
| 119 | cat > "$TMP_DIR/error_test.yue" << 'EOF' | ||
| 120 | ok, err = pcall -> | ||
| 121 | error "test error" | ||
| 122 | |||
| 123 | if not ok | ||
| 124 | print "caught: " .. err | ||
| 125 | EOF | ||
| 126 | |||
| 127 | assert_output_contains "Error handling" "caught:" $YUE_BIN -e "$TMP_DIR/error_test.yue" | ||
| 128 | |||
| 129 | # Test 13: Execute with export statement | ||
| 130 | echo "" | ||
| 131 | echo "Testing export in execute mode..." | ||
| 132 | cat > "$TMP_DIR/export_test.yue" << 'EOF' | ||
| 133 | export value = 42 | ||
| 134 | print value | ||
| 135 | EOF | ||
| 136 | |||
| 137 | assert_output_contains "Export value" "42" $YUE_BIN -e "$TMP_DIR/export_test.yue" | ||
| 138 | |||
| 139 | # Test 14: Execute with macro | ||
| 140 | echo "" | ||
| 141 | echo "Testing macro in execute mode..." | ||
| 142 | cat > "$TMP_DIR/macro_test.yue" << 'EOF' | ||
| 143 | macro double = (x) -> "#{x} * 2" | ||
| 144 | |||
| 145 | result = $double 21 | ||
| 146 | print result | ||
| 147 | EOF | ||
| 148 | |||
| 149 | assert_output_contains "Macro execution" "42" $YUE_BIN -e "$TMP_DIR/macro_test.yue" | ||
| 150 | |||
| 151 | # Test 15: Execute with string literal | ||
| 152 | echo "" | ||
| 153 | echo "Testing string literals..." | ||
| 154 | # Use grep without -F to match patterns with newlines | ||
| 155 | # We'll match just the first part to avoid newline issues | ||
| 156 | assert_output_contains "String with escape" "line1" $YUE_BIN -e 'print "line1\nline2"' | ||
| 157 | |||
| 158 | echo "" | ||
| 159 | print_summary | ||
