11#! /bin/bash
22
33# Test runner script for utest library
4- # Compiles and runs all test*.cpp files in tests/ directory
4+ # Runs all pre-built test binaries from the build directory
55
66echo " ========================================"
77echo " Running all utest library tests"
88echo " ========================================"
99
1010# Set up variables
11- TEST_DIR=" tests"
12- INCLUDE_DIR=" include"
11+ BUILD_DIR=" build/bin/tests"
1312FAILED_TESTS=0
1413TOTAL_TESTS=0
1514PASS_COUNT=0
1615
16+ # Check if tests are built
17+ if [ ! -d " $BUILD_DIR " ]; then
18+ echo " Error: $BUILD_DIR directory not found!"
19+ echo " Please build the project first with: ./rebuild.sh"
20+ exit 1
21+ fi
22+
1723# Function to run a single test
1824run_test () {
19- local test_file=" $1 "
20- local test_name=$( basename " $test_file " .cpp)
21- local test_exec=" $TEST_DIR /$test_name "
25+ local test_exec=" $1 "
26+ local test_name=$( basename " $test_exec " )
2227
2328 echo " "
2429 echo " ========================================="
25- echo " Compiling and running : $test_name "
30+ echo " Running : $test_name "
2631 echo " ========================================="
2732
28- # Compile the test
29- if g++ -std=c++11 -I " $INCLUDE_DIR " " $test_file " -o " $test_exec " 2> /dev/null; then
30- echo " ✓ Compilation successful"
31-
33+ if [ -f " $test_exec " ]; then
3234 # Run the test and capture exit code
3335 if " $test_exec " > /dev/null 2>&1 ; then
3436 local exit_code=$?
@@ -46,38 +48,28 @@ run_test() {
4648 fi
4749 fi
4850 else
49- echo " ✗ Compilation failed "
51+ echo " ✗ Test executable not found: $test_exec "
5052 (( FAILED_TESTS++ ))
5153 fi
5254
5355 (( TOTAL_TESTS++ ))
54-
55- # Clean up executable
56- if [ -f " $test_exec " ]; then
57- rm " $test_exec "
58- fi
5956}
6057
6158# Function to run detailed test output
6259run_test_detailed () {
63- local test_file=" $1 "
64- local test_name=$( basename " $test_file " .cpp)
65- local test_exec=" $TEST_DIR /$test_name "
60+ local test_exec=" $1 "
61+ local test_name=$( basename " $test_exec " )
6662
6763 echo " "
6864 echo " ========================================="
6965 echo " Running detailed output for: $test_name "
7066 echo " ========================================="
7167
72- # Compile the test
73- if g++ -std=c++11 -I " $INCLUDE_DIR " " $test_file " -o " $test_exec " 2> /dev/null; then
68+ if [ -f " $test_exec " ]; then
7469 # Run the test with full output
7570 " $test_exec " || true
76- fi
77-
78- # Clean up executable
79- if [ -f " $test_exec " ]; then
80- rm " $test_exec "
71+ else
72+ echo " ✗ Test executable not found: $test_exec "
8173 fi
8274}
8375
@@ -88,17 +80,17 @@ cd "$(dirname "$0")"
8880if [[ " $1 " == " --detailed" ]] || [[ " $1 " == " -d" ]]; then
8981 echo " Running in detailed mode..."
9082
91- # Find and run all test*.cpp files with detailed output
92- for test_file in " $TEST_DIR " /test* .cpp ; do
93- if [ -f " $test_file " ]; then
94- run_test_detailed " $test_file "
83+ # Find and run all test executables with detailed output
84+ for test_exec in " $BUILD_DIR " /test* ; do
85+ if [ -f " $test_exec " ]; then
86+ run_test_detailed " $test_exec "
9587 fi
9688 done
9789else
98- # Find and run all test*.cpp files
99- for test_file in " $TEST_DIR " /test* .cpp ; do
100- if [ -f " $test_file " ]; then
101- run_test " $test_file "
90+ # Find and run all test executables
91+ for test_exec in " $BUILD_DIR " /test* ; do
92+ if [ -f " $test_exec " ]; then
93+ run_test " $test_exec "
10294 fi
10395 done
10496
0 commit comments