Skip to content

Commit 581957e

Browse files
committed
fix: Let gix_testtools::Env undo multiple changes to the same var
Previously, an `Env` instance would restore the original state on drop if no more than one modification was made to any one variable through it, but would restore an intermediate state if the same variable was ever set multiple times, unset multiple times, or both set and unset in any order. The state it would restore for each variable was its state immediately before the most recent modification (through the `Env` instance) that affected it, rather than its original state before the first time it was modified through that `Env` instance. This fixes that by undoing the changes in the opposite of the order they were made.
1 parent 505151c commit 581957e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tests/tools/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ impl<'a> Env<'a> {
857857

858858
impl<'a> Drop for Env<'a> {
859859
fn drop(&mut self) {
860-
for (var, prev_value) in &self.altered_vars {
860+
for (var, prev_value) in self.altered_vars.iter().rev() {
861861
match prev_value {
862862
Some(value) => std::env::set_var(var, value),
863863
None => std::env::remove_var(var),

0 commit comments

Comments
 (0)