Skip to content

Conversation

@cyqsimon
Copy link
Contributor

@cyqsimon cyqsimon commented Oct 15, 2025

Closes #4529

TODO

  • Tests

@cyqsimon cyqsimon force-pushed the uninstall-no-modify-path branch 2 times, most recently from 0f265d6 to 3ed23ab Compare October 15, 2025 04:36
@cyqsimon
Copy link
Contributor Author

Not really sure how to properly add the tests that check for environment variable configuration. There doesn't seem to be existing infrastructure for testing this sort of thing.

Also I don't really understand how the current tests are avoiding modifying the user's actual rc files. I imagine the provisions for it must be hidden away somewhere in the test harness but I just couldn't find it.

@rami3l rami3l self-assigned this Oct 15, 2025
@cyqsimon cyqsimon force-pushed the uninstall-no-modify-path branch from 3ed23ab to cf960e2 Compare October 15, 2025 09:26
@rami3l
Copy link
Member

rami3l commented Oct 15, 2025

Not really sure how to properly add the tests that check for environment variable configuration. There doesn't seem to be existing infrastructure for testing this sort of thing.

Also I don't really understand how the current tests are avoiding modifying the user's actual rc files. I imagine the provisions for it must be hidden away somewhere in the test harness but I just couldn't find it.

@cyqsimon That's a completely fine question to ask! I think you can find some inspiration from:

#[tokio::test]
async fn uninstall_removes_source_from_rcs() {
let cx = CliTestContext::new(Scenario::Empty).await;
let rcs: Vec<PathBuf> = [
".bashrc",
".bash_profile",
".bash_login",
".profile",
".zshenv",
]
.iter()
.map(|rc| cx.config.homedir.join(rc))
.collect();
for rc in &rcs {
raw::write_file(rc, FAKE_RC).unwrap();
}
cx.config.expect(&INIT_NONE).await.is_ok();
cx.config
.expect(&["rustup", "self", "uninstall", "-y"])
.await
.is_ok();
for rc in &rcs {
let new_rc = fs::read_to_string(rc).unwrap();
assert_eq!(new_rc, FAKE_RC);
}
}

Basically we use CliTestContext to create a sandboxed installation for rustup to operate in TempDir, so copying-pasting and modifying neighboring tests should do the trick for you.

@cyqsimon
Copy link
Contributor Author

Alright I've added the tests.

When I initially went over the existing tests I was fixated on tests/suite/cli_self_upd.rs and found nothing there 😅. But yeah within cli_paths.rs it's largely a copy-paste job.

How would you like me to resolve the conflict with #4536? Merge or rebase?

@djc
Copy link
Contributor

djc commented Oct 20, 2025

Rebase please!

@cyqsimon cyqsimon force-pushed the uninstall-no-modify-path branch 3 times, most recently from c9e7f33 to 3507c85 Compare October 20, 2025 10:06
@cyqsimon
Copy link
Contributor Author

cyqsimon commented Oct 20, 2025

I have having a very difficult time reproducing the CI error locally (or in fact, making sense of it at all). Will keep trying for the time being.

Edit: seems like there's some shenanigans influencing whether rustup-init sets up .zshenv or not, which is different between the CI and my local environment. That's all I can say with any degree of confidence. Zsh is not my daily shell so I'm not that familiar with it.

@rami3l
Copy link
Member

rami3l commented Oct 20, 2025

@cyqsimon Many thanks all the same! I think I can have a look at that... I'll let you know if I've found anything 🙏

@rami3l
Copy link
Member

rami3l commented Oct 21, 2025

@cyqsimon That's quite easy actually: in our Ubuntu CI environment there's no zsh so the ~/.zshenv predicate is never triggered. Maybe just remove that from the test case?

@rami3l rami3l removed their assignment Oct 21, 2025
@cyqsimon
Copy link
Contributor Author

@cyqsimon That's quite easy actually: in our Ubuntu CI environment there's no zsh so the ~/.zshenv predicate is never triggered. Maybe just remove that from the test case?

I see. But shouldn't the fix be to install zsh in the CI, so that the relevant code paths are actually tested?

@rami3l
Copy link
Member

rami3l commented Oct 22, 2025

I see. But shouldn't the fix be to install zsh in the CI, so that the relevant code paths are actually tested?

@cyqsimon I see your point here; however I don't think a typical Linux environment assumes zsh, so this might confuse more users than it should when they are developing rustup on Linux; we want the test suite to have as few surprising external dependencies as possible.

Also I don't think placing a dynamic predicate for both cases is a good choice either, the point being you are almost always testing one specific path in the CI and the opposite path almost never gets tested and could rust over time. This has happened before in this repo's history for a few times, unfortunately...

As a compromise I think you can put a cfg for darwin on that specific array item. Don't put it for linux otherwise you might break CI for other Unices (BSDs, Solaris, ...)!

@cyqsimon
Copy link
Contributor Author

As a compromise I think you can put a cfg for darwin on that specific array item. Don't put it for linux otherwise you might break CI for other Unices (BSDs, Solaris, ...)!

Yep that sounds reasonable. Will do that.

And what about uninstall_removes_source_from_rcs (the test you referenced)? That test is only passing because the lack of an intermediate assert! between init and uninstall.

@cyqsimon cyqsimon force-pushed the uninstall-no-modify-path branch from 3507c85 to 0a310b3 Compare October 22, 2025 03:09
@cyqsimon cyqsimon force-pushed the uninstall-no-modify-path branch from 0a310b3 to 8308a80 Compare October 22, 2025 03:14
@cyqsimon
Copy link
Contributor Author

Rebased to resolve merge conflicts.

@rami3l
Copy link
Member

rami3l commented Oct 22, 2025

And what about uninstall_removes_source_from_rcs (the test you referenced)? That test is only passing because the lack of an intermediate assert! between init and uninstall.

@cyqsimon You can mirror that in a separate commit if you want.

@cyqsimon cyqsimon force-pushed the uninstall-no-modify-path branch from 8308a80 to 4ab8ebf Compare October 23, 2025 02:57
@rami3l rami3l added this pull request to the merge queue Oct 23, 2025
Merged via the queue into rust-lang:main with commit 3dab87e Oct 23, 2025
29 checks passed
@cyqsimon cyqsimon deleted the uninstall-no-modify-path branch October 23, 2025 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--no-modify-path option for rustup self uninstall

3 participants