Skip to content

Commit 834cab7

Browse files
committed
Add test cases for const Location
1 parent 4e3b9ed commit 834cab7

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

library/core/tests/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(const_assume)]
88
#![feature(const_black_box)]
99
#![feature(const_bool_to_option)]
10+
#![feature(const_caller_location)]
1011
#![feature(const_cell_into_inner)]
1112
#![feature(const_convert)]
1213
#![feature(const_heap)]
@@ -131,6 +132,7 @@ mod num;
131132
mod ops;
132133
mod option;
133134
mod pattern;
135+
mod panic;
134136
mod pin;
135137
mod pin_macro;
136138
mod ptr;

library/core/tests/panic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod location;

library/core/tests/panic/location.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use core::panic::Location;
2+
3+
// Note: Some of the following tests depend on the source location,
4+
// so please be careful when editing this file.
5+
6+
#[test]
7+
fn location_const_caller() {
8+
const _CALLER_REFERENCE: &Location<'static> = Location::caller();
9+
const _CALLER: Location<'static> = *Location::caller();
10+
}
11+
12+
#[test]
13+
fn location_const_file() {
14+
const CALLER: &Location<'static> = Location::caller();
15+
const FILE: &str = CALLER.file();
16+
assert_eq!(FILE, "library/core/tests/panic/location.rs");
17+
}
18+
19+
#[test]
20+
fn location_const_line() {
21+
const CALLER: &Location<'static> = Location::caller();
22+
const LINE: u32 = CALLER.line();
23+
assert_eq!(LINE, 21);
24+
}
25+
26+
#[test]
27+
fn location_const_column() {
28+
const CALLER: &Location<'static> = Location::caller();
29+
const COLUMN: u32 = CALLER.column();
30+
assert_eq!(COLUMN, 39);
31+
}

0 commit comments

Comments
 (0)