Skip to content

Stabilize unit tests with non-() return type #51298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 9, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,6 @@ declare_features! (
// `foo.rs` as an alternative to `foo/mod.rs`
(active, non_modrs_mods, "1.24.0", Some(44660), Some(Edition::Edition2018)),

// Termination trait in tests (RFC 1937)
(active, termination_trait_test, "1.24.0", Some(48854), Some(Edition::Edition2018)),

// `extern` in paths
(active, extern_in_paths, "1.23.0", Some(44660), None),

Expand Down Expand Up @@ -612,6 +609,8 @@ declare_features! (
(accepted, fn_must_use, "1.27.0", Some(43302), None),
// Allows use of the :lifetime macro fragment specifier
(accepted, macro_lifetime_matcher, "1.27.0", Some(34303), None),
// Termination trait in tests (RFC 1937)
(accepted, termination_trait_test, "1.27.0", Some(48854), Some(Edition::Edition2018)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really clear on why the Edition::Edition2018 flag was set here, actually. I would imagine that this feature would just be generally available on any edition. Can we just change to None?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dylan-DPC

should it be None instead? feels odd 😛

Yeah, I think it should. I don't think that flag actually has meaning for accepted feature gates.

);

// If you change this, please modify src/doc/unstable-book as well. You must
Expand Down
38 changes: 7 additions & 31 deletions src/libsyntax/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
return No(BadTestSignature::NoArgumentsAllowed);
}

match (has_output, cx.features.termination_trait_test, has_should_panic_attr) {
(true, true, true) => No(BadTestSignature::ShouldPanicOnlyWithNoArgs),
(true, true, false) => if generics.is_parameterized() {
match (has_output, has_should_panic_attr) {
(true, true) => No(BadTestSignature::ShouldPanicOnlyWithNoArgs),
(true, false) => if generics.is_parameterized() {
No(BadTestSignature::WrongTypeSignature)
} else {
Yes
},
(true, false, _) => No(BadTestSignature::WrongTypeSignature),
(false, _, _) => Yes
(true, _) => No(BadTestSignature::WrongTypeSignature),
(false, _) => Yes
}
}
_ => No(BadTestSignature::NotEvenAFunction),
Expand Down Expand Up @@ -398,28 +398,9 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
fn has_bench_signature(cx: &TestCtxt, i: &ast::Item) -> bool {
match i.node {
ast::ItemKind::Fn(ref decl, _, _, _, ref generics, _) => {
let input_cnt = decl.inputs.len();

// If the termination trait is active, the compiler will check that the output
// type implements the `Termination` trait as `libtest` enforces that.
let output_matches = if cx.features.termination_trait_test {
true
} else {
let no_output = match decl.output {
ast::FunctionRetTy::Default(..) => true,
ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyKind::Tup(vec![]) => true,
_ => false
};
let tparm_cnt = generics.params.iter()
.filter(|param| param.is_type_param())
.count();

no_output && tparm_cnt == 0
};

// NB: inadequate check, but we're running
// well before resolve, can't get too deep.
input_cnt == 1 && output_matches
decl.inputs.len() == 1
}
_ => false
}
Expand All @@ -430,13 +411,8 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
if has_bench_attr && !has_bench_signature {
let diag = cx.span_diagnostic;

if cx.features.termination_trait_test {
diag.span_err(i.span, "functions used as benches must have signature \
diag.span_err(i.span, "functions used as benches must have signature \
`fn(&mut Bencher) -> impl Termination`");
} else {
diag.span_err(i.span, "functions used as benches must have signature \
`fn(&mut Bencher) -> ()`");
}
}

has_bench_attr && has_bench_signature
Expand Down
22 changes: 0 additions & 22 deletions src/test/compile-fail/feature-gate-termination_trait_test.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// compile-flags: --test

#![feature(termination_trait_test)]
#![feature(test)]

extern crate test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// compile-flags: --test
// run-pass

#![feature(termination_trait_test)]
#![feature(test)]

extern crate test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

// compile-flags: --test

#![feature(termination_trait_test)]

use std::num::ParseIntError;

#[test]
Expand Down