-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_all.sh
More file actions
executable file
·47 lines (39 loc) · 1.01 KB
/
test_all.sh
File metadata and controls
executable file
·47 lines (39 loc) · 1.01 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
#!/bin/bash
PASS=0
FAIL=0
echo "Running tests across all MAANG Prep C++ files..."
echo ""
for file in $(find . -name "*.cpp" | sort); do
DIR=$(dirname "$file")
FILE=$(basename "$file")
BIN="${FILE%.cpp}"
cd "$DIR"
# Compile
g++ -std=c++17 "$FILE" -o "$BIN" 2>/dev/null
if [ $? -ne 0 ]; then
echo "[FAIL] $DIR/$FILE failed to compile!"
FAIL=$((FAIL+1))
cd - >/dev/null
continue
fi
# Run
OUTPUT=$(./"$BIN" 2>&1)
if [ $? -ne 0 ] || echo "$OUTPUT" | grep -q "Assertion failed\|Segmentation fault\|Aborted"; then
echo "[FAIL] $DIR/$FILE crashed or failed assertions: $OUTPUT"
FAIL=$((FAIL+1))
else
# We assume if it compiles and runs without aborting, it passes its own main() tests
echo "[PASS] $DIR/$FILE"
PASS=$((PASS+1))
fi
# Cleanup
rm -f "$BIN"
cd - >/dev/null
done
echo ""
echo "Total Passed: $PASS"
echo "Total Failed: $FAIL"
if [ $FAIL -gt 0 ]; then
exit 1
fi
exit 0