run-tests.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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-skills-core.sh Test skills-core.js library functions"
  44. echo " test-tools.sh Test use_skill and find_skills tools (integration)"
  45. echo " test-priority.sh Test skill priority resolution (integration)"
  46. exit 0
  47. ;;
  48. *)
  49. echo "Unknown option: $1"
  50. echo "Use --help for usage information"
  51. exit 1
  52. ;;
  53. esac
  54. done
  55. # List of tests to run (no external dependencies)
  56. tests=(
  57. "test-plugin-loading.sh"
  58. "test-skills-core.sh"
  59. )
  60. # Integration tests (require OpenCode)
  61. integration_tests=(
  62. "test-tools.sh"
  63. "test-priority.sh"
  64. )
  65. # Add integration tests if requested
  66. if [ "$RUN_INTEGRATION" = true ]; then
  67. tests+=("${integration_tests[@]}")
  68. fi
  69. # Filter to specific test if requested
  70. if [ -n "$SPECIFIC_TEST" ]; then
  71. tests=("$SPECIFIC_TEST")
  72. fi
  73. # Track results
  74. passed=0
  75. failed=0
  76. skipped=0
  77. # Run each test
  78. for test in "${tests[@]}"; do
  79. echo "----------------------------------------"
  80. echo "Running: $test"
  81. echo "----------------------------------------"
  82. test_path="$SCRIPT_DIR/$test"
  83. if [ ! -f "$test_path" ]; then
  84. echo " [SKIP] Test file not found: $test"
  85. skipped=$((skipped + 1))
  86. continue
  87. fi
  88. if [ ! -x "$test_path" ]; then
  89. echo " Making $test executable..."
  90. chmod +x "$test_path"
  91. fi
  92. start_time=$(date +%s)
  93. if [ "$VERBOSE" = true ]; then
  94. if bash "$test_path"; then
  95. end_time=$(date +%s)
  96. duration=$((end_time - start_time))
  97. echo ""
  98. echo " [PASS] $test (${duration}s)"
  99. passed=$((passed + 1))
  100. else
  101. end_time=$(date +%s)
  102. duration=$((end_time - start_time))
  103. echo ""
  104. echo " [FAIL] $test (${duration}s)"
  105. failed=$((failed + 1))
  106. fi
  107. else
  108. # Capture output for non-verbose mode
  109. if output=$(bash "$test_path" 2>&1); then
  110. end_time=$(date +%s)
  111. duration=$((end_time - start_time))
  112. echo " [PASS] (${duration}s)"
  113. passed=$((passed + 1))
  114. else
  115. end_time=$(date +%s)
  116. duration=$((end_time - start_time))
  117. echo " [FAIL] (${duration}s)"
  118. echo ""
  119. echo " Output:"
  120. echo "$output" | sed 's/^/ /'
  121. failed=$((failed + 1))
  122. fi
  123. fi
  124. echo ""
  125. done
  126. # Print summary
  127. echo "========================================"
  128. echo " Test Results Summary"
  129. echo "========================================"
  130. echo ""
  131. echo " Passed: $passed"
  132. echo " Failed: $failed"
  133. echo " Skipped: $skipped"
  134. echo ""
  135. if [ "$RUN_INTEGRATION" = false ] && [ ${#integration_tests[@]} -gt 0 ]; then
  136. echo "Note: Integration tests were not run."
  137. echo "Use --integration flag to run tests that require OpenCode."
  138. echo ""
  139. fi
  140. if [ $failed -gt 0 ]; then
  141. echo "STATUS: FAILED"
  142. exit 1
  143. else
  144. echo "STATUS: PASSED"
  145. exit 0
  146. fi