Add C++ golden file test suite - #223
Merged
Merged
Conversation
Collaborator
Author
EricRahm
force-pushed
the
rust-backend-py-goldens
branch
from
July 2, 2025 23:55
c589fd2 to
e9fa82a
Compare
Collaborator
Author
|
Jason can you take a look? You can ignore the generated |
jasongraffius
approved these changes
Jul 8, 2025
jasongraffius
left a comment
Collaborator
There was a problem hiding this comment.
LGTM % minor copyright header nits
EricRahm
force-pushed
the
rust-backend-py-goldens
branch
from
July 8, 2025 02:35
e9fa82a to
d2f500b
Compare
This change introduces a robust, granular testing infrastructure for the C++ backend using golden files. This test suite serves as a critical safety net to enable safe and efficient refactoring of the code generator in the future. By comparing generated code against a set of "golden" (known-good) header files, we can quickly detect any unintended changes or regressions. Key Features: * **Granular Tests:** Each golden file comparison is a standalone `py_test` target, allowing for parallel execution and precise failure identification. * **`cpp_golden_test` Macro:** A new Starlark macro, `cpp_golden_test`, has been added to `compiler/back_end/cpp/build_defs.bzl`. This simplifies adding new golden tests by abstracting away the underlying `py_test` implementation details. * **Debugging:** To simplify the diagnosis of regressions, test failures produce a `diff` of the generated file against its golden counterpart. * **Full Coverage:** The suite includes tests for all `.emb` files in the `testdata` directory, including those with complex dependencies and imports. Usage: **To run all C++ golden tests:** ``` bazel test //compiler/back_end/cpp/... --test_tag_filters=golden ``` **To run a single golden test:** ``` bazel test //compiler/back_end/cpp:bits_golden_test ``` **To add a new golden test:** 1. Add your `.emb` file to `testdata/`. 2. Generate the corresponding golden `.emb.h` file (e.g., by temporarily modifying and running the `generate_golden_files.sh` script via a `sh_binary`). 3. Copy the new golden file into `testdata/golden_cpp/`. 4. Add a `cpp_golden_test()` rule to `compiler/back_end/cpp/BUILD`.
EricRahm
force-pushed
the
rust-backend-py-goldens
branch
from
July 8, 2025 02:38
d2f500b to
3e36782
Compare
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.
This change introduces a robust, granular testing infrastructure for the C++ backend using golden files. This test suite serves as a critical safety net to enable safe and efficient refactoring of the code generator in the future.
By comparing generated code against a set of "golden" (known-good) header files, we can quickly detect any unintended changes or regressions.
Key Features:
py_testtarget, allowing for parallel execution and precise failure identification.cpp_golden_testMacro: A new Starlark macro,cpp_golden_test, has been added tocompiler/back_end/cpp/build_defs.bzl. This simplifies adding new golden tests by abstracting away the underlyingpy_testimplementation details.diffof the generated file against its golden counterpart..embfiles in thetestdatadirectory, including those with complex dependencies and imports.Usage:
To run all C++ golden tests:
To run a single golden test:
To add a new golden test:
.embfile totestdata/..emb.hfile (e.g., by temporarily modifying and running thegenerate_golden_files.shscript via ash_binary).testdata/golden_cpp/.cpp_golden_test()rule tocompiler/back_end/cpp/BUILD.