Skip to content
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

Termination trait in tests #48143

Merged
merged 11 commits into from
Feb 24, 2018
Merged

Conversation

nikomatsakis
Copy link
Contributor

Support the Termination trait in unit tests (cc #43301)

Also, a drive-by fix for #47075.

This is joint work with @bkchr.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@nikomatsakis
Copy link
Contributor Author

r? @petrochenkov

ecx.lambda(
span,
vec![],
// ::std::Termination::assert_unit_test_successful(..)
Copy link
Member

Choose a reason for hiding this comment

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

Can't this function be in libtest? I do think I like the closure though - it gets coerced into a fn pointer, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you say more about what you think I should do here? You want me to generate a closure that invokes a fn in libtest that invokes std::Termination::assert_unit_test_successful? (Or I guess potentially remove assert_unit_test_successful? I'd rather not do the latter, but then it is an ad-hoc extension to the spec. It's one that makes a lot of sense to me though, since I imagine that people may want to write custom result types that print out differently in unit test failures than otherwise. But I guess there is no strong reason that said people shouldn't use a different type in their unit tests.)

Copy link
Member

Choose a reason for hiding this comment

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

I think there should be a trait in libtest that can be specialized if need be in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, so roughly what there is no, but indirecting through some random trait instead, and that trait is implemented for all T: Termination?

Copy link
Member

Choose a reason for hiding this comment

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

That sounds like a good default, yes. I'd really want to keep testing infrastructure out of libstd where possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eddyb I guess it'd be mildly easier (and equally future proof) to add a top-level function to libtest, like assert_unit_test_success(foo()). Internally, it can use Termination for now -- we can just use it indiscriminately actually, since Termination is defined for ().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But ok, I'll add something like that.

@pietroalbini pietroalbini added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 11, 2018
@@ -105,6 +105,7 @@ pub mod syntax {
pub use ext;
pub use parse;
pub use ast;
pub use tokenstream;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that is not required anymore, as you don't use the quote! anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep

Copy link
Member

Choose a reason for hiding this comment

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

Do you still need to remove this?

@matklad
Copy link
Member

matklad commented Feb 12, 2018

cc @Manishearth and custom test frameworks just in case.

@Manishearth
Copy link
Member

Hmm, this is another example of something that needs compile-time expansion tweaking to work.

// like this:
//
// fn wrapper() {
// assert_eq!(0, real_function().report());
Copy link
Contributor

Choose a reason for hiding this comment

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

sure you mean Termination::assert_unit_test_successful(real_function())?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that comment is dated I guess

@petrochenkov
Copy link
Contributor

Reviewed. Everything looks reasonable, modulo things already mentioned by other people.
There's a bunch of failing tests in libstd though.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 12, 2018
@nikomatsakis
Copy link
Contributor Author

@eddyb so I tried to do what you suggested (see most recent commit) but now I get these errors from libtest:

Building stage0 test artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling term v0.0.0 (file:///home/nmatsakis/versioned/rust-4/src/libterm)
   Compiling getopts v0.2.15
   Compiling test v0.0.0 (file:///home/nmatsakis/versioned/rust-4/src/libtest)
error: use of unstable library feature 'termination_trait' (see issue #43301)
  --> libtest/lib.rs:73:5
   |
73 | use std::Termination;
   |     ^^^^^^^^^^^^^^^^
   |
   = help: add #![feature(termination_trait)] to the crate attributes to enable

error: use of unstable library feature 'termination_trait' (see issue #43301)
   --> libtest/lib.rs:327:30
    |
327 | pub fn assert_test_result<T: Termination>(result: T) {
    |                              ^^^^^^^^^^^
    |
    = help: add #![feature(termination_trait)] to the crate attributes to enable

error: use of unstable library feature 'termination_trait' (see issue #43301)
   --> libtest/lib.rs:328:5
    |
328 |     Termination::assert_unit_test_successful(result)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: add #![feature(termination_trait)] to the crate attributes to enable

This despite the fact that we have the feature gate enabled. I'm not really sure what's going on there...

@nikomatsakis
Copy link
Contributor Author

nikomatsakis commented Feb 21, 2018

OK, so, I'm inclined to revert back to my working version and file a FIXME to extract this logic into libtest. I don't really feel like taking the time to root out this problem, and the amount of logic in question here is quite small.

@eddyb @petrochenkov -- any objection?

Extend `Termination` trait with a method to determine what happens
with a unit test.

This commit incorporates work by Bastian Köcher <git@kchr.de>.
@nikomatsakis nikomatsakis force-pushed the termination_trait_in_tests branch from 0ceff7b to 2029084 Compare February 22, 2018 22:55
@nikomatsakis
Copy link
Contributor Author

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned petrochenkov Feb 22, 2018
Also make `std::termination` module public and rename feature.

The lib feature needs a different name from the language feature.
@nikomatsakis nikomatsakis force-pushed the termination_trait_in_tests branch from 2029084 to 5f1e78f Compare February 22, 2018 22:57
@eddyb
Copy link
Member

eddyb commented Feb 23, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Feb 23, 2018

📌 Commit 0a5f4ae has been approved by eddyb

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 23, 2018
@kennytm
Copy link
Member

kennytm commented Feb 23, 2018

@bors r-

The test compile-fail/issue-12997-2.rs failed.

[01:07:29] ---- [compile-fail] compile-fail/issue-12997-2.rs stdout ----
[01:07:29] 	
[01:07:29] error: /checkout/src/test/compile-fail/issue-12997-2.rs:16: expected message not found: expected type `for<'r> fn(&'r mut __test::test::Bencher)`
[01:07:29] 
[01:07:29] error: /checkout/src/test/compile-fail/issue-12997-2.rs:16: expected message not found: found type `fn(isize) {bar}`
[01:07:29] 
[01:07:29] error: /checkout/src/test/compile-fail/issue-12997-2.rs:16: expected message not found: expected mutable reference, found isize
[01:07:29] 
[01:07:29] error: 0 unexpected errors found, 3 expected errors not found
[01:07:29] status: exit code: 101
[01:07:29] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/compile-fail/issue-12997-2.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/issue-12997-2.stage2-x86_64-unknown-linux-gnu" "-Crpath" "-O" "-Zmiri" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--test" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/issue-12997-2.stage2-x86_64-unknown-linux-gnu.aux" "-A" "unused"
[01:07:29] not found errors (from test file): [
[01:07:29]     Error {
[01:07:29]         line_num: 16,
[01:07:29]         kind: None,
[01:07:29]         msg: "expected type `for<\'r> fn(&\'r mut __test::test::Bencher)`"
[01:07:29]     },
[01:07:29]     Error {
[01:07:29]         line_num: 16,
[01:07:29]         kind: None,
[01:07:29]         msg: "found type `fn(isize) {bar}`"
[01:07:29]     },
[01:07:29]     Error {
[01:07:29]         line_num: 16,
[01:07:29]         kind: None,
[01:07:29]         msg: "expected mutable reference, found isize"
[01:07:29]     }
[01:07:29] ]
[01:07:29] 
[01:07:29] thread '[compile-fail] compile-fail/issue-12997-2.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:1253:13
[01:07:29] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:07:29] 
[01:07:29] 
[01:07:29] failures:
[01:07:29]     [compile-fail] compile-fail/issue-12997-2.rs
[01:07:29] 
[01:07:29] test result: FAILED. 2303 passed; 1 failed; 15 ignored; 0 measured; 0 filtered out
[01:07:29] 
[01:07:29] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:476:22

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 23, 2018
@nikomatsakis
Copy link
Contributor Author

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Feb 23, 2018

📌 Commit 10f7c11 has been approved by eddyb

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 23, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 24, 2018
…ests, r=eddyb

Termination trait in tests

Support the `Termination` trait in unit tests (cc rust-lang#43301)

Also, a drive-by fix for rust-lang#47075.

This is joint work with @bkchr.
bors added a commit that referenced this pull request Feb 24, 2018
Rollup of 15 pull requests

- Successful merges: #47987, #48056, #48061, #48084, #48143, #48185, #48206, #48208, #48232, #48246, #48258, #48317, #48353, #48356, #48402
- Failed merges:
Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 24, 2018
…ests, r=eddyb

Termination trait in tests

Support the `Termination` trait in unit tests (cc rust-lang#43301)

Also, a drive-by fix for rust-lang#47075.

This is joint work with @bkchr.
bors added a commit that referenced this pull request Feb 24, 2018
Rollup of 15 pull requests

- Successful merges: #47987, #48056, #48061, #48084, #48143, #48185, #48206, #48208, #48232, #48246, #48258, #48317, #48353, #48356, #48402
- Failed merges:
@bors bors merged commit 10f7c11 into rust-lang:master Feb 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.