diff --git a/native/interceptor/fatal_fatal_test.go b/native/interceptor/fatal_fatal_test.go new file mode 100644 index 0000000..613dda3 --- /dev/null +++ b/native/interceptor/fatal_fatal_test.go @@ -0,0 +1,35 @@ +//go:build !darwin +// +build !darwin + +// This test should currently really not run on macOS, because it might +// lead to crashes. + +package interceptor + +import ( + "os" + "os/exec" + "testing" + + "github.com/echocat/slf4g/internal/test/assert" +) + +func Test_fatalExit(t *testing.T) { + if os.Getenv("DO_IT_NOW_REALLY") == "1" { + fatalExit(66) + return + } + + cmd := exec.Command(os.Args[0], "-test.run="+t.Name()) + cmd.Env = append(os.Environ(), "DO_IT_NOW_REALLY=1") + err := cmd.Run() + if e, ok := err.(*exec.ExitError); ok { + if e.ExitCode() != 66 { + assert.Failf(t, "Expected to fail with exit code <1>; bot got error: <%+v>", e.ExitCode()) + } + } else if err != nil { + assert.Failf(t, "Expected to fail with exit code <1>; bot got error: <%+v>", err) + } else { + assert.Fail(t, "Expected to fail with exit code <1>; bot it exists with 0.") + } +} diff --git a/native/interceptor/fatal_test.go b/native/interceptor/fatal_test.go index bf00be9..b8ff4eb 100644 --- a/native/interceptor/fatal_test.go +++ b/native/interceptor/fatal_test.go @@ -3,8 +3,6 @@ package interceptor import ( "fmt" "math" - "os" - "os/exec" "testing" "github.com/echocat/slf4g/fields" @@ -97,23 +95,3 @@ func Test_Fatal_GetPriority(t *testing.T) { assert.ToBeEqual(t, int16(math.MaxInt16), actual) } - -func Test_fatalExit(t *testing.T) { - if os.Getenv("DO_IT_NOW_REALLY") == "1" { - fatalExit(66) - return - } - - cmd := exec.Command(os.Args[0], "-test.run="+t.Name()) - cmd.Env = append(os.Environ(), "DO_IT_NOW_REALLY=1") - err := cmd.Run() - if e, ok := err.(*exec.ExitError); ok { - if e.ExitCode() != 66 { - assert.Failf(t, "Expected to fail with exit code <1>; bot got error: <%+v>", e.ExitCode()) - } - } else if err != nil { - assert.Failf(t, "Expected to fail with exit code <1>; bot got error: <%+v>", err) - } else { - assert.Fail(t, "Expected to fail with exit code <1>; bot it exists with 0.") - } -} diff --git a/sdk/bridge/logger_impl_fatal_test.go b/sdk/bridge/logger_impl_fatal_test.go new file mode 100644 index 0000000..e3e6b6b --- /dev/null +++ b/sdk/bridge/logger_impl_fatal_test.go @@ -0,0 +1,35 @@ +//go:build !darwin +// +build !darwin + +// This test should currently really not run on macOS, because it might +// lead to crashes. + +package sdk + +import ( + "os" + "os/exec" + "testing" + + "github.com/echocat/slf4g/internal/test/assert" +) + +func Test_DefaultOnFatal(t *testing.T) { + if os.Getenv("DO_IT_NOW_REALLY") == "1" { + DefaultOnFatal(nil) + return + } + + cmd := exec.Command(os.Args[0], "-test.run="+t.Name()) + cmd.Env = append(os.Environ(), "DO_IT_NOW_REALLY=1") + err := cmd.Run() + if e, ok := err.(*exec.ExitError); ok { + if e.ExitCode() != 1 { + assert.Failf(t, "Expected to fail with exit code <1>; bot got error: <%+v>", e.ExitCode()) + } + } else if err != nil { + assert.Failf(t, "Expected to fail with exit code <1>; bot got error: <%+v>", err) + } else { + assert.Fail(t, "Expected to fail with exit code <1>; bot it exists with 0.") + } +} diff --git a/sdk/bridge/logger_impl_test.go b/sdk/bridge/logger_impl_test.go index 2a486c5..80ecd19 100644 --- a/sdk/bridge/logger_impl_test.go +++ b/sdk/bridge/logger_impl_test.go @@ -1,8 +1,6 @@ package sdk import ( - "os" - "os/exec" "testing" "github.com/echocat/slf4g/testing/recording" @@ -32,26 +30,6 @@ func Test_DefaultOnPanic(t *testing.T) { DefaultOnPanic(givenEvent) } -func Test_DefaultOnFatal(t *testing.T) { - if os.Getenv("DO_IT_NOW_REALLY") == "1" { - DefaultOnFatal(nil) - return - } - - cmd := exec.Command(os.Args[0], "-test.run="+t.Name()) - cmd.Env = append(os.Environ(), "DO_IT_NOW_REALLY=1") - err := cmd.Run() - if e, ok := err.(*exec.ExitError); ok { - if e.ExitCode() != 1 { - assert.Failf(t, "Expected to fail with exit code <1>; bot got error: <%+v>", e.ExitCode()) - } - } else if err != nil { - assert.Failf(t, "Expected to fail with exit code <1>; bot got error: <%+v>", err) - } else { - assert.Fail(t, "Expected to fail with exit code <1>; bot it exists with 0.") - } -} - func Test_LoggerImpl_Print_withNoArgs(t *testing.T) { instance, logger, horror := prepareLoggerImpl() instance.PrintLevel = level.Warn