-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
eRFC: Custom test frameworks #2318
Conversation
33262d2
to
8af46d5
Compare
Had a talk with @eddyb who was concerned with compiler impact, and suggested a cleaner form of the alternate proposal that minimizes the impact on the compiler to almost nothing. Basically, the harness becomes a completely normal proc macro attribute crate, and everything else is provided by the utility crate. Cargo continues to orchestrate it all. Added it to the alternates section. Thoughts? |
@Manishearth How does that fit with default folders and default sets? That section feels a bit underspecified atm - not sure I fully understand what it entails. |
Currently default folders and sets are left unresolved, and the idea was that if we wanted to implement those they would be done in the context's Cargo.toml. I'll expand that into a section of the RFC |
For future reference, the original idea I had with default folders & sets were that you specify them as: #[post_build_context(
test, attributes(foo, bar),
default_folders("src", "test"),
default_sets("test"))]
pub fn like_todays_test(items: &[AnnotatedItem]) -> TokenStream {
// ...
} But doing it via |
57cfcb4
to
4c51527
Compare
To avoid confusion, I uplifted all the ideas from "other questions" and put them under "unresolved questions" as proper sections, some of which have partial solutions. |
4c51527
to
55860d5
Compare
This seems to have missed a bunch of changes made in jonhoo@3f4425e — was that intentional? |
I wasn't aware of those patches. If you had pushed them to my branch, sorry, I'd forgotten that I'd asked you to do that :) It seems like the main missing thing is renaming it from post-build to build-context? I find that build-context would be confusing with custom profiles (which is the feature that comes to mind when you say "build profile"). We should add it in the list of alternative names. I don't think we should bikeshed this much now; seems like a question for the final non-experimental RFC. All the other changes seem to be addressed in some form here. If not, let me know. |
(I'm aware I said "this is better" for the term "build contexts", but that was relative to "execution contexts". I already mentioned in the thread why I didn't like "build contexts") |
Let me factor out the parts of that change related to the post-build context renaming. Many of the changes are about clarifying the proposed syntax and the examples, but others are somewhat larger. For example, some of the things we talked about regarding folders, |
I fixed folders and single-target. I kept the folders key named "folder" because that's the common case but it takes with a string and array value. There's also single-target somewhere here under a similar name. Clarifying syntax would be nice. |
Extracted the changes and rebased in jonhoo@68695a6. I think most of them are things we've talked about in the past. I think |
I still find the description "post-build" wildly confusing, but maybe that's just me. I agree that bikeshedding on the name here is not a good use of time. |
Merged in and pushed, thanks (plus some fixups). Yeah, I'm not very strongly on either side of "folder" vs "folders" so that works. Moving I'm not really fond of either |
I think we should be wary of referring to this as being about tests, because it causes us to use a pretty limited mental model of going on. To me, what all of this is proposing is a way for a crate to opt in to a build process defined by another crate. But it also isn't quite a full-blown build process, because it's only "transforming some special items" and "produce a binary this way". This is why "execution context" seemed right for me, and Perhaps a better description is "execution harness"? And then |
Yeah. I like having the term "harness" in there. I still am wary of the "produce a binary this way" thing because from a user's perspective that's an implementation detail (and the binary targets are different so it doesn't map cleanly) |
To me "produce a binary" == "produce a EDIT: or maybe a better way to say it is "tests are just a different way of executing your code". |
cc @rust-lang/cargo |
|
||
```rust | ||
[testing.framework] | ||
kind = "test" # or bench |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The meaning of this flag is not explained anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this entire section needs to be updated a bit, we removed a bunch of stuff
extern crate proc_macro; | ||
use proc_macro::{TestFrameworkContext, TokenStream}; | ||
|
||
// attributes() is optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is entirely unclear what this comment refers to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can be removed, it refers to an older version of the proposal
Hey all, I've come up with a simplified proposal and I have an implementation now (though it needs a little cleaning up before a PR). https://blog.jrenner.net/rust/testing/2018/08/06/custom-test-framework-prop.html Lemme know what you think! |
@djrenren: This looks really great! One question that I have after a quick scan is
You have this in your example repo
but I'm interested in what happens if someone puts a regular |
So I just tested it out on my implementation compiling this:
and got:
Which is an admittedly not very great error message. (though it's also not terrible). I'm definitely open to suggestions here. |
I'd really like to see a way for testsuite authors to write a test suite that provides special support for their custom test suites, but can also run less specific tests. Here's a few test-runners that I've wanted in the past:
The 1st of these would need to interact with all kinds of tests (including |
This is definitely supported, the proposal provides no constraints on output formats (though it suggests we come up with a crate for a standardized format you can choose to use)
Redirecting output from within the same program is tricky, but you can have your test functions return a string and have your test runner recognize it. |
Looks great. Would it be hard to extract the macro that collects array of annotated items as a separate base feature? I can imagine it could have other uses, perhaps in a dependency-injection framework or some resource collection (it is hard to do as proc macro, because it interferes with incremental compilation). |
@Manishearth the current I think that the point that I'm trying to make is that there are three concepts that people care about configuring:
|
So this proposal gives you control over all those, however a single test framework will make all the choices here -- it doesn't give you a way to mix and match output formats and runners. That said, one of the hopes is to standardize a test runner output crate that has multiple output formats (stdout, json, perhaps html). Most test frameworks can just use this and expose the same options, and the json side can be plugged into everything else.
ah, looks like |
@jan-hudec Yeah such a thing would be possible, but it's also probably not a great thing to rely on. I believe it would have negative effects on incremental compilation, as well as violate the structure of the language. All told it's a scary enough change to not be included as part of this work, but by all mean throw up an RFC. It's definitely possible. |
Just to have it said in this thread as well, Stdout/stderr capture is kind of messy. The current framework for tests a) only works on one thread and b) only works with If you go check the tracking issue I went into more depth there. |
An interesting trick for custom testing frameworks might be access to "paths not taken" in specialization, probably by exploiting some delegation tooling. It'd be cool to have a convenient way to test performance oriented specializations using the general one. |
See also: the internals discussion at https://internals.rust-lang.org/t/past-present-and-future-for-rust-testing/6354/103
cc @rust-lang/dev-tools @jonhoo
Rendered
Tracking issue