diff options
| author | Luqman Aden <me@luqman.ca> | 2022-07-19 19:13:33 -0700 |
|---|---|---|
| committer | Luqman Aden <me@luqman.ca> | 2022-07-20 00:23:38 -0700 |
| commit | 5d7cd652942e5ce4ca7c673a6e44618bae655598 (patch) | |
| tree | 030a07cf56e331a81adc802f1f73dbb18f577914 /src/tools | |
| parent | 8de7f0477a08d0edb199140d3fbc9444c99e69ac (diff) | |
| download | rust-5d7cd652942e5ce4ca7c673a6e44618bae655598.tar.gz rust-5d7cd652942e5ce4ca7c673a6e44618bae655598.zip | |
compiletest: dedup revision line logic.
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/compiletest/src/header.rs | 36 | ||||
| -rw-r--r-- | src/tools/compiletest/src/runtest/debugger.rs | 22 |
2 files changed, 27 insertions, 31 deletions
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 17f2b77dab0..02f4d29a2f0 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -535,6 +535,29 @@ impl TestProps { } } +pub fn line_directive<'line>( + comment: &str, + ln: &'line str, +) -> Option<(Option<&'line str>, &'line str)> { + if ln.starts_with(comment) { + let ln = ln[comment.len()..].trim_start(); + if ln.starts_with('[') { + // A comment like `//[foo]` is specific to revision `foo` + if let Some(close_brace) = ln.find(']') { + let lncfg = &ln[1..close_brace]; + + Some((Some(lncfg), ln[(close_brace + 1)..].trim_start())) + } else { + panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln) + } + } else { + Some((None, ln)) + } + } else { + None + } +} + fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>, &str)) { if testfile.is_dir() { return; @@ -557,17 +580,8 @@ fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str> let ln = ln.trim(); if ln.starts_with("fn") || ln.starts_with("mod") { return; - } else if ln.starts_with(comment) && ln[comment.len()..].trim_start().starts_with('[') { - // A comment like `//[foo]` is specific to revision `foo` - if let Some(close_brace) = ln.find(']') { - let open_brace = ln.find('[').unwrap(); - let lncfg = &ln[open_brace + 1..close_brace]; - it(Some(lncfg), ln[(close_brace + 1)..].trim_start()); - } else { - panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln) - } - } else if ln.starts_with(comment) { - it(None, ln[comment.len()..].trim_start()); + } else if let Some((lncfg, ln)) = line_directive(comment, ln) { + it(lncfg, ln); } } } diff --git a/src/tools/compiletest/src/runtest/debugger.rs b/src/tools/compiletest/src/runtest/debugger.rs index 99394c3bfbf..379ff0bab40 100644 --- a/src/tools/compiletest/src/runtest/debugger.rs +++ b/src/tools/compiletest/src/runtest/debugger.rs @@ -1,4 +1,5 @@ use crate::common::Config; +use crate::header::line_directive; use crate::runtest::ProcRes; use std::fs::File; @@ -32,26 +33,7 @@ impl DebuggerCommands { counter += 1; match line { Ok(line) => { - let (line, lnrev) = if line.starts_with("//") { - let line = line[2..].trim_start(); - if line.starts_with('[') { - if let Some(close_brace) = line.find(']') { - let open_brace = line.find('[').unwrap(); - let lnrev = &line[open_brace + 1..close_brace]; - let line = line[(close_brace + 1)..].trim_start(); - (line, Some(lnrev)) - } else { - panic!( - "malformed condition direction: expected `//[foo]`, found `{}`", - line - ) - } - } else { - (line, None) - } - } else { - (line.as_str(), None) - }; + let (lnrev, line) = line_directive("//", &line).unwrap_or((None, &line)); // Skip any revision specific directive that doesn't match the current // revision being tested |
