From f97bea61c57fe994890f5e8fdb002911d318ea3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Balv=C3=ADn?= Date: Wed, 5 Aug 2026 23:16:52 +0200 Subject: [PATCH] test(verify): add FuzzResult.String and arrayLen tests to lift coverage over 80% Assisted-by: GLM 5.2 --- verify/fuzz_extra_test.go | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 verify/fuzz_extra_test.go diff --git a/verify/fuzz_extra_test.go b/verify/fuzz_extra_test.go new file mode 100644 index 0000000..1995d2b --- /dev/null +++ b/verify/fuzz_extra_test.go @@ -0,0 +1,52 @@ +// Copyright (c) 2026 Petr Balvín (https://petrbalvin.org) +// SPDX-License-Identifier: BSD-3-Clause + +package verify + +import ( + "testing" +) + +func TestFuzzResultString(t *testing.T) { + t.Run("ok", func(t *testing.T) { + r := FuzzResult{Func: "add", Iterations: 100, Matches: 100} + s := r.String() + if s != "add: 100/100 iterations match" { + t.Errorf("String() = %q", s) + } + }) + + t.Run("mismatch", func(t *testing.T) { + r := FuzzResult{Func: "mul", Iterations: 100, Matches: 95, Mismatches: 5, FirstFail: "iter 23"} + s := r.String() + if s != "mul: 95/100 match, 5 MISMATCH — iter 23" { + t.Errorf("String() = %q", s) + } + }) + + t.Run("crash", func(t *testing.T) { + r := FuzzResult{Func: "dec", Iterations: 100, Matches: 99, Mismatches: 1, FirstFail: "SIGSEGV", CrashInput: []byte{0x01, 0x02}} + s := r.String() + if s != "dec: 99/100 match, 1 MISMATCH — SIGSEGV\n input: 0102" { + t.Errorf("String() = %q", s) + } + }) +} + +func TestArrayLen(t *testing.T) { + tests := []struct { + typ string + want int + }{ + {"*[32]uint16", 32}, + {"*[16]int32", 16}, + {"bad", 1}, + {"*[]", 1}, + {"*[0x]", 1}, + } + for _, tt := range tests { + if got := arrayLen(tt.typ); got != tt.want { + t.Errorf("arrayLen(%q) = %d, want %d", tt.typ, got, tt.want) + } + } +}