mirror of
https://github.com/stretchr/testify.git
synced 2025-05-22 15:30:09 +00:00
1. Isolate tests that use the "unsafe" package in a separate package assert/internal/unsafetests. That way the assert package is not tainted with unsafe. 2. Remove one reference to the private assert.isNil() in assert tests. 3. Add more tests of assert.Nil and assert.NotNil with unsafe.Pointer.
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
package unsafetests_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"unsafe"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type ignoreTestingT struct{}
|
|
|
|
var _ assert.TestingT = ignoreTestingT{}
|
|
|
|
func (ignoreTestingT) Helper() {}
|
|
|
|
func (ignoreTestingT) Errorf(format string, args ...interface{}) {
|
|
// Run the formatting, but ignore the result
|
|
msg := fmt.Sprintf(format, args...)
|
|
_ = msg
|
|
}
|
|
|
|
func TestUnsafePointers(t *testing.T) {
|
|
var ignore ignoreTestingT
|
|
|
|
assert.True(t, assert.Nil(t, unsafe.Pointer(nil), "unsafe.Pointer(nil) is nil"))
|
|
assert.False(t, assert.NotNil(ignore, unsafe.Pointer(nil), "unsafe.Pointer(nil) is nil"))
|
|
|
|
assert.True(t, assert.Nil(t, unsafe.Pointer((*int)(nil)), "unsafe.Pointer((*int)(nil)) is nil"))
|
|
assert.False(t, assert.NotNil(ignore, unsafe.Pointer((*int)(nil)), "unsafe.Pointer((*int)(nil)) is nil"))
|
|
|
|
assert.False(t, assert.Nil(ignore, unsafe.Pointer(new(int)), "unsafe.Pointer(new(int)) is NOT nil"))
|
|
assert.True(t, assert.NotNil(t, unsafe.Pointer(new(int)), "unsafe.Pointer(new(int)) is NOT nil"))
|
|
}
|