Skip to content

Commit 12e0420

Browse files
committed
Update dbg macro test to use check-run-results flag for run-pass test
Updates the dbg-macro-expected behavior test to remove the workaround and use the `check-run-result` flag/feature in compiletest. This serves to test the feature on a real use-case (as mentioned in rust-lang#63751)
1 parent 0e3bc62 commit 12e0420

File tree

2 files changed

+30
-82
lines changed

2 files changed

+30
-82
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// run-pass
2-
// ignore-cloudabi no processes
3-
// ignore-emscripten no processes
4-
// ignore-sgx no processes
2+
// check-run-results
53

64
// Tests ensuring that `dbg!(expr)` has the expected run-time behavior.
75
// as well as some compile time properties we expect.
@@ -18,7 +16,7 @@ struct Point<T> {
1816
#[derive(Debug, PartialEq)]
1917
struct NoCopy(usize);
2018

21-
fn test() {
19+
fn main() {
2220
let a: Unit = dbg!(Unit);
2321
let _: Unit = dbg!(a);
2422
// We can move `a` because it's Copy.
@@ -67,81 +65,3 @@ fn test() {
6765
assert_eq!((1u8, 2u32, "Yeah"), dbg!(1u8, 2u32,
6866
"Yeah",));
6967
}
70-
71-
fn validate_stderr(stderr: Vec<String>) {
72-
assert_eq!(stderr, &[
73-
":22] Unit = Unit",
74-
75-
":23] a = Unit",
76-
77-
":29] Point{x: 42, y: 24,} = Point {",
78-
" x: 42,",
79-
" y: 24,",
80-
"}",
81-
82-
":30] b = Point {",
83-
" x: 42,",
84-
" y: 24,",
85-
"}",
86-
87-
":38]",
88-
89-
":42] &a = NoCopy(",
90-
" 1337,",
91-
")",
92-
93-
":42] dbg!(& a) = NoCopy(",
94-
" 1337,",
95-
")",
96-
":47] f(&42) = 42",
97-
98-
"before",
99-
":52] { foo += 1; eprintln!(\"before\"); 7331 } = 7331",
100-
101-
":60] (\"Yeah\",) = (",
102-
" \"Yeah\",",
103-
")",
104-
105-
":63] 1 = 1",
106-
":63] 2 = 2",
107-
108-
":67] 1u8 = 1",
109-
":67] 2u32 = 2",
110-
":67] \"Yeah\" = \"Yeah\"",
111-
]);
112-
}
113-
114-
fn main() {
115-
// The following is a hack to deal with compiletest's inability
116-
// to check the output (to stdout) of run-pass tests.
117-
use std::env;
118-
use std::process::Command;
119-
120-
let mut args = env::args();
121-
let prog = args.next().unwrap();
122-
let child = args.next();
123-
if let Some("child") = child.as_ref().map(|s| &**s) {
124-
// Only run the test if we've been spawned as 'child'
125-
test()
126-
} else {
127-
// This essentially spawns as 'child' to run the tests
128-
// and then it collects output of stderr and checks the output
129-
// against what we expect.
130-
let out = Command::new(&prog).arg("child").output().unwrap();
131-
assert!(out.status.success());
132-
assert!(out.stdout.is_empty());
133-
134-
let stderr = String::from_utf8(out.stderr).unwrap();
135-
let stderr = stderr.lines().map(|mut s| {
136-
if s.starts_with("[") {
137-
// Strip `[` and file path:
138-
s = s.trim_start_matches("[");
139-
assert!(s.starts_with(file!()));
140-
s = s.trim_start_matches(file!());
141-
}
142-
s.to_owned()
143-
}).collect();
144-
145-
validate_stderr(stderr);
146-
}
147-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[$DIR/dbg-macro-expected-behavior.rs:20] Unit = Unit
2+
[$DIR/dbg-macro-expected-behavior.rs:21] a = Unit
3+
[$DIR/dbg-macro-expected-behavior.rs:27] Point{x: 42, y: 24,} = Point {
4+
x: 42,
5+
y: 24,
6+
}
7+
[$DIR/dbg-macro-expected-behavior.rs:28] b = Point {
8+
x: 42,
9+
y: 24,
10+
}
11+
[$DIR/dbg-macro-expected-behavior.rs:36]
12+
[$DIR/dbg-macro-expected-behavior.rs:40] &a = NoCopy(
13+
1337,
14+
)
15+
[$DIR/dbg-macro-expected-behavior.rs:40] dbg!(& a) = NoCopy(
16+
1337,
17+
)
18+
[$DIR/dbg-macro-expected-behavior.rs:45] f(&42) = 42
19+
before
20+
[$DIR/dbg-macro-expected-behavior.rs:50] { foo += 1; eprintln!("before"); 7331 } = 7331
21+
[$DIR/dbg-macro-expected-behavior.rs:58] ("Yeah",) = (
22+
"Yeah",
23+
)
24+
[$DIR/dbg-macro-expected-behavior.rs:61] 1 = 1
25+
[$DIR/dbg-macro-expected-behavior.rs:61] 2 = 2
26+
[$DIR/dbg-macro-expected-behavior.rs:65] 1u8 = 1
27+
[$DIR/dbg-macro-expected-behavior.rs:65] 2u32 = 2
28+
[$DIR/dbg-macro-expected-behavior.rs:65] "Yeah" = "Yeah"

0 commit comments

Comments
 (0)