Skip to content

Commit bfe591b

Browse files
committed
add test
1 parent 2572659 commit bfe591b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/capture.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,42 @@ mod serde_impls {
527527
}
528528
}
529529
}
530+
531+
#[cfg(test)]
532+
mod tests {
533+
use super::*;
534+
535+
#[test]
536+
fn test_frame_conversion() {
537+
// captures an original backtrace, and makes sure that the manual conversion
538+
// to frames yields the same results.
539+
let bt = Backtrace::new();
540+
let original_frames = bt.frames();
541+
542+
let mut frames = vec![];
543+
crate::trace(|frame| {
544+
let converted = BacktraceFrame::from(frame.clone());
545+
frames.push(converted);
546+
true
547+
});
548+
549+
// the first frames can be different because we call from slightly different places,
550+
// and the `trace` version has an extra capture. But because of inlining the number of
551+
// frames that differ may be different between release and debug versions. Plus who knows
552+
// what the compiler will do in the future. So we just take 4 frames from the end and make
553+
// sure they match
554+
for (converted, og) in frames
555+
.iter()
556+
.rev()
557+
.take(4)
558+
.zip(original_frames.iter().rev().take(4))
559+
{
560+
println!(
561+
"converted {:?}, og {:?}",
562+
converted.symbol_address(),
563+
og.symbol_address()
564+
);
565+
assert_eq!(converted.symbol_address(), og.symbol_address());
566+
}
567+
}
568+
}

0 commit comments

Comments
 (0)