use std::path::PathBuf;
use std::process::Command;
fn pounce_exe() -> PathBuf {
PathBuf::from(env!("CARGO_BIN_EXE_pounce"))
}
#[test]
fn auto_solves_builtin_unchanged() {
let output = Command::new(pounce_exe())
.arg("--problem")
.arg("rosenbrock")
.arg("solver_selection=auto")
.output()
.expect("spawn pounce");
assert_eq!(
output.status.code(),
Some(0),
"auto should solve rosenbrock; stderr={}",
String::from_utf8_lossy(&output.stderr)
);
}
#[test]
fn default_has_no_solver_selection_regression() {
let output = Command::new(pounce_exe())
.arg("--problem")
.arg("rosenbrock")
.output()
.expect("spawn pounce");
assert_eq!(output.status.code(), Some(0));
}
#[test]
fn forced_lp_on_nlp_errors() {
let output = Command::new(pounce_exe())
.arg("--problem")
.arg("rosenbrock")
.arg("solver_selection=lp-ipm")
.output()
.expect("spawn pounce");
assert_eq!(
output.status.code(),
Some(2),
"forced mismatch should exit 2"
);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("NLP") && stderr.contains("lp-ipm"),
"error should name detected class and forced solver: {stderr}"
);
}
#[test]
fn forced_qp_solvers_on_nlp_error() {
for sel in ["qp-ipm", "qp-active-set"] {
let output = Command::new(pounce_exe())
.arg("--problem")
.arg("rosenbrock")
.arg(format!("solver_selection={sel}"))
.output()
.expect("spawn pounce");
assert_eq!(
output.status.code(),
Some(2),
"{sel} on an NLP should exit 2"
);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("NLP") && stderr.contains(sel),
"{sel}: error should name detected class and forced solver: {stderr}"
);
}
}
#[test]
fn unknown_solver_selection_rejected() {
let output = Command::new(pounce_exe())
.arg("--problem")
.arg("rosenbrock")
.arg("solver_selection=lp-simplex")
.output()
.expect("spawn pounce");
assert_eq!(output.status.code(), Some(2));
}