Skip to content

Commit e9fcc7c

Browse files
committed
fix: skip fallback header_contents tests on clang 9
clang 9's clang_Cursor_Evaluate returns CXEval_UnExposed instead of CXEval_Int for macro-expanded expressions loaded through a PCH, so clang_macro_fallback produces no constants on that version. The existing header-based fallback tests already handle this with clang-9-specific empty expectation files; apply the same pattern to the new inline tests by skipping when libclang 9 is detected.
1 parent cf7c69e commit e9fcc7c

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

bindgen-tests/tests/tests.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,19 @@ fn test_macro_fallback_non_system_dir() {
617617
}
618618
}
619619

620+
/// clang 9's `clang_Cursor_Evaluate` returns `CXEval_UnExposed` instead
621+
/// of `CXEval_Int` for macro-expanded expressions loaded through a PCH
622+
/// built from materialized `header_contents()` files, so fallback
623+
/// constant evaluation produces no results in that specific path.
624+
fn clang9_fallback_header_contents_works() -> bool {
625+
!matches!(clang_version().parsed, Some((9, _)))
626+
}
627+
620628
#[test]
621629
fn test_macro_fallback_header_contents() {
630+
if !clang9_fallback_header_contents_works() {
631+
return;
632+
}
622633
let tmpdir = tempfile::tempdir().unwrap();
623634
let actual = builder()
624635
.disable_header_comment()
@@ -647,6 +658,9 @@ fn test_macro_fallback_header_contents() {
647658

648659
#[test]
649660
fn test_macro_fallback_multiple_header_contents() {
661+
if !clang9_fallback_header_contents_works() {
662+
return;
663+
}
650664
let tmpdir = tempfile::tempdir().unwrap();
651665
let actual = builder()
652666
.disable_header_comment()
@@ -675,6 +689,9 @@ fn test_macro_fallback_multiple_header_contents() {
675689

676690
#[test]
677691
fn test_macro_fallback_mixed_header_and_header_contents() {
692+
if !clang9_fallback_header_contents_works() {
693+
return;
694+
}
678695
let tmpdir = tempfile::tempdir().unwrap();
679696
let actual = builder()
680697
.disable_header_comment()
@@ -709,6 +726,9 @@ fn test_macro_fallback_mixed_header_and_header_contents() {
709726

710727
#[test]
711728
fn test_macro_fallback_header_contents_duplicate_basename() {
729+
if !clang9_fallback_header_contents_works() {
730+
return;
731+
}
712732
let tmpdir = tempfile::tempdir().unwrap();
713733
let actual = builder()
714734
.disable_header_comment()
@@ -768,11 +788,13 @@ fn test_macro_fallback_header_contents_absolute_name() {
768788
.unwrap()
769789
.to_string();
770790

771-
// The fallback-only constant should be evaluated.
772-
assert!(
773-
actual.contains("pub const ABS_CONST: u32 = 55;"),
774-
"Expected ABS_CONST in output:\n{actual}"
775-
);
791+
// The fallback-only constant should be evaluated (not on clang 9).
792+
if clang9_fallback_header_contents_works() {
793+
assert!(
794+
actual.contains("pub const ABS_CONST: u32 = 55;"),
795+
"Expected ABS_CONST in output:\n{actual}"
796+
);
797+
}
776798

777799
// The original file must not have been deleted by FallbackTU drop.
778800
assert!(
@@ -811,10 +833,12 @@ fn test_macro_fallback_header_contents_parent_dir_escape() {
811833
.unwrap()
812834
.to_string();
813835

814-
assert!(
815-
actual.contains("pub const ESCAPE_CONST: u32 = 77;"),
816-
"Expected ESCAPE_CONST in output:\n{actual}"
817-
);
836+
if clang9_fallback_header_contents_works() {
837+
assert!(
838+
actual.contains("pub const ESCAPE_CONST: u32 = 77;"),
839+
"Expected ESCAPE_CONST in output:\n{actual}"
840+
);
841+
}
818842

819843
// The file outside build_dir must not have been clobbered.
820844
assert!(
@@ -826,6 +850,9 @@ fn test_macro_fallback_header_contents_parent_dir_escape() {
826850

827851
#[test]
828852
fn test_macro_fallback_cross_target() {
853+
if !clang9_fallback_header_contents_works() {
854+
return;
855+
}
829856
// Subprocess-style test: setting TARGET as an env var in a parallel
830857
// test is not robust, so we re-invoke the test binary as a child
831858
// process with TARGET set to a non-host triple. The child runs the

0 commit comments

Comments
 (0)