Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tests to be updated automatically #744

Merged
merged 8 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ chalk-integration = { version = "0.76.0-dev.0", path = "chalk-integration" }
[dev-dependencies]
# used for program_writer test errors
diff = "0.1"
expect-test = "1.2.1"
pretty_assertions = "0.6.1"
regex = "1"
15 changes: 11 additions & 4 deletions tests/logging_db/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use chalk_solve::ext::*;
use chalk_solve::logging_db::LoggingRustIrDatabase;
use chalk_solve::RustIrDatabase;

use crate::test::{assert_result, TestGoal};
use crate::test::assert_result_str;

type TestGoal = crate::test::TestGoal<&'static str>;

macro_rules! logging_db_output_sufficient {
($($arg:tt)*) => {{
Expand All @@ -25,12 +27,16 @@ macro_rules! logging_db_output_sufficient {

pub fn logging_db_output_sufficient(
program_text: &str,
goals: Vec<(&str, SolverChoice, TestGoal)>,
goals: Vec<(&str, Vec<SolverChoice>, TestGoal)>,
) {
println!("program {}", program_text);
assert!(program_text.starts_with("{"));
assert!(program_text.ends_with("}"));

let goals = goals
.iter()
.flat_map(|(a, bs, c)| bs.into_iter().map(move |b| (a, b, c)));

let output_text = {
let db = ChalkDatabase::with(
&program_text[1..program_text.len() - 1],
Expand All @@ -39,6 +45,7 @@ pub fn logging_db_output_sufficient(

let program = db.program_ir().unwrap();
let wrapped = LoggingRustIrDatabase::<_, Program, _>::new(program.clone());

chalk_integration::tls::set_current_program(&program, || {
for (goal_text, solver_choice, expected) in goals.clone() {
let mut solver = solver_choice.into_solver();
Expand All @@ -59,7 +66,7 @@ pub fn logging_db_output_sufficient(
match expected {
TestGoal::Aggregated(expected) => {
let result = solver.solve(&wrapped, &peeled_goal);
assert_result(result, expected, db.interner());
assert_result_str(result, expected, db.interner());
}
_ => panic!("only aggregated test goals supported for logger goals"),
}
Expand Down Expand Up @@ -101,7 +108,7 @@ pub fn logging_db_output_sufficient(
match expected {
TestGoal::Aggregated(expected) => {
let result = solver.solve(&db, &peeled_goal);
assert_result(result, expected, db.interner());
assert_result_str(result, expected, db.interner());
}
_ => panic!("only aggregated test goals supported for logger goals"),
}
Expand Down
16 changes: 8 additions & 8 deletions tests/test/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn arrays_are_sized() {
[u32; N]: Sized
}
} yields {
"Unique"
expect![["Unique"]]
}

}
Expand All @@ -35,7 +35,7 @@ fn arrays_are_copy_if_element_copy() {
[Foo; N]: Copy
}
} yields {
"Unique"
expect![["Unique"]]
}
}
}
Expand All @@ -55,7 +55,7 @@ fn arrays_are_not_copy_if_element_not_copy() {
[Foo; N]: Copy
}
} yields {
"No possible solution"
expect![["No possible solution"]]
}
}
}
Expand All @@ -76,7 +76,7 @@ fn arrays_are_clone_if_element_clone() {
[Foo; N]: Clone
}
} yields {
"Unique"
expect![["Unique"]]
}
}
}
Expand All @@ -96,7 +96,7 @@ fn arrays_are_not_clone_if_element_not_clone() {
[Foo; N]: Clone
}
} yields {
"No possible solution"
expect![["No possible solution"]]
}
}
}
Expand All @@ -116,23 +116,23 @@ fn arrays_are_well_formed_if_elem_sized() {
}
}
} yields {
"Unique"
expect![["Unique"]]
}

goal {
forall<const N, T> {
WellFormed([T; N])
}
} yields {
"No possible solution"
expect![["No possible solution"]]
}

goal {
exists<const N, T> {
WellFormed([T; N])
}
} yields {
"Ambiguous; no inference guidance"
expect![["Ambiguous; no inference guidance"]]
}
}
}
Loading