forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_all_tests.sh
More file actions
executable file
·261 lines (228 loc) · 6.48 KB
/
Copy pathrun_all_tests.sh
File metadata and controls
executable file
·261 lines (228 loc) · 6.48 KB
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
255
256
257
258
259
260
261
#!/bin/bash
# Test runner for probe files
# Usage: ./run_all_tests.sh [options] [pattern]
#
# Options:
# --compile-only Only test compilation, don't run
# --run Also run the compiled binaries (default)
# --verbose, -v Show detailed output
# --quick Only test known-working files
# --all Test all files (may have many failures)
# --list-working List files that compile successfully
# --list-failing List files that fail to compile
set -e
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
SCRIPT_DIR="$PROJECT_DIR/probes/tests"
RUSTC="$PROJECT_DIR/rustc"
TEMP_DIR="/tmp/probe_tests"
$RUSTC -V || (echo 'rust currently building' && exit)
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Options
COMPILE_ONLY=false
VERBOSE=false
QUICK_MODE=false
LIST_WORKING=false
LIST_FAILING=false
PATTERN=""
while [[ $# -gt 0 ]]; do
case $1 in
--compile-only) COMPILE_ONLY=true; shift ;;
--run) COMPILE_ONLY=false; shift ;;
--verbose|-v) VERBOSE=true; shift ;;
--quick) QUICK_MODE=true; shift ;;
--all) QUICK_MODE=false; shift ;;
--list-working) LIST_WORKING=true; shift ;;
--list-failing) LIST_FAILING=true; shift ;;
-*) echo "Unknown option: $1"; exit 1 ;;
*) PATTERN="$1"; shift ;;
esac
done
mkdir -p "$TEMP_DIR"
# Known-working files (compile AND run successfully)
WORKING_FILES=(
test_add.rust
test_and_or.rust
test_at_vec.rust
test_box.rust
test_check_reverse.rust
test_comments.rust
test_const_pow.rust
test_debug_imports.rust
test_for_loop.rust
test_main.rust
test_minimal_conflict.rust
test_normal_rust.rust
test_not.rust
test_null_coalesce.rust
test_optional_chain.rust
test_optional_syntax.rust
test_pow3.rust
test_power.rust
test_precedence.rust
test_put_eq.rust
test_put.rust
test_script_complex.rust
test_simple.rust
test_string_auto.rust
test_string_format_chain.rust
test_string_format_simple.rust
test_string_macro.rust
test_string_ops.rust
test_string_replace.rust
test_string_reverse.rust
test_string_special.rust
test_unicode_ops.rust
test_unused_mut.rust
test_with_main.rust
)
is_working_file() {
local name="$1"
for w in "${WORKING_FILES[@]}"; do
[[ "$name" == "$w" ]] && return 0
done
return 1
}
# List modes
if $LIST_WORKING; then
echo "Files that compile successfully:"
for f in "${WORKING_FILES[@]}"; do
[[ -f "$SCRIPT_DIR/$f" ]] && echo " $f"
done
exit 0
fi
if $LIST_FAILING; then
echo "Files that fail to compile (WIP/need features):"
for f in "$SCRIPT_DIR"/test_*.rust; do
name=$(basename "$f")
is_working_file "$name" || echo " $name"
done
exit 0
fi
PASSED=0
FAILED=0
SKIPPED=0
FAILED_TESTS=()
compile_test() {
local file="$1"
local name=$(basename "$file" .rust)
local output_bin="$TEMP_DIR/$name"
# Check if this file contains 'export fn' (library file)
if grep -q "^export fn" "$file"; then
# First compile as test binary
local test_output
test_output=$("$RUSTC" --test "$file" -o "$output_bin" -L "$SCRIPT_DIR" -A unused 2>&1) || { echo "$test_output"; return 1; }
# Fix me to do this should be decided by RustC and not here !!!
# Then compile as dylib and output to probes directory for other tests to use
# "$RUSTC" "$file" --crate-type dylib -o "$SCRIPT_DIR/lib$name.dylib" -A unused 2>&1
"$RUSTC" "$file" 2>&1
else
# Regular test - add library search path in case it uses libraries
echo "$RUSTC" --test "$file" -o "$output_bin" -L "$SCRIPT_DIR" -A unused
# "$RUSTC" --test "$file" -o "$output_bin" -L "$SCRIPT_DIR" -A unused 2>&1
"$RUSTC" "$file" 2>&1
fi
}
run_test() {
local file="$1"
local name=$(basename "$file" .rust)
local output_bin="$TEMP_DIR/$name"
if $VERBOSE; then
echo -n "Testing $name... "
fi
local compile_output
local compile_status=0
compile_output=$(compile_test "$file") || compile_status=$?
if [[ $compile_status -ne 0 ]]; then
((FAILED++))
FAILED_TESTS+=("$name")
if $VERBOSE; then
echo -e "${RED}COMPILE FAILED${NC}"
echo "$compile_output" | head -10
else
echo -e "${RED}✗${NC} $name (compile)"
fi
return 1
fi
if $COMPILE_ONLY; then
((PASSED++))
if $VERBOSE; then
echo -e "${GREEN}COMPILED${NC}"
else
echo -e "${GREEN}✓${NC} $name"
fi
return 0
fi
# Run the binary
if [[ -x "$output_bin" ]]; then
local run_output
local run_status=0
run_output=$("$output_bin" 2>&1) || run_status=$?
if [[ $run_status -ne 0 ]]; then
((FAILED++))
FAILED_TESTS+=("$name")
if $VERBOSE; then
echo -e "${RED}RUN FAILED (exit $run_status)${NC}"
echo "$run_output" | head -10
else
echo -e "${RED}✗${NC} $name (exit $run_status)"
fi
return 1
fi
fi
((PASSED++))
if $VERBOSE; then
echo -e "${GREEN}PASSED${NC}"
else
echo -e "${GREEN}✓${NC} $name"
fi
return 0
}
echo "Probe Test Runner"
echo "Using: $RUSTC"
if $QUICK_MODE; then
echo -e "Mode: ${BLUE}quick${NC} (known-working files only)"
else
echo -e "Mode: ${YELLOW}all${NC} (includes WIP files)"
fi
echo ""
# Determine which files to test
if $QUICK_MODE; then
for name in "${WORKING_FILES[@]}"; do
file="$SCRIPT_DIR/$name"
[[ -f "$file" ]] || continue
# Apply pattern filter
if [[ -n "$PATTERN" && ! "$name" =~ $PATTERN ]]; then
((SKIPPED++))
continue
fi
run_test "$file" || true
done
else
for file in "$SCRIPT_DIR"/test_*.rust; do
[[ -f "$file" ]] || continue
name=$(basename "$file")
# Apply pattern filter
if [[ -n "$PATTERN" && ! "$name" =~ $PATTERN ]]; then
((SKIPPED++))
continue
fi
run_test "$file" || true
done
fi
echo ""
echo "========================================"
echo -e "Results: ${GREEN}$PASSED passed${NC}, ${RED}$FAILED failed${NC}, $SKIPPED skipped"
echo "========================================"
if [[ ${#FAILED_TESTS[@]} -gt 0 && ${#FAILED_TESTS[@]} -le 20 ]]; then
echo ""
echo "Failed:"
for t in "${FAILED_TESTS[@]}"; do
echo " - $t"
done
fi
[[ $FAILED -eq 0 ]] && exit 0 || exit 1