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

Some expected are not overwritten with BINDGEN_OVERWRITE_EXPECTED=1 #2054

Open
Apostoln opened this issue May 15, 2021 · 1 comment
Open

Comments

@Apostoln
Copy link

STR:

  1. Change some code in src/codegen/mod.rs related to the generating tests for layout
  2. Try to overwrite expected

BINDGEN_OVERWRITE_EXPECTED=1 cargo test

  1. Run the tests again

cargo test

Actual result:

failures:
test_mixed_header_and_header_contents
test_multiple_header_calls_in_builder

There no changes in appropriate files test_mixed_header_and_header_contents.rs and test_multiple_header_calls_in_builder.rs in tests/expectations/tests/

Expected result:
Tests are passed because expected files are overwritten

As I can see, we are regenerating expected files in fn compare_generated_header inside of macro_rules! test_header which is written to $OUT_DIR/out/tests.rs by build.rs. However, in build.rs we are applying this macro only to headers from tests/headers while test_mixed_header_and_header_contents.rs is generated manually from different headers in fn test_mixed_header_and_header_contents (tests/tests.rs). So, BINDGEN_OVERWRITE_EXPECTED=1 doesn't work here.

I've caught this bug in test_mixed_header_and_header_contents and test_multiple_header_calls_in_builder but I suppose it also affects all tests generated in tests/tests.rs manually.

Sorry, the codebase is a new for me, so I don't know how to fix it easily.

@Apostoln Apostoln changed the title Some expected are not overwrited with BINDGEN_OVERWRITE_EXPECTED=1 Some expected are not overwritten with BINDGEN_OVERWRITE_EXPECTED=1 May 15, 2021
Apostoln added a commit to Apostoln/rust-bindgen that referenced this issue May 16, 2021
 - Replaced dereferencing of null ptr with
   zero bit pattern + transmute + std::ptr::addr_of!
   to avoid UB. It affects only checks of fields offsets
 - Overwritten expected with BINDGEN_OVERWRITE_EXPECTED=1
 - Overwritten test_multiple_header_calls_in_builder and test_mixed_header_and_header_contents
   manually because rust-lang#2054
 - Do not check the layout for repr(C) unions
 - Do not call the destructor of tmp struct to avoid other UB
@emilio
Copy link
Contributor

emilio commented Jun 6, 2021

Yeah, this is expected (and we try to minimize some of the hardcoded tests, and the tests that are dependent on a particular libclang version, but it's non-trivial...)

emilio pushed a commit that referenced this issue Jun 6, 2021
 - Replaced dereferencing of null ptr with
   zero bit pattern + transmute + std::ptr::addr_of!
   to avoid UB. It affects only checks of fields offsets
 - Overwritten expected with BINDGEN_OVERWRITE_EXPECTED=1
 - Overwritten test_multiple_header_calls_in_builder and test_mixed_header_and_header_contents
   manually because #2054
 - Do not check the layout for repr(C) unions
 - Do not call the destructor of tmp struct to avoid other UB
emilio pushed a commit that referenced this issue Nov 26, 2021
 - Replaced dereferencing of null ptr with
   zero bit pattern + transmute + std::ptr::addr_of!
   to avoid UB. It affects only checks of fields offsets
 - Overwritten expected with BINDGEN_OVERWRITE_EXPECTED=1
 - Overwritten test_multiple_header_calls_in_builder and test_mixed_header_and_header_contents
   manually because #2054
 - Do not check the layout for repr(C) unions
 - Do not call the destructor of tmp struct to avoid other UB
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

No branches or pull requests

2 participants