-
Notifications
You must be signed in to change notification settings - Fork 413
Config get_xdg() and and get_global() weird state behaviour... #550
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
Comments
I tried by unsetting the env vars, but this makes no difference: #[test]
fn test_get_user_config_type_xdg() {
// set up XDG
let home = assert_fs::TempDir::new().unwrap().into_persistent();
env::set_var("HOME", home.path()); //fake home directory
env::set_var("XDG_CONFIG_HOME", home.child(".config").path()); //fake XDG config directory
std::fs::create_dir_all(home.child(".config/git").path()).unwrap(); // create the actual XDG config dir
std::fs::write(home.child(".config/git/config").path(),"").unwrap(); // touch the xdg config file
let config_type = get_user_config_type();
assert_eq!(config_type.unwrap(), UserGitConfigLevel::XDG);
env::set_var("HOME", ""); //unset home directory
env::set_var("XDG_CONFIG_HOME", ""); //unset XDG config directory
home.close().unwrap()
}
#[test]
fn test_get_user_config_type_global() {
// set up home dir
let home = assert_fs::TempDir::new().unwrap().into_persistent();
env::set_var("HOME", home.path()); //fake home directory
std::fs::write(home.child(".gitconfig").path(),"").unwrap(); // touch the global config file
let config_type = get_user_config_type();
assert_eq!(config_type.unwrap(), UserGitConfigLevel::Global);
env::set_var("HOME", ""); //unset home directory
env::set_var("XDG_CONFIG_HOME", ""); //unset XDG config directory
home.close().unwrap()
} |
Environment variables are inherently global. You can maybe try with |
I already use |
I don't think |
RIght... On slack someone else pointed this out, so I did it... It was an oversight on my part... Here it is now: #[test]
fn test_get_user_config_type_xdg() {
// set up XDG
let home = assert_fs::TempDir::new().unwrap().into_persistent();
env::set_var("HOME", home.path()); //fake home directory
env::set_var("XDG_CONFIG_HOME", home.child(".config").path()); //fake XDG config directory
std::fs::create_dir_all(home.child(".config/git").path()).unwrap(); // create the actual XDG config dir
std::fs::write(home.child(".config/git/config").path(),"").unwrap(); // touch the xdg config file
let config_type = get_user_config_type();
assert_eq!(config_type.unwrap(), UserGitConfigLevel::XDG);
env::remove_var("HOME"); //unset HOME directory
env::remove_var("XDG_CONFIG_HOME"); //unset XDG config directory
home.close().unwrap()
}
#[test]
fn test_get_user_config_type_global() {
// set up home dir
let home = assert_fs::TempDir::new().unwrap().into_persistent();
env::set_var("HOME", home.path()); //fake home directory
std::fs::write(home.child(".gitconfig").path(),"").unwrap(); // touch the global config file
let config_type = get_user_config_type();
assert_eq!(config_type.unwrap(), UserGitConfigLevel::Global);
env::remove_var("HOME"); //unset HOME directory
home.close().unwrap()
} Still no change in behaviour though... This has me properly stumped... :-/ |
Yea, it does look like libgit2 caches the system directories in a global (https://github.com/libgit2/libgit2/blob/918a7d19553a9a4181bf1561b8b828a5f82e60e0/src/sysdir.c#L184-L195). I'm not sure if it will be possible to swap |
Ok, I also heard the caching thing mentioned on libgit2's slack channel. This is just for the test, not the actual code it's testing, but is there some way to perhaps restart, clear, or otherwise reset rust's binding to the underlying lib, to force this cache to reinitialise? |
I suspect the answer is "no". |
So with a bit of reworking I've made my test suite work without the need to change |
Seems reasonable to mention! |
@bradwood At gitui-org/gitui#269, we were having the same issue, and it took us some digging to uncover that |
|
Sorry I'm confused, how is the env var changes related to |
@alexcrichton it clears the caching of the env vars. |
@alexcrichton any opinion? |
Sorry I haven't dug much into this issue. Calling shutdown is likely highly unsafe since it tampers with global state that may be used by other threads. Exposing a method for it seems possible as long as it's unsafe and tested to work. |
Hi all,
I have this function:
And I have these 2 tests:
When I call each test individually, like this, they both succeed:
However, when I run them both in one
cargo test
invocation, I always get one failure:Can anyone explain why this is? There seems to be some state which is persisting when both tests are run in one invocation which seems completely weird and maybe is a bug...
Any thoughts or suggestions to make these tests work together would be much appreciated.
The text was updated successfully, but these errors were encountered: