Skip to content

Commit

Permalink
Disable fatal tests on macOS
Browse files Browse the repository at this point in the history
* Disable fatal tests on macOS
  • Loading branch information
blaubaer authored Jan 3, 2023
1 parent aceca76 commit 6d951b2
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 44 deletions.
35 changes: 35 additions & 0 deletions native/interceptor/fatal_fatal_test.go
Original file line number Diff line number Diff line change
@@ -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.")
}
}
22 changes: 0 additions & 22 deletions native/interceptor/fatal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package interceptor
import (
"fmt"
"math"
"os"
"os/exec"
"testing"

"github.com/echocat/slf4g/fields"
Expand Down Expand Up @@ -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.")
}
}
35 changes: 35 additions & 0 deletions sdk/bridge/logger_impl_fatal_test.go
Original file line number Diff line number Diff line change
@@ -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.")
}
}
22 changes: 0 additions & 22 deletions sdk/bridge/logger_impl_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package sdk

import (
"os"
"os/exec"
"testing"

"github.com/echocat/slf4g/testing/recording"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6d951b2

Please sign in to comment.