Merge ws/triage: kernel-choice tests no longer switch the process to solidcore
This commit is contained in:
commit
8ed2b2254f
2 files changed
+52
-15
No files matched your search
@@ -81,6 +81,10 @@ impl Drop for KernelChoice {
|
||||
|
||||
/// diagnostics.kernel lists every operation family with the table's kernel and the one it runs
|
||||
/// on now, and its `choice` moves them (unless SOLIDCRAFT_KERNEL overrides it).
|
||||
///
|
||||
/// The choice is process-wide and the other tests in this binary build bodies meanwhile, so only
|
||||
/// choices that route every family as the table does are set through the command; what the
|
||||
/// others would route to is read from `Op::backend_under`, which the command's own answer follows.
|
||||
#[test]
|
||||
fn diagnostics_kernel_reports_and_sets_the_choice() {
|
||||
use solidcraft_kernel::kernel_route as route;
|
||||
@@ -97,25 +101,30 @@ fn diagnostics_kernel_reports_and_sets_the_choice() {
|
||||
let environment = route::overridden();
|
||||
assert_eq!(r["environment"], json!(environment), "{r}");
|
||||
for choice in ["solidcore", "smlib", "routed"] {
|
||||
let r = s.execute("diagnostics.kernel", &json!({ "choice": choice })).unwrap();
|
||||
// Back to the table straight away: other tests in this process build bodies meanwhile.
|
||||
if choice != "routed" {
|
||||
route::set_choice(route::Choice::Routed);
|
||||
}
|
||||
if environment {
|
||||
continue; // SOLIDCRAFT_KERNEL wins: the choice and the backends stay its own
|
||||
}
|
||||
assert_eq!(r["choice"], json!(choice), "{r}");
|
||||
for (row, op) in r["routes"].as_array().unwrap().iter().zip(route::Op::ALL) {
|
||||
// `.smb` files stay on SMLib whatever is chosen.
|
||||
let c = route::Choice::from_id(choice).unwrap();
|
||||
// `.smb` files stay on SMLib whatever is chosen.
|
||||
for op in route::Op::ALL {
|
||||
let want = match choice {
|
||||
_ if op == route::Op::File => "smlib",
|
||||
"routed" => op.route().id(),
|
||||
other => other,
|
||||
};
|
||||
assert_eq!(row["backend"], json!(want), "{choice}: {r}");
|
||||
assert_eq!(op.backend_under(c).id(), want, "{choice}: {op:?}");
|
||||
}
|
||||
if !route::Op::ALL.iter().all(|op| op.backend_under(c) == op.route()) {
|
||||
continue; // it would move other tests' bodies to another kernel
|
||||
}
|
||||
let r = s.execute("diagnostics.kernel", &json!({ "choice": choice })).unwrap();
|
||||
if environment {
|
||||
continue; // SOLIDCRAFT_KERNEL wins: the choice and the backends stay its own
|
||||
}
|
||||
assert_eq!(r["choice"], json!(choice), "{r}");
|
||||
for (row, op) in r["routes"].as_array().unwrap().iter().zip(route::Op::ALL) {
|
||||
assert_eq!(row["backend"], json!(op.backend_under(c).id()), "{choice}: {r}");
|
||||
}
|
||||
}
|
||||
let r = s.execute("diagnostics.kernel", &json!({ "choice": "routed" })).unwrap();
|
||||
assert!(environment || r["choice"] == json!("routed"), "{r}");
|
||||
}
|
||||
|
||||
/// An unknown or mistyped choice is an error that changes nothing; no hostile value panics.
|
||||
|
||||
@@ -112,10 +112,16 @@ impl Op {
|
||||
/// The kernel this family runs on now: `SOLIDCRAFT_KERNEL`, else the preference, else
|
||||
/// [`Op::route`]. `.smb` files stay on SMLib whatever is chosen.
|
||||
pub fn backend(self) -> Backend {
|
||||
self.backend_under(choice())
|
||||
}
|
||||
|
||||
/// The kernel this family runs on under `c`, whatever is in force now: what [`Op::backend`]
|
||||
/// answers once `c` is the choice. `.smb` files stay on SMLib whatever is chosen.
|
||||
pub fn backend_under(self, c: Choice) -> Backend {
|
||||
if self == Op::File {
|
||||
return Backend::Smlib;
|
||||
}
|
||||
match choice() {
|
||||
match c {
|
||||
Choice::Routed => self.route(),
|
||||
Choice::Only(b) => b,
|
||||
}
|
||||
@@ -203,14 +209,36 @@ mod tests {
|
||||
assert_eq!(Op::File.backend(), Backend::Smlib);
|
||||
}
|
||||
|
||||
/// Each choice sends the families where it says, read without setting the process-wide
|
||||
/// preference: the other tests in this binary build bodies meanwhile, and one flipped to
|
||||
/// solidcore for an instant would build theirs there.
|
||||
#[test]
|
||||
fn each_choice_routes_every_family_without_touching_the_preference() {
|
||||
for op in Op::ALL {
|
||||
let want = |b: Backend| if op == Op::File { Backend::Smlib } else { b };
|
||||
assert_eq!(op.backend_under(Choice::Routed), op.route(), "{op:?}");
|
||||
assert_eq!(op.backend_under(Choice::Only(Backend::Smlib)), want(Backend::Smlib), "{op:?}");
|
||||
assert_eq!(op.backend_under(Choice::Only(Backend::Solidcore)), want(Backend::Solidcore), "{op:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The preference is what `backend` follows. Only a choice that routes every family as the
|
||||
/// table does is set here, so no other test's body changes kernel.
|
||||
#[test]
|
||||
fn the_preference_routes_unless_the_environment_overrides() {
|
||||
if overridden() {
|
||||
return;
|
||||
}
|
||||
set_choice(Choice::Only(Backend::Solidcore));
|
||||
assert_eq!(Op::Boolean.backend(), Backend::Solidcore);
|
||||
let harmless = [Choice::Only(Backend::Smlib), Choice::Only(Backend::Solidcore)]
|
||||
.into_iter()
|
||||
.find(|c| Op::ALL.iter().all(|op| op.backend_under(*c) == op.route()));
|
||||
if let Some(c) = harmless {
|
||||
set_choice(c);
|
||||
assert_eq!(choice(), c);
|
||||
assert!(Op::ALL.iter().all(|op| op.backend() == op.backend_under(c)));
|
||||
}
|
||||
set_choice(Choice::Routed);
|
||||
assert_eq!(choice(), Choice::Routed);
|
||||
assert!(Op::ALL.iter().all(|op| op.backend() == op.route()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user