Skip to content

Commit 5d7cd65

Browse files
committed
compiletest: dedup revision line logic.
1 parent 8de7f04 commit 5d7cd65

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

src/tools/compiletest/src/header.rs

+25-11
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,29 @@ impl TestProps {
535535
}
536536
}
537537

538+
pub fn line_directive<'line>(
539+
comment: &str,
540+
ln: &'line str,
541+
) -> Option<(Option<&'line str>, &'line str)> {
542+
if ln.starts_with(comment) {
543+
let ln = ln[comment.len()..].trim_start();
544+
if ln.starts_with('[') {
545+
// A comment like `//[foo]` is specific to revision `foo`
546+
if let Some(close_brace) = ln.find(']') {
547+
let lncfg = &ln[1..close_brace];
548+
549+
Some((Some(lncfg), ln[(close_brace + 1)..].trim_start()))
550+
} else {
551+
panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln)
552+
}
553+
} else {
554+
Some((None, ln))
555+
}
556+
} else {
557+
None
558+
}
559+
}
560+
538561
fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>, &str)) {
539562
if testfile.is_dir() {
540563
return;
@@ -557,17 +580,8 @@ fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>
557580
let ln = ln.trim();
558581
if ln.starts_with("fn") || ln.starts_with("mod") {
559582
return;
560-
} else if ln.starts_with(comment) && ln[comment.len()..].trim_start().starts_with('[') {
561-
// A comment like `//[foo]` is specific to revision `foo`
562-
if let Some(close_brace) = ln.find(']') {
563-
let open_brace = ln.find('[').unwrap();
564-
let lncfg = &ln[open_brace + 1..close_brace];
565-
it(Some(lncfg), ln[(close_brace + 1)..].trim_start());
566-
} else {
567-
panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln)
568-
}
569-
} else if ln.starts_with(comment) {
570-
it(None, ln[comment.len()..].trim_start());
583+
} else if let Some((lncfg, ln)) = line_directive(comment, ln) {
584+
it(lncfg, ln);
571585
}
572586
}
573587
}

src/tools/compiletest/src/runtest/debugger.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::common::Config;
2+
use crate::header::line_directive;
23
use crate::runtest::ProcRes;
34

45
use std::fs::File;
@@ -32,26 +33,7 @@ impl DebuggerCommands {
3233
counter += 1;
3334
match line {
3435
Ok(line) => {
35-
let (line, lnrev) = if line.starts_with("//") {
36-
let line = line[2..].trim_start();
37-
if line.starts_with('[') {
38-
if let Some(close_brace) = line.find(']') {
39-
let open_brace = line.find('[').unwrap();
40-
let lnrev = &line[open_brace + 1..close_brace];
41-
let line = line[(close_brace + 1)..].trim_start();
42-
(line, Some(lnrev))
43-
} else {
44-
panic!(
45-
"malformed condition direction: expected `//[foo]`, found `{}`",
46-
line
47-
)
48-
}
49-
} else {
50-
(line, None)
51-
}
52-
} else {
53-
(line.as_str(), None)
54-
};
36+
let (lnrev, line) = line_directive("//", &line).unwrap_or((None, &line));
5537

5638
// Skip any revision specific directive that doesn't match the current
5739
// revision being tested

0 commit comments

Comments
 (0)