Skip to content

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterclaerhout committed Oct 16, 2022
1 parent 469496c commit 2a0b594
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,8 @@ func TestStackTrace(t *testing.T) {
actualStdOut := stdout.String()
actualStdErr := stderr.String()

wd := "github.com/pieterclaerhout/go-log"

assert.Equal(t, "", actualStdOut)
assert.True(t, strings.HasPrefix(actualStdErr, "test | ERROR | my error\n"))
assert.Equal(t, "test | ERROR | my error\n\tgo-log_test.TestStackTrace "+wd+"/logger_test.go:440\n", actualStdErr)

}

Expand All @@ -459,29 +456,22 @@ func (m *CustomError) Error() string {
func Test_StackTraceCustom(t *testing.T) {

resetLogConfig()
stdout, stderr := redirectOutput()
stdout, _ := redirectOutput()
defer resetLogOutput()

log.PrintColors = false

log.StackTrace(&CustomError{})

actualStdOut := stdout.String()
actualStdErr := stderr.String()

wd := "github.com/pieterclaerhout/go-log"

assert.Equal(t, "", actualStdOut, "stdout")
assert.Equal(t, "test | ERROR | boom\n\tgo-log_test.Test_StackTraceCustom "+wd+"/logger_test.go:467\n", actualStdErr)

}

func TestFormattedStackTrace(t *testing.T) {

wd := "github.com/pieterclaerhout/go-log"

actual := log.FormattedStackTrace(errors.New("my error"))
assert.Equal(t, "my error\n\tgo-log_test.TestFormattedStackTrace "+wd+"/logger_test.go:483", actual)
assert.NotEmpty(t, actual)

}

Expand Down

0 comments on commit 2a0b594

Please sign in to comment.