Skip to content

Commit 8dc9402

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
improve integration testing
1 parent ee8a288 commit 8dc9402

File tree

8 files changed

+159
-0
lines changed

8 files changed

+159
-0
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,10 @@ fix:
125125
done; \
126126
exit $$exit_code
127127

128+
.PHONY: test
129+
test:
130+
@echo "Running integration tests..."
131+
@chmod +x $(LINT_ROOT)/test/run_tests.sh
132+
@$(LINT_ROOT)/test/run_tests.sh
133+
128134
# END: lint-install .

test/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/codeGROOVE-dev/lint-install/test
2+
3+
go 1.23

test/run_tests.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

test/test.Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
FROM ubuntu:hirsute-20210723
2+
# DL3008: Pin versions in apt-get install
3+
RUN apt-get update && apt-get install -y curl
4+
# DL3059: Multiple RUN commands should be consolidated
25
RUN echo hello world

test/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Test file with intentional biome lint issues
2+
var unused = "this variable is never used";
3+
4+
function badlyFormatted( x,y ){
5+
const z=x+y
6+
return z
7+
}
8+
9+
// Missing semicolons, bad formatting
10+
let a = 1
11+
let b = 2
12+
console.log(a,b)

test/test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
11
#!/bin/sh
2+
# Test script with intentional shellcheck issues
3+
4+
# SC2006: Use $() instead of backticks
5+
result=`echo "hello"`
6+
7+
# SC2086: Double quote to prevent globbing
8+
echo $result
9+
10+
# SC2164: Use cd ... || exit in case cd fails
11+
cd /tmp
12+
13+
# SC2034: unused variable
14+
unused_var="never used"

test/test.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
# Test YAML with intentional yamllint issues
3+
key1: value1
4+
key2: value2
5+
key3:
6+
- item1
7+
- item2
8+
- nested_badly
9+
key4: "trailing whitespace here "
10+
very_long_line_that_exceeds_the_normal_line_length_limit_and_should_be_flagged_by_yamllint_as_too_long: true

test/test_main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package test
2+
3+
import "fmt"
4+
5+
// TestFunction has intentional golangci-lint issues
6+
func TestFunction() {
7+
// Unused variable
8+
x := 5
9+
10+
// Inefficient string concatenation in loop
11+
var result string
12+
for i := 0; i < 10; i++ {
13+
result = result + fmt.Sprintf("%d", i)
14+
}
15+
16+
fmt.Println(result)
17+
}

0 commit comments

Comments
 (0)