Skip to content

NFC: Fix gmock integration in unit tests#8879

Merged
stevenfontanella merged 1 commit into
mainfrom
gmock
Jul 1, 2026
Merged

NFC: Fix gmock integration in unit tests#8879
stevenfontanella merged 1 commit into
mainfrom
gmock

Conversation

@stevenfontanella

@stevenfontanella stevenfontanella commented Jun 30, 2026

Copy link
Copy Markdown
Member

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):

#include "gmock/gmock-matchers.h"
...
EXPECT_THAT(1, ::testing::Eq(1));

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, 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.

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.
@stevenfontanella stevenfontanella changed the title Fix gmock integration when BUILD_FUZZTEST is ON NFC: Fix gmock integration in unit tests Jun 30, 2026
@stevenfontanella stevenfontanella marked this pull request as ready for review June 30, 2026 21:28
@stevenfontanella stevenfontanella requested a review from a team as a code owner June 30, 2026 21:28
@stevenfontanella stevenfontanella requested review from aheejin and removed request for a team June 30, 2026 21:29
@stevenfontanella stevenfontanella merged commit 8c3dfa2 into main Jul 1, 2026
16 checks passed
@stevenfontanella stevenfontanella deleted the gmock branch July 1, 2026 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants