Skip to content

Commit

Permalink
changed termination_trait's bound from Error to Debug; added compilet…
Browse files Browse the repository at this point in the history
…est header command and appropriate tests
  • Loading branch information
Xandkeeper committed Feb 12, 2018
1 parent 0bb8935 commit 7948afd
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 18 deletions.
15 changes: 3 additions & 12 deletions src/libstd/termination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,27 +45,18 @@ impl Termination for () {
}

#[unstable(feature = "termination_trait", issue = "43301")]
impl<T: Termination, E: Error> Termination for Result<T, E> {
impl<T: Termination, E: Debug> Termination for Result<T, E> {
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<E: 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!(); }
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<Error>> {
Err(Box::new(Error::new(ErrorKind::Other, "returned Box<Error> from main()")))
}
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<Error>> {
Ok(())
}
17 changes: 17 additions & 0 deletions src/test/run-pass/termination-trait-for-result-box-error_ok.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<Error>> {
Ok(())
}
13 changes: 13 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -260,6 +261,7 @@ impl TestProps {
run_pass: false,
normalize_stdout: vec![],
normalize_stderr: vec![],
failure_status: 101,
}
}

Expand Down Expand Up @@ -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"] {
Expand Down Expand Up @@ -488,6 +494,13 @@ impl Config {
self.parse_name_directive(line, "pretty-compare-only")
}

fn parse_failure_status(&self, line: &str) -> Option<i32> {
match self.parse_name_value_directive(line, "failure-status") {
Some(code) => code.trim().parse::<i32>().ok(),
_ => None,
}
}

fn parse_must_compile_successfully(&self, line: &str) -> bool {
self.parse_name_directive(line, "must-compile-successfully")
}
Expand Down
13 changes: 7 additions & 6 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -499,7 +501,6 @@ impl<'test> TestCx<'test> {
expected,
actual
);
panic!();
}
}

Expand Down

0 comments on commit 7948afd

Please sign in to comment.