Bash · 3393 bytes Raw Blame History
1 #!/bin/sh
2 # =====================================
3 # POSIX Compliance Test Runner
4 # =====================================
5 # Runs all POSIX compliance test suites for fortsh
6 # Automatically detects fortsh binary location
7
8 set -e
9
10 # Colors
11 RED='\033[0;31m'
12 GREEN='\033[0;32m'
13 YELLOW='\033[1;33m'
14 BLUE='\033[0;34m'
15 CYAN='\033[0;36m'
16 NC='\033[0m'
17
18 # Get script directory
19 SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
20
21 # Find fortsh binary - check multiple locations
22 if [ -n "$FORTSH_BIN" ] && [ -x "$FORTSH_BIN" ]; then
23 # Use environment variable if set
24 FORTSH_PATH="$FORTSH_BIN"
25 elif [ -x "$SCRIPT_DIR/../bin/fortsh" ]; then
26 # Look in ../bin/fortsh (relative to tests/)
27 FORTSH_PATH="$SCRIPT_DIR/../bin/fortsh"
28 elif [ -x "./bin/fortsh" ]; then
29 # Look in ./bin/fortsh (from project root)
30 FORTSH_PATH="./bin/fortsh"
31 elif [ -x "$(pwd)/bin/fortsh" ]; then
32 # Look in current working directory
33 FORTSH_PATH="$(pwd)/bin/fortsh"
34 else
35 printf "${RED}ERROR: fortsh binary not found!${NC}\n"
36 printf "Searched locations:\n"
37 printf " - FORTSH_BIN environment variable\n"
38 printf " - %s/bin/fortsh\n" "$SCRIPT_DIR/.."
39 printf " - ./bin/fortsh\n"
40 printf " - $(pwd)/bin/fortsh\n"
41 printf "\nPlease build fortsh first with 'make' or set FORTSH_BIN\n"
42 exit 1
43 fi
44
45 export FORTSH_BIN="$FORTSH_PATH"
46
47 # Test suite files
48 TEST_SUITES="
49 posix_compliance_test.sh
50 posix_compliance_extended.sh
51 posix_compliance_builtins.sh
52 posix_compliance_advanced.sh
53 posix_compliance_gaps.sh
54 posix_compliance_jobcontrol.sh
55 posix_compliance_coverage.sh
56 posix_compliance_untested.sh
57 "
58
59 # Print header
60 printf "${CYAN}========================================\n"
61 printf "POSIX Compliance Test Suite Runner\n"
62 printf "========================================${NC}\n"
63 printf "fortsh binary: ${GREEN}%s${NC}\n" "$FORTSH_BIN"
64 printf "Test directory: %s\n" "$SCRIPT_DIR"
65 printf "\n"
66
67 # Counters
68 TOTAL_SUITES=0
69 PASSED_SUITES=0
70 FAILED_SUITES=0
71 TOTAL_TESTS=0
72
73 # Run each test suite
74 for suite in $TEST_SUITES; do
75 suite_path="$SCRIPT_DIR/$suite"
76
77 if [ ! -f "$suite_path" ]; then
78 printf "${YELLOW}⊘ SKIP${NC}: %s (not found)\n" "$suite"
79 continue
80 fi
81
82 if [ ! -x "$suite_path" ]; then
83 printf "${YELLOW}⊘ SKIP${NC}: %s (not executable)\n" "$suite"
84 continue
85 fi
86
87 TOTAL_SUITES=$((TOTAL_SUITES + 1))
88
89 printf "${BLUE}========================================\n"
90 printf "Running: %s\n" "$suite"
91 printf "========================================${NC}\n"
92
93 # Run the test suite
94 if "$suite_path"; then
95 printf "${GREEN}✓ PASSED${NC}: %s\n\n" "$suite"
96 PASSED_SUITES=$((PASSED_SUITES + 1))
97 else
98 printf "${RED}✗ FAILED${NC}: %s\n\n" "$suite"
99 FAILED_SUITES=$((FAILED_SUITES + 1))
100 fi
101 done
102
103 # Print summary
104 printf "${CYAN}========================================\n"
105 printf "OVERALL SUMMARY\n"
106 printf "========================================${NC}\n"
107 printf "Total test suites: %d\n" "$TOTAL_SUITES"
108 printf "${GREEN}Passed suites: %d${NC}\n" "$PASSED_SUITES"
109 printf "${RED}Failed suites: %d${NC}\n" "$FAILED_SUITES"
110 printf "${CYAN}========================================${NC}\n"
111
112 if [ "$FAILED_SUITES" -eq 0 ] && [ "$TOTAL_SUITES" -gt 0 ]; then
113 printf "${GREEN}\n✓ ALL TEST SUITES PASSED!\n${NC}"
114 exit 0
115 else
116 printf "${RED}\n✗ SOME TEST SUITES FAILED\n${NC}"
117 exit 1
118 fi