Use generated fixture for wrap macro test

Co-authored-by: wravery <6502881+wravery@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]andwravery authored and GitHub committed 2026-09-06 22:03:44 +00:00
1 parent 323462ced4
commit 0a019e7fa4
1 file changed
+55 -21
+55 -21
View File
@@ -116,16 +116,64 @@ fn read_bindings(source_path: &Path) -> crate::Result<String> {
#[cfg(test)]
mod tests {
use super::parse_tree;
use std::fs;
#[test]
fn generated_wrap_macros_support_external_trait_impls() {
let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
let bindings_dir = manifest_dir
.join("..")
.join("cef")
.join("src")
.join("bindings");
let test_dir = std::env::temp_dir().join(format!(
"cef-rs-wrap-macro-generator-test-{}",
std::process::id()
));
fs::create_dir_all(&test_dir).unwrap();
let source_path = test_dir.join("bindings.rs");
fs::write(
&source_path,
r#"
#![allow(non_camel_case_types)]
pub type size_t = usize;
#[repr(C)]
pub type cef_base_ref_counted_t = _cef_base_ref_counted_t;
#[repr(C)]
pub struct _cef_base_ref_counted_t {
pub size: size_t,
pub add_ref: Option<unsafe extern "C" fn(self_: *mut _cef_base_ref_counted_t)>,
pub release: Option<unsafe extern "C" fn(self_: *mut _cef_base_ref_counted_t) -> ::std::os::raw::c_int>,
pub has_one_ref: Option<unsafe extern "C" fn(self_: *mut _cef_base_ref_counted_t) -> ::std::os::raw::c_int>,
pub has_at_least_one_ref: Option<unsafe extern "C" fn(self_: *mut _cef_base_ref_counted_t) -> ::std::os::raw::c_int>,
}
#[repr(C)]
pub struct cef_size_t {
pub width: ::std::os::raw::c_int,
pub height: ::std::os::raw::c_int,
}
#[repr(C)]
pub struct _cef_view_delegate_t {
pub base: _cef_base_ref_counted_t,
pub get_preferred_size: Option<unsafe extern "C" fn(self_: *mut _cef_view_delegate_t) -> cef_size_t>,
}
#[repr(C)]
pub struct _cef_panel_delegate_t {
pub base: _cef_view_delegate_t,
}
#[repr(C)]
pub struct _cef_window_delegate_t {
pub base: _cef_panel_delegate_t,
pub can_close: Option<unsafe extern "C" fn(self_: *mut _cef_window_delegate_t) -> ::std::os::raw::c_int>,
}
"#,
)
.unwrap();
let generated_path = parse_tree::generate_bindings(&source_path).unwrap();
let generated = fs::read_to_string(generated_path).unwrap();
let patterns = [
"pubtraitImplWindowDelegate:ImplPanelDelegate",
"pubtraitImplViewDelegate:Clone+Sized+Rc+crate::rc::WrapRcPtr",
@@ -134,21 +182,7 @@ mod tests {
]
.map(strip_whitespace);
let mut bindings = String::new();
for entry in fs::read_dir(bindings_dir).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if !path.is_file()
|| path.extension().and_then(|extension| extension.to_str()) != Some("rs")
|| path.file_name().is_some_and(|name| name == "mod.rs")
{
continue;
}
bindings.push_str(&fs::read_to_string(&path).unwrap());
}
let bindings = strip_whitespace(&bindings);
let bindings = strip_whitespace(&generated);
for pattern in patterns.iter() {
assert!(
bindings.contains(pattern),