-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
319d859
commit bbffc45
Showing
11 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
use crate::InvocationType; | ||
|
||
const KANI_RUST_VERIFIER: &str = "Kani Rust Verifier"; | ||
/// We assume this is the same as the `kani-verifier` version, but we should | ||
/// make sure it's enforced through CI: | ||
/// <https://github.com/model-checking/kani/issues/2626> | ||
const KANI_VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
|
||
/// Print Kani version. At present, this is only release version information. | ||
pub(crate) fn print_kani_version(invocation_type: InvocationType) { | ||
let kani_version = kani_version_release(invocation_type); | ||
// TODO: Print development version information. | ||
// <https://github.com/model-checking/kani/issues/2617> | ||
println!("{kani_version}"); | ||
} | ||
|
||
/// Print Kani release version as `Kani Rust Verifier <version> (<invocation>)` | ||
/// where: | ||
/// - `<version>` is the `kani-verifier` version | ||
/// - `<invocation>` is `cargo plugin` if Kani was invoked with `cargo kani` or | ||
/// `standalone` if it was invoked with `kani`. | ||
fn kani_version_release(invocation_type: InvocationType) -> String { | ||
let invocation_str = match invocation_type { | ||
InvocationType::CargoKani(_) => "cargo plugin", | ||
InvocationType::Standalone => "standalone", | ||
}; | ||
format!("{KANI_RUST_VERIFIER} {KANI_VERSION} ({invocation_str})") | ||
} |
2 changes: 2 additions & 0 deletions
2
...script-based-pre/cargo-kani-version-flag-version/cargo-kani-version-flag-version.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
success: version printed agrees | ||
success: `(cargo plugin)` appears in version line |
30 changes: 30 additions & 0 deletions
30
tests/script-based-pre/cargo-kani-version-flag-version/cargo-kani-version-flag-version.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
set -eu | ||
|
||
KANI_VERSION_CMD=`cargo kani --version` | ||
KANI_VERSION_CMD_VERSION=`echo ${KANI_VERSION_CMD} | awk '{print $2}'` | ||
|
||
# Check that the version printed is the same. Note: We use `sed -n '1p'` instead | ||
# of `head -n 1` to avoid https://github.com/model-checking/kani/issues/2618 | ||
KANI_CARGO_OUTPUT_HEAD=`cd dummy-project; cargo kani | sed -n '1p'` | ||
KANI_CARGO_OUTPUT_HEAD_VERSION=`echo ${KANI_CARGO_OUTPUT_HEAD} | awk '{print $4}'` | ||
|
||
if [[ $KANI_VERSION_CMD_VERSION == $KANI_CARGO_OUTPUT_HEAD_VERSION ]]; then | ||
echo "success: version printed agrees" | ||
else | ||
echo "failed: version printed differs ($KANI_VERSION_CMD_VERSION - $KANI_CARGO_OUTPUT_HEAD_VERSION)" | ||
exit 1 | ||
fi | ||
|
||
KANI_CARGO_OUTPUT_HEAD_MODE=`echo ${KANI_CARGO_OUTPUT_HEAD} | awk '{print $5,$6}'` | ||
|
||
# Check that `(cargo plugin)` appears in the version line | ||
if [[ $KANI_CARGO_OUTPUT_HEAD_MODE == "(cargo plugin)" ]]; then | ||
echo "success: \`(cargo plugin)\` appears in version line" | ||
else | ||
echo "failed: expected \`(cargo plugin)\` in version line" | ||
exit 1 | ||
fi |
4 changes: 4 additions & 0 deletions
4
tests/script-based-pre/cargo-kani-version-flag-version/config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: cargo-kani-version-flag-version.sh | ||
expected: cargo-kani-version-flag-version.expected |
11 changes: 11 additions & 0 deletions
11
tests/script-based-pre/cargo-kani-version-flag-version/dummy-project/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
[package] | ||
name = "dummy-project" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
14 changes: 14 additions & 0 deletions
14
tests/script-based-pre/cargo-kani-version-flag-version/dummy-project/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! This test is used to check that an invocation of `cargo kani` prints the version | ||
//! and invocation type as expected. | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
} | ||
|
||
#[kani::proof] | ||
fn dummy() { | ||
assert!(1 + 1 == 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: kani-version-flag-version.sh | ||
expected: kani-version-flag-version.expected |
10 changes: 10 additions & 0 deletions
10
tests/script-based-pre/kani-version-flag-version/dummy-file.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! This test is used to check that an invocation of `kani` or `cargo kani` | ||
//! prints the version and invocation type as expected. | ||
|
||
#[kani::proof] | ||
fn dummy() { | ||
assert!(1 + 1 == 2); | ||
} |
2 changes: 2 additions & 0 deletions
2
tests/script-based-pre/kani-version-flag-version/kani-version-flag-version.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
success: version printed agrees | ||
success: `(standalone)` appears in version line |
30 changes: 30 additions & 0 deletions
30
tests/script-based-pre/kani-version-flag-version/kani-version-flag-version.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
set -eu | ||
|
||
KANI_VERSION_CMD=`kani --version` | ||
KANI_VERSION_CMD_VERSION=`echo ${KANI_VERSION_CMD} | awk '{print $2}'` | ||
|
||
# Check that the version printed is the same. Note: We use `sed -n '1p'` instead | ||
# of `head -n 1` to avoid https://github.com/model-checking/kani/issues/2618 | ||
KANI_STANDALONE_OUTPUT_HEAD=`kani dummy-file.rs | sed -n '1p'` | ||
KANI_STANDALONE_OUTPUT_HEAD_VERSION=`echo ${KANI_STANDALONE_OUTPUT_HEAD} | awk '{print $4}'` | ||
|
||
if [[ $KANI_VERSION_CMD_VERSION == $KANI_STANDALONE_OUTPUT_HEAD_VERSION ]]; then | ||
echo "success: version printed agrees" | ||
else | ||
echo "failed: version printed differs ($KANI_VERSION_CMD_VERSION - $KANI_STANDALONE_OUTPUT_HEAD_VERSION)" | ||
exit 1 | ||
fi | ||
|
||
KANI_STANDALONE_OUTPUT_HEAD_MODE=`echo ${KANI_STANDALONE_OUTPUT_HEAD} | awk '{print $5}'` | ||
|
||
# Check that `(standalone)` appears in the version line | ||
if [[ $KANI_STANDALONE_OUTPUT_HEAD_MODE == "(standalone)" ]]; then | ||
echo "success: \`(standalone)\` appears in version line" | ||
else | ||
echo "failed: expected \`(standalone)\` in version line" | ||
exit 1 | ||
fi |