Skip to content

Commit

Permalink
Resolved formatting issues in test command output (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewnitschke-wk authored Oct 17, 2024
1 parent a43c9c9 commit 72e45aa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
34 changes: 17 additions & 17 deletions cmd/scip/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,38 +134,38 @@ func TestSCIPTests(t *testing.T) {
{"roles",
autogold.Expect("✓ passes.repro (3 assertions)\n"),
autogold.Expect(`✗ fails-wrong-role.repro
Failure - row: 0, column: 13
Failure [Ln: 1, Col: 13]
Expected: 'reference reprolang repro_manager roles 1.0.0 fails-wrong-role.repro/hello().'
Actual:
- 'definition reprolang repro_manager roles 1.0.0 fails-wrong-role.repro/hello().'✗ fails-wrong-symbol.repro
Failure - row: 0, column: 13
Actual: 'definition reprolang repro_manager roles 1.0.0 fails-wrong-role.repro/hello().'
✗ fails-wrong-symbol.repro
Failure [Ln: 1, Col: 13]
Expected: 'definition reprolang repro_manager roles 1.0.0 fails-wrong-role.repro/hello2().'
Actual:
- 'definition reprolang repro_manager roles 1.0.0 fails-wrong-symbol.repro/hello().'`),
Actual: 'definition reprolang repro_manager roles 1.0.0 fails-wrong-symbol.repro/hello().'
`),
},
{"ranges",
autogold.Expect("✓ passes.repro (3 assertions)\n"),
autogold.Expect(`✗ fails.repro
Failure - row: 0, column: 10
Failure [Ln: 1, Col: 10]
Expected: 'definition passes.repro/hello().'
Actual:
- No attributes found`),
Actual: <no attributes found>
`),
},
{"diagnostics",
autogold.Expect("✓ passes.repro (2 assertions)\n"),
autogold.Expect(`✗ fails-incorrect-diagnostic.repro
Failure - row: 0, column: 11
Failure [Ln: 1, Col: 11]
Expected: 'diagnostic Warning:'
'THIS IS NOT CORRECT'
Actual:
- 'definition reprolang repro_manager diagnostics 1.0.0 fails-incorrect-diagnostic.repro/deprecatedMethod.'
- 'diagnostic Warning'
'deprecated identifier'✗ fails-no-diagnostic.repro
Failure - row: 0, column: 11
Actual: * 'definition reprolang repro_manager diagnostics 1.0.0 fails-incorrect-diagnostic.repro/deprecatedMethod.'
* 'diagnostic Warning'
'deprecated identifier'
✗ fails-no-diagnostic.repro
Failure [Ln: 1, Col: 11]
Expected: 'diagnostic Warning:'
'deprecated identifier'
Actual:
- 'definition reprolang repro_manager diagnostics 1.0.0 fails-no-diagnostic.repro/hello().'`),
Actual: 'definition reprolang repro_manager diagnostics 1.0.0 fails-no-diagnostic.repro/hello().'
`),
},
}

Expand Down
24 changes: 17 additions & 7 deletions cmd/scip/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func testMain(
red.Fprintf(output, "✗ %s\n", document.RelativePath)

for _, failure := range failures {
fmt.Fprintf(output, indent(failure, 4))
fmt.Fprintf(output, indent(failure, 4)+"\n")
}
} else {
green := color.New(color.FgGreen)
Expand Down Expand Up @@ -421,21 +421,31 @@ func (s symbolAttributeTestCase) check(attr symbolAttribute) bool {

func formatFailure(lineNumber int, testCase symbolAttributeTestCase, attributesAtLine []symbolAttribute) string {
failureDesc := []string{
fmt.Sprintf("Failure - row: %d, column: %d", lineNumber, testCase.attribute.start),
fmt.Sprintf("Failure [Ln: %d, Col: %d]", lineNumber+1, testCase.attribute.start),
fmt.Sprintf(" Expected: '%s %s'", testCase.attribute.kind, testCase.attribute.data),
}
for _, add := range testCase.attribute.additionalData {
failureDesc = append(failureDesc, indent(fmt.Sprintf("'%s'", add), 12))
}

failureDesc = append(failureDesc, " Actual:")
if (len(attributesAtLine)) == 0 {
failureDesc = append(failureDesc, " - No attributes found")
failureDesc = append(failureDesc, " Actual: <no attributes found>")
} else {
for _, attr := range attributesAtLine {
failureDesc = append(failureDesc, fmt.Sprintf(" - '%s %s'", attr.kind, attr.data))
for i, attr := range attributesAtLine {
prefix := " "
if i == 0 {
prefix = "Actual:"
}

if len(attributesAtLine) > 1 {
prefix += " *"
} else {
prefix += " "
}

failureDesc = append(failureDesc, fmt.Sprintf(" %s '%s %s'", prefix, attr.kind, attr.data))
for _, add := range attr.additionalData {
failureDesc = append(failureDesc, indent(fmt.Sprintf("'%s'", add), 6))
failureDesc = append(failureDesc, indent(fmt.Sprintf("'%s'", add), 12))
}
}
}
Expand Down

0 comments on commit 72e45aa

Please sign in to comment.