use super::*;
#[test]
fn a_runtime_failure_exits_1_and_does_not_point_at_help() {
let t = Scratch::new("nofile");
let missing = t.out("nosuch.cnf");
let r = run(&[s(&missing), "-o", s(&t.out("bundle"))]).exit(1);
r.assert_stderr("cannot open");
r.assert_stderr("nosuch.cnf");
assert!(
!r.stderr.contains("--help"),
"a runtime failure is not answered by the usage text:\n{}",
r.stderr,
);
let bad = run(&["--bogus"]).exit(2);
bad.assert_stderr("run `vitri --help` for usage");
}
#[test]
fn a_cnf_declaring_no_variables_is_refused() {
let t = Scratch::new("zerovar");
for text in ["p cnf 0 0\n", "", "c only a comment\n"] {
let input = t.file("zero.cnf", text);
run(&[s(&input), "-o", s(&t.out("bundle"))])
.exit(1)
.assert_stderr("declares no variables");
}
}
#[test]
fn malformed_dimacs_is_reported_as_a_parse_failure() {
let t = Scratch::new("badcnf");
let input = t.file("bad.cnf", "p cnf 2 1\n1 two 0\n");
let r = run(&[s(&input), "-o", s(&t.out("bundle"))]).exit(1);
r.assert_stderr("parsing");
r.assert_stderr("bad.cnf");
r.assert_stderr("invalid token");
let headerless = t.file("noheader.cnf", "1 2 0\n");
run(&[s(&headerless), "-o", s(&t.out("bundle2"))])
.exit(1)
.assert_stderr("parsing");
}
#[test]
fn a_variable_id_above_the_declared_count_is_a_parse_failure() {
let t = Scratch::new("idrange");
let out = t.out("bundle");
let cases: [(&str, &str, &str, &str); 3] = [
(
"clause.cnf",
CLAUSE_ID_ABOVE_COUNT,
"clause literal 5",
"line 2:",
),
("show.cnf", SHOW_ID_ABOVE_COUNT, "show var 9", "line 3:"),
(
"weight.cnf",
"c t wmc\np cnf 2 1\nc p weight 9 1/3 0\n1 2 0\n",
"weight literal 9",
"line 3:",
),
];
for (name, text, construct, line) in cases {
let input = t.file(name, text);
for stages in [
&[][..],
&["--no-arjun"][..],
&["--no-simplify"][..],
&["--no-arjun", "--no-simplify"][..],
] {
let mut args = vec![s(&input), "-o", s(&out)];
args.extend_from_slice(stages);
let r = run(&args).exit(1);
r.assert_stderr("parsing");
r.assert_stderr(name);
r.assert_stderr(construct);
r.assert_stderr("declared variable count 2");
r.assert_stderr(line);
}
assert!(!out.exists(), "a rejected input leaves no bundle behind");
}
}
#[test]
fn an_out_dir_that_is_an_existing_file_fails_the_run() {
let t = Scratch::new("outfile");
let input = t.file("in.cnf", IRREDUCIBLE_5);
let blocker = t.file("blocker", "not a directory\n");
run(&[s(&input), "-o", s(&blocker)])
.exit(1)
.assert_stderr("blocker");
}