-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·130 lines (113 loc) · 3.8 KB
/
Copy pathrun_tests.sh
File metadata and controls
executable file
·130 lines (113 loc) · 3.8 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
#!/bin/bash
# Constexpr test runner - compiles each test file to verify static_assert passes
set -e # Exit on first failure
cd "$(dirname "$0")/../.."
INCLUDE_DIR="./include"
TMP_DIR="/tmp/jsonfusion_constexpr_tests"
mkdir -p "$TMP_DIR"
echo "Running JsonFusion constexpr tests..."
echo "======================================="
: ${CXX:=g++}
: ${CXX_FLAGS:=-std=c++23}
echo "Compiler: $CXX"
echo "Flags: $CXX_FLAGS"
echo ""
$CXX -v
PASS=0
FAIL=0
WARNINGS=0
# CRITICAL: Run structural detection tests FIRST
# If type detection is broken, all other tests are meaningless
STRUCTURAL_TEST="tests/constexpr/concepts/test_structural_detection.cpp"
if [ -f "$STRUCTURAL_TEST" ]; then
test_name="test_structural_detection"
category="concepts"
printf "%-20s %-20s ... " "$category" "$test_name"
if $CXX $CXX_FLAGS -I"$INCLUDE_DIR" -Itests/constexpr -c "$STRUCTURAL_TEST" -o "$TMP_DIR/$test_name.o" 2>&1 | tee "$TMP_DIR/$test_name.log" | grep -q "error:"; then
echo "❌ FAIL"
echo ""
echo "============================================================"
echo "CRITICAL FAILURE: Type detection/classification is broken!"
echo "All other tests are meaningless until this is fixed."
echo "============================================================"
echo ""
cat "$TMP_DIR/$test_name.log"
exit 1
else
if ! grep -q "warning:" "$TMP_DIR/$test_name.log" | grep -qv "overriding deployment version from"; then
echo "✅ PASS"
else
echo "⚠️ PASS (with warnings)"
WARNINGS=$((WARNINGS + 1))
fi
PASS=$((PASS + 1))
fi
fi
# Detect number of CPUs
if command -v nproc > /dev/null 2>&1; then
NPROCS=$(nproc)
elif command -v sysctl > /dev/null 2>&1; then
NPROCS=$(sysctl -n hw.ncpu)
else
NPROCS=4 # fallback
fi
echo ""
echo "Running remaining tests in parallel (using $NPROCS CPUs)..."
echo ""
# Function to run a single test (will be run in parallel)
run_test() {
test_file="$1"
test_name=$(basename "$test_file" .cpp)
category=$(basename $(dirname "$test_file"))
if $CXX $CXX_FLAGS -I"$INCLUDE_DIR" -Itests/constexpr -c "$test_file" -o "$TMP_DIR/$test_name.o" 2>&1 > "$TMP_DIR/$test_name.log" 2>&1; then
if ! grep -q "warning:" "$TMP_DIR/$test_name.log" | grep -qv "overriding deployment version from"; then
echo "PASS|$category|$test_name"
else
echo "WARN|$category|$test_name"
fi
else
echo "FAIL|$category|$test_name"
cat "$TMP_DIR/$test_name.log" > "$TMP_DIR/$test_name.errors"
fi
}
export -f run_test
export INCLUDE_DIR
export TMP_DIR
export CXX
export CXX_FLAGS
# Run all other tests in parallel
find tests/constexpr -name "test_*.cpp" | grep -v "test_structural_detection.cpp" | sort | xargs -P "$NPROCS" -I {} bash -c 'run_test "$@"' _ {} > "$TMP_DIR/parallel_results.txt"
# Process results
while IFS='|' read -r status category test_name; do
printf "%-20s %-20s ... " "$category" "$test_name"
case "$status" in
PASS)
echo "✅ PASS"
PASS=$((PASS + 1))
;;
WARN)
echo "⚠️ PASS (with warnings)"
PASS=$((PASS + 1))
WARNINGS=$((WARNINGS + 1))
;;
FAIL)
echo "❌ FAIL"
FAIL=$((FAIL + 1))
if [ -f "$TMP_DIR/$test_name.errors" ]; then
cat "$TMP_DIR/$test_name.errors"
fi
;;
esac
done < "$TMP_DIR/parallel_results.txt"
echo "======================================="
echo "Results: $PASS passed, $FAIL failed"
if [ $WARNINGS -gt 0 ]; then
echo " $WARNINGS tests passed with warnings"
fi
if [ $FAIL -eq 0 ]; then
echo "✅ All tests passed!"
exit 0
else
echo "❌ Some tests failed"
exit 1
fi