Skip to content

Commit f636b76

Browse files
committed
Add trailing newlines at the point of output
The previous approach of adding trailing newlines when the report text was generated made it difficult to keep track of how the output was formatted.
1 parent 3e6d2f6 commit f636b76

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

check/check.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333

3434
// RunChecks runs all checks for the given project and outputs the results.
3535
func RunChecks(project project.Type) {
36-
feedback.Printf("Checking %s in %s\n", project.ProjectType, project.Path)
36+
feedback.Printf("\nChecking %s in %s\n", project.ProjectType, project.Path)
3737

3838
checkdata.Initialize(project, configuration.SchemasPath())
3939

@@ -55,15 +55,15 @@ func RunChecks(project project.Type) {
5555
checkResult, checkOutput := checkConfiguration.CheckFunction()
5656
reportText := result.Results.Record(project, checkConfiguration, checkResult, checkOutput)
5757
if (checkResult == checkresult.Fail) || configuration.Verbose() {
58-
feedback.Print(reportText)
58+
feedback.Println(reportText)
5959
}
6060
}
6161

6262
// Checks are finished for this project, so summarize its check results in the report.
6363
result.Results.AddProjectSummary(project)
6464

6565
// Print the project check results summary.
66-
feedback.Print(result.Results.ProjectSummaryText(project))
66+
feedback.Printf("\n%s\n", result.Results.ProjectSummaryText(project))
6767
}
6868

6969
// shouldRun returns whether a given check should be run for the given project under the current tool configuration.

command/command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func ArduinoCheck(rootCommand *cobra.Command, cliArguments []string) {
7575
if configuration.OutputFormat() == outputformat.Text {
7676
if len(projects) > 1 {
7777
// There are multiple projects, print the summary of check results for all projects.
78-
fmt.Print(result.Results.SummaryText())
78+
fmt.Printf("\n%s\n", result.Results.SummaryText())
7979
}
8080
} else {
8181
// Print the complete JSON formatted report.

result/result.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (results *Type) Record(checkedProject project.Type, checkConfiguration chec
9999
os.Exit(1)
100100
}
101101

102-
summaryText := fmt.Sprintf("Check %s result: %s\n", checkConfiguration.ID, checkResult)
102+
summaryText := fmt.Sprintf("Check %s result: %s", checkConfiguration.ID, checkResult)
103103

104104
checkMessage := ""
105105
if checkResult == checkresult.Fail {
@@ -112,7 +112,7 @@ func (results *Type) Record(checkedProject project.Type, checkConfiguration chec
112112

113113
// Add explanation of check result if present.
114114
if checkMessage != "" {
115-
summaryText += fmt.Sprintf("%s: %s\n", checkLevel, checkMessage)
115+
summaryText += fmt.Sprintf("\n%s: %s", checkLevel, checkMessage)
116116
}
117117

118118
reportExists, projectReportIndex := results.getProjectReportIndex(checkedProject.Path)
@@ -187,7 +187,7 @@ func (results Type) ProjectSummaryText(checkedProject project.Type) string {
187187
}
188188

189189
projectSummaryReport := results.Projects[projectReportIndex].Summary
190-
return fmt.Sprintf("\nFinished checking project. Results:\nWarning count: %v\nError count: %v\nChecks passed: %v\n\n", projectSummaryReport.WarningCount, projectSummaryReport.ErrorCount, projectSummaryReport.Pass)
190+
return fmt.Sprintf("Finished checking project. Results:\nWarning count: %v\nError count: %v\nChecks passed: %v", projectSummaryReport.WarningCount, projectSummaryReport.ErrorCount, projectSummaryReport.Pass)
191191
}
192192

193193
// AddSummary summarizes the check results for all projects and adds it to the report.
@@ -212,7 +212,7 @@ func (results *Type) AddSummary() {
212212

213213
// SummaryText returns a text summary of the cumulative check results.
214214
func (results Type) SummaryText() string {
215-
return fmt.Sprintf("Finished checking projects. Results:\nWarning count: %v\nError count: %v\nChecks passed: %v\n", results.Summary.WarningCount, results.Summary.ErrorCount, results.Summary.Pass)
215+
return fmt.Sprintf("Finished checking projects. Results:\nWarning count: %v\nError count: %v\nChecks passed: %v", results.Summary.WarningCount, results.Summary.ErrorCount, results.Summary.Pass)
216216
}
217217

218218
// JSONReport returns a JSON formatted report of checks on all projects.

result/result_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func TestRecord(t *testing.T) {
7575
checkConfiguration := checkconfigurations.Configurations()[0]
7676
checkOutput := "foo"
7777
summaryText := results.Record(checkedProject, checkConfiguration, checkresult.Fail, checkOutput)
78-
assert.Equal(t, fmt.Sprintf("Check %s result: %s\n%s: %s\n", checkConfiguration.ID, checkresult.Fail, checklevel.Error, message(checkConfiguration.MessageTemplate, checkOutput)), summaryText)
78+
assert.Equal(t, fmt.Sprintf("Check %s result: %s\n%s: %s", checkConfiguration.ID, checkresult.Fail, checklevel.Error, message(checkConfiguration.MessageTemplate, checkOutput)), summaryText)
7979
summaryText = results.Record(checkedProject, checkConfiguration, checkresult.NotRun, checkOutput)
80-
assert.Equal(t, fmt.Sprintf("Check %s result: %s\n%s: %s\n", checkConfiguration.ID, checkresult.NotRun, checklevel.Notice, checkOutput), summaryText, "Non-fail result should not use message")
80+
assert.Equal(t, fmt.Sprintf("Check %s result: %s\n%s: %s", checkConfiguration.ID, checkresult.NotRun, checklevel.Notice, checkOutput), summaryText, "Non-fail result should not use message")
8181
summaryText = results.Record(checkedProject, checkConfiguration, checkresult.Pass, "")
8282
assert.Equal(t, "", "", summaryText, "Non-failure result with no check function output should result in an empty summary")
8383

@@ -198,7 +198,7 @@ func TestAddProjectSummary(t *testing.T) {
198198
assert.Equal(t, testTable.expectedPass, results.Projects[0].Summary.Pass)
199199
assert.Equal(t, testTable.expectedWarningCount, results.Projects[0].Summary.WarningCount)
200200
assert.Equal(t, testTable.expectedErrorCount, results.Projects[0].Summary.ErrorCount)
201-
assert.Equal(t, fmt.Sprintf("\nFinished checking project. Results:\nWarning count: %v\nError count: %v\nChecks passed: %v\n\n", testTable.expectedWarningCount, testTable.expectedErrorCount, testTable.expectedPass), results.ProjectSummaryText(checkedProject))
201+
assert.Equal(t, fmt.Sprintf("Finished checking project. Results:\nWarning count: %v\nError count: %v\nChecks passed: %v", testTable.expectedWarningCount, testTable.expectedErrorCount, testTable.expectedPass), results.ProjectSummaryText(checkedProject))
202202
}
203203
}
204204

@@ -281,7 +281,7 @@ func TestAddSummary(t *testing.T) {
281281
assert.Equal(t, testTable.expectedPass, results.Passed())
282282
assert.Equal(t, testTable.expectedWarningCount, results.Summary.WarningCount)
283283
assert.Equal(t, testTable.expectedErrorCount, results.Summary.ErrorCount)
284-
assert.Equal(t, fmt.Sprintf("Finished checking projects. Results:\nWarning count: %v\nError count: %v\nChecks passed: %v\n", testTable.expectedWarningCount, testTable.expectedErrorCount, testTable.expectedPass), results.SummaryText())
284+
assert.Equal(t, fmt.Sprintf("Finished checking projects. Results:\nWarning count: %v\nError count: %v\nChecks passed: %v", testTable.expectedWarningCount, testTable.expectedErrorCount, testTable.expectedPass), results.SummaryText())
285285
}
286286
}
287287

0 commit comments

Comments
 (0)