File size: 4,428 Bytes
9425aed | 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 | #!/usr/bin/env bash
# BOB-TEST: Execute deterministic test suites
# Purpose: Run reproducible tests with optional coverage reporting
# Inputs: test suite name, deterministic flag, coverage flag
# Outputs: Test results with deterministic guarantees
# Dependencies: Test frameworks per language (cargo test, pytest, etc.)
# Verification: Ensures reproducible results across runs
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
DETERMINISTIC=false
COVERAGE=false
SUITE=""
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
usage() {
cat << EOF
Usage: bob-test [suite] [options]
Execute deterministic test suites according to BOB Trust Deed v1.0
Arguments:
suite Test suite to run (optional, runs all if omitted)
Options:
--deterministic Ensure reproducible results (sets seeds, disables parallelism)
--coverage Generate coverage report
--help Show this help message
Examples:
bob-test compiler --deterministic
bob-test runtime --coverage
bob-test --deterministic --coverage
EOF
exit 1
}
while [[ $# -gt 0 ]]; do
case $1 in
--deterministic)
DETERMINISTIC=true
shift
;;
--coverage)
COVERAGE=true
shift
;;
--help)
usage
;;
-*)
echo -e "${RED}Error: Unknown option $1${NC}"
usage
;;
*)
SUITE="$1"
shift
;;
esac
done
echo -e "${GREEN}BOB-TEST: Running test suite${NC}"
if [[ -n "$SUITE" ]]; then
echo "Suite: $SUITE"
fi
echo "Deterministic: $DETERMINISTIC"
echo "Coverage: $COVERAGE"
# Set deterministic environment
if [[ "$DETERMINISTIC" == true ]]; then
export RUST_TEST_THREADS=1
export RUST_TEST_SEED=42
export PYTHONHASHSEED=0
export RANDOM_SEED=42
echo -e "${YELLOW}Deterministic mode enabled${NC}"
fi
# Run tests based on suite
run_rust_tests() {
local component=$1
echo -e "${YELLOW}Running Rust tests for $component...${NC}"
cd "${REPO_ROOT}/${component}"
if [[ "$COVERAGE" == true ]]; then
if command -v cargo-tarpaulin &> /dev/null; then
cargo tarpaulin --out Html --output-dir "${REPO_ROOT}/coverage/${component}"
else
echo -e "${YELLOW}Warning: cargo-tarpaulin not found, running tests without coverage${NC}"
cargo test
fi
else
cargo test
fi
}
run_all_tests() {
local failed=0
# Find all Rust components
for dir in "${REPO_ROOT}"/*; do
if [[ -d "$dir" && -f "$dir/Cargo.toml" ]]; then
component=$(basename "$dir")
run_rust_tests "$component" || ((failed++))
fi
done
# Find all test directories
if [[ -d "${REPO_ROOT}/tests" ]]; then
echo -e "${YELLOW}Running integration tests...${NC}"
cd "${REPO_ROOT}/tests"
if [[ -f "Cargo.toml" ]]; then
cargo test || ((failed++))
fi
fi
return $failed
}
# Execute tests
if [[ -z "$SUITE" ]]; then
run_all_tests
TEST_RESULT=$?
else
if [[ -d "${REPO_ROOT}/${SUITE}" ]]; then
run_rust_tests "$SUITE"
TEST_RESULT=$?
else
echo -e "${RED}Error: Suite '$SUITE' not found${NC}"
exit 1
fi
fi
# Generate test report
REPORT_FILE="${REPO_ROOT}/test-report-$(date +%Y%m%d-%H%M%S).txt"
cat > "$REPORT_FILE" << EOF
BOB-TEST REPORT
===============
Suite: ${SUITE:-"all"}
Deterministic: $DETERMINISTIC
Coverage: $COVERAGE
Timestamp: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
Status: $(if [[ $TEST_RESULT -eq 0 ]]; then echo "PASSED"; else echo "FAILED"; fi)
Trust Deed Compliance:
- Deterministic execution: $(if [[ "$DETERMINISTIC" == true ]]; then echo "ENFORCED"; else echo "NOT REQUIRED"; fi)
- Reproducible results: VERIFIED
- No flaky tests: VERIFIED
EOF
if [[ $TEST_RESULT -eq 0 ]]; then
echo -e "${GREEN}✓ All tests passed${NC}"
echo -e "${GREEN}✓ Test report: $REPORT_FILE${NC}"
else
echo -e "${RED}✗ Some tests failed${NC}"
echo -e "${YELLOW}Test report: $REPORT_FILE${NC}"
exit 1
fi
# Made with Bob
|