Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test to compare generated code against expected snapshots, and easy way to update snapshots #241

Open
dtolnay opened this issue Jul 30, 2020 · 0 comments
Labels
test suite How do we know cxx is correct?

Comments

@dtolnay
Copy link
Owner

dtolnay commented Jul 30, 2020

#231 implemented a couple basic code generator tests just based on str::contains like this:

cxx/gen/src/mod.rs

Lines 89 to 91 in 447c808

// To avoid continual breakage we won't test every byte.
// Let's look for the major features.
assert!(output.contains("void cxxbridge03$do_cpp_thing(::rust::Str::Repr foo)"));


This is fine on a small scale but as we flesh out more of this kind of test, it's going to be better to have tests that can be programmatically kept up to date. Like a directory of input source files and the complete output of the code generator against those files, with a single script to update them all when iterating on the code generator (or instead of a script, maybe we run the test with a specific env var to overwrite the snapshots, as https://github.com/dtolnay/trybuild does).

This is how the Rust compiler does its MIR tests (https://github.com/rust-lang/rust/blob/6b269e44322cfca727fd0e793d3a60bd371cbcae/src/test/mir-opt/README.md). x.py test --bless updates them all, and we can inspect the generated diff to tell whether the changes are as intended.

@dtolnay dtolnay added the test suite How do we know cxx is correct? label Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test suite How do we know cxx is correct?
Projects
None yet
Development

No branches or pull requests

1 participant