test_plugins.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. # Run ArchiveBox plugin tests
  3. #
  4. # All plugin tests use pytest and are located in pluginname/tests/test_*.py
  5. #
  6. # Usage: ./bin/run_plugin_tests.sh [plugin_name]
  7. #
  8. # Examples:
  9. # ./bin/run_plugin_tests.sh # Run all plugin tests
  10. # ./bin/run_plugin_tests.sh chrome # Run chrome plugin tests
  11. # ./bin/run_plugin_tests.sh parse_* # Run all parse_* plugin tests
  12. set -e
  13. # Color codes
  14. GREEN='\033[0;32m'
  15. RED='\033[0;31m'
  16. YELLOW='\033[1;33m'
  17. NC='\033[0m' # No Color
  18. # Parse arguments
  19. PLUGIN_FILTER="${1:-}"
  20. # Change to plugins directory
  21. cd "$(dirname "$0")/../archivebox/plugins" || exit 1
  22. echo "=========================================="
  23. echo "ArchiveBox Plugin Tests"
  24. echo "=========================================="
  25. echo ""
  26. if [ -n "$PLUGIN_FILTER" ]; then
  27. echo "Filter: $PLUGIN_FILTER"
  28. else
  29. echo "Running all plugin tests"
  30. fi
  31. echo ""
  32. # Track results
  33. TOTAL_PLUGINS=0
  34. PASSED_PLUGINS=0
  35. FAILED_PLUGINS=0
  36. # Find and run plugin tests
  37. if [ -n "$PLUGIN_FILTER" ]; then
  38. # Run tests for specific plugin(s) matching pattern
  39. TEST_DIRS=$(find . -maxdepth 2 -type d -path "./${PLUGIN_FILTER}*/tests" 2>/dev/null | sort)
  40. else
  41. # Run all plugin tests
  42. TEST_DIRS=$(find . -maxdepth 2 -type d -name "tests" -path "./*/tests" 2>/dev/null | sort)
  43. fi
  44. if [ -z "$TEST_DIRS" ]; then
  45. echo -e "${YELLOW}No plugin tests found${NC}"
  46. [ -n "$PLUGIN_FILTER" ] && echo "Pattern: $PLUGIN_FILTER"
  47. exit 0
  48. fi
  49. for test_dir in $TEST_DIRS; do
  50. # Check if there are any Python test files
  51. if ! compgen -G "${test_dir}/test_*.py" > /dev/null 2>&1; then
  52. continue
  53. fi
  54. plugin_name=$(basename $(dirname "$test_dir"))
  55. TOTAL_PLUGINS=$((TOTAL_PLUGINS + 1))
  56. echo -e "${YELLOW}[RUNNING]${NC} $plugin_name"
  57. if python -m pytest "$test_dir" -v --tb=short 2>&1 | grep -v "^platform\|^cachedir\|^rootdir\|^configfile\|^plugins:" | tail -100; then
  58. echo -e "${GREEN}[PASSED]${NC} $plugin_name"
  59. PASSED_PLUGINS=$((PASSED_PLUGINS + 1))
  60. else
  61. echo -e "${RED}[FAILED]${NC} $plugin_name"
  62. FAILED_PLUGINS=$((FAILED_PLUGINS + 1))
  63. fi
  64. echo ""
  65. done
  66. # Print summary
  67. echo "=========================================="
  68. echo "Test Summary"
  69. echo "=========================================="
  70. echo -e "Total plugins tested: $TOTAL_PLUGINS"
  71. echo -e "${GREEN}Passed:${NC} $PASSED_PLUGINS"
  72. echo -e "${RED}Failed:${NC} $FAILED_PLUGINS"
  73. echo ""
  74. if [ $TOTAL_PLUGINS -eq 0 ]; then
  75. echo -e "${YELLOW}⚠ No tests found${NC}"
  76. exit 0
  77. elif [ $FAILED_PLUGINS -eq 0 ]; then
  78. echo -e "${GREEN}✓ All plugin tests passed!${NC}"
  79. exit 0
  80. else
  81. echo -e "${RED}✗ Some plugin tests failed${NC}"
  82. exit 1
  83. fi