diff --git a/internal/app/table_summary.go b/internal/app/table_summary.go index 2842ac7..b422ea4 100644 --- a/internal/app/table_summary.go +++ b/internal/app/table_summary.go @@ -54,8 +54,7 @@ func (c *consoleWriter) summaryTable( skip: "Skip", } tbl.Headers(header.toRow()...) - - var rows []summaryRow + data := table.NewStringData() // Capture as separate slices because notests are optional when passed tests are available. // The only exception is if passed=0 and notests=1, then we display them regardless. This @@ -82,7 +81,7 @@ func (c *consoleWriter) summaryTable( packageName: packageName, cover: "--", pass: "--", fail: "--", skip: "--", } - rows = append(rows, row) + data.Append(row.toRow()) continue } if pkg.HasFailedBuildOrSetup { @@ -92,7 +91,7 @@ func (c *consoleWriter) summaryTable( packageName: packageName + "\n[" + pkg.Summary.Output + "]", cover: "--", pass: "--", fail: "--", skip: "--", } - rows = append(rows, row) + data.Append(row.toRow()) continue } if pkg.NoTestFiles { @@ -189,25 +188,24 @@ func (c *consoleWriter) summaryTable( passed = append(passed, row) } - if len(rows) == 0 && len(passed) == 0 && len(notests) == 0 { + if data.Rows() == 0 && len(passed) == 0 && len(notests) == 0 { return } - rows = append(rows, passed...) + for _, r := range passed { + data.Append(r.toRow()) + } // Only display the "no tests to run" cases if users want to see them when passed // tests are available. // An exception is made if there are no passed tests and only a single no test files // package. This is almost always because the user forgot to match one or more packages. if showNoTests || (len(passed) == 0 && len(notests) == 1) { - rows = append(rows, notests...) - } - // The table gets written to a strings builder so we can further modify the output - // with lipgloss. - for _, r := range rows { - tbl.Rows(r.toRow()) + for _, r := range notests { + data.Append(r.toRow()) + } } - fmt.Fprintln(c.w, tbl.Render()) + fmt.Fprintln(c.w, tbl.Data(data).Render()) } type summaryRow struct { diff --git a/internal/app/table_tests.go b/internal/app/table_tests.go index 0321f3f..06bc47e 100644 --- a/internal/app/table_tests.go +++ b/internal/app/table_tests.go @@ -63,8 +63,7 @@ func (c *consoleWriter) testsTable(packages []*parse.Package, option TestTableOp packageName: "Package", } tbl.Headers(header.toRow()...) - - var rows []testRow + data := table.NewStringData() names := make([]string, 0, len(packages)) for _, pkg := range packages { @@ -106,19 +105,16 @@ func (c *consoleWriter) testsTable(packages []*parse.Package, option TestTableOp testName: testName, packageName: packageName, } - rows = append(rows, row) + data.Append(row.toRow()) } if i != (len(packages) - 1) { // Add a blank row between packages. - rows = append(rows, testRow{}) + data.Append(testRow{}.toRow()) } } - for _, r := range rows { - tbl.Rows(r.toRow()) - } - if len(rows) > 0 { - fmt.Fprintln(c.w, tbl.Render()) + if data.Rows() > 0 { + fmt.Fprintln(c.w, tbl.Data(data).Render()) } } @@ -142,7 +138,7 @@ func (c *consoleWriter) testsTableMarkdown(packages []*parse.Package, option Tes "Test", } tbl.Headers(header...) - var rows [][]string + data := table.NewStringData() // Discard packages where we cannot generate a sensible test summary. if pkg.NoTestFiles || pkg.NoTests || pkg.HasPanic { @@ -168,16 +164,13 @@ func (c *consoleWriter) testsTableMarkdown(packages []*parse.Package, option Tes case parse.ActionFail: status = c.red(status) } - rows = append(rows, []string{ + data.Append([]string{ status, strconv.FormatFloat(t.Elapsed(), 'f', 2, 64), testName, }) } - for _, r := range rows { - tbl.Rows(r) - } - if len(rows) > 0 { + if data.Rows() > 0 { fmt.Fprintf(c.w, "## 📦 Package **`%s`**\n", pkg.Summary.Package) fmt.Fprintln(c.w) fmt.Fprintf(c.w, @@ -192,7 +185,7 @@ func (c *consoleWriter) testsTableMarkdown(packages []*parse.Package, option Tes fmt.Fprintln(c.w) fmt.Fprintln(c.w, "Click for test summary") fmt.Fprintln(c.w) - fmt.Fprintln(c.w, tbl.Render()) + fmt.Fprintln(c.w, tbl.Data(data).Render()) fmt.Fprintln(c.w, "") fmt.Fprintln(c.w) }