-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·135 lines (120 loc) · 3.66 KB
/
run-tests.sh
File metadata and controls
executable file
·135 lines (120 loc) · 3.66 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
#!/usr/bin/env bash
#
# Test runner for mudyla
#
# Usage:
# ./run-tests.sh # Run all tests
# ./run-tests.sh unit # Run only unit tests
# ./run-tests.sh integration # Run only integration tests
# ./run-tests.sh --html # Generate HTML report
# ./run-tests.sh --parallel # Run tests in parallel
# ./run-tests.sh --verbose # Verbose output
#
set -euo pipefail
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Default options
PYTEST_ARGS=()
TEST_FILTER=""
HTML_REPORT=false
PARALLEL=false
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
unit)
TEST_FILTER="-m unit"
shift
;;
integration)
TEST_FILTER="-m integration"
shift
;;
--html)
HTML_REPORT=true
shift
;;
--parallel|-n)
PARALLEL=true
shift
;;
--verbose|-v)
PYTEST_ARGS+=("-vv")
shift
;;
--help|-h)
echo "Usage: $0 [OPTIONS] [FILTER]"
echo ""
echo "Options:"
echo " unit Run only unit tests"
echo " integration Run only integration tests"
echo " --html Generate HTML report"
echo " --parallel, -n Run tests in parallel"
echo " --verbose, -v Verbose output"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " $0 # Run all tests"
echo " $0 integration # Run only integration tests"
echo " $0 --html # Run all tests with HTML report"
echo " $0 integration --html # Run integration tests with HTML report"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Always generate JUnit XML for GitHub Actions integration
PYTEST_ARGS+=("--junitxml=test-reports/junit.xml")
mkdir -p test-reports
# Add HTML report if requested
if [ "$HTML_REPORT" = true ]; then
PYTEST_ARGS+=("--html=test-reports/report.html" "--self-contained-html")
fi
# Add parallel execution if requested
if [ "$PARALLEL" = true ]; then
PYTEST_ARGS+=("-n" "auto")
fi
# Add test filter if specified
if [ -n "$TEST_FILTER" ]; then
PYTEST_ARGS+=($TEST_FILTER)
fi
# Print configuration
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Mudyla Test Runner${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
echo -e "Test filter: ${YELLOW}${TEST_FILTER:-all tests}${NC}"
echo -e "HTML report: ${YELLOW}${HTML_REPORT}${NC}"
echo -e "Parallel: ${YELLOW}${PARALLEL}${NC}"
echo ""
# Run pytest
echo -e "${BLUE}Running tests...${NC}"
echo ""
if nix develop --command pytest "${PYTEST_ARGS[@]}"; then
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}All tests passed!${NC}"
echo -e "${GREEN}========================================${NC}"
if [ "$HTML_REPORT" = true ]; then
echo ""
echo -e "${BLUE}HTML report generated: test-reports/report.html${NC}"
fi
exit 0
else
echo ""
echo -e "${RED}========================================${NC}"
echo -e "${RED}Tests failed!${NC}"
echo -e "${RED}========================================${NC}"
if [ "$HTML_REPORT" = true ]; then
echo ""
echo -e "${BLUE}HTML report generated: test-reports/report.html${NC}"
fi
exit 1
fi