Skip to content

Commit

Permalink
added file attribute to JUnit report
Browse files Browse the repository at this point in the history
  • Loading branch information
daveshanley committed Jan 7, 2025
1 parent f2331c6 commit ffc31b2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/vacuum_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func GetVacuumReportCommand() *cobra.Command {

// if we want jUnit output, then build the report and be done with it.
if junitFlag {
junitXML := vacuum_report.BuildJUnitReport(resultSet, start)
junitXML := vacuum_report.BuildJUnitReport(resultSet, start, args)
if stdOut {
fmt.Print(string(junitXML))
return nil
Expand Down
29 changes: 26 additions & 3 deletions vacuum-report/junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ type TestCase struct {
Line int `xml:"line,attr,omitempty"`
Failure *Failure `xml:"failure,omitempty"`
Properties *Properties `xml:"properties,omitempty"`
File string `xml:"file,attr,omitempty"`
}

type Failure struct {
Message string `xml:"message,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
File string `xml:"file,attr,omitempty"`
Contents string `xml:",innerxml"`
}

func BuildJUnitReport(resultSet *model.RuleResultSet, t time.Time) []byte {
func BuildJUnitReport(resultSet *model.RuleResultSet, t time.Time, args []string) []byte {

since := time.Since(t)
var suites []*TestSuite
Expand Down Expand Up @@ -86,7 +88,8 @@ func BuildJUnitReport(resultSet *model.RuleResultSet, t time.Time) []byte {
f++
gf++
}
tc = append(tc, &TestCase{

tCase := &TestCase{
Line: r.StartNode.Line,
Name: fmt.Sprintf("%s", val.Name),
ClassName: r.Rule.Id,
Expand Down Expand Up @@ -115,7 +118,27 @@ func BuildJUnitReport(resultSet *model.RuleResultSet, t time.Time) []byte {
},
},
},
})
}

if r.Origin != nil && r.Origin.AbsoluteLocation != "" {
tCase.File = r.Origin.AbsoluteLocation
tCase.Properties.Properties = append(tCase.Properties.Properties, &Property{
Name: "file",
Value: r.Origin.AbsoluteLocation,
})
tCase.Failure.File = r.Origin.AbsoluteLocation
} else {
if len(args) > 0 {
tCase.File = args[0]
tCase.Properties.Properties = append(tCase.Properties.Properties, &Property{
Name: "file",
Value: args[0],
})
tCase.Failure.File = args[0]
}
}

tc = append(tc, tCase)
}

if len(tc) > 0 {
Expand Down

0 comments on commit ffc31b2

Please sign in to comment.