Skip to content

Commit

Permalink
compiletest: Move pass mode update into a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jun 16, 2019
1 parent 932ea64 commit 0886bc4
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,38 +526,7 @@ impl TestProps {
self.check_test_line_numbers_match = config.parse_check_test_line_numbers_match(ln);
}

let check_no_run = |s| {
if config.mode != Mode::Ui && config.mode != Mode::Incremental {
panic!("`{}` header is only supported in UI and incremental tests", s);
}
if config.mode == Mode::Incremental &&
!cfg.map_or(false, |r| r.starts_with("cfail")) &&
!self.revisions.iter().all(|r| r.starts_with("cfail")) {
panic!("`{}` header is only supported in `cfail` incremental tests", s);
}
};
let pass_mode = if config.parse_name_directive(ln, "check-pass") {
check_no_run("check-pass");
Some(PassMode::Check)
} else if config.parse_name_directive(ln, "build-pass") {
check_no_run("build-pass");
Some(PassMode::Build)
} else if config.parse_name_directive(ln, "compile-pass") /* compatibility */ {
check_no_run("compile-pass");
Some(PassMode::Build)
} else if config.parse_name_directive(ln, "run-pass") {
if config.mode != Mode::Ui && config.mode != Mode::RunPass /* compatibility */ {
panic!("`run-pass` header is only supported in UI tests")
}
Some(PassMode::Run)
} else {
None
};
match (self.pass_mode, pass_mode) {
(None, Some(_)) => self.pass_mode = pass_mode,
(Some(_), Some(_)) => panic!("multiple `*-pass` headers in a single test"),
(_, None) => {}
}
self.update_pass_mode(ln, cfg, config);

if !self.disable_ui_testing_normalization {
self.disable_ui_testing_normalization =
Expand Down Expand Up @@ -604,6 +573,41 @@ impl TestProps {
}
}
}

fn update_pass_mode(&mut self, ln: &str, revision: Option<&str>, config: &Config) {
let check_no_run = |s| {
if config.mode != Mode::Ui && config.mode != Mode::Incremental {
panic!("`{}` header is only supported in UI and incremental tests", s);
}
if config.mode == Mode::Incremental &&
!revision.map_or(false, |r| r.starts_with("cfail")) &&
!self.revisions.iter().all(|r| r.starts_with("cfail")) {
panic!("`{}` header is only supported in `cfail` incremental tests", s);
}
};
let pass_mode = if config.parse_name_directive(ln, "check-pass") {
check_no_run("check-pass");
Some(PassMode::Check)
} else if config.parse_name_directive(ln, "build-pass") {
check_no_run("build-pass");
Some(PassMode::Build)
} else if config.parse_name_directive(ln, "compile-pass") /* compatibility */ {
check_no_run("compile-pass");
Some(PassMode::Build)
} else if config.parse_name_directive(ln, "run-pass") {
if config.mode != Mode::Ui && config.mode != Mode::RunPass /* compatibility */ {
panic!("`run-pass` header is only supported in UI tests")
}
Some(PassMode::Run)
} else {
None
};
match (self.pass_mode, pass_mode) {
(None, Some(_)) => self.pass_mode = pass_mode,
(Some(_), Some(_)) => panic!("multiple `*-pass` headers in a single test"),
(_, None) => {}
}
}
}

fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
Expand Down

0 comments on commit 0886bc4

Please sign in to comment.