tests: add test cases for panics on non-compatible platforms
diff --git a/cpu.go b/cpu.go
index 79ca822..a9b8fc5 100644
--- a/cpu.go
+++ b/cpu.go
@@ -202,6 +202,7 @@
int(C.eCoreL2CacheSize())
}
+// ModelName returns the model name of the CPU.
func ModelName() string {
return C.GoString(C.modelName())
}
diff --git a/incompatible.go b/incompatible.go
index 0a9ddf2..d425025 100644
--- a/incompatible.go
+++ b/incompatible.go
@@ -36,3 +36,18 @@
func ECoreCount() int {
panic("m1cpu: not a darwin/arm64 system")
}
+
+// PCoreCacheSize requires darwin/arm64
+func PCoreCache() (int, int, int) {
+ panic("m1cpu: not a darwin/arm64 system")
+}
+
+// ECoreCacheSize requires darwin/arm64
+func ECoreCache() (int, int, int) {
+ panic("m1cpu: not a darwin/arm64 system")
+}
+
+// ModelName requires darwin/arm64
+func ModelName() string {
+ panic("m1cpu: not a darwin/arm64 system")
+}
diff --git a/incompatible_test.go b/incompatible_test.go
new file mode 100644
index 0000000..fe89ee5
--- /dev/null
+++ b/incompatible_test.go
@@ -0,0 +1,70 @@
+//go:build !darwin || !arm64 || !cgo
+
+package m1cpu
+
+import (
+ "testing"
+
+ "github.com/shoenig/test/must"
+)
+
+const (
+ message = "m1cpu: not a darwin/arm64 system"
+)
+
+func panics(f func()) (message string) {
+ defer func() {
+ if r := recover(); r != nil {
+ message = r.(string)
+ }
+ }()
+ f()
+ return
+}
+
+func Test_IsAppleSilicon(t *testing.T) {
+ result := IsAppleSilicon()
+ must.False(t, result)
+}
+
+func check(t *testing.T, f func()) {
+ t.Helper()
+ result := panics(f)
+ must.Eq(t, result, message)
+}
+
+func Test_PCoreHz(t *testing.T) {
+ check(t, func() { _ = PCoreHz() })
+}
+
+func Test_ECoreHz(t *testing.T) {
+ check(t, func() { _ = ECoreHz() })
+}
+
+func Test_PCoreGHz(t *testing.T) {
+ check(t, func() { _ = PCoreGHz() })
+}
+
+func Test_ECoreGHz(t *testing.T) {
+ check(t, func() { _ = ECoreGHz() })
+}
+
+func Test_PCoreCount(t *testing.T) {
+ check(t, func() { _ = PCoreCount() })
+}
+
+func Test_ECoreCount(t *testing.T) {
+ check(t, func() { _ = ECoreCount() })
+}
+
+func Test_PCoreCache(t *testing.T) {
+ check(t, func() { _, _, _ = PCoreCache() })
+}
+
+func Test_ECoreCache(t *testing.T) {
+ check(t, func() { _, _, _ = ECoreCache() })
+}
+
+func Test_ModelName(t *testing.T) {
+ check(t, func() { _ = ModelName() })
+}