2 // ignore-cloudabi no processes
3 // ignore-emscripten no processes
5 // Tests ensuring that `dbg!(expr)` has the expected run-time behavior.
6 // as well as some compile time properties we expect.
10 #[derive(Copy, Clone, Debug)]
13 #[derive(Copy, Clone, Debug, PartialEq)]
19 #[derive(Debug, PartialEq)]
23 let a: Unit = dbg!(Unit);
24 let _: Unit = dbg!(a);
25 // We can move `a` because it's Copy.
28 // `Point<T>` will be faithfully formatted according to `{:#?}`.
29 let a = Point { x: 42, y: 24 };
30 let b: Point<u8> = dbg!(Point { x: 42, y: 24 }); // test stringify!(..)
31 let c: Point<u8> = dbg!(b);
32 // Identity conversion:
35 // We can move `b` because it's Copy.
38 // Test that we can borrow and that successive applications is still identity.
40 let b: &NoCopy = dbg!(dbg!(&a));
43 // Test involving lifetimes of temporaries:
44 fn f<'a>(x: &'a u8) -> &'a u8 { x }
45 let a: &u8 = dbg!(f(&42));
50 assert_eq!(7331, dbg!({
58 fn validate_stderr(stderr: Vec<String>) {
64 ":30] Point{x: 42, y: 24,} = Point {",
78 ":40] dbg!(& a) = NoCopy(",
84 ":50] { foo += 1; eprintln!(\"before\"); 7331 } = 7331",
89 // The following is a hack to deal with compiletest's inability
90 // to check the output (to stdout) of run-pass tests.
92 use std::process::Command;
94 let mut args = env::args();
95 let prog = args.next().unwrap();
96 let child = args.next();
97 if let Some("child") = child.as_ref().map(|s| &**s) {
98 // Only run the test if we've been spawned as 'child'
101 // This essentially spawns as 'child' to run the tests
102 // and then it collects output of stderr and checks the output
103 // against what we expect.
104 let out = Command::new(&prog).arg("child").output().unwrap();
105 assert!(out.status.success());
106 assert!(out.stdout.is_empty());
108 let stderr = String::from_utf8(out.stderr).unwrap();
109 let stderr = stderr.lines().map(|mut s| {
110 if s.starts_with("[") {
111 // Strip `[` and file path:
112 s = s.trim_start_matches("[");
113 assert!(s.starts_with(file!()));
114 s = s.trim_start_matches(file!());
119 validate_stderr(stderr);