Skip to content

Commit

Permalink
Run most core::num tests in const context too
Browse files Browse the repository at this point in the history
  • Loading branch information
clarfonthey committed Oct 14, 2024
1 parent ecb3830 commit acaf7e2
Show file tree
Hide file tree
Showing 3 changed files with 539 additions and 525 deletions.
35 changes: 35 additions & 0 deletions core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
#![feature(clone_to_uninit)]
#![feature(const_align_of_val_raw)]
#![feature(const_align_offset)]
#![feature(const_bigint_helper_methods)]
#![feature(const_black_box)]
#![feature(const_eval_select)]
#![feature(const_hash)]
#![feature(const_heap)]
#![feature(const_likely)]
#![feature(const_nonnull_new)]
#![feature(const_num_midpoint)]
#![feature(const_option_ext)]
#![feature(const_pin)]
#![feature(const_pointer_is_aligned)]
Expand All @@ -45,6 +48,7 @@
#![feature(get_many_mut)]
#![feature(hasher_prefixfree_extras)]
#![feature(hashmap_internals)]
#![feature(inline_const_pat)]
#![feature(int_roundings)]
#![feature(ip)]
#![feature(ip_from)]
Expand Down Expand Up @@ -104,6 +108,37 @@
#![deny(fuzzy_provenance_casts)]
#![deny(unsafe_op_in_unsafe_fn)]

/// Version of `assert_matches` that ignores fancy runtime printing in const context and uses structural equality.
macro_rules! assert_eq_const_safe {
($left:expr, $right:expr$(, $($arg:tt)+)?) => {
{
fn runtime() {
assert_eq!($left, $right, $($arg)*);
}
const fn compiletime() {
assert!(matches!($left, const { $right }));
}
core::intrinsics::const_eval_select((), compiletime, runtime)
}
};
}

/// Creates a test for runtime and a test for constant-time.
macro_rules! test_runtime_and_compiletime {
($(
$(#[$attr:meta])*
fn $test:ident() $block:block
)*) => {
$(
$(#[$attr])*
#[test]
fn $test() $block
$(#[$attr])*
const _: () = $block;
)*
}
}

mod alloc;
mod any;
mod array;
Expand Down
Loading

0 comments on commit acaf7e2

Please sign in to comment.