Skip to content

Commit

Permalink
Add warnings_as_errors test
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSignPainter98 committed Nov 22, 2023
1 parent 2b68bc7 commit bb8e3d5
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion crates/emblem_core/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub use module::{Module, ModuleVersion};
use once_cell::unsync::OnceCell;
pub use resource_limit::ResourceLimit;
pub use resources::{Iteration, Memory, Resource, Step};
use std::cell::RefCell;
use std::cell::{Ref, RefCell};
use std::fmt::Debug;

pub struct Context<L: Logger> {
Expand Down Expand Up @@ -136,6 +136,10 @@ impl Context<BatchLogger> {
logger: RefCell::new(BatchLogger::new(Verbosity::Debug)),
}
}

pub fn logger(&self) -> Ref<'_, BatchLogger> {
self.logger.borrow()
}
}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -292,6 +296,32 @@ impl TypesetterParameters {
mod test {
use super::*;

use strum::IntoEnumIterator;

#[test]
fn warnings_as_errors() {
for verbosity in Verbosity::iter() {
for do_conversion in [false, true] {
let logger = BatchLogger::new(verbosity);
let ctx = Context::new(logger).warnings_as_errors(do_conversion);

ctx.print(Log::error("error")).unwrap();
ctx.print(Log::warn("warn")).unwrap();
ctx.print(Log::info("info")).unwrap();

let logger = ctx.logger();
let logs = logger.logs();
assert!(logs[0].msg_type() == MessageType::Error);
if do_conversion {
assert!(logs[1].msg_type() == MessageType::Error);
} else {
assert!(logs[1].msg_type() == MessageType::Warning);
}
assert!(logs[2].msg_type() == MessageType::Info);
}
}
}

#[test]
fn alloc_file_name() {
let ctx = Context::test_new();
Expand Down

0 comments on commit bb8e3d5

Please sign in to comment.