Skip to content

Commit 6203f68

Browse files
committed
compiletest: Introduce // {check,build,run}-pass pass modes
1 parent 374c63e commit 6203f68

File tree

4 files changed

+32
-56
lines changed

4 files changed

+32
-56
lines changed

Diff for: src/test/incremental/no_mangle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// revisions:rpass1 rpass2
1+
// revisions:cfail1 cfail2
22
// compile-flags: --crate-type cdylib
33
// skip-codegen
44

Diff for: src/test/run-pass/compiletest-skip-codegen.rs

-7
This file was deleted.

Diff for: src/tools/compiletest/src/header.rs

+18-32
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@ impl EarlyProps {
290290
}
291291
}
292292

293+
#[derive(Clone, Copy, PartialEq, Debug)]
294+
pub enum PassMode {
295+
Check,
296+
Build,
297+
Run,
298+
}
299+
293300
#[derive(Clone, Debug)]
294301
pub struct TestProps {
295302
// Lines that should be expected, in order, on standard out
@@ -349,14 +356,10 @@ pub struct TestProps {
349356
// testing harness and used when generating compilation
350357
// arguments. (In particular, it propagates to the aux-builds.)
351358
pub incremental_dir: Option<PathBuf>,
352-
// Specifies that a test must actually compile without errors.
353-
pub compile_pass: bool,
359+
// How far should the test proceed while still passing.
360+
pub pass_mode: Option<PassMode>,
354361
// rustdoc will test the output of the `--test` option
355362
pub check_test_line_numbers_match: bool,
356-
// The test must be compiled and run successfully. Only used in UI tests for now.
357-
pub run_pass: bool,
358-
// Skip any codegen step and running the executable. Only for run-pass.
359-
pub skip_codegen: bool,
360363
// Do not pass `-Z ui-testing` to UI tests
361364
pub disable_ui_testing_normalization: bool,
362365
// customized normalization rules
@@ -396,10 +399,8 @@ impl TestProps {
396399
pretty_compare_only: false,
397400
forbid_output: vec![],
398401
incremental_dir: None,
399-
compile_pass: false,
402+
pass_mode: None,
400403
check_test_line_numbers_match: false,
401-
run_pass: false,
402-
skip_codegen: false,
403404
disable_ui_testing_normalization: false,
404405
normalize_stdout: vec![],
405406
normalize_stderr: vec![],
@@ -525,17 +526,14 @@ impl TestProps {
525526
self.check_test_line_numbers_match = config.parse_check_test_line_numbers_match(ln);
526527
}
527528

528-
if !self.run_pass {
529-
self.run_pass = config.parse_run_pass(ln);
530-
}
531-
532-
if !self.compile_pass {
533-
// run-pass implies compile_pass
534-
self.compile_pass = config.parse_compile_pass(ln) || self.run_pass;
535-
}
536-
537-
if !self.skip_codegen {
538-
self.skip_codegen = config.parse_skip_codegen(ln);
529+
if config.parse_name_directive(ln, "check-pass") ||
530+
config.parse_name_directive(ln, "skip-codegen") {
531+
self.pass_mode = Some(PassMode::Check);
532+
} else if config.parse_name_directive(ln, "build-pass") ||
533+
config.parse_name_directive(ln, "compile-pass") {
534+
self.pass_mode = Some(PassMode::Build);
535+
} else if config.parse_name_directive(ln, "run-pass") {
536+
self.pass_mode = Some(PassMode::Run);
539537
}
540538

541539
if !self.disable_ui_testing_normalization {
@@ -710,10 +708,6 @@ impl Config {
710708
}
711709
}
712710

713-
fn parse_compile_pass(&self, line: &str) -> bool {
714-
self.parse_name_directive(line, "compile-pass")
715-
}
716-
717711
fn parse_disable_ui_testing_normalization(&self, line: &str) -> bool {
718712
self.parse_name_directive(line, "disable-ui-testing-normalization")
719713
}
@@ -722,14 +716,6 @@ impl Config {
722716
self.parse_name_directive(line, "check-test-line-numbers-match")
723717
}
724718

725-
fn parse_run_pass(&self, line: &str) -> bool {
726-
self.parse_name_directive(line, "run-pass")
727-
}
728-
729-
fn parse_skip_codegen(&self, line: &str) -> bool {
730-
self.parse_name_directive(line, "skip-codegen")
731-
}
732-
733719
fn parse_assembly_output(&self, line: &str) -> Option<String> {
734720
self.parse_name_value_directive(line, "assembly-output")
735721
.map(|r| r.trim().to_string())

Diff for: src/tools/compiletest/src/runtest.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::common::{Config, TestPaths};
1010
use crate::common::{Incremental, MirOpt, RunMake, Ui, JsDocTest, Assembly};
1111
use diff;
1212
use crate::errors::{self, Error, ErrorKind};
13-
use crate::header::TestProps;
13+
use crate::header::{TestProps, PassMode};
1414
use crate::json;
1515
use regex::{Captures, Regex};
1616
use rustfix::{apply_suggestions, get_suggestions_from_json, Filter};
@@ -310,28 +310,27 @@ impl<'test> TestCx<'test> {
310310
}
311311

312312
fn should_run_successfully(&self) -> bool {
313-
let run_pass = match self.config.mode {
313+
match self.config.mode {
314314
RunPass => true,
315-
Ui => self.props.run_pass,
316-
_ => unimplemented!(),
317-
};
318-
return run_pass && !self.props.skip_codegen;
315+
Ui => self.props.pass_mode == Some(PassMode::Run),
316+
mode => panic!("unimplemented for mode {:?}", mode),
317+
}
319318
}
320319

321320
fn should_compile_successfully(&self) -> bool {
322321
match self.config.mode {
323-
CompileFail => self.props.compile_pass,
322+
CompileFail => false,
324323
RunPass => true,
325324
JsDocTest => true,
326-
Ui => self.props.compile_pass,
325+
Ui => self.props.pass_mode.is_some(),
327326
Incremental => {
328327
let revision = self.revision
329328
.expect("incremental tests require a list of revisions");
330329
if revision.starts_with("rpass") || revision.starts_with("rfail") {
331330
true
332331
} else if revision.starts_with("cfail") {
333332
// FIXME: would be nice if incremental revs could start with "cpass"
334-
self.props.compile_pass
333+
self.props.pass_mode.is_some()
335334
} else {
336335
panic!("revision name must begin with rpass, rfail, or cfail");
337336
}
@@ -433,11 +432,9 @@ impl<'test> TestCx<'test> {
433432
"run-pass tests with expected warnings should be moved to ui/"
434433
);
435434

436-
if !self.props.skip_codegen {
437-
let proc_res = self.exec_compiled_test();
438-
if !proc_res.status.success() {
439-
self.fatal_proc_rec("test run failed!", &proc_res);
440-
}
435+
let proc_res = self.exec_compiled_test();
436+
if !proc_res.status.success() {
437+
self.fatal_proc_rec("test run failed!", &proc_res);
441438
}
442439
}
443440

@@ -1344,7 +1341,7 @@ impl<'test> TestCx<'test> {
13441341
fn check_error_patterns(&self, output_to_check: &str, proc_res: &ProcRes) {
13451342
debug!("check_error_patterns");
13461343
if self.props.error_patterns.is_empty() {
1347-
if self.props.compile_pass {
1344+
if self.props.pass_mode.is_some() {
13481345
return;
13491346
} else {
13501347
self.fatal(&format!(
@@ -1971,7 +1968,7 @@ impl<'test> TestCx<'test> {
19711968
}
19721969
}
19731970

1974-
if self.props.skip_codegen {
1971+
if self.props.pass_mode == Some(PassMode::Check) {
19751972
assert!(
19761973
!self
19771974
.props

0 commit comments

Comments
 (0)