Files

37 lines
874 B
Go

package gameserver
import (
"fmt"
"os"
"path/filepath"
"runtime"
"testing"
)
func TestMain(m *testing.M) {
_, source, _, ok := runtime.Caller(0)
if !ok {
fmt.Fprintln(os.Stderr, "cannot locate gameserver test helper source")
os.Exit(2)
}
root := filepath.Clean(filepath.Join(filepath.Dir(source), "..", ".."))
if err := os.Chdir(root); err != nil {
fmt.Fprintf(os.Stderr, "cannot change to repository root %s: %v\n", root, err)
os.Exit(2)
}
os.Exit(m.Run())
}
func chdirRepositoryRoot(t *testing.T) {
t.Helper()
_, source, _, ok := runtime.Caller(0)
if !ok {
t.Fatal("cannot locate gameserver test helper source")
}
root := filepath.Clean(filepath.Join(filepath.Dir(source), "..", ".."))
if _, err := os.Stat(filepath.Join(root, "go.mod")); err != nil {
t.Fatalf("cannot locate repository root from %s: %v", source, err)
}
t.Chdir(root)
}