Skip to content
Closed
Changes from all 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
31 changes: 28 additions & 3 deletions crates/taco-smt-encoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,29 @@ fn get_smt_solver_version(cmd: &str) -> Result<(i32, i32, i32), GetVersionError>
return Err(GetVersionError::NotInstalled(cmd.to_owned()));
}
let out = out.unwrap();
if let Ok(version) = parse_smt_solver_version_output(&out.stdout, &out.stderr) {
return Ok(version);
}
if !out.status.success() {
return Err(GetVersionError::NotInstalled(cmd.to_owned()));
}
Err(GetVersionError::ParseVersionError)
}

let out_str =
std::str::from_utf8(&out.stdout).map_err(|_| GetVersionError::ParseVersionError)?;
parse_smt_solver_version(out_str)
fn parse_smt_solver_version_output(
stdout: &[u8],
stderr: &[u8],
) -> Result<(i32, i32, i32), GetVersionError> {
for out in [stdout, stderr] {
if out.is_empty() {
continue;
}
let out_str = std::str::from_utf8(out).map_err(|_| GetVersionError::ParseVersionError)?;
if let Ok(version) = parse_smt_solver_version(out_str) {
return Ok(version);
}
}
Err(GetVersionError::ParseVersionError)
}

/// This function attempts to parse the version number from the output of the
Expand Down Expand Up @@ -722,6 +738,15 @@ Z3 version 4.8.12 - 64 bit";
assert_eq!(got, Ok((4, 8, 12)))
}

#[test]
fn test_parse_version_from_stderr() {
let stderr = "\
This is cvc5 version 1.4.0
compiled with GCC version 14.2.1";
let got = parse_smt_solver_version_output(&[], stderr.as_bytes());
assert_eq!(got, Ok((1, 4, 0)));
}

#[test]
fn test_z3_get_version() {
let version = get_smt_solver_version(Z3_PRG);
Expand Down
Loading