48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package tests
|
|
|
|
import (
|
|
"testing"
|
|
|
|
assert "git.sharkk.net/Go/Assert"
|
|
)
|
|
|
|
// This file serves as a meta-test to make sure all our tests are working
|
|
|
|
func TestTestFramework(t *testing.T) {
|
|
// Verify that our assert package works
|
|
assert.Equal(t, 5, 5)
|
|
assert.NotEqual(t, 5, 10)
|
|
assert.True(t, true)
|
|
assert.False(t, false)
|
|
assert.NotNil(t, "not nil")
|
|
assert.Contains(t, "Hello World", "World")
|
|
assert.NotContains(t, "Hello World", "Goodbye")
|
|
|
|
// Create a failing test context that doesn't actually fail
|
|
testFailContext := new(testing.T)
|
|
failingTestContext := &testContext{T: testFailContext}
|
|
|
|
// These should not cause the overall test to fail
|
|
assert.Equal(failingTestContext, 1, 2)
|
|
assert.NotEqual(failingTestContext, 5, 5)
|
|
|
|
// Check that the failing tests did record failures
|
|
assert.True(t, failingTestContext.failed)
|
|
assert.Equal(t, 2, failingTestContext.failCount)
|
|
}
|
|
|
|
// Helper type to capture test failures without actually failing the test
|
|
type testContext struct {
|
|
*testing.T
|
|
failed bool
|
|
failCount int
|
|
}
|
|
|
|
func (t *testContext) Errorf(format string, args ...any) {
|
|
t.failCount++
|
|
}
|
|
|
|
func (t *testContext) FailNow() {
|
|
t.failed = true
|
|
}
|