-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 testing supports tests those need multiple compile commands #1298
Comments
The main thing we need this for is to compile a crate, then run a test that depends on that crate. |
I'm not sure I understand what this bug is about. Can you clarify? |
I updated the description. Please feel free to reword it. |
Thought about this more... How about put tests in a single file that could be preprocessed by test runner. When run the test, the test runner will:
Below are two examples: // Test rustc correctly handle input file with relative path
// and outputs properly named library.
// file: foo.rs
// compile-cmd:--lib ./foo.rs
fn main() { }
// run:ls libfoo-8e702f2a2bfac15b-0.0.so // test re-export works across several crates
// file:foo.rs
// compile-flags:--lib
use std;
mod o {
fn test() { std::io::println("foo::test"); }
}
// file:bar.rs
// compile-flags:--lib
use foo;
import foo::o::test;
export test;
// file:baz.rs
// compile-flags:--lib
use bar;
import tz = bar::test;
export tz;
// file:main.rs
// compile-flags:-L .
use baz;
fn main() {
baz::tz();
}
// run:./main |
There are two issues being solved here: 1 is expressing dependencies between test crates, 2 is running arbitrary commands to test various properties. Let's avoid adding a feature that instructs the test runner to execute arbitrary commands, because it's too open-ended and could make things harder to maintain later. In your example above where you want to test that rustc names the output correctly, I would suggest that the best way to do this would be to write unit tests in rustc itself. That would verify that the functions that are responsible for naming output produce the correct result. It's true that it wouldn't strictly test that the actual file showed up as expected, but you can still get a lot of guarantees out of fine-grained unit tests. Frankly, I'm not crazy about having the test runner create a workspace for every test and split them up like that. Not sure why, but it seems like too many moving parts. For expressing dependencies between crates we could do something like the following:
This replaces our little but growing comment-language with an existing mechanism. I'm still not sure this is a good idea either for a few reasons:
After writing all those negatives I am less fond of this idea. |
I agree with the comment of running arbitrary commands. I prefer testing the functionality as unit tests. Make a temporary work space for each test creates a "namespace" for crate libraries. So we can have lots of libfoo without wasting time finding new name or solving name collisions. A work space can also be created by putting many source files in one folder, then we need to invent another format for specifying the build order. Writing them all down in one file implies the build order. And it's easier to read when all code are in one file, presumably they are all short enough. I actually like the "comment directives", it has limitations but it's also more intuitive and self-contained. The compiler is just a hundred lines of code? Attributes may be well used for unit tests, but I feel comment directive serves better when testing the compiler as a black box. I am thinking this all as one single test. Building a dependent relationship makes things more complex, and maybe unnecessary. |
I really need something like this for CCI. @brson and I discussed it and we were thinking of doing the following, which seems like "the simplest thing that could possibly work":
|
Sorry, that's not quite right: probably the |
Also, //build will probably just take a filename: |
Sorry for the many small comments... one last thought, probably just |
Is this done? We have the aux-build attribute now, and I can't tell whether there's more beyond that that we want to implement. |
I think it's done enough. Going to close (feel free to re-open). |
Introduce CargoProject type and use it where possible
* Also added dockerfiles for AL2, Ubuntu 22.04. Not in CI yet.
For example, I need to test the re-export issue (#1115). Steps are:
This requires executing rustc twice, and we don't have this kind of support in the test framework now.
I believe there are more places where combining rustc and shell commands is needed. Like verifying metadata dumped by "rustc --ls". Check rustc generated filenames.
And add missing tests when the infrastructure is ready.
The text was updated successfully, but these errors were encountered: