From 80c7905063d3a312338b87be2350da058a2d9270 Mon Sep 17 00:00:00 2001 From: Yixin Wei Date: Wed, 16 Sep 2026 05:32:03 -0700 Subject: [PATCH] move FuzzCompute to its own file (#582) Summary: OSS-Fuzz compiles the file holding a fuzz target as a non-test file, so it cannot see declarations in other _test.go files. FuzzCompute shared leaphash_test.go with three tests that use testDoc from testdata_test.go, so the CIFuzz build fails: leaphash/leaphash_test.go_fuzz.go:13:30: undefined: testDoc Move FuzzCompute to its own file. The converted file then references only Compute, and leaphash_test.go is free to grow without breaking the fuzz build. oss-fuzz's build.sh currently seds out one such test to work around this, which only holds until the next one is added. Differential Revision: D120340800 --- leaphash/fuzz_test.go | 28 ++++++++++++++++++++++++++++ leaphash/leaphash_test.go | 6 ------ 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 leaphash/fuzz_test.go diff --git a/leaphash/fuzz_test.go b/leaphash/fuzz_test.go new file mode 100644 index 00000000..a84432b3 --- /dev/null +++ b/leaphash/fuzz_test.go @@ -0,0 +1,28 @@ +/* +Copyright (c) Facebook, Inc. and its affiliates. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package leaphash + +import "testing" + +// Keep this file to FuzzCompute alone. OSS-Fuzz compiles the file holding a fuzz +// target as a non-test file, so it cannot see anything declared in other +// _test.go files. +func FuzzCompute(f *testing.F) { + f.Fuzz(func(_ *testing.T, input string) { + _ = Compute(input) + }) +} diff --git a/leaphash/leaphash_test.go b/leaphash/leaphash_test.go index 1ea1af6d..c5034470 100644 --- a/leaphash/leaphash_test.go +++ b/leaphash/leaphash_test.go @@ -54,9 +54,3 @@ func TestHashIgnoresCarriageReturns(t *testing.T) { t.Fatalf("invalid hash value, got '%s', expected '%s'", hash, testDocHash) } } - -func FuzzCompute(f *testing.F) { - f.Fuzz(func(t *testing.T, input string) { - _ = Compute(input) - }) -}