From 0886bc4cbf3ec9b782b2dc9ed99ac6bed9df7b00 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 16 Jun 2019 12:43:35 +0300 Subject: [PATCH] compiletest: Move pass mode update into a separate function --- src/tools/compiletest/src/header.rs | 68 +++++++++++++++-------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index e4765c641aa8e..6ce7461f759a4 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -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 = @@ -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)) {