From 72e45aa20140149f0241aaca4d7284c2fe794b95 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke <39171685+matthewnitschke-wk@users.noreply.github.com> Date: Wed, 16 Oct 2024 22:12:48 -0600 Subject: [PATCH] Resolved formatting issues in test command output (#281) --- cmd/scip/main_test.go | 34 +++++++++++++++++----------------- cmd/scip/test.go | 24 +++++++++++++++++------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/cmd/scip/main_test.go b/cmd/scip/main_test.go index 307b88a3..556e60c2 100644 --- a/cmd/scip/main_test.go +++ b/cmd/scip/main_test.go @@ -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: +`), }, {"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().' +`), }, } diff --git a/cmd/scip/test.go b/cmd/scip/test.go index 42e4d23a..3977ba10 100644 --- a/cmd/scip/test.go +++ b/cmd/scip/test.go @@ -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) @@ -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: ") } 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)) } } }