1
0

run-tests.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/usr/bin/env bash
  2. # Main test runner for OpenCode plugin test suite
  3. # Runs all tests and reports results
  4. set -euo pipefail
  5. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  6. cd "$SCRIPT_DIR"
  7. echo "========================================"
  8. echo " OpenCode Plugin Test Suite"
  9. echo "========================================"
  10. echo ""
  11. echo "Repository: $(cd ../.. && pwd)"
  12. echo "Test time: $(date)"
  13. echo ""
  14. # Parse command line arguments
  15. RUN_INTEGRATION=false
  16. VERBOSE=false
  17. SPECIFIC_TEST=""
  18. while [[ $# -gt 0 ]]; do
  19. case $1 in
  20. --integration|-i)
  21. RUN_INTEGRATION=true
  22. shift
  23. ;;
  24. --verbose|-v)
  25. VERBOSE=true
  26. shift
  27. ;;
  28. --test|-t)
  29. SPECIFIC_TEST="$2"
  30. shift 2
  31. ;;
  32. --help|-h)
  33. echo "Usage: $0 [options]"
  34. echo ""
  35. echo "Options:"
  36. echo " --integration, -i Run integration tests (requires OpenCode)"
  37. echo " --verbose, -v Show verbose output"
  38. echo " --test, -t NAME Run only the specified test"
  39. echo " --help, -h Show this help"
  40. echo ""
  41. echo "Tests:"
  42. echo " test-plugin-loading.sh Verify plugin installation and structure"
  43. echo " test-tools.sh Test use_skill and find_skills tools (integration)"
  44. echo " test-priority.sh Test skill priority resolution (integration)"
  45. exit 0
  46. ;;
  47. *)
  48. echo "Unknown option: $1"
  49. echo "Use --help for usage information"
  50. exit 1
  51. ;;
  52. esac
  53. done
  54. # List of tests to run (no external dependencies)
  55. tests=(
  56. "test-plugin-loading.sh"
  57. )
  58. # Integration tests (require OpenCode)
  59. integration_tests=(
  60. "test-tools.sh"
  61. "test-priority.sh"
  62. )
  63. # Add integration tests if requested
  64. if [ "$RUN_INTEGRATION" = true ]; then
  65. tests+=("${integration_tests[@]}")
  66. fi
  67. # Filter to specific test if requested
  68. if [ -n "$SPECIFIC_TEST" ]; then
  69. tests=("$SPECIFIC_TEST")
  70. fi
  71. # Track results
  72. passed=0
  73. failed=0
  74. skipped=0
  75. # Run each test
  76. for test in "${tests[@]}"; do
  77. echo "----------------------------------------"
  78. echo "Running: $test"
  79. echo "----------------------------------------"
  80. test_path="$SCRIPT_DIR/$test"
  81. if [ ! -f "$test_path" ]; then
  82. echo " [SKIP] Test file not found: $test"
  83. skipped=$((skipped + 1))
  84. continue
  85. fi
  86. if [ ! -x "$test_path" ]; then
  87. echo " Making $test executable..."
  88. chmod +x "$test_path"
  89. fi
  90. start_time=$(date +%s)
  91. if [ "$VERBOSE" = true ]; then
  92. if bash "$test_path"; then
  93. end_time=$(date +%s)
  94. duration=$((end_time - start_time))
  95. echo ""
  96. echo " [PASS] $test (${duration}s)"
  97. passed=$((passed + 1))
  98. else
  99. end_time=$(date +%s)
  100. duration=$((end_time - start_time))
  101. echo ""
  102. echo " [FAIL] $test (${duration}s)"
  103. failed=$((failed + 1))
  104. fi
  105. else
  106. # Capture output for non-verbose mode
  107. if output=$(bash "$test_path" 2>&1); then
  108. end_time=$(date +%s)
  109. duration=$((end_time - start_time))
  110. echo " [PASS] (${duration}s)"
  111. passed=$((passed + 1))
  112. else
  113. end_time=$(date +%s)
  114. duration=$((end_time - start_time))
  115. echo " [FAIL] (${duration}s)"
  116. echo ""
  117. echo " Output:"
  118. echo "$output" | sed 's/^/ /'
  119. failed=$((failed + 1))
  120. fi
  121. fi
  122. echo ""
  123. done
  124. # Print summary
  125. echo "========================================"
  126. echo " Test Results Summary"
  127. echo "========================================"
  128. echo ""
  129. echo " Passed: $passed"
  130. echo " Failed: $failed"
  131. echo " Skipped: $skipped"
  132. echo ""
  133. if [ "$RUN_INTEGRATION" = false ] && [ ${#integration_tests[@]} -gt 0 ]; then
  134. echo "Note: Integration tests were not run."
  135. echo "Use --integration flag to run tests that require OpenCode."
  136. echo ""
  137. fi
  138. if [ $failed -gt 0 ]; then
  139. echo "STATUS: FAILED"
  140. exit 1
  141. else
  142. echo "STATUS: PASSED"
  143. exit 0
  144. fi