Skip to content

Commit 98a6c9c

Browse files
committed
move pmd test files
1 parent 891d477 commit 98a6c9c

File tree

6 files changed

+26
-278
lines changed

6 files changed

+26
-278
lines changed
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tools
1+
package pmd
22

33
import (
44
"encoding/xml"
@@ -7,6 +7,9 @@ import (
77
"strings"
88
"testing"
99

10+
"codacy/cli-v2/tools"
11+
"codacy/cli-v2/tools/pmd"
12+
1013
"github.com/stretchr/testify/assert"
1114
)
1215

@@ -35,13 +38,18 @@ type PMDProperty struct {
3538
Value string `xml:"value,attr"`
3639
}
3740

41+
// CreatePmdConfig is a wrapper around the actual implementation to make it testable
42+
func CreatePmdConfig(config tools.ToolConfiguration) string {
43+
return pmd.CreatePmdConfig(config)
44+
}
45+
3846
func TestCreatePmdConfig(t *testing.T) {
3947
// Setup test configuration with patterns
40-
config := ToolConfiguration{
41-
PatternsConfiguration: []PatternConfiguration{
48+
config := tools.ToolConfiguration{
49+
PatternsConfiguration: []tools.PatternConfiguration{
4250
{
4351
PatternId: "java/codestyle/AtLeastOneConstructor",
44-
ParameterConfigurations: []PatternParameterConfiguration{
52+
ParameterConfigurations: []tools.PatternParameterConfiguration{
4553
{
4654
Name: "enabled",
4755
Value: "true",
@@ -50,7 +58,7 @@ func TestCreatePmdConfig(t *testing.T) {
5058
},
5159
{
5260
PatternId: "java/design/UnusedPrivateField",
53-
ParameterConfigurations: []PatternParameterConfiguration{
61+
ParameterConfigurations: []tools.PatternParameterConfiguration{
5462
{
5563
Name: "enabled",
5664
Value: "true",
@@ -59,7 +67,7 @@ func TestCreatePmdConfig(t *testing.T) {
5967
},
6068
{
6169
PatternId: "java/design/LoosePackageCoupling",
62-
ParameterConfigurations: []PatternParameterConfiguration{
70+
ParameterConfigurations: []tools.PatternParameterConfiguration{
6371
{
6472
Name: "enabled",
6573
Value: "true",
@@ -77,7 +85,7 @@ func TestCreatePmdConfig(t *testing.T) {
7785
generatedConfig := CreatePmdConfig(config)
7886

7987
// Read expected ruleset
80-
expectedRulesetPath := filepath.Join("testdata", "repositories", "pmd", "expected-ruleset.xml")
88+
expectedRulesetPath := "expected-ruleset.xml"
8189
expectedRulesetBytes, err := os.ReadFile(expectedRulesetPath)
8290
if err != nil {
8391
t.Fatalf("Failed to read expected ruleset: %v", err)
@@ -105,11 +113,11 @@ func TestCreatePmdConfig(t *testing.T) {
105113
}
106114

107115
func TestCreatePmdConfigWithDisabledRules(t *testing.T) {
108-
config := ToolConfiguration{
109-
PatternsConfiguration: []PatternConfiguration{
116+
config := tools.ToolConfiguration{
117+
PatternsConfiguration: []tools.PatternConfiguration{
110118
{
111119
PatternId: "java/codestyle/AtLeastOneConstructor",
112-
ParameterConfigurations: []PatternParameterConfiguration{
120+
ParameterConfigurations: []tools.PatternParameterConfiguration{
113121
{
114122
Name: "enabled",
115123
Value: "false",
@@ -163,8 +171,8 @@ func TestCreatePmdConfigEmpty(t *testing.T) {
163171
}
164172
defer os.Chdir(cwd)
165173

166-
config := ToolConfiguration{
167-
PatternsConfiguration: []PatternConfiguration{},
174+
config := tools.ToolConfiguration{
175+
PatternsConfiguration: []tools.PatternConfiguration{},
168176
}
169177

170178
obtainedConfig := CreatePmdConfig(config)
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tools
1+
package pmd
22

33
import (
44
"encoding/json"
@@ -8,6 +8,8 @@ import (
88
"strings"
99
"testing"
1010

11+
"codacy/cli-v2/tools/pmd"
12+
1113
"github.com/stretchr/testify/assert"
1214
)
1315

@@ -50,20 +52,20 @@ func TestRunPmdToFile(t *testing.T) {
5052
}
5153

5254
// Use the correct path relative to tools directory
53-
testDirectory := filepath.Join(currentDirectory, "testdata", "repositories", "pmd")
55+
testDirectory := "."
5456
tempResultFile := filepath.Join(os.TempDir(), "pmd.sarif")
5557
defer os.Remove(tempResultFile)
5658

5759
// Use absolute paths
5860
repositoryToAnalyze := testDirectory
5961
// Use the standard ruleset file for testing the PMD runner functionality
60-
rulesetFile := filepath.Join(testDirectory, "pmd-ruleset.xml")
62+
rulesetFile := "pmd-ruleset.xml"
6163

6264
// Use the same path as defined in plugin.yaml
6365
pmdBinary := filepath.Join(homeDirectory, ".cache/codacy/tools/[email protected]/pmd-bin-6.55.0/bin/run.sh")
6466

6567
// Run PMD
66-
err = RunPmd(repositoryToAnalyze, pmdBinary, nil, tempResultFile, "sarif", rulesetFile)
68+
err = pmd.RunPmd(repositoryToAnalyze, pmdBinary, nil, tempResultFile, "sarif", rulesetFile)
6769
if err != nil {
6870
t.Fatalf("Failed to run pmd: %v", err)
6971
}

tools/testdata/repositories/pmd/RulesBreaker.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

tools/testdata/repositories/pmd/expected-ruleset.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.

tools/testdata/repositories/pmd/expected.sarif

Lines changed: 0 additions & 203 deletions
This file was deleted.

tools/testdata/repositories/pmd/pmd-ruleset.xml

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)