Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename file implementing reporter (#95) #95

Merged
merged 1 commit into from
Oct 20, 2024
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
8 changes: 4 additions & 4 deletions test/caller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ var (
}()
// CallerTestError provides the file with the line number of the `Error`
// call in the test context implementation.
CallerTestError = path.Join(SourceDir, "context.go:356")
CallerTestError = path.Join(SourceDir, "context.go:333")
// CallerReporterErrorf provides the file with the line number of the
// `Errorf` call in the test reporter/validator implementation.
CallerReporterError = path.Join(SourceDir, "gomock.go:60")
CallerReporterError = path.Join(SourceDir, "reporter.go:83")

// CallerTestErrorf provides the file with the line number of the `Errorf`
// call in the test context implementation.
CallerTestErrorf = path.Join(SourceDir, "context.go:374")
CallerTestErrorf = path.Join(SourceDir, "context.go:351")
// CallerReporterErrorf provides the file with the line number of the
// `Errorf` call in the test reporter/validator implementation.
CallerReporterErrorf = path.Join(SourceDir, "gomock.go:82")
CallerReporterErrorf = path.Join(SourceDir, "reporter.go:105")
)
23 changes: 0 additions & 23 deletions test/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,6 @@ type Test interface { //nolint:interfacebloat // Minimal interface.
Cleanup(cleanup func())
}

// Reporter is a minimal interface for abstracting test report methods that are
// needed to setup an isolated test environment for GoMock and Testify.
type Reporter interface {
// Error reports a failure messages when a test is supposed to continue.
Error(args ...any)
// Errorf reports a failure messages when a test is supposed to continue.
Errorf(format string, args ...any)
// Fatal reports a fatal failure message that immediate aborts of the test
// execution.
Fatal(args ...any)
// Fatalf reports a fatal failure message that immediate aborts of the test
// execution.
Fatalf(format string, args ...any)
// Fail reports a failure message that immediate aborts of the test
// execution.
Fail()
// FailNow reports fatal failure notifications without log output that
// aborts test execution immediately.
FailNow()
// Panic reports a panic.
Panic(arg any)
}

// Cleanuper defines an interface to add a custom mehtod that is called after
// the test execution to cleanup the test environment.
type Cleanuper interface {
Expand Down
23 changes: 23 additions & 0 deletions test/gomock.go → test/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ import (
"github.com/tkrop/go-testing/mock"
)

// Reporter is a minimal interface for abstracting test report methods that are
// needed to setup an isolated test environment for GoMock and Testify.
type Reporter interface {
// Error reports a failure messages when a test is supposed to continue.
Error(args ...any)
// Errorf reports a failure messages when a test is supposed to continue.
Errorf(format string, args ...any)
// Fatal reports a fatal failure message that immediate aborts of the test
// execution.
Fatal(args ...any)
// Fatalf reports a fatal failure message that immediate aborts of the test
// execution.
Fatalf(format string, args ...any)
// Fail reports a failure message that immediate aborts of the test
// execution.
Fail()
// FailNow reports fatal failure notifications without log output that
// aborts test execution immediately.
FailNow()
// Panic reports a panic.
Panic(arg any)
}

// Validator a test failure validator based on the test reporter interface.
type Validator struct {
ctrl *gomock.Controller
Expand Down
File renamed without changes.
Loading