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

./x.py test should be able to run individual tests #49729

Merged
merged 2 commits into from
May 10, 2018

Conversation

collin5
Copy link
Contributor

@collin5 collin5 commented Apr 6, 2018

Allows user to be able to run individual tests by specifying filename i.e ./x.py test src/test/run-pass/foo.rs

Fixes #48483

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2018
@alexcrichton
Copy link
Member

Thanks for the PR! I've long wanted to do this!

I think though this may be best done in rustbuild itself because we can't always just chop off one filename, but instead may have to chop off a few to get to the name of the test suite. (which the python script doens't know about but rustbuild does)

@collin5
Copy link
Contributor Author

collin5 commented Apr 6, 2018

Going to try doing this. Thank you 👍

@collin5 collin5 force-pushed the b48483 branch 2 times, most recently from f565e32 to db57d81 Compare April 13, 2018 09:04
@collin5
Copy link
Contributor Author

collin5 commented Apr 13, 2018

Hi @alexcrichton, I've made the requested changes. PR should now be ready for another review. Thank you.

@alexcrichton
Copy link
Member

Thanks! Looks reasonable to me, but to double check...

r? @Mark-Simulacrum

// Get test-args by striping suite path
let mut test_args: Vec<&str> = vec![];
paths.iter().filter(|p| p.starts_with(path) && p.is_file())
.for_each(|p| test_args.push(&p.strip_prefix(path).unwrap().to_str().unwrap()));
Copy link
Member

Choose a reason for hiding this comment

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

This should be possible the rewrite as a collect.

@@ -70,6 +70,8 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
/// Run this rule for all hosts without cross compiling.
const ONLY_HOSTS: bool = false;

const PATH: &'static str = "not set";
Copy link
Member

Choose a reason for hiding this comment

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

I would rather not add this here as it feels like the wrong place to put it, could you try instead having it returned as part of ShouldRun? I think that should be relatively minimally impactful on the code, just moving a few things around. Calling should_run multiple times is fine. I'd also appreciate renaming it to suite_path and making it an Option.

Please also verify that a mix of specific tests and crates works: ./x.py test src/test/run-pass/foo.rs src/bootstrap should test both the specific test and bootstrap. I think the current code might not quite do this, but I'm not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I'm on it

@collin5 collin5 force-pushed the b48483 branch 2 times, most recently from ff88d09 to 312e32f Compare April 15, 2018 08:59
@rust-highfive
Copy link
Collaborator

Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
Resolving deltas: 100% (615027/615027), completed with 4886 local objects.
---
[00:00:51] configure: rust.quiet-tests     := True
---
[00:05:49] tidy error: /checkout/src/bootstrap/test.rs:927: line longer than 100 chars
[00:05:51] some tidy checks failed
[00:05:51]
[00:05:51]
[00:05:51] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:05:51] expected success, got: exit code: 1
[00:05:51]
[00:05:51]
[00:05:51] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:05:51] Build completed unsuccessfully in 0:02:27
[00:05:51] Makefile:79: recipe for target 'tidy' failed
[00:05:51] make: *** [tidy] Error 1
---
$ ls -lat $HOME/Library/Logs/DiagnosticReports/
ls: cannot access /home/travis/Library/Logs/DiagnosticReports/: No such file or directory
travis_time:end:0bfa28ef:start=1523783239475498643,finish=1523783239482607040,duration=7108397
travis_fold:end:after_failure.2
travis_fold:start:after_failure.3
travis_time:start:0a59e890
$ find $HOME/Library/Logs/DiagnosticReports -type f -name '*.crash' -not -name '*.stage2-*.crash' -not -name 'com.apple.CoreSimulator.CoreSimulatorService-*.crash' -exec printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" {} \; -exec head -750 {} \; -exec echo travis_fold":"end:crashlog \; || true
find: `/home/travis/Library/Logs/DiagnosticReports': No such file or directory
travis_time:end:0a59e890:start=1523783239488911685,finish=1523783239496142286,duration=7230601
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0339a260
$ dmesg | grep -i kill
[   10.599429] init: failsafe main process (1094) killed by TERM signal

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@collin5
Copy link
Contributor Author

collin5 commented Apr 15, 2018

@Mark-Simulacrum Thanks! I've worked on the feedback. Also mix of specific tests and crates i.e /x.py test src/test/run-pass/foo.rs src/bootstrap should now work just fine 👍

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

I think a few more comments, but this is looking better! Thanks for working through this.

for p in paths {
if p.starts_with(&suite) {
suites.push(PathBuf::from(suite));
break
Copy link
Member

Choose a reason for hiding this comment

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

This feels wrong to me; if ./x.py test src/test/run-pass src/test/compile-fail is invoked I'd expect the break to exit too early for us to populate suites for both tests.

It'd would also somewhat surprise me if this will work as-is when given a path to say src/libstd since those are all set as individual paths inside the pathset, whereas the "suite" detection only matches the last path given. It might be best to restructure to have suite-matching be separate and orthogonal to the path-matching to avoid that problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, Could you please clarify on this if you don't mind.

Copy link
Member

Choose a reason for hiding this comment

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

Basically, the way this code handles suites conflates them with the paths that could invoke a given Step. I think that's the wrong distinction to have as it adds little benefit and increases maintenance burden by connecting two concepts that are mostly unrelated. Instead, I would rather see these modifications contained to changes in maybe_run and the code that calls it. Essentially, I'd expect another case added that calls should_run.is_suite_path(path) or something like and then maybe_run can be called with a PathSet::Suite (making PathSet an enum). Does that help clarify? I can maybe explain in further detail.

Sorry for the somewhat moving target here!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's alright. I now get it. Thanks! Will let you know if I get any more questions.


// Get test-args by striping suite path
let mut test_args: Vec<&str> = paths.iter().filter(|p| p.starts_with(suite_path) &&
p.is_file()).map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap()).collect();
Copy link
Member

Choose a reason for hiding this comment

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

We should probably error out here if the argument is going to be silently ignored because it's part of our suite yet not a file (and as such we don't know what to do with it).

let mut test_args: Vec<&str> = paths.iter().filter(|p| p.starts_with(suite_path) &&
p.is_file()).map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap()).collect();

if test_args.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

Any additional test args passed the command line should rather be appended to the existing set of paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! going to fix this ASAP

@bors
Copy link
Contributor

bors commented Apr 18, 2018

☔ The latest upstream changes (presumably #49972) made this pull request unmergeable. Please resolve the merge conflicts.

@pietroalbini pietroalbini 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 Apr 23, 2018
@collin5
Copy link
Contributor Author

collin5 commented Apr 24, 2018

Hi @Mark-Simulacrum, sorry for the delay on this, I've been kind of busy lately. You can now take another look. Thanks

self.set.iter().any(|p| p.ends_with(needle))
match self {
PathSet::Set(set) => set.iter().any(|p| p.ends_with(needle)),
_ => false
Copy link
Member

Choose a reason for hiding this comment

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

Please be explicit about which variant's are false here.

self.set.iter().next().unwrap_or(&builder.build.src).to_path_buf()
match self {
PathSet::Set(set) => set.iter().next().unwrap_or(&builder.build.src).to_path_buf(),
_ => PathBuf::from("")
Copy link
Member

Choose a reason for hiding this comment

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

Let's instead return an Option from path or panic if we don't expect it to be called on suites.

if let Some(suite) = should_run.is_suite_path(path) {
attempted_run = true;
desc.maybe_run(builder, suite);
}
if let Some(pathset) = should_run.pathset_for_path(path) {
Copy link
Member

Choose a reason for hiding this comment

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

Just for sanity's sake, let's make this an else perhaps? I think it'll make it easier to reason about when steps are run.

@@ -672,12 +674,13 @@ macro_rules! test_definitions {
});
}

fn run(self, builder: &Builder) {
fn run(self,builder: &Builder) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: space required


// Get test-args by striping suite path
let is_file = |p: &PathBuf| {
assert!(p.is_file(), "{:?} is not a valid file", p);
Copy link
Member

Choose a reason for hiding this comment

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

Let's change the message here to be Expected {:?} to be a path to a test file to be clearer about the reason for this error.

};

// Get test-args by striping suite path
let is_file = |p: &PathBuf| {
Copy link
Member

Choose a reason for hiding this comment

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

Please change this to assert_file to be clearer.

@@ -7,7 +7,6 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

Copy link
Member

Choose a reason for hiding this comment

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

nit: This line should stay.

@collin5
Copy link
Contributor Author

collin5 commented Apr 27, 2018

Thanks! Fixed.

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 1, 2018
@shepmaster
Copy link
Member

Ping from triage, @Mark-Simulacrum — looks like it's ready again!

@Mark-Simulacrum
Copy link
Member

Thank you for taking this on! Let me know if you'd like another project in rustbuild to work on (there's a few cleanups that should be relatively straightforward, if you're interested); we can also put you in touch with other rust teams/working groups if you'd like to try something different.

@bors r+

@bors
Copy link
Contributor

bors commented May 7, 2018

📌 Commit 281f534 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 7, 2018
@rust-highfive
Copy link
Collaborator

The job asmjs of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:04:01] DirectMap2M:     3074048 kB
[00:04:01] DirectMap1G:    14680064 kB
[00:04:02] + python2.7 ../x.py test --target asmjs-unknown-emscripten src/test/run-pass src/test/run-fail src/libstd src/liballoc src/libcore
[00:04:02]     Finished dev [unoptimized] target(s) in 0.0 secs
[00:04:03] thread 'main' panicked at 'Expected "src/test/run-pass" to be a path to a test file', bootstrap/test.rs:1015:13
[00:04:03] travis_fold:end:log-system-info
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test --target asmjs-unknown-emscripten src/test/run-pass src/test/run-fail src/libstd src/liballoc src/libcore
[00:04:03] Build completed unsuccessfully in 0:00:01
travis_time:end:0f7434aa:start=1525727844324493913,finish=1525728087973454601,duration=243648960688

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)


// Get test-args by striping suite path
let assert_file = |p: &PathBuf| {
assert!(p.is_file(), "Expected {:?} to be a path to a test file", p);
Copy link
Contributor Author

@collin5 collin5 May 7, 2018

Choose a reason for hiding this comment

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

Hi @Mark-Simulacrum Sorry, I missed this. Looks like this panics with ./x.py test suite_path I think we should just ignore test args if suite path is specified.

@kennytm kennytm added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 8, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.

[00:05:37] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:05:38] tidy error: /checkout/src/bootstrap/test.rs:1015: line longer than 100 chars
[00:05:39] some tidy checks failed
[00:05:39] 
[00:05:39] 
[00:05:39] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:05:39] 
[00:05:39] 
[00:05:39] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:05:39] Build completed unsuccessfully in 0:02:28
[00:05:39] Build completed unsuccessfully in 0:02:28
[00:05:39] make: *** [tidy] Error 1
[00:05:39] Makefile:79: recipe for target 'tidy' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:08b2d318
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented May 8, 2018

📌 Commit bd8f2a0 has been approved by Mark-Simulacrum

@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. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 8, 2018
@collin5
Copy link
Contributor Author

collin5 commented May 9, 2018

Fixed! r? @Mark-Simulacrum
cc @kennytm

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 9, 2018
@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented May 9, 2018

📌 Commit 2f8c2a9 has been approved by Mark-Simulacrum

@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-review Status: Awaiting review from the assignee but also interested parties. labels May 9, 2018
@bors
Copy link
Contributor

bors commented May 10, 2018

⌛ Testing commit 2f8c2a9 with merge 95d0b9e...

bors added a commit that referenced this pull request May 10, 2018
./x.py test should be able to run individual tests

Allows user to be able to run individual tests by specifying filename i.e `./x.py test src/test/run-pass/foo.rs`

Fixes #48483
@bors
Copy link
Contributor

bors commented May 10, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: Mark-Simulacrum
Pushing 95d0b9e to master...

@bors bors merged commit 2f8c2a9 into rust-lang:master May 10, 2018
@collin5 collin5 deleted the b48483 branch May 12, 2018 02:29
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.

None yet

8 participants