Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ce6f304

Browse files
committed
move basic track_caller test into their own fn
1 parent 4989b2e commit ce6f304

File tree

1 file changed

+39
-36
lines changed

1 file changed

+39
-36
lines changed

src/tools/miri/tests/pass/track-caller-attribute.rs

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,44 @@ macro_rules! caller_location_from_macro {
2121
};
2222
}
2323

24+
fn test_basic() {
25+
let location = Location::caller();
26+
let expected_line = line!() - 1;
27+
assert_eq!(location.file(), file!());
28+
assert_eq!(location.line(), expected_line);
29+
assert_eq!(location.column(), 20);
30+
31+
let tracked = tracked();
32+
let expected_line = line!() - 1;
33+
assert_eq!(tracked.file(), file!());
34+
assert_eq!(tracked.line(), expected_line);
35+
assert_eq!(tracked.column(), 19);
36+
37+
let nested = nested_intrinsic();
38+
assert_eq!(nested.file(), file!());
39+
assert_eq!(nested.line(), 11);
40+
assert_eq!(nested.column(), 5);
41+
42+
let contained = nested_tracked();
43+
assert_eq!(contained.file(), file!());
44+
assert_eq!(contained.line(), 15);
45+
assert_eq!(contained.column(), 5);
46+
47+
// `Location::caller()` in a macro should behave similarly to `file!` and `line!`,
48+
// i.e. point to where the macro was invoked, instead of the macro itself.
49+
let inmacro = caller_location_from_macro!();
50+
let expected_line = line!() - 1;
51+
assert_eq!(inmacro.file(), file!());
52+
assert_eq!(inmacro.line(), expected_line);
53+
assert_eq!(inmacro.column(), 19);
54+
55+
let intrinsic = core::intrinsics::caller_location();
56+
let expected_line = line!() - 1;
57+
assert_eq!(intrinsic.file(), file!());
58+
assert_eq!(intrinsic.line(), expected_line);
59+
assert_eq!(intrinsic.column(), 21);
60+
}
61+
2462
fn test_fn_ptr() {
2563
fn pass_to_ptr_call<T>(f: fn(T), x: T) {
2664
f(x);
@@ -88,42 +126,7 @@ fn test_trait_obj2() {
88126
}
89127

90128
fn main() {
91-
let location = Location::caller();
92-
let expected_line = line!() - 1;
93-
assert_eq!(location.file(), file!());
94-
assert_eq!(location.line(), expected_line);
95-
assert_eq!(location.column(), 20);
96-
97-
let tracked = tracked();
98-
let expected_line = line!() - 1;
99-
assert_eq!(tracked.file(), file!());
100-
assert_eq!(tracked.line(), expected_line);
101-
assert_eq!(tracked.column(), 19);
102-
103-
let nested = nested_intrinsic();
104-
assert_eq!(nested.file(), file!());
105-
assert_eq!(nested.line(), 11);
106-
assert_eq!(nested.column(), 5);
107-
108-
let contained = nested_tracked();
109-
assert_eq!(contained.file(), file!());
110-
assert_eq!(contained.line(), 15);
111-
assert_eq!(contained.column(), 5);
112-
113-
// `Location::caller()` in a macro should behave similarly to `file!` and `line!`,
114-
// i.e. point to where the macro was invoked, instead of the macro itself.
115-
let inmacro = caller_location_from_macro!();
116-
let expected_line = line!() - 1;
117-
assert_eq!(inmacro.file(), file!());
118-
assert_eq!(inmacro.line(), expected_line);
119-
assert_eq!(inmacro.column(), 19);
120-
121-
let intrinsic = core::intrinsics::caller_location();
122-
let expected_line = line!() - 1;
123-
assert_eq!(intrinsic.file(), file!());
124-
assert_eq!(intrinsic.line(), expected_line);
125-
assert_eq!(intrinsic.column(), 21);
126-
129+
test_basic();
127130
test_fn_ptr();
128131
test_trait_obj();
129132
test_trait_obj2();

0 commit comments

Comments
 (0)