Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions internal/app/table_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type packageTests struct {
skipped []*parse.Test
passedCount int
passed []*parse.Test
failed []*parse.Test
failedCount int
}

func (c *consoleWriter) testsTable(packages []*parse.Package, option TestTableOptions) {
Expand Down Expand Up @@ -77,9 +79,10 @@ func (c *consoleWriter) testsTable(packages []*parse.Package, option TestTableOp
continue
}
pkgTests := getTestsFromPackages(pkg, option)
all := make([]*parse.Test, 0, len(pkgTests.passed)+len(pkgTests.skipped))
all := make([]*parse.Test, 0, len(pkgTests.passed)+len(pkgTests.skipped)+len(pkgTests.failed))
all = append(all, pkgTests.passed...)
all = append(all, pkgTests.skipped...)
all = append(all, pkgTests.failed...)

for _, t := range all {
// TODO(mf): why are we sorting this?
Expand Down Expand Up @@ -145,9 +148,10 @@ func (c *consoleWriter) testsTableMarkdown(packages []*parse.Package, option Tes
continue
}
pkgTests := getTestsFromPackages(pkg, option)
all := make([]*parse.Test, 0, len(pkgTests.passed)+len(pkgTests.skipped))
all := make([]*parse.Test, 0, len(pkgTests.passed)+len(pkgTests.skipped)+len(pkgTests.failed))
all = append(all, pkgTests.passed...)
all = append(all, pkgTests.skipped...)
all = append(all, pkgTests.failed...)

for _, t := range all {
// TODO(mf): why are we sorting this?
Expand All @@ -174,9 +178,10 @@ func (c *consoleWriter) testsTableMarkdown(packages []*parse.Package, option Tes
fmt.Fprintf(c.w, "## 📦 Package **`%s`**\n", pkg.Summary.Package)
fmt.Fprintln(c.w)

msg := fmt.Sprintf("Tests: ✓ %d passed | %d skipped\n",
msg := fmt.Sprintf("Tests: ✓ %d passed | %d skipped | %d failed\n",
pkgTests.passedCount,
pkgTests.skippedCount,
pkgTests.failedCount,
)
if option.Slow > 0 && option.Slow < pkgTests.passedCount {
msg += fmt.Sprintf("↓ Slowest %d passed tests shown (of %d)\n",
Expand Down Expand Up @@ -205,6 +210,8 @@ func getTestsFromPackages(pkg *parse.Package, option TestTableOptions) *packageT
tests.skippedCount = len(skipped)
passed := pkg.TestsByAction(parse.ActionPass)
tests.passedCount = len(passed)
failed := pkg.TestsByAction(parse.ActionFail)
tests.failedCount = len(failed)
if option.Skip {
tests.skipped = append(tests.skipped, skipped...)
}
Expand All @@ -219,6 +226,7 @@ func getTestsFromPackages(pkg *parse.Package, option TestTableOptions) *packageT
tests.passed = tests.passed[:option.Slow]
}
}
tests.failed = append(tests.failed, failed...)
return tests
}

Expand Down
56 changes: 56 additions & 0 deletions tests/failed_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package parsetest

import (
"bytes"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/mfridman/tparse/internal/app"
"github.com/mfridman/tparse/parse"
)

func TestFailedTestsTable(t *testing.T) {
t.Parallel()

base := filepath.Join("testdata", "failed")

tt := []struct {
fileName string
exitCode int
}{
{"test_01", 1},
{"test_02", 1},
{"test_03", 1},
{"test_04", 1},
}

for _, tc := range tt {
t.Run(tc.fileName, func(t *testing.T) {
buf := bytes.NewBuffer(nil)
inputFile := filepath.Join(base, tc.fileName+".jsonl")
options := app.Options{
FileName: inputFile,
Output: buf,
Sorter: parse.SortByPackageName,
TestTableOptions: app.TestTableOptions{
Pass: true, // Enable test table output
Skip: true, // Also show skipped tests
},
}
gotExitCode, err := app.Run(options)
require.NoError(t, err)
assert.Equal(t, tc.exitCode, gotExitCode)

goldenFile := filepath.Join(base, tc.fileName+".golden")
want, err := os.ReadFile(goldenFile)
if err != nil {
t.Fatal(err)
}
checkGolden(t, inputFile, goldenFile, buf.Bytes(), want)
})
}
}
132 changes: 132 additions & 0 deletions tests/testdata/failed/test_01.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
╭────────┬─────────┬───────────────────────────────────────┬───────────────────────────────────────╮
│ Status │ Elapsed │ Test │ Package │
├────────┼─────────┼───────────────────────────────────────┼───────────────────────────────────────┤
│ PASS │ 5.45 │ TestMigrateUpWithReset │ github.com/pressly/goose/v3/tests/e2e │
│ PASS │ 5.39 │ TestMigrateUpTo │ github.com/pressly/goose/v3/tests/e2e │
│ PASS │ 4.96 │ TestMigrateUpByOne │ github.com/pressly/goose/v3/tests/e2e │
│ PASS │ 3.37 │ TestMigrateFull │ github.com/pressly/goose/v3/tests/e2e │
│ PASS │ 2.53 │ TestMigrateUpWithRedo │ github.com/pressly/goose/v3/tests/e2e │
│ PASS │ 2.32 │ TestNoVersioning │ github.com/pressly/goose/v3/tests/e2e │
│ PASS │ 0.02 │ TestNoVersioning/seed-up-down-to-zero │ github.com/pressly/goose/v3/tests/e2e │
│ PASS │ 0.02 │ TestNoVersioning/test-seed-up-reset │ github.com/pressly/goose/v3/tests/e2e │
│ PASS │ 0.01 │ TestNoVersioning/test-seed-up-redo │ github.com/pressly/goose/v3/tests/e2e │
│ FAIL │ 3.71 │ TestNotAllowMissing │ github.com/pressly/goose/v3/tests/e2e │
│ FAIL │ 2.55 │ TestAllowMissingUpWithRedo │ github.com/pressly/goose/v3/tests/e2e │
│ FAIL │ 3.16 │ TestNowAllowMissingUpByOne │ github.com/pressly/goose/v3/tests/e2e │
│ FAIL │ 4.13 │ TestAllowMissingUpWithReset │ github.com/pressly/goose/v3/tests/e2e │
│ FAIL │ 3.15 │ TestAllowMissingUpByOne │ github.com/pressly/goose/v3/tests/e2e │
│ FAIL │ 5.11 │ TestMigrateAllowMissingDown │ github.com/pressly/goose/v3/tests/e2e │
╰────────┴─────────┴───────────────────────────────────────┴───────────────────────────────────────╯
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ FAIL package: github.com/pressly/goose/v3/tests/e2e ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

--- FAIL: TestAllowMissingUpByOne (3.15s)

allow_missing_test.go:329: unexpected number value: got:0 want:1
2022/05/19 22:03:07 OK 00001_a.sql
2022/05/19 22:03:07 OK 00002_b.sql
2022/05/19 22:03:07 OK 00003_c.sql
2022/05/19 22:03:07 OK 00004_d.sql
2022/05/19 22:03:07 OK 00005_e.sql
2022/05/19 22:03:07 OK 00006_f.sql
2022/05/19 22:03:07 OK 00007_g.sql
2022/05/19 22:03:07 OK 00008_h.sql
2022/05/19 22:03:07 OK 00009_i.sql
2022/05/19 22:03:07 OK 00010_j.sql
2022/05/19 22:03:07 OK 00011_k.sql
2022/05/19 22:03:07 goose: no migrations to run. current version: 11
2022/05/19 22:03:07 OK 00011_k.sql
2022/05/19 22:03:07 OK 00010_j.sql

────────────────────────────────────────────────────────────────────────────────────────────────

--- FAIL: TestAllowMissingUpWithRedo (2.55s)

allow_missing_test.go:329: unexpected number value: got:0 want:1

────────────────────────────────────────────────────────────────────────────────────────────────

--- FAIL: TestAllowMissingUpWithReset (4.13s)

allow_missing_test.go:329: unexpected number value: got:0 want:1
2022/05/19 22:03:08 OK 00001_a.sql
2022/05/19 22:03:08 OK 00002_b.sql
2022/05/19 22:03:08 OK 00003_c.sql
2022/05/19 22:03:08 OK 00004_d.sql
2022/05/19 22:03:08 OK 00005_e.sql
2022/05/19 22:03:08 OK 00006_f.sql
2022/05/19 22:03:08 OK 00007_g.sql
2022/05/19 22:03:08 OK 00008_h.sql
2022/05/19 22:03:08 OK 00009_i.sql
2022/05/19 22:03:08 OK 00010_j.sql
2022/05/19 22:03:08 OK 00011_k.sql
2022/05/19 22:03:08 goose: no migrations to run. current version: 11

────────────────────────────────────────────────────────────────────────────────────────────────

--- FAIL: TestMigrateAllowMissingDown (5.11s)

allow_missing_test.go:329: unexpected number value: got:0 want:1
2022/05/19 22:03:09 OK 00005_e.sql
2022/05/19 22:03:09 OK 00006_f.sql
2022/05/19 22:03:09 OK 00007_g.sql
2022/05/19 22:03:09 OK 00008_h.sql
2022/05/19 22:03:09 OK 00009_i.sql
2022/05/19 22:03:09 OK 00010_j.sql
2022/05/19 22:03:09 OK 00001_a.sql
2022/05/19 22:03:09 OK 00001_a.sql
2022/05/19 22:03:09 OK 00011_k.sql
2022/05/19 22:03:09 goose: no migrations to run. current version: 11
2022/05/19 22:03:09 OK 00001_a.sql
2022/05/19 22:03:09 OK 00011_k.sql
2022/05/19 22:03:09 OK 00002_b.sql
2022/05/19 22:03:09 OK 00010_j.sql
2022/05/19 22:03:09 OK 00009_i.sql
2022/05/19 22:03:09 OK 00002_b.sql
2022/05/19 22:03:09 OK 00008_h.sql
2022/05/19 22:03:09 OK 00001_a.sql
2022/05/19 22:03:09 OK 00002_b.sql
2022/05/19 22:03:09 OK 00003_c.sql
2022/05/19 22:03:09 OK 00007_g.sql
2022/05/19 22:03:09 OK 00002_b.sql
2022/05/19 22:03:09 goose: no migrations to run. current version: 2
2022/05/19 22:03:09 OK 00006_f.sql
2022/05/19 22:03:09 OK 00003_c.sql
2022/05/19 22:03:09 OK 00005_e.sql
2022/05/19 22:03:09 OK 00003_c.sql
2022/05/19 22:03:09 OK 00004_d.sql
2022/05/19 22:03:09 OK 00004_d.sql
2022/05/19 22:03:09 OK 00003_c.sql
2022/05/19 22:03:09 OK 00004_d.sql
2022/05/19 22:03:09 OK 00002_b.sql
2022/05/19 22:03:09 OK 00004_d.sql
2022/05/19 22:03:09 OK 00001_a.sql
2022/05/19 22:03:09 OK 00005_e.sql
2022/05/19 22:03:09 OK 00005_e.sql
2022/05/19 22:03:09 OK 00005_e.sql
2022/05/19 22:03:09 OK 00006_f.sql
2022/05/19 22:03:09 OK 00006_f.sql
2022/05/19 22:03:09 OK 00006_f.sql
2022/05/19 22:03:09 OK 00007_g.sql
2022/05/19 22:03:09 OK 00007_g.sql
2022/05/19 22:03:09 OK 00007_g.sql
2022/05/19 22:03:09 OK 00008_h.sql

────────────────────────────────────────────────────────────────────────────────────────────────

--- FAIL: TestNotAllowMissing (3.71s)

allow_missing_test.go:329: unexpected number value: got:0 want:1

────────────────────────────────────────────────────────────────────────────────────────────────

--- FAIL: TestNowAllowMissingUpByOne (3.16s)

allow_missing_test.go:329: unexpected number value: got:0 want:1

╭────────┬─────────┬───────────────────────────────────────┬───────┬──────┬──────┬──────╮
│ Status │ Elapsed │ Package │ Cover │ Pass │ Fail │ Skip │
├────────┼─────────┼───────────────────────────────────────┼───────┼──────┼──────┼──────┤
│ FAIL │ 9.00s │ github.com/pressly/goose/v3/tests/e2e │ -- │ 9 │ 6 │ 0 │
╰────────┴─────────┴───────────────────────────────────────┴───────┴──────┴──────┴──────╯
28 changes: 28 additions & 0 deletions tests/testdata/failed/test_02.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
╭────────┬─────────┬──────────────┬──────────────────────────────────────╮
│ Status │ Elapsed │ Test │ Package │
├────────┼─────────┼──────────────┼──────────────────────────────────────┤
│ FAIL │ 1.00 │ TestWhatever │ github.com/mfridman/debug-go/testing │
╰────────┴─────────┴──────────────┴──────────────────────────────────────╯
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ FAIL package: github.com/mfridman/debug-go/testing ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

--- FAIL: TestWhatever (1.00s)

main_test.go:13: assert error
main_test.go:14:
Error Trace: main_test.go:14
Error: "does not contain" does not contain "ostriche"
Test: TestWhatever
main_test.go:15:
Error Trace: main_test.go:15
Error: Received unexpected error:
make the errorss..
Test: TestWhatever
main_test.go:17: skdhjfg

╭────────┬─────────┬──────────────────────────────────────┬───────┬──────┬──────┬──────╮
│ Status │ Elapsed │ Package │ Cover │ Pass │ Fail │ Skip │
├────────┼─────────┼──────────────────────────────────────┼───────┼──────┼──────┼──────┤
│ FAIL │ 1.11s │ github.com/mfridman/debug-go/testing │ -- │ 0 │ 1 │ 0 │
╰────────┴─────────┴──────────────────────────────────────┴───────┴──────┴──────┴──────╯
Loading
Loading