Skip to content

Commit c6f3651

Browse files
authored
test: add some debug calls (#11762)
1 parent 55dab5e commit c6f3651

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/forge/tests/it/test_helpers.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use foundry_evm::{constants::CALLER, opts::EvmOpts};
1818
use foundry_test_utils::{
1919
fd_lock, init_tracing,
2020
rpc::{next_http_archive_rpc_url, next_rpc_endpoint},
21+
test_debug,
2122
};
2223
use revm::primitives::hardfork::SpecId;
2324
use std::{
@@ -278,6 +279,7 @@ pub fn get_vyper() -> Vyper {
278279
};
279280
let url = format!("https://github.com/vyperlang/vyper/releases/download/v0.4.3/vyper.0.4.3+commit.bff19ea2.{suffix}");
280281

282+
test_debug!("downloading vyper from {url}");
281283
let res = reqwest::Client::builder().build().unwrap().get(url).send().await.unwrap();
282284

283285
assert!(res.status().is_success());
@@ -293,6 +295,7 @@ pub fn get_vyper() -> Vyper {
293295
})
294296
}
295297

298+
#[tracing::instrument]
296299
pub fn get_compiled(project: &mut Project) -> ProjectCompileOutput {
297300
let lock_file_path = project.sources_path().join(".lock");
298301
// Compile only once per test run.
@@ -307,13 +310,18 @@ pub fn get_compiled(project: &mut Project) -> ProjectCompileOutput {
307310
if !project.cache_path().exists() || std::fs::read(&lock_file_path).unwrap() != b"1" {
308311
drop(read);
309312
write = Some(lock.write().unwrap());
313+
test_debug!("cache miss for {}", lock_file_path.display());
314+
} else {
315+
test_debug!("cache hit for {}", lock_file_path.display());
310316
}
311317

312318
if project.compiler.vyper.is_none() {
313319
project.compiler.vyper = Some(get_vyper());
314320
}
315321

322+
test_debug!("compiling {}", lock_file_path.display());
316323
out = project.compile().unwrap();
324+
test_debug!("compiled {}", lock_file_path.display());
317325

318326
if out.has_compiler_errors() {
319327
panic!("Compiled with errors:\n{out}");

crates/test-utils/src/lib.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
extern crate tracing;
1212

1313
// Macros useful for testing.
14+
#[macro_use]
1415
mod macros;
1516

1617
pub mod rpc;
@@ -36,18 +37,32 @@ pub use snapbox::{self, assert_data_eq, file, str};
3637

3738
/// Initializes tracing for tests.
3839
pub fn init_tracing() {
39-
if std::env::var_os("RUST_BACKTRACE").is_none() {
40-
unsafe { std::env::set_var("RUST_BACKTRACE", "1") };
41-
}
42-
let _ = tracing_subscriber::FmtSubscriber::builder().with_env_filter(env_filter()).try_init();
43-
let _ = ui_test::color_eyre::install();
40+
use std::sync::Once;
41+
static ONCE: Once = Once::new();
42+
ONCE.call_once(|| {
43+
if std::env::var_os("RUST_BACKTRACE").is_none() {
44+
unsafe { std::env::set_var("RUST_BACKTRACE", "1") };
45+
}
46+
let _ = tracing_subscriber::FmtSubscriber::builder()
47+
.with_env_filter(env_filter())
48+
.with_test_writer()
49+
.try_init();
50+
let _ = ui_test::color_eyre::install();
51+
});
4452
}
4553

4654
fn env_filter() -> tracing_subscriber::EnvFilter {
4755
const DEFAULT_DIRECTIVES: &[&str] = &include!("../../cli/src/utils/default_directives.txt");
48-
let mut filter = tracing_subscriber::EnvFilter::from_default_env();
56+
let mut filter = tracing_subscriber::EnvFilter::builder()
57+
.with_default_directive("foundry_test_utils=debug".parse().unwrap())
58+
.from_env_lossy();
4959
for &directive in DEFAULT_DIRECTIVES {
5060
filter = filter.add_directive(directive.parse().unwrap());
5161
}
5262
filter
5363
}
64+
65+
pub fn test_debug(args: std::fmt::Arguments<'_>) {
66+
init_tracing();
67+
debug!("{args}");
68+
}

crates/test-utils/src/macros.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,10 @@ macro_rules! forgesoldeer {
122122
}
123123
};
124124
}
125+
126+
#[macro_export]
127+
macro_rules! test_debug {
128+
($($args:tt)*) => {
129+
$crate::test_debug(format_args!($($args)*))
130+
}
131+
}

crates/test-utils/src/rpc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ pub fn next_ws_archive_rpc_url() -> String {
128128
fn next_archive_url(is_ws: bool) -> String {
129129
let domain = next(if is_ws { &WS_ARCHIVE_DOMAINS } else { &HTTP_ARCHIVE_DOMAINS });
130130
let url = if is_ws { format!("wss://{domain}") } else { format!("https://{domain}") };
131-
eprintln!("--- next_archive_url(is_ws={is_ws}) = {url} ---");
131+
test_debug!("next_archive_url(is_ws={is_ws}) = {url}");
132132
url
133133
}
134134

135135
/// Returns the next etherscan api key.
136136
pub fn next_etherscan_api_key() -> String {
137137
let key = next(&ETHERSCAN_KEYS).to_string();
138-
eprintln!("--- next_etherscan_api_key() = {key} ---");
138+
test_debug!("next_etherscan_api_key() = {key}");
139139
key
140140
}
141141

@@ -175,7 +175,7 @@ fn next_url(is_ws: bool, chain: NamedChain) -> String {
175175

176176
let url = if is_ws { format!("wss://{domain}") } else { format!("https://{domain}") };
177177

178-
eprintln!("--- next_url(is_ws={is_ws}, chain={chain:?}) = {url} ---");
178+
test_debug!("next_url(is_ws={is_ws}, chain={chain:?}) = {url}");
179179
url
180180
}
181181

0 commit comments

Comments
 (0)