Skip to content

Commit 5ebec91

Browse files
committed
compiletest: Parse EarlyProps from a reader
1 parent a6137fb commit 5ebec91

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/tools/compiletest/src/header.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ pub struct EarlyProps {
3434

3535
impl EarlyProps {
3636
pub fn from_file(config: &Config, testfile: &Path) -> Self {
37+
let file = File::open(testfile).unwrap();
38+
Self::from_reader(config, testfile, file)
39+
}
40+
41+
pub fn from_reader<R: Read>(config: &Config, testfile: &Path, rdr: R) -> Self {
3742
let mut props = EarlyProps {
3843
ignore: false,
3944
should_fail: false,
@@ -45,7 +50,7 @@ impl EarlyProps {
4550
let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some();
4651
let rustc_has_sanitizer_support = env::var_os("RUSTC_SANITIZER_SUPPORT").is_some();
4752

48-
iter_header(testfile, None, &mut |ln| {
53+
iter_header(testfile, None, rdr, &mut |ln| {
4954
// we should check if any only-<platform> exists and if it exists
5055
// and does not matches the current platform, skip the test
5156
if !props.ignore {
@@ -392,7 +397,8 @@ impl TestProps {
392397
/// `//[foo]`), then the property is ignored unless `cfg` is
393398
/// `Some("foo")`.
394399
fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
395-
iter_header(testfile, cfg, &mut |ln| {
400+
let file = File::open(testfile).unwrap();
401+
iter_header(testfile, cfg, file, &mut |ln| {
396402
if let Some(ep) = config.parse_error_pattern(ln) {
397403
self.error_patterns.push(ep);
398404
}
@@ -617,7 +623,7 @@ impl TestProps {
617623
}
618624
}
619625

620-
fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
626+
fn iter_header<R: Read>(testfile: &Path, cfg: Option<&str>, rdr: R, it: &mut dyn FnMut(&str)) {
621627
if testfile.is_dir() {
622628
return;
623629
}
@@ -628,7 +634,7 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
628634
// It took me like 2 days to debug why compile-flags weren’t taken into account for my test :)
629635
let comment_with_brace = comment.to_string() + "[";
630636

631-
let mut rdr = BufReader::new(File::open(testfile).unwrap());
637+
let mut rdr = BufReader::new(rdr);
632638
let mut ln = String::new();
633639

634640
loop {

0 commit comments

Comments
 (0)