]> git.proxmox.com Git - cargo.git/blob - vendor/backtrace-0.3.3/tests/long_fn_name.rs
New upstream version 0.23.0
[cargo.git] / vendor / backtrace-0.3.3 / tests / long_fn_name.rs
1 extern crate backtrace;
2
3 #[cfg(all(windows, feature = "dbghelp"))]
4 extern crate winapi;
5
6 use backtrace::Backtrace;
7
8 // 50-character module name
9 mod _234567890_234567890_234567890_234567890_234567890 {
10 // 50-character struct name
11 #[allow(non_camel_case_types)]
12 pub struct _234567890_234567890_234567890_234567890_234567890<T>(T);
13 impl<T> _234567890_234567890_234567890_234567890_234567890<T> {
14 #[allow(dead_code)]
15 pub fn new() -> ::Backtrace {
16 ::Backtrace::new()
17 }
18 }
19 }
20
21 // Long function names must be truncated to (MAX_SYM_NAME - 1) characters.
22 // Only run this test for msvc, since gnu prints "<no info>" for all frames.
23 #[test]
24 #[cfg(all(windows, feature = "dbghelp", target_env = "msvc"))]
25 fn test_long_fn_name() {
26 use _234567890_234567890_234567890_234567890_234567890::
27 _234567890_234567890_234567890_234567890_234567890 as S;
28
29 // 10 repetitions of struct name, so fully qualified function name is
30 // atleast 10 * (50 + 50) * 2 = 2000 characters long.
31 // It's actually longer since it also includes `::`, `<>` and the
32 // name of the current module
33 let bt = S::<S<S<S<S<S<S<S<S<S<i32>>>>>>>>>>::new();
34 println!("{:?}", bt);
35
36 let mut found_long_name_frame = false;
37
38 for frame in bt.frames() {
39 let symbols = frame.symbols();
40 if symbols.is_empty() {
41 continue;
42 }
43
44 if let Some(function_name) = symbols[0].name() {
45 let function_name = function_name.as_str().unwrap();
46 if function_name.contains(
47 "::_234567890_234567890_234567890_234567890_234567890")
48 {
49 found_long_name_frame = true;
50 assert_eq!(function_name.len(), winapi::MAX_SYM_NAME - 1);
51 }
52 }
53 }
54
55 assert!(found_long_name_frame);
56 }