@@ -1785,23 +1785,8 @@ mod tests {
17851785 }
17861786 }
17871787
1788- struct EnvVarGuard ;
1789-
1790- // prevents race conditions on the env variable PIXI_OVERRIDE_PLATFORM
1791- static ENV_VAR_MUTEX : std:: sync:: Mutex < ( ) > = std:: sync:: Mutex :: new ( ( ) ) ;
1792-
1793- impl Drop for EnvVarGuard {
1794- fn drop ( & mut self ) {
1795- unsafe {
1796- std:: env:: remove_var ( consts:: PIXI_OVERRIDE_PLATFORM ) ;
1797- }
1798- }
1799- }
1800-
18011788 #[ test]
18021789 fn test_best_declared_platform_override_env_var ( ) {
1803- let _lock = ENV_VAR_MUTEX . lock ( ) . unwrap ( ) ;
1804-
18051790 let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
18061791 let contents = r#"
18071792 [project]
@@ -1810,30 +1795,30 @@ mod tests {
18101795 platforms = []
18111796 "# ;
18121797 let workspace = Workspace :: from_str ( & temp_dir. path ( ) . join ( "pixi.toml" ) , contents) . unwrap ( ) ;
1813- unsafe {
1814- std:: env:: set_var ( consts:: PIXI_OVERRIDE_PLATFORM , "linux-aarch64" ) ;
1815- }
1816- let _guard = EnvVarGuard ;
18171798
1818- let env = workspace. default_environment ( ) ;
1819- // No declared platforms → None even with a valid override.
1820- assert ! ( env. best_declared_platform( ) . is_none( ) ) ;
1821- // The host_platform helper honours the override.
1822- assert_eq ! (
1823- workspace
1824- . host_platform(
1825- PlatformSource :: Defaults ,
1826- PlatformOverrides :: EnvironmentVariableOverrides
1827- )
1828- . subdir( ) ,
1829- Platform :: LinuxAarch64 ,
1799+ temp_env:: with_var (
1800+ consts:: PIXI_OVERRIDE_PLATFORM ,
1801+ Some ( "linux-aarch64" ) ,
1802+ || {
1803+ let env = workspace. default_environment ( ) ;
1804+ // No declared platforms → None even with a valid override.
1805+ assert ! ( env. best_declared_platform( ) . is_none( ) ) ;
1806+ // The host_platform helper honours the override.
1807+ assert_eq ! (
1808+ workspace
1809+ . host_platform(
1810+ PlatformSource :: Defaults ,
1811+ PlatformOverrides :: EnvironmentVariableOverrides
1812+ )
1813+ . subdir( ) ,
1814+ Platform :: LinuxAarch64 ,
1815+ ) ;
1816+ } ,
18301817 ) ;
18311818 }
18321819
18331820 #[ test]
18341821 fn test_best_declared_platform_override_invalid_value ( ) {
1835- let _lock = ENV_VAR_MUTEX . lock ( ) . unwrap ( ) ;
1836-
18371822 let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
18381823 let contents = r#"
18391824 [project]
@@ -1842,23 +1827,26 @@ mod tests {
18421827 platforms = []
18431828 "# ;
18441829 let workspace = Workspace :: from_str ( & temp_dir. path ( ) . join ( "pixi.toml" ) , contents) . unwrap ( ) ;
1845- unsafe {
1846- std:: env:: set_var ( consts:: PIXI_OVERRIDE_PLATFORM , "not-a-platform" ) ;
1847- }
1848- let _guard = EnvVarGuard ;
18491830
1850- let env = workspace. default_environment ( ) ;
1851- // No declared platforms → None regardless of the (invalid) override.
1852- assert ! ( env. best_declared_platform( ) . is_none( ) ) ;
1853- // The host_platform helper still falls back to Platform::current() on invalid values.
1854- assert_eq ! (
1855- workspace
1856- . host_platform(
1857- PlatformSource :: Defaults ,
1858- PlatformOverrides :: EnvironmentVariableOverrides
1859- )
1860- . subdir( ) ,
1861- Platform :: current( ) ,
1831+ temp_env:: with_var (
1832+ consts:: PIXI_OVERRIDE_PLATFORM ,
1833+ Some ( "not-a-platform" ) ,
1834+ || {
1835+ let env = workspace. default_environment ( ) ;
1836+ // No declared platforms → None regardless of the (invalid) override.
1837+ assert ! ( env. best_declared_platform( ) . is_none( ) ) ;
1838+ // The host_platform helper still falls back to Platform::current()
1839+ // on invalid values.
1840+ assert_eq ! (
1841+ workspace
1842+ . host_platform(
1843+ PlatformSource :: Defaults ,
1844+ PlatformOverrides :: EnvironmentVariableOverrides
1845+ )
1846+ . subdir( ) ,
1847+ Platform :: current( ) ,
1848+ ) ;
1849+ } ,
18621850 ) ;
18631851 }
18641852}
0 commit comments