diff options
| author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2018-09-05 21:40:39 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-05 21:40:39 -0700 |
| commit | 3dab33225a8c74dcf1f6a4f6161a10b60d5944e9 (patch) | |
| tree | 24f2e486873ff3f12493265327d999767cf21599 /src/test | |
| parent | 482346ce75ff112bfbe991d37fb66057cb80c804 (diff) | |
| parent | 27e5457f3fa6c6e322e05352f0109f2cd511396c (diff) | |
| download | rust-3dab33225a8c74dcf1f6a4f6161a10b60d5944e9.tar.gz rust-3dab33225a8c74dcf1f6a4f6161a10b60d5944e9.zip | |
Merge branch 'master' into fix-submodules
Diffstat (limited to 'src/test')
23 files changed, 316 insertions, 29 deletions
diff --git a/src/test/incremental/issue-49595/issue_49595.rs b/src/test/incremental/issue-49595/issue_49595.rs index 134f114e6ac..7067e725072 100644 --- a/src/test/incremental/issue-49595/issue_49595.rs +++ b/src/test/incremental/issue-49595/issue_49595.rs @@ -15,12 +15,11 @@ #![feature(rustc_attrs)] #![crate_type = "rlib"] -#![rustc_partition_codegened(module="issue_49595-__test", cfg="cfail2")] +#![rustc_partition_codegened(module="issue_49595-tests", cfg="cfail2")] #![rustc_partition_codegened(module="issue_49595-lit_test", cfg="cfail3")] mod tests { - #[cfg_attr(not(cfail1), ignore)] - #[test] + #[cfg_attr(not(cfail1), test)] fn test() { } } diff --git a/src/test/run-make-fulldeps/libtest-json/output.json b/src/test/run-make-fulldeps/libtest-json/output.json index 235f8cd7c72..d8169ece89b 100644 --- a/src/test/run-make-fulldeps/libtest-json/output.json +++ b/src/test/run-make-fulldeps/libtest-json/output.json @@ -1,4 +1,4 @@ -{ "type": "suite", "event": "started", "test_count": "4" } +{ "type": "suite", "event": "started", "test_count": 4 } { "type": "test", "event": "started", "name": "a" } { "type": "test", "name": "a", "event": "ok" } { "type": "test", "event": "started", "name": "b" } @@ -7,4 +7,4 @@ { "type": "test", "name": "c", "event": "ok" } { "type": "test", "event": "started", "name": "d" } { "type": "test", "name": "d", "event": "ignored" } -{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "allowed_fail": 0, "ignored": 1, "measured": 0, "filtered_out": "0" } +{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "allowed_fail": 0, "ignored": 1, "measured": 0, "filtered_out": 0 } diff --git a/src/test/ui/cfg-non-opt-expr.rs b/src/test/ui/cfg-non-opt-expr.rs index a4b24fa8b4b..55eca7f45a5 100644 --- a/src/test/ui/cfg-non-opt-expr.rs +++ b/src/test/ui/cfg-non-opt-expr.rs @@ -9,6 +9,7 @@ // except according to those terms. #![feature(stmt_expr_attributes)] +#![feature(custom_test_frameworks)] fn main() { let _ = #[cfg(unset)] (); @@ -17,6 +18,4 @@ fn main() { //~^ ERROR removing an expression is not supported in this position let _ = [1, 2, 3][#[cfg(unset)] 1]; //~^ ERROR removing an expression is not supported in this position - let _ = #[test] (); - //~^ ERROR removing an expression is not supported in this position } diff --git a/src/test/ui/cfg-non-opt-expr.stderr b/src/test/ui/cfg-non-opt-expr.stderr index 0511c575546..1892cee113e 100644 --- a/src/test/ui/cfg-non-opt-expr.stderr +++ b/src/test/ui/cfg-non-opt-expr.stderr @@ -1,26 +1,20 @@ error: removing an expression is not supported in this position - --> $DIR/cfg-non-opt-expr.rs:14:13 + --> $DIR/cfg-non-opt-expr.rs:15:13 | LL | let _ = #[cfg(unset)] (); | ^^^^^^^^^^^^^ error: removing an expression is not supported in this position - --> $DIR/cfg-non-opt-expr.rs:16:21 + --> $DIR/cfg-non-opt-expr.rs:17:21 | LL | let _ = 1 + 2 + #[cfg(unset)] 3; | ^^^^^^^^^^^^^ error: removing an expression is not supported in this position - --> $DIR/cfg-non-opt-expr.rs:18:23 + --> $DIR/cfg-non-opt-expr.rs:19:23 | LL | let _ = [1, 2, 3][#[cfg(unset)] 1]; | ^^^^^^^^^^^^^ -error: removing an expression is not supported in this position - --> $DIR/cfg-non-opt-expr.rs:20:13 - | -LL | let _ = #[test] (); - | ^^^^^^^ - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors diff --git a/src/test/ui/custom-test-frameworks-simple.rs b/src/test/ui/custom-test-frameworks-simple.rs new file mode 100644 index 00000000000..39a4dc569fa --- /dev/null +++ b/src/test/ui/custom-test-frameworks-simple.rs @@ -0,0 +1,32 @@ +// Copyright 2017 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. + +// compile-flags: --test +// run-pass + +#![feature(custom_test_frameworks)] +#![test_runner(crate::foo_runner)] + +#[cfg(test)] +fn foo_runner(ts: &[&Fn(usize)->()]) { + for (i, t) in ts.iter().enumerate() { + t(i); + } +} + +#[test_case] +fn test1(i: usize) { + println!("Hi #{}", i); +} + +#[test_case] +fn test2(i: usize) { + println!("Hey #{}", i); +} diff --git a/src/test/ui/custom_test_frameworks/auxiliary/dynamic_runner.rs b/src/test/ui/custom_test_frameworks/auxiliary/dynamic_runner.rs new file mode 100644 index 00000000000..c204e69eafc --- /dev/null +++ b/src/test/ui/custom_test_frameworks/auxiliary/dynamic_runner.rs @@ -0,0 +1,45 @@ +// 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. + +use std::process::exit; + +pub trait Testable { + // Name of the test + fn name(&self) -> String; + + // Tests pass by default + fn run(&self) -> bool { + true + } + + // A test can generate subtests + fn subtests(&self) -> Vec<Box<dyn Testable>> { + vec![] + } +} + +fn run_test(t: &dyn Testable) -> bool { + let success = t.subtests().into_iter().all(|sub_t| run_test(&*sub_t)) && t.run(); + println!("{}...{}", t.name(), if success { "SUCCESS" } else { "FAIL" }); + success +} + +pub fn runner(tests: &[&dyn Testable]) { + let mut failed = false; + for t in tests { + if !run_test(*t) { + failed = true; + } + } + + if failed { + exit(1); + } +} diff --git a/src/test/ui/custom_test_frameworks/auxiliary/example_runner.rs b/src/test/ui/custom_test_frameworks/auxiliary/example_runner.rs new file mode 100644 index 00000000000..7b6b5e02955 --- /dev/null +++ b/src/test/ui/custom_test_frameworks/auxiliary/example_runner.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 <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. + +pub trait Testable { + fn name(&self) -> String; + fn run(&self) -> Option<String>; // None will be success, Some is the error message +} + +pub fn runner(tests: &[&dyn Testable]) { + for t in tests { + print!("{}........{}", t.name(), t.run().unwrap_or_else(|| "SUCCESS".to_string())); + } +} diff --git a/src/test/ui/custom_test_frameworks/dynamic.rs b/src/test/ui/custom_test_frameworks/dynamic.rs new file mode 100644 index 00000000000..f82571b948a --- /dev/null +++ b/src/test/ui/custom_test_frameworks/dynamic.rs @@ -0,0 +1,45 @@ +// 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. + +// run-pass +// aux-build:dynamic_runner.rs +// compile-flags:--test +#![feature(custom_test_frameworks)] +#![test_runner(dynamic_runner::runner)] + +extern crate dynamic_runner; + +pub struct AllFoo(&'static str); +struct IsFoo(String); + +impl dynamic_runner::Testable for AllFoo { + fn name(&self) -> String { + String::from(self.0) + } + + fn subtests(&self) -> Vec<Box<dyn dynamic_runner::Testable>> { + self.0.split(" ").map(|word| + Box::new(IsFoo(word.into())) as Box<dyn dynamic_runner::Testable> + ).collect() + } +} + +impl dynamic_runner::Testable for IsFoo { + fn name(&self) -> String { + self.0.clone() + } + + fn run(&self) -> bool { + self.0 == "foo" + } +} + +#[test_case] +const TEST_2: AllFoo = AllFoo("foo foo"); diff --git a/src/test/ui/custom_test_frameworks/full.rs b/src/test/ui/custom_test_frameworks/full.rs new file mode 100644 index 00000000000..9fcf76ec33e --- /dev/null +++ b/src/test/ui/custom_test_frameworks/full.rs @@ -0,0 +1,38 @@ +// 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. + +// run-pass +// aux-build:example_runner.rs +// compile-flags:--test + +#![feature(custom_test_frameworks)] +#![test_runner(example_runner::runner)] +extern crate example_runner; + +pub struct IsFoo(&'static str); + +impl example_runner::Testable for IsFoo { + fn name(&self) -> String { + self.0.to_string() + } + + fn run(&self) -> Option<String> { + if self.0 != "foo" { + return Some(format!("{} != foo", self.0)); + } + None + } +} + +#[test_case] +const TEST_1: IsFoo = IsFoo("hello"); + +#[test_case] +const TEST_2: IsFoo = IsFoo("foo"); diff --git a/src/test/ui/custom_test_frameworks/mismatch.rs b/src/test/ui/custom_test_frameworks/mismatch.rs new file mode 100644 index 00000000000..28753f1649a --- /dev/null +++ b/src/test/ui/custom_test_frameworks/mismatch.rs @@ -0,0 +1,19 @@ +// 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. + +// aux-build:example_runner.rs +// compile-flags:--test +#![feature(custom_test_frameworks)] +#![test_runner(example_runner::runner)] + +extern crate example_runner; + +#[test] +fn wrong_kind(){} diff --git a/src/test/ui/custom_test_frameworks/mismatch.stderr b/src/test/ui/custom_test_frameworks/mismatch.stderr new file mode 100644 index 00000000000..8e2afaedfff --- /dev/null +++ b/src/test/ui/custom_test_frameworks/mismatch.stderr @@ -0,0 +1,11 @@ +error[E0277]: the trait bound `test::TestDescAndFn: example_runner::Testable` is not satisfied + --> $DIR/mismatch.rs:19:1 + | +LL | fn wrong_kind(){} + | ^^^^^^^^^^^^^^^^^ the trait `example_runner::Testable` is not implemented for `test::TestDescAndFn` + | + = note: required for the cast to the object type `dyn example_runner::Testable` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/feature-gate-custom_test_frameworks.rs b/src/test/ui/feature-gate-custom_test_frameworks.rs new file mode 100644 index 00000000000..7c9f7dd0402 --- /dev/null +++ b/src/test/ui/feature-gate-custom_test_frameworks.rs @@ -0,0 +1,13 @@ +// Copyright 2017 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. + +#![test_runner(main)] //~ ERROR custom test frameworks are an unstable feature + +fn main() {} diff --git a/src/test/ui/feature-gate-custom_test_frameworks.stderr b/src/test/ui/feature-gate-custom_test_frameworks.stderr new file mode 100644 index 00000000000..bfcbab50067 --- /dev/null +++ b/src/test/ui/feature-gate-custom_test_frameworks.stderr @@ -0,0 +1,11 @@ +error[E0658]: custom test frameworks are an unstable feature (see issue #50297) + --> $DIR/feature-gate-custom_test_frameworks.rs:11:1 + | +LL | #![test_runner(main)] //~ ERROR custom test frameworks are an unstable feature + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(custom_test_frameworks)] to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/inaccessible-test-modules.stderr b/src/test/ui/inaccessible-test-modules.stderr index ce8eaf59027..5b964c1a14b 100644 --- a/src/test/ui/inaccessible-test-modules.stderr +++ b/src/test/ui/inaccessible-test-modules.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `__test` --> $DIR/inaccessible-test-modules.rs:15:5 | LL | use __test as x; //~ ERROR unresolved import `__test` - | ^^^^^^^^^^^ no `__test` in the root. Did you mean to use `__test`? + | ^^^^^^^^^^^ no `__test` in the root. Did you mean to use `test`? error[E0432]: unresolved import `__test_reexports` --> $DIR/inaccessible-test-modules.rs:16:5 diff --git a/src/test/ui/issues/issue-11692-2.rs b/src/test/ui/issues/issue-11692-2.rs index acac2d151fe..424cbd981c8 100644 --- a/src/test/ui/issues/issue-11692-2.rs +++ b/src/test/ui/issues/issue-11692-2.rs @@ -10,5 +10,5 @@ fn main() { concat!(test!()); - //~^ ERROR cannot find macro `test!` in this scope + //~^ error: cannot find macro `test!` in this scope } diff --git a/src/test/ui/issues/issue-12997-2.stderr b/src/test/ui/issues/issue-12997-2.stderr index 3030ee4779b..853a2a0f1b4 100644 --- a/src/test/ui/issues/issue-12997-2.stderr +++ b/src/test/ui/issues/issue-12997-2.stderr @@ -5,7 +5,7 @@ LL | fn bar(x: isize) { } | ^^^^^^^^^^^^^^^^^^^^ expected isize, found mutable reference | = note: expected type `isize` - found type `&mut __test::test::Bencher` + found type `&mut test::Bencher` error: aborting due to previous error diff --git a/src/test/ui/lint/test-inner-fn.rs b/src/test/ui/lint/test-inner-fn.rs index 4304c96197f..a7727c69e4c 100644 --- a/src/test/ui/lint/test-inner-fn.rs +++ b/src/test/ui/lint/test-inner-fn.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --test -D unnameable_test_functions +// compile-flags: --test -D unnameable_test_items #[test] fn foo() { - #[test] //~ ERROR cannot test inner function [unnameable_test_functions] + #[test] //~ ERROR cannot test inner items [unnameable_test_items] fn bar() {} bar(); } @@ -20,7 +20,7 @@ fn foo() { mod x { #[test] fn foo() { - #[test] //~ ERROR cannot test inner function [unnameable_test_functions] + #[test] //~ ERROR cannot test inner items [unnameable_test_items] fn bar() {} bar(); } diff --git a/src/test/ui/lint/test-inner-fn.stderr b/src/test/ui/lint/test-inner-fn.stderr index 37f0c161036..182fb31a9aa 100644 --- a/src/test/ui/lint/test-inner-fn.stderr +++ b/src/test/ui/lint/test-inner-fn.stderr @@ -1,15 +1,15 @@ -error: cannot test inner function +error: cannot test inner items --> $DIR/test-inner-fn.rs:15:5 | -LL | #[test] //~ ERROR cannot test inner function [unnameable_test_functions] +LL | #[test] //~ ERROR cannot test inner items [unnameable_test_items] | ^^^^^^^ | - = note: requested on the command line with `-D unnameable-test-functions` + = note: requested on the command line with `-D unnameable-test-items` -error: cannot test inner function +error: cannot test inner items --> $DIR/test-inner-fn.rs:23:9 | -LL | #[test] //~ ERROR cannot test inner function [unnameable_test_functions] +LL | #[test] //~ ERROR cannot test inner items [unnameable_test_items] | ^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr b/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr index 0972a0994fc..0e95c053ce4 100644 --- a/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr +++ b/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr @@ -7,7 +7,7 @@ LL | | } | |_^ `main` can only return types that implement `std::process::Termination` | = help: the trait `std::process::Termination` is not implemented for `std::result::Result<f32, std::num::ParseIntError>` - = note: required by `__test::test::assert_test_result` + = note: required by `test::assert_test_result` error: aborting due to previous error diff --git a/src/test/ui/test-on-macro.rs b/src/test/ui/test-on-macro.rs new file mode 100644 index 00000000000..a153e634434 --- /dev/null +++ b/src/test/ui/test-on-macro.rs @@ -0,0 +1,23 @@ +// 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. + +// compile-pass +// compile-flags:--test + +#![deny(warnings)] + +macro_rules! foo { + () => (fn foo(){}) +} + +#[test] +foo!(); + +fn main(){} diff --git a/src/test/ui/test-on-macro.stderr b/src/test/ui/test-on-macro.stderr new file mode 100644 index 00000000000..a45bb25255e --- /dev/null +++ b/src/test/ui/test-on-macro.stderr @@ -0,0 +1,6 @@ +warning: #[test] attribute should not be used on macros. Use #[cfg(test)] instead. + --> $DIR/test-on-macro.rs:21:1 + | +LL | foo!(); + | ^^^^^^^ + diff --git a/src/test/ui/test-shadowing/auxiliary/test_macro.rs b/src/test/ui/test-shadowing/auxiliary/test_macro.rs new file mode 100644 index 00000000000..2e9d2dcc410 --- /dev/null +++ b/src/test/ui/test-shadowing/auxiliary/test_macro.rs @@ -0,0 +1,14 @@ +// 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. + +#[macro_export] +macro_rules! test { + () => {}; +} diff --git a/src/test/ui/test-shadowing/test-cant-be-shadowed.rs b/src/test/ui/test-shadowing/test-cant-be-shadowed.rs new file mode 100644 index 00000000000..4b1a437818f --- /dev/null +++ b/src/test/ui/test-shadowing/test-cant-be-shadowed.rs @@ -0,0 +1,18 @@ +// 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. + +// compile-pass +// aux-build:test_macro.rs +// compile-flags:--test + +#[macro_use] extern crate test_macro; + +#[test] +fn foo(){} |
