diff --git a/build.psm1 b/build.psm1 index 625996e4a2..4878a6d82f 100644 --- a/build.psm1 +++ b/build.psm1 @@ -554,23 +554,43 @@ function Start-PSPester { [string]$Path = "$PSScriptRoot/test/powershell" ) - $tagString = "-outputFormat ${OutputFormat} -outputFile ${outputFile} " - if ( ! $DisableExit ) { $tagString += " -EnableExit" } - if ( $ExcludeTag -and ($ExcludeTag -ne "")) { $tagString += " -ExcludeTag @('" + (${ExcludeTag} -join "','") + "')" } - if ( $Tag ) { $tagString += " -Tag @('" + (${Tag} -join "','") + "')" } + $powershell = Get-PSOutput - $powershell = get-psoutput - $psdir = [io.path]::GetDirectoryName($powershell) - $moduleDir = [io.path]::Combine($psdir,"Modules","Pester") + # All concatenated commands/arguments are suffixed with the delimiter (space) + $Command = "" - Write-Verbose "Import-Module '$moduleDir'; Invoke-Pester $tagString $Path" - $powershellexe = get-psoutput - $execPolicy = "" - if ($IsWindows) - { - $execPolicy = "Set-ExecutionPolicy -Scope Process Unrestricted; " + # Windows needs the execution policy adjusted + if ($IsWindows) { + $Command += "Set-ExecutionPolicy -Scope Process Unrestricted; " } - & $powershell -noprofile -c "$execPolicy Import-Module '$moduleDir'; Invoke-Pester $tagString $Path" + + $PesterModule = [IO.Path]::Combine((Split-Path $powershell), "Modules", "Pester") + $Command += "Import-Module $PesterModule; " + $Command += "Invoke-Pester " + + $Command += "-OutputFormat ${OutputFormat} -OutputFile ${OutputFile} " + if (!$DisableExit) { + $Command += "-EnableExit " + } + if ($ExcludeTag -and ($ExcludeTag -ne "")) { + $Command += "-ExcludeTag @('" + (${ExcludeTag} -join "','") + "') " + } + if ($Tag) { + $Command += "-Tag @('" + (${Tag} -join "','") + "') " + } + + $Command += $Path + + Write-Verbose $Command + # To ensure proper testing, the module path must not be inherited by the spawned process + try { + $originalModulePath = $env:PSMODULEPATH + $env:PSMODULEPATH = "" + & $powershell -noprofile -c $Command + } finally { + $env:PSMODULEPATH = $originalModulePath + } + if ($LASTEXITCODE -ne 0) { throw "$LASTEXITCODE Pester tests failed" } diff --git a/src/Modules/Unix/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.psd1 b/src/Modules/Unix/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.psd1 index 3140a1d1f2..ade5527e30 100644 --- a/src/Modules/Unix/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.psd1 +++ b/src/Modules/Unix/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.psd1 @@ -7,7 +7,7 @@ ModuleVersion="3.0.0.0" PowerShellVersion="3.0" AliasesToExport = @() FunctionsToExport = @() -CmdletsToExport="Get-Credential", "ConvertFrom-SecureString", "ConvertTo-SecureString" +CmdletsToExport="Get-Credential", "Get-ExecutionPolicy", "Set-ExecutionPolicy", "ConvertFrom-SecureString", "ConvertTo-SecureString" NestedModules="Microsoft.PowerShell.Security.dll" HelpInfoURI = 'http://go.microsoft.com/fwlink/?linkid=390786' } diff --git a/src/powershell-unix/project.json b/src/powershell-unix/project.json index bb497e1600..f2d93ea8ee 100644 --- a/src/powershell-unix/project.json +++ b/src/powershell-unix/project.json @@ -37,6 +37,7 @@ "Modules/" : { "include": [ "../Modules/Windows+Unix-Core", + "../Modules/Unix", "../Modules/Shared" ], "exclude": [