Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't skip testNumAndList if Get* fails or isn't supported #101

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions numcpus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,24 @@ func TestGetKernelMax(t *testing.T) {
func testNumAndList(t *testing.T, name string, get func() (int, error), list func() ([]int, error)) int {
t.Helper()

n, err := get()
if errors.Is(err, numcpus.ErrNotSupported) {
t.Skipf("Get%s not supported on %s", name, runtime.GOOS)
} else if err != nil {
t.Fatalf("Get%s: %v", name, err)
n, errGet := get()
if errors.Is(errGet, numcpus.ErrNotSupported) {
t.Logf("Get%s not supported on %s", name, runtime.GOOS)
} else if errGet != nil {
t.Errorf("Get%s: %v", name, errGet)
} else {
t.Logf("%s = %v", name, n)
}
t.Logf("%s = %v", name, n)

l, err := list()
if errors.Is(err, numcpus.ErrNotSupported) {
l, errList := list()
if errors.Is(errList, numcpus.ErrNotSupported) {
t.Skipf("List%s not supported on %s", name, runtime.GOOS)
} else if err != nil {
t.Fatalf("List%s: %v", name, err)
} else if errList != nil {
t.Fatalf("List%s: %v", name, errList)
}
t.Logf("List%s = %v", name, l)

if len(l) != n {
if errGet == nil && len(l) != n {
t.Errorf("number of online CPUs in list %v doesn't match expected number of CPUs %d", l, n)
}

Expand All @@ -116,7 +117,6 @@ func TestOnline(t *testing.T) {
n := testNumAndList(t, "Online", numcpus.GetOnline, numcpus.ListOnline)

testGetconf(t, n, "GetOnline", confName("_NPROCESSORS_ONLN"))

}

func TestPossible(t *testing.T) {
Expand Down
Loading