a1ca700bff
Introduced a new `Logger` trait which can be used to access all log events emitted during compilation. Currently these only include messages emitted by the `@debug` and `@warn` statements. Changes were implemented in a backwards-compatible manner, but the current `Options::quiet` method has been marked as deprecated, as its behavior can be achieved using the `NullLogger` structure. The default logger used is `StdLogger` which writes all log events to standard error. This reflect the default behavior prior to introduction of `Logger`. With these new changes, it is also now possible to properly test the `@debug` and `@warn` statements.
38 lines
1.3 KiB
Rust
38 lines
1.3 KiB
Rust
use macros::TestLogger;
|
|
|
|
#[macro_use]
|
|
mod macros;
|
|
|
|
#[test]
|
|
fn simple_debug() {
|
|
let input = "@debug 2";
|
|
let logger = TestLogger::default();
|
|
let options = grass::Options::default().logger(&logger);
|
|
let output = grass::from_string(input.to_string(), &options).expect(input);
|
|
assert_eq!(&output, "");
|
|
assert_eq!(&[String::from("2")], logger.debug_messages().as_slice());
|
|
assert_eq!(&[] as &[String], logger.warning_messages().as_slice());
|
|
}
|
|
|
|
#[test]
|
|
fn simple_debug_with_semicolon() {
|
|
let input = "@debug 2;";
|
|
let logger = TestLogger::default();
|
|
let options = grass::Options::default().logger(&logger);
|
|
let output = grass::from_string(input.to_string(), &options).expect(input);
|
|
assert_eq!(&output, "");
|
|
assert_eq!(&[String::from("2")], logger.debug_messages().as_slice());
|
|
assert_eq!(&[] as &[String], logger.warning_messages().as_slice());
|
|
}
|
|
|
|
#[test]
|
|
fn debug_while_quiet() {
|
|
let input = "@debug 2;";
|
|
let logger = TestLogger::default();
|
|
let options = grass::Options::default().logger(&logger).quiet(true);
|
|
let output = grass::from_string(input.to_string(), &options).expect(input);
|
|
assert_eq!(&output, "");
|
|
assert_eq!(&[] as &[String], logger.debug_messages().as_slice());
|
|
assert_eq!(&[] as &[String], logger.warning_messages().as_slice());
|
|
}
|