2 releases
Uses new Rust 2024
| 0.0.11 | Jul 6, 2026 |
|---|---|
| 0.0.10 | May 31, 2026 |
#631 in Testing
280KB
5K
SLoC
rlg-test
Test utilities for downstream crates that depend on rlg.
Capture records and assert on them inside #[test] scopes.
Install
[dev-dependencies]
rlg-test = "0.0.11"
Requires Rust 1.88.0 or newer (edition 2024).
Usage
use rlg::log::Log;
use rlg::log_level::LogLevel;
use rlg_test::{capture, LogExt, assert_logged};
#[test]
fn emits_auth_record() {
let capture = capture();
// Route the record into the capture handle instead of the engine.
Log::info("user authenticated")
.component("auth")
.with("user_id", 42_u64)
.log_to(&capture);
assert_logged!(capture, level == LogLevel::INFO);
assert_logged!(capture, contains "authenticated");
assert_logged!(capture, component "auth");
assert_logged!(capture, attribute "user_id" => 42_u64);
assert_logged!(capture, len == 1);
}
Predicates
| Form | Predicate |
|---|---|
level == LogLevel::INFO |
record at the given level exists |
contains "needle" |
record description contains the substring |
attribute "k" => v |
record's attribute equals the value |
component "name" |
record's component equals the string |
len == n |
exactly n records were captured |
Each is also exposed as a free function (has_level,
description_contains, attribute_eq, has_component) so you can
compose them or use them outside the macro.
License
Dual-licensed under Apache 2.0 or MIT, at your option.
Dependencies
~7–10MB
~205K SLoC