-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add compile-fail and compile-pass tests #17
Conversation
Thanks for digging into this @LukasKalbertodt and awesome job putting it all together. I'm pretty excited to see some more effort to rethink compile-fail tests, like you said they're a bit rough around the edges with
This seems totally fine to me. As far as I know this is the sort of case that
Absolutely! I think working on the script using
Absolutely! So I have no problem merging this in and we can work on inspecting the error messages in a follow-up. As a random aside, I've found matching error strings in output is pretty brittle and discourages (at least discourages me) from tuning error messages. What do you think about adding our own simple error codes to diagnostic messages that we can use to assert the presence of in compile tests? |
@LukasKalbertodt would you like to work more in this PR or are you happy for me to drop the |
That sounds like a good idea. I'm also not sure what to think of error message checks. I can see their benefits, but yeah, they make changing the error message difficult. I'm still puzzled how the Rust compiler switched to the new error format (one or two years ago? Can't quite remember). Some poor soul probably had to fix all ui tests ...
I'd just like to polish it before merging. In particular, my crate I'm using should be on crates.io and |
@KodrAus I pushed two commits. If you want to take a look again, go ahead and just merge it if it looks good to you. If you don't have time, that's no problem -- I will just merge it in the next couple of days (since you already said OK and the additional changes are small). |
We don't need these files, but apparently one cannot tell rustc not to emit any files. So we just place them there and ignore them.
@KodrAus I decided to include more changes in this PR. First I thought that I would make all compile-pass tests (formerly in So instead I decided to create a I hope you agree with those changes! If yes, you can merge, this is ready. |
Removing the `script` value completely makes Travis execute a default script for the language.
This is a great improvement! Thanks @LukasKalbertodt |
Hi @KodrAus,
I'd like to hear your opinion about this change :). See "questions" at the end.
Sorry for the long text, but it's necessary ...
... Story time!
(don't worry, there is a summary at the end)
So in order to tackle #15, I thought about having compile-fail tests. There is the crate
compiletest-rs
which is basically the extracted test utility fromrustc
which also offers compile-fail tests. However, I decided not to use that for several reasons. The code of said crate is really old and messy, since it lived in therustc
repo for quite some time already. The API is really not nice. Additionally, it offers far more than compile-fail tests ... which we don't need. Many crates do use that crate to do compile-fail tests, but I don't think that's the way to go.So I started writing my own little script (it works by adding a
harness = false
test). While writing that, I noticed that I tried to make the script look and behave like the default test harness (with the familiar testing output). This seemed like something that can be extracted into a crate to avoid everyone writing the same code over and over again. That's why I wrotelibtest-mimic
which help to mimic the output and behavior of the standard libtest. I have to say that I'm pretty happy how it turned out.My crate is not yet on crates.io and is not considered stable yet! That's why this PR is still marked as WIP.
One problem occurred while writing the compile-fail script. To compile all tests I have to call
rustc
. But I also need to pass a proper--extern auto_impl=path-to-auto-impl-artifact
flag. The path is something like/target/debug/deps/libauto_impl-9ba2e80e05cf7099.so
... so not something one could guess. So this is tricky. There are several possibilities:cargo build
. Apart from the fact that writing stuff to disk during testing is a bit ugly,cargo
has a bunch of output we don't really want.--extern
path on your own, but that's hard if not impossible.cargo
. Either by executingcargo build -v
and parsing that output OR, much better, by using Cargo's build-plans. Turns out, Cargo has a--build-plan
flag which prints the plan of tasks to do in JSON format instead of doing something. This output contains the path we need.I decided to go with the last possibility. But it has a disadvantage: build-plans are still unstable (tracking issue). This means that these compile-fail tests can only be executed on nightly! This might not yet be a problem, since the whole crate requires nightly, but it might be annoying in the future. Also: changes to the build plan could of course break the tests.
Through the build-plans tracking issue I found the
build-plan
crate which parses the build plan for me. That made it possible to remove a bunch of ugly JSON code.Last part of my story: the
build-plan
crate is written by Jonas Schievink, someone who studies at the same university as I do and closely worked with me for my German "Programmieren in Rust" lecture. So that's always fun. While looking through his crates, I foundcompile-fail
-- a crate that is an alternative tocompiletest-rs
!I think it would be awesome to have a proper
compile-fail
test crate so that everyone (likeauto_impl
) can just use it. Sadly Jonas' crate is still WIP and... I disagree with a few decisions. But I'm talking to him right nowish and we'll see if we can polish that crate. Then I could use it here inauto_impl
. I would also try to use mylibtest-mimic
crate incompile-fail
.Summary
This PR ...
cargo test
now looks like this:Questions
[[test]]
withharness = false
) is good?If you think this is basically good to merge, I'd polish the
libtest-mimic
crate, publish it to crates.io and adjust this PR.Well... this took longer than expected :P Writing this
compile-fail
script really lead me deep into the rabbit hole. Anyway: I think starting with good tests is really important for this crate.Again, thank you for your time thinking about my questions! And maybe even reviewing the code changes, if you have that time.