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