-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make run-pass/env-home-dir.rs test more robust #47718
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
src/test/run-pass/env-home-dir.rs
Outdated
@@ -18,16 +18,18 @@ use std::path::PathBuf; | |||
|
|||
#[cfg(unix)] | |||
fn main() { | |||
let oldhome = var("HOME"); | |||
let oldhome = var("HOME").unwrap_or("/home".into()); | |||
let newhome = format!("{}/new", oldhome); |
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.
Why did you change to now construct a relative path instead of some random string?
It seems like before we never even looked at the value we got back, is that right?
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.
I could have only changed the line that assume the home_dir returns Some, that is
- assert!(home_dir().is_some());
+ assert_ne!(home_dir(), Some(PathBuf::from("/home/MountainView")));
but that could fail if getpwuid_r
returns "/home/MountainView"
(or other chosen string). Setting newhome
to a relative path avoids this situation.
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.
You're saying that could fail if set_var
had no effect, but it just happens that the directory name is /home/MountainView
? I suppose that's true. It just seems a bit weird for the windows test (below) to be asymmetric.
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.
I think I don't quite understand what is being fixed here =)
We're still asserting that home_dir
returns Some
-- how was the test failing before?
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.
(Anyway, the patch seems fine, just trying to understand. =)
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.
You're saying that could fail if set_var had no effect, but it just happens that the directory name is /home/MountainView? I suppose that's true. It just seems a bit weird for the windows test (below) to be asymmetric.
I changed the unix case because that's was failing for me, but in the end, I just need that the test does not assume home_dir
return Some
.
We're still asserting that home_dir returns Some -- how was the test failing before?
The test was failing because home_dir
was returning None
. Now we are using assert_ne!
, so it pass if home_dir
returns None
.
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.
Ah, I missed the assert_ne
thing somehow. Can you add a comment on top saying something like:
/// When HOME is not set, some platforms return `None`, but others return `Some` with a default.
/// Just check that it is not the `newhome_path`.
Also, I think it'd be best if the unix + windows tests match up -- I'm ok with either your new version or the old one, but I guess it's easier to just revert those commits.
Remove the assumption that home_dir always returns Some This allows the test to be executed with [cross](https://github.com/japaric/cross).
15abe46
to
898fdcc
Compare
Updated. |
@bors r+ -- thanks! |
📌 Commit adeb0ae has been approved by |
@bors rollup |
Make run-pass/env-home-dir.rs test more robust Remove the assumption that home_dir always returns Some. This allows the test to be executed with [cross](https://github.com/japaric/cross).
Make run-pass/env-home-dir.rs test more robust Remove the assumption that home_dir always returns Some. This allows the test to be executed with [cross](https://github.com/japaric/cross).
Remove the assumption that home_dir always returns Some.
This allows the test to be executed with cross.