NFC: Fix gmock integration in unit tests#8879
Merged
Merged
Conversation
Previously, when `BUILD_FUZZTEST=ON`, the `fuzztest` dependency would download its own newer version of `googletest` (v1.14.0) via CMake `FetchContent`. The `gmock` headers bundled in Binaryen's `third_party/googletest/googlemock` were incompatible with this newer `googletest`. This caused compilation failures for tests using `gmock`. As a workaround, `source-map.cpp` was completely excluded from the test suite during fuzztest builds. This fix works because `fuzztest`'s `FetchContent` actually makes the `gmock` target available as well. By linking `binaryen-unittests` against the `gmock` target when `BUILD_FUZZTEST=ON`, CMake correctly configures the include paths to use the newly fetched `gmock` headers instead of the bundled ones, seamlessly resolving the incompatibility. - Unconditionally include `source-map.cpp` in unit tests, rather than conditionally disabling it when `BUILD_FUZZTEST` is ON. - Link against the `gmock` target for `binaryen-unittests` when `BUILD_FUZZTEST` is ON. - Add a simple gmock test in `arena.cpp` to demonstrate that it correctly compiles and links.
aheejin
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tested with the following code which passes (in arena.cpp, not in source-map.cpp which would have already worked previously due to how it was handled in the build file):
This was written by Gemini. I didn't quite understand the fix but I figured it's worth doing to make tests easier to write. Below is Gemini's description of the fix.
Previously, when
BUILD_FUZZTEST=ON, thefuzztestdependency would download its own newer version ofgoogletest(v1.14.0) via CMakeFetchContent. Thegmockheaders bundled in Binaryen'sthird_party/googletest/googlemockwere incompatible with this newergoogletest. This caused compilation failures for tests usinggmock. As a workaround,source-map.cppwas completely excluded from the test suite during fuzztest builds.This fix works because
fuzztest'sFetchContentactually makes thegmocktarget available as well. By linkingbinaryen-unittestsagainst thegmocktarget whenBUILD_FUZZTEST=ON, CMake correctly configures the include paths to use the newly fetchedgmockheaders instead of the bundled ones, seamlessly resolving the incompatibility.source-map.cppin unit tests, rather than conditionally disabling it whenBUILD_FUZZTESTis ON.gmocktarget forbinaryen-unittestswhenBUILD_FUZZTESTis ON.