From: Matt Corallo Date: Tue, 20 Jun 2023 17:14:21 +0000 (+0000) Subject: Ensure we build if a downstream crate sets `--cfg=fuzzing` X-Git-Tag: v0.0.116-alpha1~5^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=e49a1ba96ddf16cfc7aa027f7b56a50cd9a3e16a;p=rust-lightning Ensure we build if a downstream crate sets `--cfg=fuzzing` Downstream crates building fur fuzzing will usually set `--cfg=fuzzing` as a side-effect of the Rust fuzzing tooling. Thus, we should ensure we build without failure in such cases. We do this here by simply relying on the `_test_utils` feature, rather than conditionally-compiling in modules based on the `fuzzing` flag. --- diff --git a/lightning/src/chain/chainmonitor.rs b/lightning/src/chain/chainmonitor.rs index 261e5593b..8ce59597d 100644 --- a/lightning/src/chain/chainmonitor.rs +++ b/lightning/src/chain/chainmonitor.rs @@ -502,7 +502,7 @@ where C::Target: chain::Filter, self.event_notifier.notify(); } - #[cfg(any(test, fuzzing, feature = "_test_utils"))] + #[cfg(any(test, feature = "_test_utils"))] pub fn get_and_clear_pending_events(&self) -> Vec { use crate::events::EventsProvider; let events = core::cell::RefCell::new(Vec::new()); diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index cea15b21a..cf0a04aab 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -38,7 +38,7 @@ //! * `max_level_trace` #![cfg_attr(not(any(test, fuzzing, feature = "_test_utils")), deny(missing_docs))] -#![cfg_attr(not(any(test, fuzzing, feature = "_test_utils")), forbid(unsafe_code))] +#![cfg_attr(not(any(test, feature = "_test_utils")), forbid(unsafe_code))] // Prefix these with `rustdoc::` when we update our MSRV to be >= 1.52 to remove warnings. #![deny(broken_intra_doc_links)] @@ -67,7 +67,7 @@ extern crate bitcoin; extern crate core; #[cfg(any(test, feature = "_test_utils"))] extern crate hex; -#[cfg(any(test, fuzzing, feature = "_test_utils"))] extern crate regex; +#[cfg(any(test, feature = "_test_utils"))] extern crate regex; #[cfg(not(feature = "std"))] extern crate core2; diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 595fad60f..7bcc75c01 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -6171,7 +6171,7 @@ where inflight_htlcs } - #[cfg(any(test, fuzzing, feature = "_test_utils"))] + #[cfg(any(test, feature = "_test_utils"))] pub fn get_and_clear_pending_events(&self) -> Vec { let events = core::cell::RefCell::new(Vec::new()); let event_handler = |event: events::Event| events.borrow_mut().push(event); diff --git a/lightning/src/util/mod.rs b/lightning/src/util/mod.rs index 3dbf4f896..dd9d2744e 100644 --- a/lightning/src/util/mod.rs +++ b/lightning/src/util/mod.rs @@ -50,11 +50,11 @@ pub(crate) mod crypto; pub mod logger; pub mod config; -#[cfg(any(test, fuzzing, feature = "_test_utils"))] +#[cfg(any(test, feature = "_test_utils"))] pub mod test_utils; /// impls of traits that add exra enforcement on the way they're called. Useful for detecting state /// machine errors and used in fuzz targets and tests. -#[cfg(any(test, fuzzing, feature = "_test_utils"))] +#[cfg(any(test, feature = "_test_utils"))] pub mod enforcing_trait_impls; diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index fe61e9c72..24979036e 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -45,6 +45,7 @@ use bitcoin::secp256k1::{SecretKey, PublicKey, Secp256k1, ecdsa::Signature, Scal use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1::ecdsa::RecoverableSignature; +#[cfg(any(test, feature = "_test_utils"))] use regex; use crate::io; @@ -738,6 +739,7 @@ impl TestLogger { /// 1. belong to the specified module and /// 2. match the given regex pattern. /// Assert that the number of occurrences equals the given `count` + #[cfg(any(test, feature = "_test_utils"))] pub fn assert_log_regex(&self, module: &str, pattern: regex::Regex, count: usize) { let log_entries = self.lines.lock().unwrap(); let l: usize = log_entries.iter().filter(|&(&(ref m, ref l), _c)| {