aboutsummaryrefslogtreecommitdiff
path: root/spec/cli/test_compilation.sh
diff options
context:
space:
mode:
Diffstat (limited to 'spec/cli/test_compilation.sh')
-rwxr-xr-xspec/cli/test_compilation.sh148
1 files changed, 148 insertions, 0 deletions
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
5SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6source "$SCRIPT_DIR/cli_test_helper.sh"
7
8# Check binary
9check_yue_binary
10
11# Setup test environment
12setup_test_env
13TMP_DIR=$(get_test_tmp_dir)
14
15echo "========================================"
16echo "Testing Compilation Functionality"
17echo "========================================"
18echo ""
19
20# Test 1: Compile a simple file to stdout
21echo "Testing simple file compilation to stdout..."
22cat > "$TMP_DIR/simple.yue" << 'EOF'
23print "Hello, World!"
24EOF
25
26assert_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
29echo ""
30echo "Testing file compilation to disk..."
31cat > "$TMP_DIR/test1.yue" << 'EOF'
32x = 1 + 2
33print x
34EOF
35
36assert_success "Compile test1.yue to disk" $YUE_BIN "$TMP_DIR/test1.yue"
37assert_file_exists "Output file test1.lua should exist" "$TMP_DIR/test1.lua"
38
39# Test 3: Compile with -o option
40echo ""
41echo "Testing compilation with -o option..."
42cat > "$TMP_DIR/test2.yue" << 'EOF'
43x = 10
44print x
45EOF
46
47assert_success "Compile with -o option" $YUE_BIN -o "$TMP_DIR/output.lua" "$TMP_DIR/test2.yue"
48assert_file_exists "Custom output file should exist" "$TMP_DIR/output.lua"
49
50# Test 4: Compile directory with -t option (target directory)
51echo ""
52echo "Testing compilation with -t option..."
53mkdir -p "$TMP_DIR/src"
54mkdir -p "$TMP_DIR/build"
55cat > "$TMP_DIR/src/test3.yue" << 'EOF'
56print "test"
57EOF
58
59assert_success "Compile directory with -t option" $YUE_BIN "$TMP_DIR/src" -t "$TMP_DIR/build"
60assert_file_exists "Output should be in target directory" "$TMP_DIR/build/test3.lua"
61
62# Test 5: Compile directory recursively
63echo ""
64echo "Testing directory compilation..."
65mkdir -p "$TMP_DIR/project/src"
66mkdir -p "$TMP_DIR/project/build"
67
68cat > "$TMP_DIR/project/src/file1.yue" << 'EOF'
69print "file1"
70EOF
71
72cat > "$TMP_DIR/project/src/file2.yue" << 'EOF'
73print "file2"
74EOF
75
76assert_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
78assert_file_exists "file1.lua should exist" "$TMP_DIR/project/build/file1.lua"
79assert_file_exists "file2.lua should exist" "$TMP_DIR/project/build/file2.lua"
80
81# Test 6: Compile with line numbers (-l)
82echo ""
83echo "Testing compilation with line numbers..."
84cat > "$TMP_DIR/test_line.yue" << 'EOF'
85print "line test"
86EOF
87
88assert_success "Compile with line numbers" $YUE_BIN -l "$TMP_DIR/test_line.yue" -o "$TMP_DIR/test_line.lua"
89assert_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)
92echo ""
93echo "Testing compilation with spaces..."
94cat > "$TMP_DIR/test_spaces.yue" << 'EOF'
95x = 1
96EOF
97
98assert_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)
101echo ""
102echo "Testing compilation with minify..."
103cat > "$TMP_DIR/test_minify.yue" << 'EOF'
104-- this is a comment
105x = 1 + 2
106print x
107EOF
108
109assert_success "Compile with minify option" $YUE_BIN -m "$TMP_DIR/test_minify.yue" -o "$TMP_DIR/test_minify.lua"
110assert_file_exists "Minified file should exist" "$TMP_DIR/test_minify.lua"
111
112# Test 9: Stdin/stdout compilation
113echo ""
114echo "Testing stdin/stdout compilation..."
115echo 'print "stdin test"' | assert_output_contains "Compile from stdin" "print" $YUE_BIN -
116
117# Test 10: Glob variable dumping (-g)
118echo ""
119echo "Testing global variable dumping..."
120cat > "$TMP_DIR/test_globals.yue" << 'EOF'
121local x = 1
122print unknown_global
123EOF
124
125# -g dumps globals in format: NAME LINE COLUMN
126assert_output_contains "Dump global variables" "unknown_global" $YUE_BIN -g "$TMP_DIR/test_globals.yue"
127
128# Test 11: Benchmark compilation (-b)
129echo ""
130echo "Testing benchmark compilation..."
131cat > "$TMP_DIR/test_bench.yue" << 'EOF'
132print "benchmark"
133EOF
134
135assert_output_contains "Benchmark should show compile time" "Compile time:" $YUE_BIN -b "$TMP_DIR/test_bench.yue"
136
137# Test 12: Target version option
138echo ""
139echo "Testing target version option..."
140cat > "$TMP_DIR/test_target.yue" << 'EOF'
141print "target test"
142EOF
143
144assert_success "Compile with target 5.1" $YUE_BIN "$TMP_DIR/test_target.yue" -o "$TMP_DIR/test_target.lua" --target 5.1
145assert_file_exists "Target version compilation should succeed" "$TMP_DIR/test_target.lua"
146
147echo ""
148print_summary