blueprint_core_testing_utils/
lib.rs

1use cargo_toml::Manifest;
2pub use error::TestRunnerError;
3pub use runner::TestRunner;
4use std::path::Path;
5
6mod error;
7pub use error::TestRunnerError as Error;
8
9pub mod runner;
10
11/// Reads the manifest at `path`
12///
13/// # Errors
14///
15/// * The manifest is invalid
16/// * The manifest does not have a `package` section
17pub fn read_cargo_toml_file<P: AsRef<Path>>(path: P) -> std::io::Result<Manifest> {
18    let manifest = cargo_toml::Manifest::from_path(path)
19        .map_err(|err| std::io::Error::other(format!("Failed to read Cargo.toml: {err}")))?;
20    if manifest.package.is_none() {
21        return Err(std::io::Error::other(
22            "No package section found in Cargo.toml",
23        ));
24    }
25
26    Ok(manifest)
27}
28
29pub fn setup_log() {
30    use tracing_subscriber::filter::LevelFilter;
31    use tracing_subscriber::util::SubscriberInitExt;
32
33    let _ = tracing_subscriber::fmt::SubscriberBuilder::default()
34        .without_time()
35        .with_span_events(tracing_subscriber::fmt::format::FmtSpan::NONE)
36        .with_env_filter(
37            tracing_subscriber::EnvFilter::builder()
38                .with_default_directive(LevelFilter::INFO.into())
39                .from_env_lossy(),
40        )
41        .finish()
42        .try_init();
43}