2018-10-10 00:35:57 +00:00
|
|
|
use crate::constants;
|
2018-09-30 10:59:28 +00:00
|
|
|
use crate::counter::Counter;
|
|
|
|
use crate::log::Log;
|
2018-10-01 12:23:18 +00:00
|
|
|
use crate::memoized_dep_inputs;
|
2018-09-30 14:50:46 +00:00
|
|
|
use crate::memoized_inputs;
|
2018-09-30 14:34:52 +00:00
|
|
|
use crate::memoized_volatile;
|
|
|
|
|
2018-10-09 19:34:30 +00:00
|
|
|
pub(crate) trait TestContext: salsa::Database {
|
2018-09-30 14:34:52 +00:00
|
|
|
fn clock(&self) -> &Counter;
|
|
|
|
fn log(&self) -> &Log;
|
|
|
|
}
|
2018-09-30 10:59:28 +00:00
|
|
|
|
2019-01-25 00:02:56 +00:00
|
|
|
#[salsa::database(
|
2019-01-25 15:25:17 +00:00
|
|
|
constants::Constants,
|
|
|
|
memoized_dep_inputs::MemoizedDepInputs,
|
|
|
|
memoized_inputs::MemoizedInputs,
|
|
|
|
memoized_volatile::MemoizedVolatile
|
2019-01-25 00:02:56 +00:00
|
|
|
)]
|
2018-09-30 10:59:28 +00:00
|
|
|
#[derive(Default)]
|
2018-10-09 19:34:30 +00:00
|
|
|
pub(crate) struct TestContextImpl {
|
2018-10-07 11:08:22 +00:00
|
|
|
runtime: salsa::Runtime<TestContextImpl>,
|
2018-09-30 10:59:28 +00:00
|
|
|
clock: Counter,
|
|
|
|
log: Log,
|
|
|
|
}
|
|
|
|
|
2018-09-30 14:34:52 +00:00
|
|
|
impl TestContextImpl {
|
2018-10-09 19:34:30 +00:00
|
|
|
pub(crate) fn assert_log(&self, expected_log: &[&str]) {
|
2018-09-30 14:34:52 +00:00
|
|
|
let expected_text = &format!("{:#?}", expected_log);
|
|
|
|
let actual_text = &format!("{:#?}", self.log().take());
|
|
|
|
|
|
|
|
if expected_text == actual_text {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-22 13:12:15 +00:00
|
|
|
for diff in diff::lines(expected_text, actual_text) {
|
|
|
|
match diff {
|
|
|
|
diff::Result::Left(l) => println!("-{}", l),
|
|
|
|
diff::Result::Both(l, _) => println!(" {}", l),
|
|
|
|
diff::Result::Right(r) => println!("+{}", r),
|
2018-09-30 14:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
panic!("incorrect log results");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TestContext for TestContextImpl {
|
2018-09-30 10:59:28 +00:00
|
|
|
fn clock(&self) -> &Counter {
|
|
|
|
&self.clock
|
|
|
|
}
|
|
|
|
|
|
|
|
fn log(&self) -> &Log {
|
|
|
|
&self.log
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 08:54:51 +00:00
|
|
|
impl salsa::Database for TestContextImpl {
|
2018-10-07 11:08:22 +00:00
|
|
|
fn salsa_runtime(&self) -> &salsa::Runtime<TestContextImpl> {
|
2018-09-30 10:59:28 +00:00
|
|
|
&self.runtime
|
|
|
|
}
|
|
|
|
}
|