Skip to content

Commit

Permalink
Don't run the creusot_contracts ui test if it is not in the filter
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgolfouse committed Feb 20, 2025
1 parent 494523c commit 3cdb3cd
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions creusot/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,22 @@ fn main() {
temp_file.push("libcreusot_contracts.cmeta");
let temp_file = temp_file.to_string_lossy();

let success = translate_creusot_contracts(&args, creusot_rustc, &base_path, &temp_file);
let mut test_creusot_contracts = true;
if let Some(ref filter) = args.filter {
if !"creusot/tests/creusot-contracts/creusot-contracts.rs".contains(filter) {
test_creusot_contracts = false;
}
}
let contracts_success = translate_creusot_contracts(
&args,
creusot_rustc,
&base_path,
&temp_file,
test_creusot_contracts,
);

let (mut failed, mut total) =
(if contracts_success { 0 } else { 1 }, if test_creusot_contracts { 1 } else { 0 });

let (fail1, total1) = should_fail("tests/should_fail/**/*.rs", &args, |p| {
run_creusot(creusot_rustc, p, &temp_file)
Expand All @@ -78,8 +93,8 @@ fn main() {
run_creusot(creusot_rustc, p, &temp_file)
});

let total = 1 + total1 + total2;
let failed = if success { 0 } else { 1 } + fail1 + fail2;
total += total1 + total2;
failed += fail1 + fail2;
if failed > 0 {
let mut out =
StandardStream::stdout(if args.force_color || std::io::stdout().is_terminal() {
Expand All @@ -97,11 +112,14 @@ fn main() {
}

/// Returns `false` if the translation changed
///
/// This will only check the output of `creusot-contracts` if `test_creusot_contracts` is true.
fn translate_creusot_contracts(
args: &Args,
creusot_rustc: &Path,
base_path: &PathBuf,
temp_file: &str,
test_creusot_contracts: bool,
) -> bool {
println! {"Building cargo-creusot..."};
let cargo_creusot = escargot::CargoBuild::new()
Expand All @@ -113,13 +131,15 @@ fn translate_creusot_contracts(
.unwrap()
.command();

print! {"Translating creusot-contracts... "};
std::io::stdout().flush().unwrap();
std::process::Command::new("touch")
.current_dir(&base_path)
.args(["creusot-contracts/src/lib.rs"])
.status()
.unwrap();
if test_creusot_contracts {
print!("Translating creusot-contracts... ");
std::io::stdout().flush().unwrap();
std::process::Command::new("touch")
.current_dir(&base_path)
.args(["creusot-contracts/src/lib.rs"])
.status()
.unwrap();
}
let mut creusot_contracts = cargo_creusot;
creusot_contracts.current_dir(base_path);
creusot_contracts
Expand All @@ -139,16 +159,24 @@ fn translate_creusot_contracts(
.env("CREUSOT_CONTINUE", "true");

let output = creusot_contracts.output().expect("could not translate `creusot_contracts`");
let expect = PathBuf::from("tests/creusot-contracts/creusot-contracts.coma");
if !output.status.success() {
eprintln!("Translation of creusot-contracts failed");
std::process::exit(1);
}

if !test_creusot_contracts {
return true;
}

let expect = PathBuf::from("tests/creusot-contracts/creusot-contracts.coma");
let is_tty = std::io::stdout().is_terminal();
let mut out = StandardStream::stdout(if args.force_color || is_tty {
ColorChoice::Always
} else {
ColorChoice::Never
});

let mut succeeded = true;

if args.bless {
if output.stdout.is_empty() {
panic!(
Expand Down Expand Up @@ -187,10 +215,6 @@ fn translate_creusot_contracts(
out.flush().unwrap();
}

if !output.status.success() {
eprintln!("Translation of creusot-contracts failed");
std::process::exit(1);
}
succeeded
}

Expand Down

0 comments on commit 3cdb3cd

Please sign in to comment.