From cd798653f390e0545b5ef70c20bd4d007d81aa5a Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Thu, 24 Feb 2022 12:35:30 +0100 Subject: [PATCH] test: always enable syn support in test --- src/lib.rs | 4 ++-- src/tests.rs | 67 ++++++++++++++++++++++++---------------------------- 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 56defc3..c9bdcf5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,7 +101,7 @@ impl Expander { self } - #[cfg(feature = "syndicate")] + #[cfg(any(feature = "syndicate", test))] /// Create a file with `filename` under `env!("OUT_DIR")` if it's not an `Err(_)`. pub fn maybe_write_to_out_dir( self, @@ -119,7 +119,7 @@ impl Expander { self.write_to(tokens, out.as_path()) } - #[cfg(feature = "syndicate")] + #[cfg(any(feature = "syndicate", test))] /// Create a file with `filename` at `dest` if it's not an `Err(_)`. pub fn maybe_write_to( self, diff --git a/src/tests.rs b/src/tests.rs index b85a038..5129613 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,4 +1,5 @@ use super::*; +use proc_macro2::Span; #[test] fn dry() -> Result<(), std::io::Error> { @@ -40,43 +41,37 @@ fn basic() -> Result<(), std::io::Error> { Ok(()) } -#[cfg(feature = "syndicate")] -mod syndicate { - use super::*; - use proc_macro2::Span; - - #[test] - fn ok_is_written_to_external_file() -> Result<(), std::io::Error> { - let ts = Ok(quote! { - pub struct X { - x: [u8;32], - } - }); - let modified = Expander::new("bar") - .add_comment("This is generated code!".to_owned()) - .fmt(Edition::_2021) - // .dry(false) - .maybe_write_to_out_dir(ts.clone())?; +#[test] +fn syn_ok_is_written_to_external_file() -> Result<(), std::io::Error> { + let ts = Ok(quote! { + pub struct X { + x: [u8;32], + } + }); + let modified = Expander::new("bar") + .add_comment("This is generated code!".to_owned()) + .fmt(Edition::_2021) + // .dry(false) + .maybe_write_to_out_dir(ts.clone())?; - let s = modified.to_string(); - assert_ne!(s, ts.unwrap().to_string()); - assert!(s.contains("include ! (")); - Ok(()) - } + let s = modified.to_string(); + assert_ne!(s, ts.unwrap().to_string()); + assert!(s.contains("include ! (")); + Ok(()) +} - #[test] - fn errors_are_not_written_to_external_file() -> Result<(), std::io::Error> { - let ts = Err(syn::Error::new(Span::call_site(), "Hajajajaiii!")); - let modified = Expander::new("") - .add_comment("This is generated code!".to_owned()) - .fmt(Edition::_2021) - // .dry(false) - .maybe_write_to_out_dir(ts.clone())?; +#[test] +fn syn_error_is_not_written_to_external_file() -> Result<(), std::io::Error> { + let ts = Err(syn::Error::new(Span::call_site(), "Hajajajaiii!")); + let modified = Expander::new("") + .add_comment("This is generated code!".to_owned()) + .fmt(Edition::_2021) + // .dry(false) + .maybe_write_to_out_dir(ts.clone())?; - assert_eq!( - ts.unwrap_err().to_compile_error().to_string(), - modified.to_string() - ); - Ok(()) - } + assert_eq!( + ts.unwrap_err().to_compile_error().to_string(), + modified.to_string() + ); + Ok(()) }