diff options
| author | Jesse Vincent <jesse@fsck.com> | 2025-11-23 12:28:58 -0800 |
|---|---|---|
| committer | Jesse Vincent <jesse@fsck.com> | 2025-11-23 12:28:58 -0800 |
| commit | f3d6c331a1950abb19ef1f28a78b01765ad1b873 (patch) | |
| tree | ca3c38443b66345816a8a1557b7cc464f911eec6 /tests/opencode/run-tests.sh | |
| parent | b0ba2cf15afc786940c2cdd984962d4f7d278b4a (diff) | |
test: add automated test suite for opencode plugin
Create comprehensive tests in tests/opencode/ that verify the plugin
works correctly in an isolated test environment:
- setup.sh: Creates temp HOME and installs plugin with proper symlinks
- test-plugin-loading.sh: Verifies plugin structure and JavaScript syntax
- test-skills-core.sh: Unit tests for skills-core.js library functions
- test-tools.sh: Integration tests for use_skill/find_skills (requires OpenCode)
- test-priority.sh: Tests project > personal > superpowers priority
- run-tests.sh: Main test runner with options for integration tests
Run basic tests: ./tests/opencode/run-tests.sh
Run all tests: ./tests/opencode/run-tests.sh --integration
Diffstat (limited to 'tests/opencode/run-tests.sh')
| -rwxr-xr-x | tests/opencode/run-tests.sh | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/tests/opencode/run-tests.sh b/tests/opencode/run-tests.sh new file mode 100755 index 0000000..3ccd93d --- /dev/null +++ b/tests/opencode/run-tests.sh @@ -0,0 +1,165 @@ +#!/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-skills-core.sh Test skills-core.js library functions" + 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" + "test-skills-core.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++)) + 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++)) + else + end_time=$(date +%s) + duration=$((end_time - start_time)) + echo "" + echo " [FAIL] $test (${duration}s)" + ((failed++)) + 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++)) + else + end_time=$(date +%s) + duration=$((end_time - start_time)) + echo " [FAIL] (${duration}s)" + echo "" + echo " Output:" + echo "$output" | sed 's/^/ /' + ((failed++)) + 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 |
