blob: 8b639f4895948ef30d551488c77f4383c0c69dca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
#!/usr/bin/env bats
# AzerothCore Compiler Integration Test Suite
# Tests edge cases and integration scenarios for the compiler module
# Load the AzerothCore test framework
load '../../test-framework/bats_libs/acore-support'
load '../../test-framework/bats_libs/acore-assert'
# Setup that runs before each test
setup() {
compiler_setup
export SCRIPT_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
}
# Cleanup that runs after each test
teardown() {
acore_test_teardown
}
# ===== INTEGRATION TESTS =====
@test "integration: should handle full compiler.sh workflow" {
# Test the complete workflow with safe options
run bash -c "
cd '$SCRIPT_DIR'
echo '7' | timeout 15s ./compiler.sh
echo 'First command completed'
echo 'quit' | timeout 10s ./compiler.sh
echo 'Quit command completed'
"
[ "$status" -eq 0 ]
[[ "$output" =~ "First command completed" ]]
[[ "$output" =~ "Quit command completed" ]]
}
@test "integration: should handle multiple consecutive commands" {
# Test running multiple safe commands in sequence
run bash -c "
cd '$SCRIPT_DIR'
timeout 10s ./compiler.sh ccacheShowStats
echo 'Command 1 done'
timeout 10s ./compiler.sh quit
echo 'Command 2 done'
"
[ "$status" -eq 0 ]
[[ "$output" =~ "Command 1 done" ]]
[[ "$output" =~ "Command 2 done" ]]
}
@test "integration: should preserve working directory" {
# Test that the script doesn't change the working directory unexpectedly
local original_pwd="$(pwd)"
run bash -c "
cd '$SCRIPT_DIR'
original_dir=\$(pwd)
timeout 10s ./compiler.sh quit
current_dir=\$(pwd)
echo \"ORIGINAL: \$original_dir\"
echo \"CURRENT: \$current_dir\"
[ \"\$original_dir\" = \"\$current_dir\" ] && echo 'DIRECTORY_PRESERVED'
"
[ "$status" -eq 0 ]
[[ "$output" =~ "DIRECTORY_PRESERVED" ]]
}
# ===== ERROR HANDLING TESTS =====
@test "error_handling: should handle script errors gracefully" {
# Test script behavior with set -e when encountering errors
run bash -c "
cd '$SCRIPT_DIR'
# Try to source a non-existent file to test error handling
timeout 5s bash -c 'set -e; source /nonexistent/file.sh' || echo 'ERROR_HANDLED'
"
[ "$status" -eq 0 ]
[[ "$output" =~ "ERROR_HANDLED" ]]
}
@test "error_handling: should validate function availability" {
# Test that required functions are available after sourcing
run bash -c "
source '$SCRIPT_DIR/includes/functions.sh'
# Check for key functions
type comp_clean > /dev/null && echo 'COMP_CLEAN_AVAILABLE'
type comp_configure > /dev/null && echo 'COMP_CONFIGURE_AVAILABLE'
type comp_compile > /dev/null && echo 'COMP_COMPILE_AVAILABLE'
type comp_build > /dev/null && echo 'COMP_BUILD_AVAILABLE'
type comp_all > /dev/null && echo 'COMP_ALL_AVAILABLE'
"
[ "$status" -eq 0 ]
[[ "$output" =~ "COMP_CLEAN_AVAILABLE" ]]
[[ "$output" =~ "COMP_CONFIGURE_AVAILABLE" ]]
[[ "$output" =~ "COMP_COMPILE_AVAILABLE" ]]
[[ "$output" =~ "COMP_BUILD_AVAILABLE" ]]
[[ "$output" =~ "COMP_ALL_AVAILABLE" ]]
}
# ===== PERMISSION TESTS =====
@test "permissions: should handle permission requirements" {
# Test script behavior with different permission scenarios
run bash -c "
# Test SUDO variable detection
source '$SCRIPT_DIR/includes/functions.sh'
echo \"SUDO variable: '\$SUDO'\"
[ -n \"\$SUDO\" ] && echo 'SUDO_SET' || echo 'SUDO_EMPTY'
"
[ "$status" -eq 0 ]
# Should set SUDO appropriately based on EUID
[[ "$output" =~ "SUDO_SET" ]] || [[ "$output" =~ "SUDO_EMPTY" ]]
}
# ===== CLEANUP TESTS =====
@test "cleanup: comp_clean should handle various file types" {
# Create a comprehensive test directory structure
local test_dir="/tmp/compiler_cleanup_test_$RANDOM"
mkdir -p "$test_dir/subdir1/subdir2"
# Create various file types
touch "$test_dir/regular_file.txt"
touch "$test_dir/executable_file.sh"
touch "$test_dir/.hidden_file"
touch "$test_dir/subdir1/nested_file.obj"
touch "$test_dir/subdir1/subdir2/deep_file.a"
ln -s "$test_dir/regular_file.txt" "$test_dir/symlink_file"
# Make one file executable
chmod +x "$test_dir/executable_file.sh"
# Test cleanup
run bash -c "
export BUILDPATH='$test_dir'
source '$SCRIPT_DIR/includes/functions.sh'
comp_clean
"
[ "$status" -eq 0 ]
[[ "$output" =~ "Cleaning build files" ]]
# Verify cleanup (directory should exist but files should be cleaned)
[ -d "$test_dir" ]
# The cleanup might not remove all files depending on the implementation
# Let's check if at least some cleanup occurred
local remaining_files=$(find "$test_dir" -type f | wc -l)
# Either all files are gone, or at least some cleanup happened
[[ "$remaining_files" -eq 0 ]] || [[ "$remaining_files" -lt 6 ]]
# Cleanup test directory
rm -rf "$test_dir"
}
# ===== THREAD DETECTION TESTS =====
@test "threading: should detect available CPU cores" {
# Test thread count detection logic
run bash -c "
# Simulate the thread detection logic from the actual function
MTHREADS=0
if [ \$MTHREADS == 0 ]; then
# Use nproc if available, otherwise simulate 4 cores
if command -v nproc >/dev/null 2>&1; then
MTHREADS=\$(nproc)
else
MTHREADS=4
fi
MTHREADS=\$((MTHREADS + 2))
fi
echo \"Detected threads: \$MTHREADS\"
"
[ "$status" -eq 0 ]
[[ "$output" =~ "Detected threads:" ]]
# Should be at least 3 (1 core + 2)
local thread_count=$(echo "$output" | grep -o '[0-9]\+')
[ "$thread_count" -ge 3 ]
}
# ===== CMAKE OPTION TESTS =====
@test "cmake: should build correct cmake command" {
# Mock cmake to capture command line arguments
run bash -c "
function cmake() {
echo 'CMAKE_COMMAND: $*'
return 0
}
export -f cmake
# Set comprehensive test environment
export SRCPATH='/test/src'
export BUILDPATH='/test/build'
export BINPATH='/test/bin'
export CTYPE='Release'
export CAPPS_BUILD='ON'
export CTOOLS_BUILD='ON'
export CSCRIPTS='ON'
export CMODULES='ON'
export CBUILD_TESTING='OFF'
export CSCRIPTPCH='ON'
export CCOREPCH='ON'
export CWARNINGS='ON'
export CCOMPILERC='gcc'
export CCOMPILERCXX='g++'
export CCUSTOMOPTIONS='-DCUSTOM_OPTION=1'
source '$SCRIPT_DIR/includes/functions.sh'
# Change to buildpath and run configure
cd /test || cd /tmp
comp_configure 2>/dev/null || echo 'Configure completed with warnings'
"
[ "$status" -eq 0 ]
[[ "$output" =~ "CMAKE_COMMAND:" ]] || [[ "$output" =~ "Configure completed" ]]
}
# ===== PLATFORM SPECIFIC TESTS =====
@test "platform: should set correct options for detected platform" {
# Test platform-specific CMAKE options
run bash -c "
# Mock cmake to capture platform-specific options
function cmake() {
echo 'CMAKE_PLATFORM_ARGS: $*'
return 0
}
export -f cmake
export BUILDPATH='/tmp'
export SRCPATH='/tmp'
export BINPATH='/tmp'
export CTYPE='Release'
source '$SCRIPT_DIR/includes/functions.sh'
# Change to buildpath and run configure
cd /tmp
comp_configure 2>/dev/null || echo 'Configure completed with warnings'
"
[ "$status" -eq 0 ]
[[ "$output" =~ "CMAKE_PLATFORM_ARGS:" ]] || [[ "$output" =~ "Configure completed" ]]
}
|