From 834cab724441b1c538f5a84b0fef8f0052714137 Mon Sep 17 00:00:00 2001 From: woppopo Date: Tue, 27 Sep 2022 19:09:32 +0000 Subject: [PATCH] Add test cases for const `Location` --- library/core/tests/lib.rs | 2 ++ library/core/tests/panic.rs | 1 + library/core/tests/panic/location.rs | 31 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 library/core/tests/panic.rs create mode 100644 library/core/tests/panic/location.rs diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 59510d3cc2a..548c1884ecd 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -7,6 +7,7 @@ #![feature(const_assume)] #![feature(const_black_box)] #![feature(const_bool_to_option)] +#![feature(const_caller_location)] #![feature(const_cell_into_inner)] #![feature(const_convert)] #![feature(const_heap)] @@ -131,6 +132,7 @@ mod ops; mod option; mod pattern; +mod panic; mod pin; mod pin_macro; mod ptr; diff --git a/library/core/tests/panic.rs b/library/core/tests/panic.rs new file mode 100644 index 00000000000..b7056bdf36e --- /dev/null +++ b/library/core/tests/panic.rs @@ -0,0 +1 @@ +mod location; \ No newline at end of file diff --git a/library/core/tests/panic/location.rs b/library/core/tests/panic/location.rs new file mode 100644 index 00000000000..ba066bfbc53 --- /dev/null +++ b/library/core/tests/panic/location.rs @@ -0,0 +1,31 @@ +use core::panic::Location; + +// Note: Some of the following tests depend on the source location, +// so please be careful when editing this file. + +#[test] +fn location_const_caller() { + const _CALLER_REFERENCE: &Location<'static> = Location::caller(); + const _CALLER: Location<'static> = *Location::caller(); +} + +#[test] +fn location_const_file() { + const CALLER: &Location<'static> = Location::caller(); + const FILE: &str = CALLER.file(); + assert_eq!(FILE, "library/core/tests/panic/location.rs"); +} + +#[test] +fn location_const_line() { + const CALLER: &Location<'static> = Location::caller(); + const LINE: u32 = CALLER.line(); + assert_eq!(LINE, 21); +} + +#[test] +fn location_const_column() { + const CALLER: &Location<'static> = Location::caller(); + const COLUMN: u32 = CALLER.column(); + assert_eq!(COLUMN, 39); +} \ No newline at end of file