Skip to content

Commit bb0e525

Browse files
Make runtest::check_debugger_output() handle wildcards at end.
1 parent 4230353 commit bb0e525

File tree

1 file changed

+51
-47
lines changed

1 file changed

+51
-47
lines changed

src/tools/compiletest/src/runtest.rs

+51-47
Original file line numberDiff line numberDiff line change
@@ -880,58 +880,62 @@ fn cleanup_debug_info_options(options: &Option<String>) -> Option<String> {
880880

881881
fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String]) {
882882
let num_check_lines = check_lines.len();
883-
if num_check_lines > 0 {
883+
884+
let mut check_line_index = 0;
885+
for line in debugger_run_result.stdout.lines() {
886+
if check_line_index >= num_check_lines {
887+
break;
888+
}
889+
890+
if check_single_line(line, &(check_lines[check_line_index])[..]) {
891+
check_line_index += 1;
892+
}
893+
}
894+
if check_line_index != num_check_lines && num_check_lines > 0 {
895+
fatal_proc_rec(None, &format!("line not found in debugger output: {}",
896+
check_lines[check_line_index]),
897+
debugger_run_result);
898+
}
899+
900+
fn check_single_line(line: &str, check_line: &str) -> bool {
884901
// Allow check lines to leave parts unspecified (e.g., uninitialized
885-
// bits in the wrong case of an enum) with the notation "[...]".
886-
let check_fragments: Vec<Vec<String>> =
887-
check_lines.iter().map(|s| {
888-
s
889-
.trim()
890-
.split("[...]")
891-
.map(str::to_owned)
892-
.collect()
893-
}).collect();
894-
// check if each line in props.check_lines appears in the
895-
// output (in order)
896-
let mut i = 0;
897-
for line in debugger_run_result.stdout.lines() {
898-
let mut rest = line.trim();
899-
let mut first = true;
900-
let mut failed = false;
901-
for frag in &check_fragments[i] {
902-
let found = if first {
903-
if rest.starts_with(frag) {
904-
Some(0)
905-
} else {
906-
None
907-
}
908-
} else {
909-
rest.find(frag)
910-
};
911-
match found {
912-
None => {
913-
failed = true;
914-
break;
915-
}
916-
Some(i) => {
917-
rest = &rest[(i + frag.len())..];
918-
}
919-
}
920-
first = false;
921-
}
922-
if !failed && rest.is_empty() {
923-
i += 1;
902+
// bits in the wrong case of an enum) with the notation "[...]".
903+
let line = line.trim();
904+
let check_line = check_line.trim();
905+
let can_start_anywhere = check_line.starts_with("[...]");
906+
let can_end_anywhere = check_line.ends_with("[...]");
907+
908+
let check_fragments: Vec<&str> = check_line.split("[...]")
909+
.filter(|frag| !frag.is_empty())
910+
.collect();
911+
if check_fragments.is_empty() {
912+
return true;
913+
}
914+
915+
let (mut rest, first_fragment) = if can_start_anywhere {
916+
match line.find(check_fragments[0]) {
917+
Some(pos) => (&line[pos + check_fragments[0].len() ..], 1),
918+
None => return false
924919
}
925-
if i == num_check_lines {
926-
// all lines checked
927-
break;
920+
} else {
921+
(line, 0)
922+
};
923+
924+
for fragment_index in first_fragment .. check_fragments.len() {
925+
let current_fragment = check_fragments[fragment_index];
926+
match rest.find(current_fragment) {
927+
Some(pos) => {
928+
rest = &rest[pos + current_fragment.len() .. ];
929+
}
930+
None => return false
928931
}
929932
}
930-
if i != num_check_lines {
931-
fatal_proc_rec(None, &format!("line not found in debugger output: {}",
932-
check_lines.get(i).unwrap()),
933-
debugger_run_result);
933+
934+
if !can_end_anywhere && !rest.is_empty() {
935+
return false;
934936
}
937+
938+
return true;
935939
}
936940
}
937941

0 commit comments

Comments
 (0)