Skip to content

Commit

Permalink
Don't skip testNumAndList if Get* fails or isn't supported
Browse files Browse the repository at this point in the history
  • Loading branch information
tklauser committed Oct 4, 2024
1 parent 8c67b16 commit 515bd58
Showing 1 changed file with 12 additions and 12 deletions.
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

0 comments on commit 515bd58

Please sign in to comment.