salsa/tests/synthetic_write.rs

44 lines
1,002 B
Rust
Raw Normal View History

2024-07-26 13:56:51 +00:00
//! Test that a constant `tracked` fn (has no inputs)
//! compiles and executes successfully.
#![allow(warnings)]
mod common;
use common::{LogDatabase, Logger};
2024-07-26 13:56:51 +00:00
use expect_test::expect;
use salsa::{Database, DatabaseImpl, Durability, Event, EventKind};
2024-07-26 13:56:51 +00:00
#[salsa::input]
struct MyInput {
field: u32,
}
#[salsa::tracked]
fn tracked_fn(db: &dyn Database, input: MyInput) -> u32 {
2024-07-26 13:56:51 +00:00
input.field(db) * 2
}
#[test]
fn execute() {
let mut db = common::ExecuteValidateLoggerDatabase::default();
2024-07-26 13:56:51 +00:00
let input = MyInput::new(&db, 22);
assert_eq!(tracked_fn(&db, input), 44);
db.assert_logs(expect![[r#"
[
"salsa_event(WillExecute { database_key: tracked_fn(0) })",
2024-07-26 13:56:51 +00:00
]"#]]);
// Bumps the revision
db.synthetic_write(Durability::LOW);
// Query should re-run
assert_eq!(tracked_fn(&db, input), 44);
db.assert_logs(expect![[r#"
[
"salsa_event(DidValidateMemoizedValue { database_key: tracked_fn(0) })",
2024-07-26 13:56:51 +00:00
]"#]]);
}