std::log::testing
Records what a body logs, as values a test asserts on.
testing.run(fn logger -> body) hands the body a Logger that
writes nowhere, and returns the body’s value with every record it
logged through that logger, in order. A body that logs through an app
field gives it the recorder with with App.logger = logger.
Import with import std::log::testing.
Exports
Section titled “Exports”struct Record
Section titled “struct Record”struct Record at: Instant level: Level message: String fields: List<Field> end
One record a logger wrote.
Record.inspect
Section titled “Record.inspect”impl Debug for Record
fn inspect(value: Record) -> String
impl Debug.inspect
Record.equal
Section titled “Record.equal”impl Equatable for Record
fn equal(a: Record, b: Record) -> Bool
impl Equatable.equal
struct Logged
Section titled “struct Logged”struct Logged<T> value: T records: List<Record> end
What run returns: the body’s value and the records it logged.
Logged.inspect
Section titled “Logged.inspect”impl Debug for Logged<T>
fn inspect<T>(value: Logged<T>) -> String where T: Debug
impl Debug.inspect
testing.run
Section titled “testing.run”fn run<T>(min: Level = Level.Debug, body: (Logger) -> T) -> Logged<T>
Runs body with a logger that records each record at min or above,
Debug unless set, and returns its value and the records, in order.
import std::log
got = run(fn logger -> log.warn(logger, "slow", [log.int("ms", 900)]))
assert Iter.count(got.records) == 1
only = List.first(got.records)!
assert only.level == log.Level.Warn
assert only.message == "slow"
assert only.fields == [log.int("ms", 900)]
testing.messages
Section titled “testing.messages”fn messages(records: List<Record>) -> List<String>
The messages of records, for a test that checks only what was said.