Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash when rustfmt fails. #2511

Merged
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion kani-driver/src/concrete_playback/test_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ impl KaniSession {
file: file_name,
line_range: Some((unit_test_start_line, unit_test_end_line)),
}];
self.run_rustfmt(&file_line_ranges, Some(&path))?;
self.run_rustfmt(&file_line_ranges, Some(&path))
.unwrap_or_else(|err| println!("WARNING: {}", err));
}

Ok(())
Expand Down
8 changes: 8 additions & 0 deletions tests/script-based-pre/playback_no_rustfmt/bin/rustfmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

# This is a fake `rustfmt` for testing what happens when rustfmt is not found
# or overridden.

exit 1
4 changes: 4 additions & 0 deletions tests/script-based-pre/playback_no_rustfmt/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
script: playback_no_rustfmt.sh
expected: playback_no_rustfmt.expected
27 changes: 27 additions & 0 deletions tests/script-based-pre/playback_no_rustfmt/original.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Check that Kani correctly adds tests to the cover checks reachable in a harness.
extern crate kani;

#[cfg(kani)]
mod verify {
use kani::cover;
use std::convert::TryFrom;
use std::num::NonZeroU8;

#[kani::proof]
fn try_nz_u8() {
let val: u8 = kani::any();
let result = NonZeroU8::try_from(val);
match result {
Ok(nz_val) => {
cover!(true, "Ok");
assert_eq!(nz_val.get(), val);
}
Err(_) => {
cover!(true, "Not ok");
assert_eq!(val, 0);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[TEST] Generate test...
Checking harness verify::try_nz_u8

WARNING: Failed to rustfmt modified source code

[TEST] Run test...
test result: ok. 2 passed; 0 failed;

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
# Test that concrete playback -Z concrete-playback executes as expected
set -o pipefail
set -o nounset

RS_FILE="modified.rs"
cp original.rs ${RS_FILE}

# override rustfmt binary to make it crash.
export PATH=$(pwd)/bin:$PATH

echo "[TEST] Generate test..."
kani ${RS_FILE} -Z concrete-playback --concrete-playback=inplace

echo "[TEST] Run test..."
kani playback -Z concrete-playback ${RS_FILE} -- kani_concrete_playback

# Cleanup
rm ${RS_FILE}