-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·173 lines (146 loc) · 4.01 KB
/
Copy pathrun_tests.sh
File metadata and controls
executable file
·173 lines (146 loc) · 4.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
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
#!/bin/bash
# YASH Test Runner Script
# This script provides convenient commands for running tests locally
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to show help
show_help() {
echo "YASH Test Runner"
echo ""
echo "Usage: $0 [COMMAND]"
echo ""
echo "Commands:"
echo " test Run all unit tests (default)"
echo " build Build the project and tests"
echo " clean Clean build artifacts"
echo " format Format source code"
echo " coverage Run tests with coverage analysis"
echo " valgrind Run tests with valgrind memory checking"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " $0 test # Run all tests"
echo " $0 coverage # Run tests with coverage"
echo " $0 valgrind # Run tests with memory checking"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to run tests
run_tests() {
print_status "Building and running tests..."
if ! make test; then
print_error "Tests failed!"
exit 1
fi
print_success "All tests passed!"
}
# Function to build project
build_project() {
print_status "Building project..."
make clean
make all
make test
print_success "Build completed successfully!"
}
# Function to clean build artifacts
clean_project() {
print_status "Cleaning build artifacts..."
make clean
print_success "Clean completed!"
}
# Function to format code
format_code() {
print_status "Formatting source code..."
make format
print_success "Code formatting completed!"
}
# Function to run tests with coverage
run_coverage() {
if ! command_exists gcov; then
print_error "gcov not found. Please install gcc with coverage support."
exit 1
fi
print_status "Running tests with coverage analysis..."
# Clean and rebuild with coverage flags
make clean
CFLAGS="-Wall -Wextra -std=c99 -I./include -g -O0 --coverage" make all
CFLAGS="-Wall -Wextra -std=c99 -I./include -g -O0 --coverage" make test
# Run tests
./build/test/test_runner
# Generate coverage report
print_status "Generating coverage report..."
gcov -r src/*.c
lcov --capture --directory . --output-file coverage.info
genhtml coverage.info --output-directory coverage_html
print_success "Coverage report generated in coverage_html/"
print_status "Open coverage_html/index.html in your browser to view the report"
}
# Function to run tests with valgrind
run_valgrind() {
if ! command_exists valgrind; then
print_error "valgrind not found. Please install valgrind."
exit 1
fi
print_status "Running tests with valgrind memory checking..."
# Build tests first
make test
# Run with valgrind
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes \
--verbose --log-file=valgrind-out.txt ./build/test/test_runner
if [ $? -eq 0 ]; then
print_success "Valgrind check passed! No memory leaks found."
else
print_error "Valgrind found issues. Check valgrind-out.txt for details."
exit 1
fi
}
# Main script logic
case "${1:-test}" in
"test")
run_tests
;;
"build")
build_project
;;
"clean")
clean_project
;;
"format")
format_code
;;
"coverage")
run_coverage
;;
"valgrind")
run_valgrind
;;
"help"|"-h"|"--help")
show_help
;;
*)
print_error "Unknown command: $1"
echo ""
show_help
exit 1
;;
esac