Skip to content

Commit e8ff10d

Browse files
committed
Store effective check message in report
Previously, the message in the report was always that of the failure state of the check, regardless of the actual check result.
1 parent a74c218 commit e8ff10d

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

Diff for: result/result.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ func (results *Type) Initialize() {
9292

9393
// Record records the result of a check and returns a text summary for it.
9494
func (results *Type) Record(checkedProject project.Type, checkConfiguration checkconfigurations.Type, checkResult checkresult.Type, checkOutput string) string {
95-
checkMessage := message(checkConfiguration.MessageTemplate, checkOutput)
96-
9795
checkLevel, err := checklevel.CheckLevel(checkConfiguration, checkResult)
9896
if err != nil {
9997
feedback.Errorf("Error while determining check level: %v", err)
@@ -102,11 +100,17 @@ func (results *Type) Record(checkedProject project.Type, checkConfiguration chec
102100

103101
summaryText := fmt.Sprintf("%s\n", checkResult)
104102

105-
if checkResult == checkresult.NotRun {
106-
if checkOutput != "" {
107-
summaryText += fmt.Sprintf("%s: %s\n", checklevel.Notice, checkOutput)
108-
}
109-
} else if checkResult != checkresult.Pass {
103+
checkMessage := ""
104+
if checkLevel == checklevel.Error {
105+
checkMessage = message(checkConfiguration.MessageTemplate, checkOutput)
106+
} else {
107+
// Checks may provide an explanation for their non-fail result.
108+
// The message template should not be used in this case, since it is written for a failure result.
109+
checkMessage = checkOutput
110+
}
111+
112+
// Add explanation of check result if present.
113+
if checkMessage != "" {
110114
summaryText += fmt.Sprintf("%s: %s\n", checkLevel, checkMessage)
111115
}
112116

Diff for: result/result_test.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,12 @@ func TestRecord(t *testing.T) {
6161
var results Type
6262
checkConfiguration := checkconfigurations.Configurations()[0]
6363
checkOutput := "foo"
64-
summaryText := results.Record(checkedProject, checkConfiguration, checkresult.Pass, checkOutput)
65-
assert.Equal(t, fmt.Sprintf("%s\n", checkresult.Pass), summaryText)
66-
summaryText = results.Record(checkedProject, checkConfiguration, checkresult.NotRun, checkOutput)
67-
assert.Equal(t, fmt.Sprintf("%s\n%s: %s\n", checkresult.NotRun, checklevel.Notice, checkOutput), summaryText)
68-
summaryText = results.Record(checkedProject, checkConfiguration, checkresult.NotRun, "")
69-
assert.Equal(t, "", "", summaryText)
70-
summaryText = results.Record(checkedProject, checkConfiguration, checkresult.Fail, checkOutput)
64+
summaryText := results.Record(checkedProject, checkConfiguration, checkresult.Fail, checkOutput)
7165
assert.Equal(t, fmt.Sprintf("%s\n%s: %s\n", checkresult.Fail, checklevel.Error, message(checkConfiguration.MessageTemplate, checkOutput)), summaryText)
66+
summaryText = results.Record(checkedProject, checkConfiguration, checkresult.NotRun, checkOutput)
67+
assert.Equal(t, fmt.Sprintf("%s\n%s: %s\n", checkresult.NotRun, checklevel.Notice, checkOutput), summaryText, "Non-fail result should not use message")
68+
summaryText = results.Record(checkedProject, checkConfiguration, checkresult.Pass, "")
69+
assert.Equal(t, "", "", summaryText, "Non-failure result with no check function output should result in an empty summary")
7270

7371
checkResult := checkresult.Pass
7472
results = Type{}
@@ -92,7 +90,7 @@ func TestRecord(t *testing.T) {
9290
assert.Equal(t, checkResult.String(), checkReport.Result)
9391
checkLevel, _ := checklevel.CheckLevel(checkConfiguration, checkResult)
9492
assert.Equal(t, checkLevel.String(), checkReport.Level)
95-
assert.Equal(t, message(checkConfiguration.MessageTemplate, checkOutput), checkReport.Message)
93+
assert.Equal(t, checkOutput, checkReport.Message)
9694

9795
assert.Len(t, results.Projects, 1)
9896
previousProjectPath := checkedProject.Path

0 commit comments

Comments
 (0)