| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- #!/usr/bin/env bash
- # Main test runner for OpenCode plugin test suite
- # Runs all tests and reports results
- set -euo pipefail
- SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
- cd "$SCRIPT_DIR"
- echo "========================================"
- echo " OpenCode Plugin Test Suite"
- echo "========================================"
- echo ""
- echo "Repository: $(cd ../.. && pwd)"
- echo "Test time: $(date)"
- echo ""
- # Parse command line arguments
- RUN_INTEGRATION=false
- VERBOSE=false
- SPECIFIC_TEST=""
- while [[ $# -gt 0 ]]; do
- case $1 in
- --integration|-i)
- RUN_INTEGRATION=true
- shift
- ;;
- --verbose|-v)
- VERBOSE=true
- shift
- ;;
- --test|-t)
- SPECIFIC_TEST="$2"
- shift 2
- ;;
- --help|-h)
- echo "Usage: $0 [options]"
- echo ""
- echo "Options:"
- echo " --integration, -i Run integration tests (requires OpenCode)"
- echo " --verbose, -v Show verbose output"
- echo " --test, -t NAME Run only the specified test"
- echo " --help, -h Show this help"
- echo ""
- echo "Tests:"
- echo " test-plugin-loading.sh Verify plugin installation and structure"
- echo " test-tools.sh Test use_skill and find_skills tools (integration)"
- echo " test-priority.sh Test skill priority resolution (integration)"
- exit 0
- ;;
- *)
- echo "Unknown option: $1"
- echo "Use --help for usage information"
- exit 1
- ;;
- esac
- done
- # List of tests to run (no external dependencies)
- tests=(
- "test-plugin-loading.sh"
- )
- # Integration tests (require OpenCode)
- integration_tests=(
- "test-tools.sh"
- "test-priority.sh"
- )
- # Add integration tests if requested
- if [ "$RUN_INTEGRATION" = true ]; then
- tests+=("${integration_tests[@]}")
- fi
- # Filter to specific test if requested
- if [ -n "$SPECIFIC_TEST" ]; then
- tests=("$SPECIFIC_TEST")
- fi
- # Track results
- passed=0
- failed=0
- skipped=0
- # Run each test
- for test in "${tests[@]}"; do
- echo "----------------------------------------"
- echo "Running: $test"
- echo "----------------------------------------"
- test_path="$SCRIPT_DIR/$test"
- if [ ! -f "$test_path" ]; then
- echo " [SKIP] Test file not found: $test"
- skipped=$((skipped + 1))
- continue
- fi
- if [ ! -x "$test_path" ]; then
- echo " Making $test executable..."
- chmod +x "$test_path"
- fi
- start_time=$(date +%s)
- if [ "$VERBOSE" = true ]; then
- if bash "$test_path"; then
- end_time=$(date +%s)
- duration=$((end_time - start_time))
- echo ""
- echo " [PASS] $test (${duration}s)"
- passed=$((passed + 1))
- else
- end_time=$(date +%s)
- duration=$((end_time - start_time))
- echo ""
- echo " [FAIL] $test (${duration}s)"
- failed=$((failed + 1))
- fi
- else
- # Capture output for non-verbose mode
- if output=$(bash "$test_path" 2>&1); then
- end_time=$(date +%s)
- duration=$((end_time - start_time))
- echo " [PASS] (${duration}s)"
- passed=$((passed + 1))
- else
- end_time=$(date +%s)
- duration=$((end_time - start_time))
- echo " [FAIL] (${duration}s)"
- echo ""
- echo " Output:"
- echo "$output" | sed 's/^/ /'
- failed=$((failed + 1))
- fi
- fi
- echo ""
- done
- # Print summary
- echo "========================================"
- echo " Test Results Summary"
- echo "========================================"
- echo ""
- echo " Passed: $passed"
- echo " Failed: $failed"
- echo " Skipped: $skipped"
- echo ""
- if [ "$RUN_INTEGRATION" = false ] && [ ${#integration_tests[@]} -gt 0 ]; then
- echo "Note: Integration tests were not run."
- echo "Use --integration flag to run tests that require OpenCode."
- echo ""
- fi
- if [ $failed -gt 0 ]; then
- echo "STATUS: FAILED"
- exit 1
- else
- echo "STATUS: PASSED"
- exit 0
- fi
|