Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use util function for tracing_subscriber in tests
  • Loading branch information
ascjones committed Aug 23, 2022
commit d57174b786ef935a6e291ea69821cfd98751c677
18 changes: 1 addition & 17 deletions src/cmd/extrinsics/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,6 @@ impl ContractsNodeProcess {
}
}

/// Init a tracing subscriber for logging in tests.
///
/// Be aware that this enables `TRACE` by default. It also ignores any error
/// while setting up the logger.
///
/// The logs are not shown by default, logs are only shown when the test fails
/// or if [`nocapture`](https://doc.rust-lang.org/cargo/commands/cargo-test.html#display-options)
/// is being used.
#[cfg(feature = "std")]
pub fn init_tracing_subscriber() {
let _ = tracing_subscriber::fmt()
.with_max_level(tracing::Level::TRACE)
.with_test_writer()
.try_init();
}

/// Sanity test the whole lifecycle of:
/// new -> build -> upload -> instantiate -> call
///
Expand All @@ -152,7 +136,7 @@ pub fn init_tracing_subscriber() {
#[ignore]
#[async_std::test]
async fn build_upload_instantiate_call() {
init_tracing_subscriber();
crate::util::tests::init_tracing_subscriber();

let tmp_dir = tempfile::Builder::new()
.prefix("cargo-contract.cli.test.")
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ mod tests {

#[test]
fn generate_metadata() {
tracing_subscriber::fmt::init();
crate::util::tests::init_tracing_subscriber();
with_new_contract_project(|manifest_path| {
// add optional metadata fields
let mut test_manifest = TestContractManifest::new(manifest_path)?;
Expand Down
16 changes: 16 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,22 @@ pub mod tests {
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o777))
.expect("setting permissions failed");
}


/// Init a tracing subscriber for logging in tests.
///
/// Be aware that this enables `TRACE` by default. It also ignores any error
/// while setting up the logger.
///
/// The logs are not shown by default, logs are only shown when the test fails
/// or if [`nocapture`](https://doc.rust-lang.org/cargo/commands/cargo-test.html#display-options)
/// is being used.
pub fn init_tracing_subscriber() {
let _ = tracing_subscriber::fmt()
.with_max_level(tracing::Level::TRACE)
.with_test_writer()
.try_init();
}
}

// Unzips the file at `template` to `out_dir`.
Expand Down