|
| 1 | +#!/bin/bash |
| 2 | +# Integration tests for lint-install |
| 3 | +# This script verifies that each linter catches intentional issues in test files |
| 4 | + |
| 5 | +set -e |
| 6 | + |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 8 | +ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 9 | + |
| 10 | +echo "Running lint-install integration tests..." |
| 11 | +echo "==========================================" |
| 12 | +echo "" |
| 13 | + |
| 14 | +# Colors for output |
| 15 | +RED='\033[0;31m' |
| 16 | +GREEN='\033[0;32m' |
| 17 | +YELLOW='\033[1;33m' |
| 18 | +NC='\033[0m' # No Color |
| 19 | + |
| 20 | +test_count=0 |
| 21 | +pass_count=0 |
| 22 | +fail_count=0 |
| 23 | + |
| 24 | +# Helper function to run a test |
| 25 | +run_test() { |
| 26 | + local linter_name=$1 |
| 27 | + local command=$2 |
| 28 | + local expected_failure=$3 # "should_fail" or "should_pass" |
| 29 | + |
| 30 | + test_count=$((test_count + 1)) |
| 31 | + echo -n "Testing ${linter_name}... " |
| 32 | + |
| 33 | + if eval "$command" > /dev/null 2>&1; then |
| 34 | + # Command succeeded |
| 35 | + if [ "$expected_failure" = "should_fail" ]; then |
| 36 | + echo -e "${RED}FAIL${NC} (expected to catch issues but passed)" |
| 37 | + fail_count=$((fail_count + 1)) |
| 38 | + return 1 |
| 39 | + else |
| 40 | + echo -e "${GREEN}PASS${NC}" |
| 41 | + pass_count=$((pass_count + 1)) |
| 42 | + return 0 |
| 43 | + fi |
| 44 | + else |
| 45 | + # Command failed |
| 46 | + if [ "$expected_failure" = "should_fail" ]; then |
| 47 | + echo -e "${GREEN}PASS${NC} (correctly caught issues)" |
| 48 | + pass_count=$((pass_count + 1)) |
| 49 | + return 0 |
| 50 | + else |
| 51 | + echo -e "${RED}FAIL${NC} (unexpected failure)" |
| 52 | + fail_count=$((fail_count + 1)) |
| 53 | + return 1 |
| 54 | + fi |
| 55 | + fi |
| 56 | +} |
| 57 | + |
| 58 | +# Build the lint-install binary if needed |
| 59 | +cd "$ROOT_DIR" |
| 60 | +if [ ! -f "./lint-install" ]; then |
| 61 | + echo "Building lint-install..." |
| 62 | + go build -o lint-install . |
| 63 | + echo "" |
| 64 | +fi |
| 65 | + |
| 66 | +# Test 1: Shellcheck should catch issues in test.sh |
| 67 | +run_test "shellcheck" "make shellcheck-lint" "should_fail" |
| 68 | + |
| 69 | +# Test 2: Hadolint should catch issues in test.Dockerfile |
| 70 | +run_test "hadolint" "make hadolint-lint" "should_fail" |
| 71 | + |
| 72 | +# Test 3: Biome should catch issues in test.js |
| 73 | +run_test "biome" "make biome-lint" "should_fail" |
| 74 | + |
| 75 | +# Test 4: Yamllint should catch issues in test.yaml |
| 76 | +run_test "yamllint" "make yamllint-lint" "should_fail" |
| 77 | + |
| 78 | +# Test 5: Golangci-lint should catch issues in test/test_main.go |
| 79 | +run_test "golangci-lint" "cd test && make golangci-lint-lint" "should_fail" |
| 80 | + |
| 81 | +echo "" |
| 82 | +echo "==========================================" |
| 83 | +echo "Test Results:" |
| 84 | +echo -e " ${GREEN}Passed: ${pass_count}${NC}" |
| 85 | +echo -e " ${RED}Failed: ${fail_count}${NC}" |
| 86 | +echo -e " Total: ${test_count}" |
| 87 | +echo "" |
| 88 | + |
| 89 | +if [ $fail_count -eq 0 ]; then |
| 90 | + echo -e "${GREEN}All tests passed!${NC}" |
| 91 | + exit 0 |
| 92 | +else |
| 93 | + echo -e "${RED}Some tests failed.${NC}" |
| 94 | + exit 1 |
| 95 | +fi |
0 commit comments