From 879cbcbeb8d048941059901468763aeedd107fb3 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 2 Dec 2024 11:04:52 -0500 Subject: [PATCH] test: disable formatting on demand --- .../tests/derive-and-attribute-order.rs | 12 +++------ .../headers/derive-and-attribute-order.h | 1 + bindgen-tests/tests/tests.rs | 26 ++++++++++++++----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/derive-and-attribute-order.rs b/bindgen-tests/tests/expectations/tests/derive-and-attribute-order.rs index 02afb8d203..ecb81f3f93 100644 --- a/bindgen-tests/tests/expectations/tests/derive-and-attribute-order.rs +++ b/bindgen-tests/tests/expectations/tests/derive-and-attribute-order.rs @@ -1,9 +1,5 @@ + #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, serde::Serialize)] -#[serde(rename_all = "UPPERCASE")] -pub struct color { - pub red: ::std::os::raw::c_int, - pub green: ::std::os::raw::c_int, - pub blue: ::std::os::raw::c_int, -} + + +# [repr (C)] # [derive (Debug , Default , Copy , Clone , serde :: Serialize)] # [serde (rename_all = "UPPERCASE")] pub struct color { pub red : :: std :: os :: raw :: c_int , pub green : :: std :: os :: raw :: c_int , pub blue : :: std :: os :: raw :: c_int , } \ No newline at end of file diff --git a/bindgen-tests/tests/headers/derive-and-attribute-order.h b/bindgen-tests/tests/headers/derive-and-attribute-order.h index 7a71a4f69b..f404b3abd1 100644 --- a/bindgen-tests/tests/headers/derive-and-attribute-order.h +++ b/bindgen-tests/tests/headers/derive-and-attribute-order.h @@ -1,5 +1,6 @@ // bindgen-flags: --no-layout-tests // bindgen-parse-callbacks: derive-uppercase-serialize=color +// bindgen-skip-formatting typedef struct { int red; int green; diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 0b3ebe1533..40486eda40 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -187,17 +187,23 @@ fn compare_generated_header( looked_at, ), }; - + let do_formatting = builder.do_formatting; let (builder, roundtrip_builder) = builder.into_builder(check_roundtrip)?; // We skip the generate() error here so we get a full diff below let actual = match builder.generate() { - Ok(bindings) => format_code(bindings.to_string()).map_err(|err| { - Error::new( - ErrorKind::Other, - format!("Cannot parse the generated bindings: {err}"), - ) - })?, + Ok(bindings) => { + if do_formatting { + format_code(bindings.to_string()).map_err(|err| { + Error::new( + ErrorKind::Other, + format!("Cannot parse the generated bindings: {err}"), + ) + })? + } else { + bindings.to_string() + } + } Err(_) => "/* error generating bindings */\n".into(), }; @@ -237,6 +243,7 @@ fn builder() -> Builder { struct BuilderState { builder: Builder, parse_callbacks: Option, + do_formatting: bool, } impl BuilderState { @@ -255,6 +262,7 @@ impl BuilderState { Some(BuilderState { builder, parse_callbacks: self.parse_callbacks, + do_formatting: self.do_formatting, }) } else { None @@ -273,6 +281,7 @@ fn create_bindgen_builder(header: &Path) -> Result { // Scoop up bindgen-flags from test header let mut flags = Vec::with_capacity(2); let mut parse_callbacks = None; + let mut do_formatting = true; for line in reader.lines() { let line = line?; @@ -298,6 +307,8 @@ fn create_bindgen_builder(header: &Path) -> Result { let parse_cb = line.split("bindgen-parse-callbacks: ").last().unwrap(); parse_callbacks = Some(parse_cb.to_owned()); + } else if line.contains("bindgen-skip-formatting") { + do_formatting = false; } } @@ -345,6 +356,7 @@ fn create_bindgen_builder(header: &Path) -> Result { Ok(BuilderState { builder, parse_callbacks, + do_formatting, }) }