Skip to content

Fix public facing #4

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

Merged
merged 5 commits into from
May 6, 2024
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"
rust-version = "1.62.1"

[dependencies]
serde = { version = "1.0.103", features = ["derive"] }
serde_json = "1.0.25"
libloading = "0.8"
libc = "0.2.64"
Expand All @@ -13,8 +14,5 @@ rustc_version_runtime = "0.3"
once_cell = "1"
linkme = "0.3.17"

[dev-dependencies]
serde = { version = "1.0.60", features = ["derive"] }

[features]
no-antithesis-sdk = []
61 changes: 40 additions & 21 deletions lib/src/assert/macros.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
/// Common handling used by all the assertion-related macros
#[cfg(not(feature="no-antithesis-sdk"))]
#[doc(hidden)]
#[macro_export]
macro_rules! assert_helper {
(condition = $condition:expr, $message:literal, $details:expr, $assert_type:literal, $display_type:literal, must_hit = $must_hit:literal) => {{
// The handling of this pattern-arm of assert_helper
// is wrapped in a block {} to avoid name collisions
(condition = $condition:expr, $message:literal, $details:expr, $assert_type:path, $display_type:literal, must_hit = $must_hit:literal) => {{
// Force evaluation of expressions.
let condition = $condition;
let details = $details;

// Define a do-nothing function 'f()' within the context of
// the function invoking an assertion. Then the type_name of
// this do-nothing will be something like:
//
// bincrate::binmod::do_stuff::f
//
// After trimming off the last three chars `::f` what remains is
// the full path to the name of the function invoking the assertion
//
// Both the untrimmed `NAME` and trimmed `FUN_NAME` are lazily
// initialized statics so that `FUN_NAME` can be available at
// assertion catalog registration time.
use $crate::once_cell::sync::Lazy;
fn f(){}
fn type_name_of<T>(_: T) -> &'static str {
Expand All @@ -31,30 +46,34 @@ macro_rules! assert_helper {
id: $message
};

let function = Lazy::force(&FUN_NAME);
let ptr_function = Lazy::force(&FUN_NAME);

$crate::assert::assert_impl(
$assert_type, /* assert_type */
$display_type, /* display_type */
$display_type.to_owned(), /* display_type */
condition, /* condition */
$message, /* message */
::std::module_path!(), /* class */
function, /* function */
::std::file!(), /* file */
$message.to_owned(), /* message */
::std::module_path!().to_owned(), /* class */
String::from(*ptr_function), /* function */
::std::file!().to_owned(), /* file */
::std::line!(), /* line */
::std::column!(), /* column */
true,/* hit */
$must_hit, /* must-hit */
$message, /* id */
$message.to_owned(), /* id */
details /* details */
)
}}
}} // end pattern-arm block
}
#[cfg(feature="no-antithesis-sdk")]
#[doc(hidden)]
#[macro_export]
macro_rules! assert_helper {
(condition = $condition:expr, $message:literal, $details:expr, $assert_type:literal, $display_type:literal, must_hit = $must_hit:literal) => {{
// Force evaluation of expressions.
(condition = $condition:expr, $message:literal, $details:expr, $assert_type:path, $display_type:literal, must_hit = $must_hit:literal) => {{
// Force evaluation of expressions, ensuring that
// any side effects of these expressions will always be
// evaluated at runtime - even if the assertion itself
// is supressed by the `no-antithesis-sdk` feature
let condition = $condition;
let details = $details;
}}
Expand All @@ -64,9 +83,9 @@ macro_rules! assert_helper {
/// called at least once. This test property will be viewable in the "Antithesis SDK: Always"
/// group of your triage report.
#[macro_export]
macro_rules! always {
macro_rules! assert_always {
($condition:expr, $message:literal, $details:expr) => {
$crate::assert_helper!(condition = $condition, $message, $details, "always", "Always", must_hit = true)
$crate::assert_helper!(condition = $condition, $message, $details, AssertType::Always, "Always", must_hit = true)
}
}

Expand All @@ -75,9 +94,9 @@ macro_rules! always {
/// failing if the function is never invoked. This test property will be viewable in
/// the "Antithesis SDK: Always" group of your triage report.
#[macro_export]
macro_rules! always_or_unreachable {
macro_rules! assert_always_or_unreachable {
($condition:expr, $message:literal, $details:expr) => {
$crate::assert_helper!(condition = $condition, $message, $details, "always", "AlwaysOrUnreachable", must_hit = false)
$crate::assert_helper!(condition = $condition, $message, $details, AssertType::Always, "AlwaysOrUnreachable", must_hit = false)
}
}

Expand All @@ -86,29 +105,29 @@ macro_rules! always_or_unreachable {
/// is never called, or if condition is false every time that it is called. This
/// test property will be viewable in the "Antithesis SDK: Sometimes" group.
#[macro_export]
macro_rules! sometimes {
macro_rules! assert_sometimes {
($condition:expr, $message:literal, $details:expr) => {
$crate::assert_helper!(condition = $condition, $message, $details, "sometimes", "Sometimes", must_hit = true)
$crate::assert_helper!(condition = $condition, $message, $details, AssertType::Sometimes, "Sometimes", must_hit = true)
}
}

/// Assert that a line of code is reached at least once. The test property spawned by
/// Reachable will be marked as failing if this function is never called. This test
/// property will be viewable in the "Antithesis SDK: Reachablity assertions" group.
#[macro_export]
macro_rules! reachable {
macro_rules! assert_reachable {
($message:literal, $details:expr) => {
$crate::assert_helper!(condition = true, $message, $details, "reachability", "Reachable", must_hit = true)
$crate::assert_helper!(condition = true, $message, $details, AssertType::Reachability, "Reachable", must_hit = true)
}
}

/// Assert that a line of code is never reached. The test property spawned by Unreachable
/// will be marked as failing if this function is ever called. This test property will
/// be viewable in the "Antithesis SDK: Reachablity assertions" group.
#[macro_export]
macro_rules! unreachable {
macro_rules! assert_unreachable {
($message:literal, $details:expr) => {
$crate::assert_helper!(condition = false, $message, $details, "reachability", "Unreachable", must_hit = false)
$crate::assert_helper!(condition = false, $message, $details, AssertType::Reachability, "Unreachable", must_hit = false)
}
}

Loading
Loading