From 7948afdc53cabf9330662ec894bf668839880a3c Mon Sep 17 00:00:00 2001 From: Brad Gibson Date: Sun, 11 Feb 2018 16:38:26 -0800 Subject: [PATCH] changed termination_trait's bound from Error to Debug; added compiletest header command and appropriate tests --- src/libstd/termination.rs | 15 +++----------- .../termination-trait-main-wrong-type.rs} | 0 .../termination-trait-not-satisfied.rs | 0 ...mination-trait-for-result-box-error_err.rs | 20 +++++++++++++++++++ .../termination-trait-for-empty.rs | 0 .../termination-trait-for-i32.rs | 0 ...rmination-trait-for-result-box-error_ok.rs | 17 ++++++++++++++++ .../termination-trait-for-result.rs | 0 ...rmination-trait-for-result-box-error_ok.rs | 17 ++++++++++++++++ src/tools/compiletest/src/header.rs | 13 ++++++++++++ src/tools/compiletest/src/runtest.rs | 13 ++++++------ 11 files changed, 77 insertions(+), 18 deletions(-) rename src/test/compile-fail/{main-wrong-type-2.rs => rfc-1937-termination-trait/termination-trait-main-wrong-type.rs} (100%) rename src/test/compile-fail/{ => rfc-1937-termination-trait}/termination-trait-not-satisfied.rs (100%) create mode 100644 src/test/run-fail/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs rename src/test/run-pass/{ => rfc-1937-termination-trait}/termination-trait-for-empty.rs (100%) rename src/test/run-pass/{ => rfc-1937-termination-trait}/termination-trait-for-i32.rs (100%) create mode 100644 src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-result-box-error_ok.rs rename src/test/run-pass/{ => rfc-1937-termination-trait}/termination-trait-for-result.rs (100%) create mode 100644 src/test/run-pass/termination-trait-for-result-box-error_ok.rs diff --git a/src/libstd/termination.rs b/src/libstd/termination.rs index 93a913bb540b7..dc7fa53aab632 100644 --- a/src/libstd/termination.rs +++ b/src/libstd/termination.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use error::Error; +use fmt::Debug; #[cfg(target_arch = "wasm32")] mod exit { pub const SUCCESS: i32 = 0; @@ -45,27 +45,18 @@ impl Termination for () { } #[unstable(feature = "termination_trait", issue = "43301")] -impl Termination for Result { +impl Termination for Result { fn report(self) -> i32 { match self { Ok(val) => val.report(), Err(err) => { - print_error(err); + eprintln!("Error: {:?}", err); exit::FAILURE } } } } -#[unstable(feature = "termination_trait", issue = "43301")] -fn print_error(err: E) { - eprintln!("Error: {}", err.description()); - - if let Some(ref err) = err.cause() { - eprintln!("Caused by: {}", err.description()); - } -} - #[unstable(feature = "termination_trait", issue = "43301")] impl Termination for ! { fn report(self) -> i32 { unreachable!(); } diff --git a/src/test/compile-fail/main-wrong-type-2.rs b/src/test/compile-fail/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs similarity index 100% rename from src/test/compile-fail/main-wrong-type-2.rs rename to src/test/compile-fail/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs diff --git a/src/test/compile-fail/termination-trait-not-satisfied.rs b/src/test/compile-fail/rfc-1937-termination-trait/termination-trait-not-satisfied.rs similarity index 100% rename from src/test/compile-fail/termination-trait-not-satisfied.rs rename to src/test/compile-fail/rfc-1937-termination-trait/termination-trait-not-satisfied.rs diff --git a/src/test/run-fail/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs b/src/test/run-fail/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs new file mode 100644 index 0000000000000..8ce27c0a06250 --- /dev/null +++ b/src/test/run-fail/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs @@ -0,0 +1,20 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// must-compile-successfully +// failure-status: 1 + +#![feature(termination_trait)] + +use std::io::{Error, ErrorKind}; + +fn main() -> Result<(), Box> { + Err(Box::new(Error::new(ErrorKind::Other, "returned Box from main()"))) +} diff --git a/src/test/run-pass/termination-trait-for-empty.rs b/src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-empty.rs similarity index 100% rename from src/test/run-pass/termination-trait-for-empty.rs rename to src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-empty.rs diff --git a/src/test/run-pass/termination-trait-for-i32.rs b/src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-i32.rs similarity index 100% rename from src/test/run-pass/termination-trait-for-i32.rs rename to src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-i32.rs diff --git a/src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-result-box-error_ok.rs b/src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-result-box-error_ok.rs new file mode 100644 index 0000000000000..269ac451cf4d8 --- /dev/null +++ b/src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-result-box-error_ok.rs @@ -0,0 +1,17 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(termination_trait)] + +use std::io::Error; + +fn main() -> Result<(), Box> { + Ok(()) +} diff --git a/src/test/run-pass/termination-trait-for-result.rs b/src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-result.rs similarity index 100% rename from src/test/run-pass/termination-trait-for-result.rs rename to src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-result.rs diff --git a/src/test/run-pass/termination-trait-for-result-box-error_ok.rs b/src/test/run-pass/termination-trait-for-result-box-error_ok.rs new file mode 100644 index 0000000000000..269ac451cf4d8 --- /dev/null +++ b/src/test/run-pass/termination-trait-for-result-box-error_ok.rs @@ -0,0 +1,17 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(termination_trait)] + +use std::io::Error; + +fn main() -> Result<(), Box> { + Ok(()) +} diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 80750f9a3fee0..d4d3d6c6e9a18 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -232,6 +232,7 @@ pub struct TestProps { // customized normalization rules pub normalize_stdout: Vec<(String, String)>, pub normalize_stderr: Vec<(String, String)>, + pub failure_status: i32, } impl TestProps { @@ -260,6 +261,7 @@ impl TestProps { run_pass: false, normalize_stdout: vec![], normalize_stderr: vec![], + failure_status: 101, } } @@ -383,6 +385,10 @@ impl TestProps { if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stderr") { self.normalize_stderr.push(rule); } + + if let Some(code) = config.parse_failure_status(ln) { + self.failure_status = code; + } }); for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] { @@ -488,6 +494,13 @@ impl Config { self.parse_name_directive(line, "pretty-compare-only") } + fn parse_failure_status(&self, line: &str) -> Option { + match self.parse_name_value_directive(line, "failure-status") { + Some(code) => code.trim().parse::().ok(), + _ => None, + } + } + fn parse_must_compile_successfully(&self, line: &str) -> bool { self.parse_name_directive(line, "must-compile-successfully") } diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 46df211cbaf65..a3b6d16270bb5 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -295,11 +295,14 @@ impl<'test> TestCx<'test> { } fn check_correct_failure_status(&self, proc_res: &ProcRes) { - // The value the rust runtime returns on failure - const RUST_ERR: i32 = 101; - if proc_res.status.code() != Some(RUST_ERR) { + let expected_status = Some(self.props.failure_status); + let received_status = proc_res.status.code(); + + if expected_status != received_status { self.fatal_proc_rec( - &format!("failure produced the wrong error: {}", proc_res.status), + &format!("Error: expected failure status ({:?}) but received status {:?}.", + expected_status, + received_status), proc_res, ); } @@ -320,7 +323,6 @@ impl<'test> TestCx<'test> { ); let proc_res = self.exec_compiled_test(); - if !proc_res.status.success() { self.fatal_proc_rec("test run failed!", &proc_res); } @@ -499,7 +501,6 @@ impl<'test> TestCx<'test> { expected, actual ); - panic!(); } }