From 76de340e790171c16193f3a19ce33410e495c319 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 15 Mar 2017 12:04:28 -0700 Subject: [PATCH] corrected use of PSModulePath casing to be consistent with Windows PowerShell (#3255) * corrected use of PSModulePath casing to be consistent with Windows PowerShell addresses #3227 * addressing review feedback make "PSModulePath" into const fixed some test workarounds due to failures for external reasons that wasn't meant to be checked in * addressing review feedback make "PSModulePath" into const fixed some test workarounds due to failures for external reasons that wasn't meant to be checked in --- assets/powershell.1.ronn | 2 +- build.psm1 | 6 +++--- demos/Azure/Azure-Demo.ps1 | 2 +- docs/cmdlet-example/README.md | 2 +- .../Activities/WorkflowJobConverter.cs | 2 +- .../engine/Modules/ModuleIntrinsics.cs | 21 ++++++++++++------- .../engine/PropertyAccessor.cs | 6 +++--- test/powershell/Host/Base-Directory.Tests.ps1 | 20 +++++++++--------- .../Scripting.Classes.Modules.Tests.ps1 | 14 ++++++------- .../scripting.Classes.NestedModules.tests.ps1 | 8 +++---- .../Classes/scripting.Classes.using.tests.ps1 | 18 ++++++++-------- .../Debugging/DebuggerScriptTests.Tests.ps1 | 6 +++--- .../Pester.Commands.Cmdlets.Archive.Tests.ps1 | 6 +++--- .../CmsMessage.Tests.ps1 | 6 +++--- .../MOF-Compilation.Tests.ps1 | 6 +++--- .../engine/Basic/CommandDiscovery.Tests.ps1 | 6 +++--- .../engine/Module/ModulePath.Tests.ps1 | 16 +++++++------- test/tools/OpenCover/OpenCover.psm1 | 10 ++++----- 18 files changed, 81 insertions(+), 76 deletions(-) diff --git a/assets/powershell.1.ronn b/assets/powershell.1.ronn index 4f9f87d206..cb4b70432b 100644 --- a/assets/powershell.1.ronn +++ b/assets/powershell.1.ronn @@ -90,7 +90,7 @@ PowerShell accepts both `-` and `--` prefixed arguments. These are environment variables used by PowerShell. -* `$PSMODULEPATH`: +* `$PSModulePath`: A colon (`:`) separated load path for PowerShell modules. ## AUTOMATIC VARIABLES diff --git a/build.psm1 b/build.psm1 index 6145a52d35..37ffe0137e 100644 --- a/build.psm1 +++ b/build.psm1 @@ -771,7 +771,7 @@ function Start-PSPester { } else { try { - $originalModulePath = $env:PSMODULEPATH + $originalModulePath = $env:PSModulePath if ($Unelevate) { Start-UnelevatedProcess -process $powershell -arguments @('-noprofile', '-c', $Command) @@ -801,7 +801,7 @@ function Start-PSPester { & $powershell -noprofile -c $Command } } finally { - $env:PSMODULEPATH = $originalModulePath + $env:PSModulePath = $originalModulePath if ($Unelevate) { Remove-Item $outputBufferFilePath @@ -1784,7 +1784,7 @@ function Start-DevPowerShell { if (-not $Command) { $ArgumentList = @('-NoExit') + $ArgumentList } - $Command = '$env:PSMODULEPATH = Join-Path $env:DEVPATH Modules; ' + $Command + $Command = '$env:PSModulePath = Join-Path $env:DEVPATH Modules; ' + $Command } if ($Command) { diff --git a/demos/Azure/Azure-Demo.ps1 b/demos/Azure/Azure-Demo.ps1 index e08371d109..a7245e1e54 100644 --- a/demos/Azure/Azure-Demo.ps1 +++ b/demos/Azure/Azure-Demo.ps1 @@ -10,7 +10,7 @@ ### ### Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2 -ProviderName NuGet -ExcludeVersion -Destination ### -### Ensure $env:PSMODULEPATH is updated with the location you used to install. +### Ensure $env:PSModulePath is updated with the location you used to install. Import-Module AzureRM.NetCore.Preview ### Supply your Azure Credentials diff --git a/docs/cmdlet-example/README.md b/docs/cmdlet-example/README.md index 16a9688f79..5648e384dc 100644 --- a/docs/cmdlet-example/README.md +++ b/docs/cmdlet-example/README.md @@ -110,7 +110,7 @@ This build/restore process should work anywhere .NET Core works, including Windo Deployment ---------- -In PowerShell, check `$env:PSMODULEPATH` and install the new cmdlet in its own +In PowerShell, check `$env:PSModulePath` and install the new cmdlet in its own module folder, such as, on Linux, `~/.powershell/Modules/SendGreeting/SendGreeting.dll`. diff --git a/src/Microsoft.PowerShell.Activities/Activities/WorkflowJobConverter.cs b/src/Microsoft.PowerShell.Activities/Activities/WorkflowJobConverter.cs index fc02a62f7a..72b81219da 100644 --- a/src/Microsoft.PowerShell.Activities/Activities/WorkflowJobConverter.cs +++ b/src/Microsoft.PowerShell.Activities/Activities/WorkflowJobConverter.cs @@ -3933,7 +3933,7 @@ namespace Microsoft.PowerShell.Workflow } else { - continue; // Something like $env:psmodulepath + continue; // Something like $env:PSModulePath } } else diff --git a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs index abbede5925..7e684260b1 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs @@ -14,6 +14,11 @@ using Dbg = System.Management.Automation.Diagnostics; namespace System.Management.Automation { + internal static class Constants + { + public const string PSModulePathEnvVar = "PSModulePath"; + } + /// /// Encapsulates the basic module operations for a PowerShell engine instance... /// @@ -710,7 +715,7 @@ namespace System.Management.Automation /// /// Check if the current powershell is likely running in following scenarios: - /// - sxs ps started on windows [machine-wide env:psmodulepath will influence] + /// - sxs ps started on windows [machine-wide env:PSModulePath will influence] /// - sxs ps started from full ps /// - sxs ps started from inbox nano/iot ps /// - full ps started from sxs ps @@ -734,8 +739,8 @@ namespace System.Management.Automation // so if the current process module path contains any of them, it's likely that the sxs // ps was started directly on windows, or from full ps. The same goes for the legacy personal // and shared module paths. - string hklmModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Machine); - string hkcuModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.User); + string hklmModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.Machine); + string hkcuModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.User); string legacyPersonalModulePath = personalModulePath.Replace(winSxSModuleDirectory, winLegacyModuleDirectory); string legacyProgramFilesModulePath = sharedModulePath.Replace(winSxSModuleDirectory, winLegacyModuleDirectory); @@ -824,7 +829,7 @@ namespace System.Management.Automation NeedToClearProcessModulePath(currentProcessModulePath, personalModulePath, sharedModulePath, runningSxS)) { // Clear the current process module path in the following cases - // - start sxs ps on windows [machine-wide env:psmodulepath will influence] + // - start sxs ps on windows [machine-wide env:PSModulePath will influence] // - start sxs ps from full ps // - start sxs ps from inbox nano/iot ps // - start full ps from sxs ps @@ -971,7 +976,7 @@ namespace System.Management.Automation /// internal static string GetModulePath() { - string currentModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Process); + string currentModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.Process); return currentModulePath; } /// @@ -981,7 +986,7 @@ namespace System.Management.Automation /// internal static string SetModulePath() { - string currentModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Process); + string currentModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.Process); string systemWideModulePath = ConfigPropertyAccessor.Instance.GetModulePath(ConfigPropertyAccessor.PropertyScope.SystemWide); string personalModulePath = ConfigPropertyAccessor.Instance.GetModulePath(ConfigPropertyAccessor.PropertyScope.CurrentUser); @@ -990,7 +995,7 @@ namespace System.Management.Automation if (!string.IsNullOrEmpty(newModulePathString)) { // Set the environment variable... - Environment.SetEnvironmentVariable("PSMODULEPATH", newModulePathString); + Environment.SetEnvironmentVariable(Constants.PSModulePathEnvVar, newModulePathString); } return newModulePathString; @@ -1013,7 +1018,7 @@ namespace System.Management.Automation /// The module path as an array of strings internal static IEnumerable GetModulePath(bool includeSystemModulePath, ExecutionContext context) { - string modulePathString = Environment.GetEnvironmentVariable("PSMODULEPATH") ?? SetModulePath(); + string modulePathString = Environment.GetEnvironmentVariable(Constants.PSModulePathEnvVar) ?? SetModulePath(); HashSet processedPathSet = new HashSet(StringComparer.OrdinalIgnoreCase); diff --git a/src/System.Management.Automation/engine/PropertyAccessor.cs b/src/System.Management.Automation/engine/PropertyAccessor.cs index f6a166c069..aefbc868fb 100644 --- a/src/System.Management.Automation/engine/PropertyAccessor.cs +++ b/src/System.Management.Automation/engine/PropertyAccessor.cs @@ -169,7 +169,7 @@ namespace System.Management.Automation string fileName = Path.Combine(scopeDirectory, configFileName); - string modulePath = ReadValueFromFile(fileName, "PsModulePath"); + string modulePath = ReadValueFromFile(fileName, Constants.PSModulePathEnvVar); if (!string.IsNullOrEmpty(modulePath)) { modulePath = Environment.ExpandEnvironmentVariables(modulePath); @@ -518,11 +518,11 @@ namespace System.Management.Automation { if (PropertyScope.CurrentUser == scope) { - return ModuleIntrinsics.GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.User); + return ModuleIntrinsics.GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.User); } else { - return ModuleIntrinsics.GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Machine); + return ModuleIntrinsics.GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.Machine); } } diff --git a/test/powershell/Host/Base-Directory.Tests.ps1 b/test/powershell/Host/Base-Directory.Tests.ps1 index 625c64b1de..7cf3774a41 100644 --- a/test/powershell/Host/Base-Directory.Tests.ps1 +++ b/test/powershell/Host/Base-Directory.Tests.ps1 @@ -30,20 +30,20 @@ Describe "Configuration file locations" -tags "CI","Slow" { } BeforeEach { - $original_PSMODULEPATH = $env:PSMODULEPATH + $original_PSModulePath = $env:PSModulePath } AfterEach { - $env:PSMODULEPATH = $original_PSMODULEPATH + $env:PSModulePath = $original_PSModulePath } It @ItArgs "Profile location should be correct" { & $powershell -noprofile `$PROFILE | Should Be $expectedProfile } - It @ItArgs "PSMODULEPATH should contain the correct path" { - $env:PSMODULEPATH = "" - $actual = & $powershell -noprofile `$env:PSMODULEPATH + It @ItArgs "PSModulePath should contain the correct path" { + $env:PSModulePath = "" + $actual = & $powershell -noprofile `$env:PSModulePath $actual | Should Match ([regex]::Escape($expectedModule)) } @@ -72,14 +72,14 @@ Describe "Configuration file locations" -tags "CI","Slow" { } BeforeEach { - $original_PSMODULEPATH = $env:PSMODULEPATH + $original_PSModulePath = $env:PSModulePath $original_XDG_CONFIG_HOME = $env:XDG_CONFIG_HOME $original_XDG_CACHE_HOME = $env:XDG_CACHE_HOME $original_XDG_DATA_HOME = $env:XDG_DATA_HOME } AfterEach { - $env:PSMODULEPATH = $original_PSMODULEPATH + $env:PSModulePath = $original_PSModulePath $env:XDG_CONFIG_HOME = $original_XDG_CONFIG_HOME $env:XDG_CACHE_HOME = $original_XDG_CACHE_HOME $env:XDG_DATA_HOME = $original_XDG_DATA_HOME @@ -91,11 +91,11 @@ Describe "Configuration file locations" -tags "CI","Slow" { & $powershell -noprofile `$PROFILE | Should Be $expected } - It @ItArgs "PSMODULEPATH should respect XDG_DATA_HOME" { - $env:PSMODULEPATH = "" + It @ItArgs "PSModulePath should respect XDG_DATA_HOME" { + $env:PSModulePath = "" $env:XDG_DATA_HOME = $TestDrive $expected = [IO.Path]::Combine($TestDrive, "powershell", "Modules") - $actual = & $powershell -noprofile `$env:PSMODULEPATH + $actual = & $powershell -noprofile `$env:PSModulePath $actual | Should Match $expected } diff --git a/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 index 5a1e4f2e85..f3791a1bb9 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 @@ -24,12 +24,12 @@ Describe 'use of a module from two runspaces' -Tags "CI" { } New-ModuleManifest @manifestParams - if ($env:PSMODULEPATH -notlike "*$TestModulePath*") { - $env:PSMODULEPATH += "$([System.IO.Path]::PathSeparator)$TestModulePath" + if ($env:PSModulePath -notlike "*$TestModulePath*") { + $env:PSModulePath += "$([System.IO.Path]::PathSeparator)$TestModulePath" } } - $originalPSMODULEPATH = $env:PSMODULEPATH + $originalPSModulePath = $env:PSModulePath try { New-TestModule -Name 'Random' -Content @' @@ -67,7 +67,7 @@ Import-Module Random } } finally { - $env:PSMODULEPATH = $originalPSMODULEPATH + $env:PSModulePath = $originalPSModulePath } } @@ -76,9 +76,9 @@ Describe 'Module reloading with Class definition' -Tags "CI" { BeforeAll { Set-Content -Path TestDrive:\TestModule.psm1 -Value @' -$passedArgs = $args -class Root { $passedIn = $passedArgs } -function Get-PassedArgsRoot { [Root]::new().passedIn } +$passedArgs = $args +class Root { $passedIn = $passedArgs } +function Get-PassedArgsRoot { [Root]::new().passedIn } function Get-PassedArgsNoRoot { $passedArgs } '@ $Arg_Hello = 'Hello' diff --git a/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 b/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 index 1888c07722..12f07535e8 100644 --- a/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 +++ b/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 @@ -30,12 +30,12 @@ Describe 'NestedModules' -Tags "CI" { New-ModuleManifest @manifestParams $resolvedTestDrivePath = Split-Path ((get-childitem TestDrive:\)[0].FullName) - if (-not ($env:PSMODULEPATH -like "*$resolvedTestDrivePath*")) { - $env:PSMODULEPATH += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath" + if (-not ($env:PSModulePath -like "*$resolvedTestDrivePath*")) { + $env:PSModulePath += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath" } } - $originalPSMODULEPATH = $env:PSMODULEPATH + $originalPSModulePath = $env:PSModulePath try { @@ -120,7 +120,7 @@ using module WithRoot } } finally { - $env:PSMODULEPATH = $originalPSMODULEPATH + $env:PSModulePath = $originalPSModulePath Get-Module @('ABC', 'NoRoot', 'WithRoot') | Remove-Module } } diff --git a/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 b/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 index b8955df693..27bbbfac13 100644 --- a/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 +++ b/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 @@ -1,6 +1,6 @@ Describe 'using module' -Tags "CI" { BeforeAll { - $originalPSMODULEPATH = $env:PSMODULEPATH + $originalPSModulePath = $env:PSModulePath Import-Module $PSScriptRoot\..\LanguageTestSupport.psm1 @@ -23,15 +23,15 @@ Describe 'using module' -Tags "CI" { } $resolvedTestDrivePath = Split-Path ((get-childitem "${TestDrive}\$ModulePathPrefix")[0].FullName) - if (-not ($env:PSMODULEPATH -like "*$resolvedTestDrivePath*")) { - $env:PSMODULEPATH += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath" + if (-not ($env:PSModulePath -like "*$resolvedTestDrivePath*")) { + $env:PSModulePath += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath" } } } AfterAll { - $env:PSMODULEPATH = $originalPSMODULEPATH + $env:PSModulePath = $originalPSModulePath } It 'Import-Module has ImplementedAssembly, when classes are present in the module' { @@ -349,7 +349,7 @@ using module Foo # 'using module' behavior must be aligned with Import-Module. # Import-Module does the following: - # 1) find the first directory from $env:PSMODULEPATH that contains the module + # 1) find the first directory from $env:PSModulePath that contains the module # 2) Import highest available version of the module # In out case TestDrive:\Module is before TestDrive:\Modules2 and so 2.3.0 is the right version It "uses the last module, if multiple versions are present" { @@ -436,12 +436,12 @@ function foo() } - # here we are back to normal $env:PSMODULEPATH, but all modules are there + # here we are back to normal $env:PSModulePath, but all modules are there Context "Module by path" { BeforeAll { # this is a setup for Context "Module by path" New-TestModule -Name FooForPaths -Content 'class Foo { [string] GetModuleName() { return "FooForPaths" } }' - $env:PSMODULEPATH = $originalPSMODULEPATH + $env:PSModulePath = $originalPSModulePath new-item -type directory -Force TestDrive:\FooRelativeConsumer Set-Content -Path "${TestDrive}\FooRelativeConsumer\FooRelativeConsumer.ps1" -Value @' @@ -457,8 +457,8 @@ class Bar : Foo {} '@ } - It 'use non-modified PSMODULEPATH' { - $env:PSMODULEPATH | Should Be $originalPSMODULEPATH + It 'use non-modified PSModulePath' { + $env:PSModulePath | Should Be $originalPSModulePath } It "can be accessed by relative path" { diff --git a/test/powershell/Language/Scripting/Debugging/DebuggerScriptTests.Tests.ps1 b/test/powershell/Language/Scripting/Debugging/DebuggerScriptTests.Tests.ps1 index 414dccd4c0..dec3cb1710 100644 --- a/test/powershell/Language/Scripting/Debugging/DebuggerScriptTests.Tests.ps1 +++ b/test/powershell/Language/Scripting/Debugging/DebuggerScriptTests.Tests.ps1 @@ -507,7 +507,7 @@ Describe "Unit tests for line breakpoints on modules" -Tags "CI" { # Unit tests for line breakpoints on modules... # # - $oldModulePath = $env:PSMODULEPATH + $oldModulePath = $env:PSModulePath try { # @@ -560,7 +560,7 @@ Describe "Unit tests for line breakpoints on modules" -Tags "CI" { # # Load the module # - $ENV:PSMODULEPATH = $moduleRoot + $ENV:PSModulePath = $moduleRoot import-module $moduleName @@ -594,7 +594,7 @@ Describe "Unit tests for line breakpoints on modules" -Tags "CI" { } finally { - $env:PSMODULEPATH = $oldModulePath + $env:PSModulePath = $oldModulePath if ($breakpoint1 -ne $null) { Remove-PSBreakpoint $breakpoint1 } if ($breakpoint2 -ne $null) { Remove-PSBreakpoint $breakpoint2 } if ($breakpoint3 -ne $null) { Remove-PSBreakpoint $breakpoint3 } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Archive/Pester.Commands.Cmdlets.Archive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Archive/Pester.Commands.Cmdlets.Archive.Tests.ps1 index 6cb22c642b..9842f74a67 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Archive/Pester.Commands.Cmdlets.Archive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Archive/Pester.Commands.Cmdlets.Archive.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "CI" { AfterAll { $global:ProgressPreference = $_progressPreference - $env:PSMODULEPATH = $_modulePath + $env:PSModulePath = $_modulePath } BeforeAll { # remove the archive module forcefully, to be sure we get the correct version @@ -19,9 +19,9 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "CI" { # Write-Progress not supported yet on Core $_progressPreference = $ProgressPreference # we need to be sure that we get the correct archive module - $_modulePath = $env:PSMODULEPATH + $_modulePath = $env:PSModulePath $powershellexe = (get-process -pid $PID).MainModule.FileName - $env:PSMODULEPATH = join-path ([io.path]::GetDirectoryName($powershellexe)) Modules + $env:PSModulePath = join-path ([io.path]::GetDirectoryName($powershellexe)) Modules if ( $IsCoreCLR ) { $global:ProgressPreference = "SilentlyContinue" } Setup -d SourceDir diff --git a/test/powershell/Modules/Microsoft.PowerShell.Security/CmsMessage.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Security/CmsMessage.Tests.ps1 index 7e78499f9a..2e021e250c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Security/CmsMessage.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Security/CmsMessage.Tests.ps1 @@ -163,8 +163,8 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" { $fullPowerShell = Join-Path "$env:SystemRoot" "System32\WindowsPowerShell\v1.0\powershell.exe" try { - $modulePathCopy = $env:PSMODULEPATH - $env:PSMODULEPATH = $null + $modulePathCopy = $env:PSModulePath + $env:PSModulePath = $null $command = @" Import-PfxCertificate $certLocation -CertStoreLocation cert:\CurrentUser\My | % PSPath @@ -176,7 +176,7 @@ Import-Certificate $badCertLocation -CertStoreLocation Cert:\CurrentUser\My | % $importedCert = Get-ChildItem $certPaths[0] $testBadCert = Get-ChildItem $certPaths[1] } finally { - $env:PSMODULEPATH = $modulePathCopy + $env:PSModulePath = $modulePathCopy } } else diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index 3159aba478..b89ac49d5c 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -1,13 +1,13 @@ Describe "DSC MOF Compilation" -tags "CI" { AfterAll { - $env:PSMODULEPATH = $_modulePath + $env:PSModulePath = $_modulePath } BeforeAll { $env:DSC_HOME = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath dsc - $_modulePath = $env:PSMODULEPATH + $_modulePath = $env:PSModulePath $powershellexe = (get-process -pid $PID).MainModule.FileName - $env:PSMODULEPATH = join-path ([io.path]::GetDirectoryName($powershellexe)) Modules + $env:PSModulePath = join-path ([io.path]::GetDirectoryName($powershellexe)) Modules } It "Should be able to compile a MOF from a basic configuration" -Skip:($IsOSX -or $IsWindows) { diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 82d73a19be..3a5bacf0fb 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -27,19 +27,19 @@ } It "Command lookup with duplicate paths" { - $previousPath = $env:PSMODULEPATH + $previousPath = $env:PSModulePath try { New-Item -Path "$TestDrive\TestFunctionA" -ItemType Directory New-Item -Path "$TestDrive\\TestFunctionA\TestFunctionA.psm1" -Value "function TestFunctionA {}" | Out-Null - $env:PSMODULEPATH = "$TestDrive" + [System.IO.Path]::PathSeparator + "$TestDrive" + $env:PSModulePath = "$TestDrive" + [System.IO.Path]::PathSeparator + "$TestDrive" (Get-command 'TestFunctionA').count | Should Be 1 } finally { - $env:PSMODULEPATH = $previousPath + $env:PSModulePath = $previousPath } } diff --git a/test/powershell/engine/Module/ModulePath.Tests.ps1 b/test/powershell/engine/Module/ModulePath.Tests.ps1 index 476b7da419..0fe8b80597 100644 --- a/test/powershell/engine/Module/ModulePath.Tests.ps1 +++ b/test/powershell/engine/Module/ModulePath.Tests.ps1 @@ -32,18 +32,18 @@ Describe "SxS Module Path Basic Tests" -tags "CI" { } BeforeEach { - $originalModulePath = $env:PSMODULEPATH + $originalModulePath = $env:PSModulePath } AfterEach { - $env:PSMODULEPATH = $originalModulePath + $env:PSModulePath = $originalModulePath } It "validate sxs module path" { - $env:PSMODULEPATH = "" - $defaultModulePath = & $powershell -nopro -c '$env:PSMODULEPATH' + $env:PSModulePath = "" + $defaultModulePath = & $powershell -nopro -c '$env:PSModulePath' $paths = $defaultModulePath -split [System.IO.Path]::PathSeparator @@ -64,8 +64,8 @@ Describe "SxS Module Path Basic Tests" -tags "CI" { try { ## PSHome module path derived from another powershell core instance should be ignored - $env:PSMODULEPATH = $fakePSHomeModuleDir - $newModulePath = & $powershell -nopro -c '$env:PSMODULEPATH' + $env:PSModulePath = $fakePSHomeModuleDir + $newModulePath = & $powershell -nopro -c '$env:PSModulePath' $paths = $newModulePath -split [System.IO.Path]::PathSeparator $paths.Count | Should Be 3 @@ -85,8 +85,8 @@ Describe "SxS Module Path Basic Tests" -tags "CI" { ## non-pshome module path derived from another powershell core instance should be preserved $customeModules = Join-Path -Path $TestDrive -ChildPath 'CustomModules' - $env:PSMODULEPATH = $fakePSHomeModuleDir, $customeModules -join ([System.IO.Path]::PathSeparator) - $newModulePath = & $powershell -nopro -c '$env:PSMODULEPATH' + $env:PSModulePath = $fakePSHomeModuleDir, $customeModules -join ([System.IO.Path]::PathSeparator) + $newModulePath = & $powershell -nopro -c '$env:PSModulePath' $paths = $newModulePath -split [System.IO.Path]::PathSeparator $paths.Count | Should Be 5 diff --git a/test/tools/OpenCover/OpenCover.psm1 b/test/tools/OpenCover/OpenCover.psm1 index dbc2f21ae7..485a4f7213 100644 --- a/test/tools/OpenCover/OpenCover.psm1 +++ b/test/tools/OpenCover/OpenCover.psm1 @@ -481,12 +481,12 @@ function Invoke-OpenCover try { # check to be sure that the module path is present - # this isn't done earlier because there's no need to change env:psmodulepath unless we're going to really run tests - $saveModPath = $env:psmodulepath - $env:psmodulepath = "${PowerShellExeDirectory}\Modules" - if ( ! (test-path $env:psmodulepath) ) + # this isn't done earlier because there's no need to change env:PSModulePath unless we're going to really run tests + $saveModPath = $env:PSModulePath + $env:PSModulePath = "${PowerShellExeDirectory}\Modules" + if ( ! (test-path $env:PSModulePath) ) { - throw "${env:psmodulepath} does not exist" + throw "${env:PSModulePath} does not exist" } # invoke OpenCover elevated