Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upeRFC: Custom test frameworks #2318
Conversation
Manishearth
force-pushed the
Manishearth:post-build-contexts
branch
from
33262d2
to
8af46d5
Feb 1, 2018
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 |
Manishearth
force-pushed the
Manishearth:post-build-contexts
branch
from
57cfcb4
to
4c51527
Feb 1, 2018
This comment has been minimized.
This comment has been minimized.
|
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. |
Manishearth
added some commits
Jan 25, 2018
Manishearth
force-pushed the
Manishearth:post-build-contexts
branch
from
4c51527
to
55860d5
Feb 1, 2018
Manishearth
added
the
T-dev-tools
label
Feb 1, 2018
This comment has been minimized.
This comment has been minimized.
|
This seems to have missed a bunch of changes made in jonhoo@3f4425e — was that intentional? |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
(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") |
This comment has been minimized.
This comment has been minimized.
|
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, |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
Extracted the changes and rebased in jonhoo@68695a6. I think most of them are things we've talked about in the past. I think |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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) |
This comment has been minimized.
This comment has been minimized.
|
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". |
aturon
added
the
T-cargo
label
Feb 1, 2018
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
CAD97
commented
Apr 25, 2018
|
Just to get one more voice on it: don't leave out documentation tests! (Or at least put some effort into bringing them towards being first-class tests.) One of the trickiest things about measuring coverage or mutagen or whatever testing framework is that often times in libraries, documentation tests can be a major part of test coverage. I, at least, primarily write tests as compiled documentation; this is how a function is used. So it's useful to have that in the documentation, whether it's public documentation or internal. Just to spitball an idea to add to the table: documentation tests are a specialization of integration tests, right? And if I recall correctly from my digging around trying to find binaries to tool for coverage, they work by building integration tests in temporary directories. Maybe rustdoc-test could be a pass that extracts doctests and puts them in e.g. |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Apr 28, 2018
|
The final comment period is now complete. |
Centril
referenced this pull request
Apr 28, 2018
Open
Tracking issue for eRFC 2318, Custom test frameworks #50297
Centril
merged commit c25cfbf
into
rust-lang:master
Apr 28, 2018
This comment has been minimized.
This comment has been minimized.
|
Huzzah! This experimental RFC is now merged! Tracking issue: rust-lang/rust#50297 |
RalfJung
reviewed
May 2, 2018
|
|
||
| ```rust | ||
| [testing.framework] | ||
| kind = "test" # or bench |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Manishearth
May 3, 2018
•
Author
Member
looks like this entire section needs to be updated a bit, we removed a bunch of stuff
RalfJung
reviewed
May 2, 2018
| extern crate proc_macro; | ||
| use proc_macro::{TestFrameworkContext, TokenStream}; | ||
| // attributes() is optional |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Manishearth
May 3, 2018
Author
Member
it can be removed, it refers to an older version of the proposal
memoryruins
referenced this pull request
May 4, 2018
Open
Comments for "https://os.phil-opp.com/unit-testing/" #429
Seeker14491
referenced this pull request
Jun 26, 2018
Closed
Clarify whether binary crates and private functions can be benchmarked #158
This comment has been minimized.
This comment has been minimized.
djrenren
commented
Aug 7, 2018
|
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! |
This comment has been minimized.
This comment has been minimized.
TyOverby
commented
Aug 7, 2018
|
@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 |
This comment has been minimized.
This comment has been minimized.
djrenren
commented
Aug 7, 2018
•
|
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. |
This comment has been minimized.
This comment has been minimized.
TyOverby
commented
Aug 10, 2018
|
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 |
Manishearth
deleted the
Manishearth:post-build-contexts
branch
Aug 10, 2018
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
jan-hudec
commented
Aug 10, 2018
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). |
This comment has been minimized.
This comment has been minimized.
TyOverby
commented
Aug 10, 2018
|
@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:
|
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
djrenren
commented
Aug 10, 2018
|
@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. |
This comment has been minimized.
This comment has been minimized.
CAD97
commented
Aug 10, 2018
|
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. |
bheisler
referenced this pull request
Aug 21, 2018
Closed
Directory name escaping does not take name limits into account #190
tomaka
referenced this pull request
Oct 19, 2018
Open
Tracking issue for #[bench] and benchmarking support #29553
Centril
added
A-test
A-attributes
labels
Nov 23, 2018
This comment has been minimized.
This comment has been minimized.
burdges
commented
Jan 1, 2019
•
|
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. |
Manishearth commentedFeb 1, 2018
•
edited by Centril
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