show env_logger working in wiggle tracing example
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2113,6 +2113,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "a7c6b59d116d218cb2d990eb06b77b64043e0268ef7323aae63d8b30ae462923"
|
checksum = "a7c6b59d116d218cb2d990eb06b77b64043e0268ef7323aae63d8b30ae462923"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
"log",
|
||||||
"tracing-attributes",
|
"tracing-attributes",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
@@ -2656,6 +2657,7 @@ dependencies = [
|
|||||||
name = "wiggle-test"
|
name = "wiggle-test"
|
||||||
version = "0.17.0"
|
version = "0.17.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"env_logger 0.7.1",
|
||||||
"proptest",
|
"proptest",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|||||||
@@ -12,12 +12,13 @@ include = ["src/**/*", "LICENSE"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
proptest = "0.9"
|
proptest = "0.9"
|
||||||
wiggle = { path = ".." }
|
wiggle = { path = "..", features = ["tracing_log"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
tracing = "0.1.14"
|
tracing = "0.1.14"
|
||||||
tracing-subscriber = "0.2.4"
|
tracing-subscriber = "0.2.4"
|
||||||
|
env_logger="0.7"
|
||||||
|
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
|
|||||||
@@ -68,51 +68,56 @@ impl<'a> one_error_conversion::OneErrorConversion for WasiCtx<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let subscriber = tracing_subscriber::fmt()
|
if std::env::var("RUST_LOG").is_err() {
|
||||||
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
|
// with no RUST_LOG env variable: use the tracing subscriber.
|
||||||
// will be written to stdout.
|
let subscriber = tracing_subscriber::fmt()
|
||||||
.with_max_level(tracing::Level::TRACE)
|
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
|
||||||
// builds the subscriber.
|
// will be written to stdout.
|
||||||
.finish();
|
.with_max_level(tracing::Level::TRACE)
|
||||||
|
// builds the subscriber.
|
||||||
|
.finish();
|
||||||
|
tracing::subscriber::set_global_default(subscriber).expect("set global tracing subscriber");
|
||||||
|
} else {
|
||||||
|
// with RUST_LOG set: use the env_logger backend to tracing.
|
||||||
|
env_logger::init();
|
||||||
|
}
|
||||||
|
|
||||||
tracing::subscriber::with_default(subscriber, || {
|
let ctx = WasiCtx::new();
|
||||||
let ctx = WasiCtx::new();
|
let host_memory = HostMemory::new();
|
||||||
let host_memory = HostMemory::new();
|
|
||||||
|
|
||||||
// Exercise each of the branches in `foo`.
|
// Exercise each of the branches in `foo`.
|
||||||
// Start with the success case:
|
// Start with the success case:
|
||||||
let r0 = one_error_conversion::foo(&ctx, &host_memory, 0, 0, 8);
|
let r0 = one_error_conversion::foo(&ctx, &host_memory, 0, 0, 8);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r0,
|
r0,
|
||||||
i32::from(types::Errno::Ok),
|
i32::from(types::Errno::Ok),
|
||||||
"Expected return value for strike=0"
|
"Expected return value for strike=0"
|
||||||
);
|
);
|
||||||
assert!(ctx.log.borrow().is_empty(), "No error log for strike=0");
|
assert!(ctx.log.borrow().is_empty(), "No error log for strike=0");
|
||||||
|
|
||||||
// First error case:
|
// First error case:
|
||||||
let r1 = one_error_conversion::foo(&ctx, &host_memory, 1, 0, 8);
|
let r1 = one_error_conversion::foo(&ctx, &host_memory, 1, 0, 8);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r1,
|
r1,
|
||||||
i32::from(types::Errno::PicketLine),
|
i32::from(types::Errno::PicketLine),
|
||||||
"Expected return value for strike=1"
|
"Expected return value for strike=1"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ctx.log.borrow_mut().pop().expect("one log entry"),
|
ctx.log.borrow_mut().pop().expect("one log entry"),
|
||||||
"Won't cross picket line: I'm not a scab",
|
"Won't cross picket line: I'm not a scab",
|
||||||
"Expected log entry for strike=1",
|
"Expected log entry for strike=1",
|
||||||
);
|
);
|
||||||
|
|
||||||
// Second error case:
|
// Second error case:
|
||||||
let r2 = one_error_conversion::foo(&ctx, &host_memory, 2, 0, 8);
|
let r2 = one_error_conversion::foo(&ctx, &host_memory, 2, 0, 8);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r2,
|
r2,
|
||||||
i32::from(types::Errno::InvalidArg),
|
i32::from(types::Errno::InvalidArg),
|
||||||
"Expected return value for strike=2"
|
"Expected return value for strike=2"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ctx.log.borrow_mut().pop().expect("one log entry"),
|
ctx.log.borrow_mut().pop().expect("one log entry"),
|
||||||
"Invalid argument: out-of-bounds: 2",
|
"Invalid argument: out-of-bounds: 2",
|
||||||
"Expected log entry for strike=2",
|
"Expected log entry for strike=2",
|
||||||
);
|
);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user