Skip to content

Commit 1e5f33f

Browse files
committed
Add java to it tests
1 parent c29ef51 commit 1e5f33f

14 files changed

Lines changed: 219 additions & 253 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'Tool Tests'
2+
description: 'Run tool tests with specified shell'
3+
4+
inputs:
5+
shell:
6+
description: 'Shell to use (bash or pwsh)'
7+
required: true
8+
default: 'bash'
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Run tool tests
14+
shell: ${{ inputs.shell }}
15+
run: |
16+
if [ "${{ inputs.shell }}" = "pwsh" ]; then
17+
# Windows native execution
18+
Get-ChildItem -Path "plugins/tools" -Directory | ForEach-Object {
19+
$toolDir = $_.FullName
20+
$testDir = Join-Path $toolDir "test"
21+
if (Test-Path $testDir) {
22+
Write-Host "Running tests for $testDir..."
23+
& ./integration-tests/run.ps1 $testDir
24+
if ($LASTEXITCODE -ne 0) {
25+
Add-Content -Path "failed_tests.txt" -Value $testDir
26+
}
27+
}
28+
}
29+
else
30+
# Unix/WSL execution
31+
chmod +x integration-tests/run.sh
32+
echo "" > failed_tests.txt
33+
for tool_dir in plugins/tools/*/test; do
34+
if [ -d "$tool_dir" ]; then
35+
echo "Running tests for $tool_dir..."
36+
if ! ./integration-tests/run.sh "$tool_dir"; then
37+
echo "$tool_dir" >> failed_tests.txt
38+
fi
39+
fi
40+
done
41+
fi
42+
43+
# Check if any tests failed
44+
if [ -s failed_tests.txt ]; then
45+
echo "The following tests failed:"
46+
cat failed_tests.txt
47+
exit 1
48+
fi

.github/workflows/it-test.yml

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,10 @@ jobs:
6868
if: matrix.os != 'windows-latest'
6969
run: chmod +x cli-v2
7070

71-
- name: Install yq on Windows
72-
if: matrix.os == 'windows-latest'
73-
shell: pwsh
74-
run: |
75-
choco install yq -y
76-
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
77-
refreshenv
78-
79-
- name: Run init tests on Windows
71+
- name: Run init tests on Windows native
8072
if: matrix.os == 'windows-latest'
73+
id: run_init_tests_windows
74+
continue-on-error: true
8175
shell: pwsh
8276
run: |
8377
$ErrorActionPreference = "Stop"
@@ -100,43 +94,49 @@ jobs:
10094
chmod +x integration-tests/run.sh
10195
./integration-tests/run.sh
10296
103-
- name: Run tool tests
97+
- name: Run tool tests on Windows
98+
if: matrix.os == 'windows-latest'
99+
id: run_tool_tests_windows_wsl
100+
uses: ./.github/actions/tool-tests
101+
with:
102+
shell: pwsh
103+
104+
- name: Run tool tests on Unix
104105
if: matrix.os != 'windows-latest'
105-
id: run_tests
106-
continue-on-error: true
106+
id: run_tool_tests_unix
107+
uses: ./.github/actions/tool-tests
108+
with:
109+
shell: bash
110+
111+
- name: Check test results
112+
if: always()
107113
shell: bash
108114
run: |
109-
# Make the script executable
110-
chmod +x run-tool-tests.sh
115+
FAILED=false
111116
112-
# Initialize failed tools file
113-
rm -f /tmp/failed_tools.txt
114-
touch /tmp/failed_tools.txt
115-
116-
# Run tests for each tool directory
117-
for tool_dir in plugins/tools/*/; do
118-
tool_name=$(basename "$tool_dir")
119-
if [ -d "$tool_dir/test/src" ]; then
120-
echo "Running tests for $tool_name..."
121-
./run-tool-tests.sh "$tool_name" || {
122-
echo "❌ Test failed for $tool_name"
123-
echo "$tool_name" >> /tmp/failed_tools.txt
124-
}
117+
# Check init tests
118+
if [ "${{ matrix.os }}" = "windows-latest" ]; then
119+
if [ "${{ steps.run_init_tests_windows.outcome }}" = "failure" ]; then
120+
echo "::error::Windows init tests failed"
121+
FAILED=true
122+
fi
123+
if [ "${{ steps.run_tool_tests_windows.outcome }}" = "failure" ]; then
124+
echo "::error::Windows tool tests failed"
125+
FAILED=true
125126
fi
126-
done
127-
128-
# Check if any tools failed
129-
if [ -s /tmp/failed_tools.txt ] && [ "$(wc -l < /tmp/failed_tools.txt)" -gt 0 ]; then
130-
echo -e "\n❌ The following tools failed their tests:"
131-
cat /tmp/failed_tools.txt
132-
echo "::error::Some tool tests failed. Please check the logs above for details."
133-
exit 1
134127
else
135-
echo "✅ All tool tests passed successfully!"
128+
if [ "${{ steps.run_init_tests_unix.outcome }}" = "failure" ]; then
129+
echo "::error::Unix init tests failed"
130+
FAILED=true
131+
fi
132+
if [ "${{ steps.run_tool_tests_unix.outcome }}" = "failure" ]; then
133+
echo "::error::Unix tool tests failed"
134+
FAILED=true
135+
fi
136136
fi
137-
138-
- name: Check test results
139-
if: failure()
140-
run: |
141-
echo "Job failed because some tests failed. Please check the logs above for details."
142-
exit 1
137+
138+
# Fail if any tests failed
139+
if [ "${FAILED:-false}" = "true" ]; then
140+
echo "Some tests failed. Please check the logs above for details."
141+
exit 1
142+
fi

.github/workflows/tool-tests.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Tool Tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
shell:
7+
required: true
8+
type: string
9+
description: 'Shell to use (bash or wsl)'
10+
11+
jobs:
12+
tool-tests:
13+
runs-on: ${{ matrix.os }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: '1.21'
24+
cache: true
25+
26+
- name: Download CLI binaries
27+
uses: actions/download-artifact@v4
28+
with:
29+
name: cli-binaries
30+
path: .
31+
32+
- name: Select correct binary
33+
shell: bash
34+
run: |
35+
if [ "${{ matrix.os }}" = "windows-latest" ]; then
36+
# Keep the .exe extension for Windows
37+
echo "Using Windows binary with .exe extension"
38+
elif [ "${{ matrix.os }}" = "macos-latest" ]; then
39+
mv cli-v2-macos cli-v2
40+
else
41+
mv cli-v2-linux cli-v2
42+
fi
43+
44+
- name: Make binary executable
45+
if: matrix.os != 'windows-latest'
46+
run: chmod +x cli-v2
47+
48+
- name: Run tool tests
49+
id: run_tests
50+
continue-on-error: true
51+
shell: ${{ inputs.shell }}
52+
run: |
53+
# Make the script executable
54+
chmod +x run-tool-tests.sh
55+
56+
# Initialize failed tools file
57+
rm -f /tmp/failed_tools.txt
58+
touch /tmp/failed_tools.txt
59+
60+
# Run tests for each tool directory
61+
for tool_dir in plugins/tools/*/; do
62+
tool_name=$(basename "$tool_dir")
63+
if [ -d "$tool_dir/test/src" ]; then
64+
echo "Running tests for $tool_name..."
65+
./run-tool-tests.sh "$tool_name" || {
66+
echo "❌ Test failed for $tool_name"
67+
echo "$tool_name" >> /tmp/failed_tools.txt
68+
}
69+
fi
70+
done
71+
72+
# Check if any tools failed
73+
if [ -s /tmp/failed_tools.txt ] && [ "$(wc -l < /tmp/failed_tools.txt)" -gt 0 ]; then
74+
echo -e "\n❌ The following tools failed their tests:"
75+
cat /tmp/failed_tools.txt
76+
echo "::error::Some tool tests failed. Please check the logs above for details."
77+
exit 1
78+
else
79+
echo "✅ All tool tests passed successfully!"
80+
fi

integration-tests/init-with-token/expected/codacy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
runtimes:
22
- node@22.2.0
33
- python@3.11.11
4+
- java@17.0.10
45
tools:
56
- eslint@8.57.0
67
- trivy@0.59.1

integration-tests/init-without-token/expected/codacy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ runtimes:
22
- node@22.2.0
33
- python@3.11.11
44
- dart@3.7.2
5+
- java@17.0.10
56
tools:
67
- eslint@9.3.0
78
- trivy@0.59.1

integration-tests/run.ps1

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,41 @@ function Normalize-Config {
2020
$ext = [System.IO.Path]::GetExtension($file).TrimStart('.')
2121

2222
switch ($ext) {
23-
{ $_ -in @('yaml', 'yml') } { yq e '.' $file | Sort-Object }
23+
{ $_ -in @('yaml', 'yml') } {
24+
# Parse YAML content and sort
25+
$content = Get-Content $file -Raw
26+
$lines = $content -split "`n"
27+
$sortedLines = @()
28+
$currentSection = @()
29+
30+
foreach ($line in $lines) {
31+
if ($line -match '^\s*-') {
32+
# This is a list item, add to current section
33+
$currentSection += $line
34+
} elseif ($line -match '^\s*[a-zA-Z]') {
35+
# This is a new section, sort previous section if exists
36+
if ($currentSection.Count -gt 0) {
37+
$sortedLines += ($currentSection | Sort-Object)
38+
$currentSection = @()
39+
}
40+
$sortedLines += $line
41+
} else {
42+
# Keep other lines as is
43+
if ($currentSection.Count -gt 0) {
44+
$sortedLines += ($currentSection | Sort-Object)
45+
$currentSection = @()
46+
}
47+
$sortedLines += $line
48+
}
49+
}
50+
51+
# Add any remaining section
52+
if ($currentSection.Count -gt 0) {
53+
$sortedLines += ($currentSection | Sort-Object)
54+
}
55+
56+
$sortedLines
57+
}
2458
{ $_ -in @('rc', 'conf', 'ini', 'xml') } {
2559
Get-Content $file | ForEach-Object {
2660
if ($_ -match '^[^#].*=.*,') {

plugins/tools/codacy-enigma-cli/test/expected.sarif

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
{
66
"tool": {
77
"driver": {
8-
"name": "codacy-enigma-cli"
8+
"name": "codacy-enigma-cli",
9+
"rules": null
910
}
1011
},
1112
"results": [

plugins/tools/dartanalyzer/test/expected.sarif

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@
4242
],
4343
"tool": {
4444
"driver": {
45-
"name": "dartanalyzer"
45+
"name": "dartanalyzer",
46+
"rules": null
4647
}
4748
}
4849
}
4950
],
5051
"version": "2.1.0"
51-
}
52+
}

plugins/tools/eslint/test/expected.sarif

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
"driver": {
4545
"informationUri": "https://eslint.org",
4646
"name": "ESLint",
47-
"rules": [],
47+
"rules": null,
4848
"version": "8.57.0"
4949
}
5050
}
5151
}
5252
],
5353
"version": "2.1.0"
54-
}
54+
}

plugins/tools/lizard/test/expected.sarif

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,7 @@
88
"name": "Lizard",
99
"version": "1.17.10",
1010
"informationUri": "https://github.com/terryyin/lizard",
11-
"rules": [
12-
{
13-
"id": "Lizard_ccn-medium",
14-
"shortDescription": {
15-
"text": "Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Medium issue. The default threshold is 8."
16-
},
17-
"properties": {
18-
"tags": [
19-
"warning"
20-
]
21-
}
22-
},
23-
{
24-
"id": "Lizard_file-nloc-medium",
25-
"shortDescription": {
26-
"text": "Check the number of lines of code (without comments) in a file. If the threshold is not met, raise a Medium issue. The default threshold is 500."
27-
},
28-
"properties": {
29-
"tags": [
30-
"warning"
31-
]
32-
}
33-
},
34-
{
35-
"id": "Lizard_nloc-medium",
36-
"shortDescription": {
37-
"text": "Check the number of lines of code (without comments) in a function. If the threshold is not met, raise a Medium issue. The default threshold is 50."
38-
},
39-
"properties": {
40-
"tags": [
41-
"warning"
42-
]
43-
}
44-
},
45-
{
46-
"id": "Lizard_parameter-count-medium",
47-
"shortDescription": {
48-
"text": "Check the number of parameters sent to a function. If the threshold is not met, raise a Medium issue. The default threshold is 8."
49-
},
50-
"properties": {
51-
"tags": [
52-
"warning"
53-
]
54-
}
55-
}
56-
]
11+
"rules": null
5712
}
5813
},
5914
"results": [

0 commit comments

Comments
 (0)