Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 93 additions & 25 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,53 @@ function Show-PSPesterError

}

function Test-XUnitTestResults
{
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $TestResultsFile
)

if(-not (Test-Path $TestResultsFile))
{
throw "File not found $TestResultsFile"
}

try
{
$results = [xml] (Get-Content $TestResultsFile)
}
catch
{
throw "Cannot convert $TestResultsFile to xml : $($_.message)"
}

$failedTests = $results.assemblies.assembly.collection | Where-Object failed -gt 0

if(-not $failedTests)
{
return $true
}

foreach($failure in $failedTests)
{
$description = $failure.test.type
$name = $failure.test.method
$message = $failure.test.failure.message.'#cdata-section'
$stackTrace = $failure.test.failure.'stack-trace'.'#cdata-section'

logerror ("Description: " + $description)
logerror ("Name: " + $name)
logerror "message:"
logerror $message
logerror "stack-trace:"
logerror $stackTrace
}

throw "$($failedTests.failed) tests failed"
}

#
# Read the test result file and
# Throw if a test failed
Expand Down Expand Up @@ -1251,46 +1298,67 @@ function Test-PSPesterResults


function Start-PSxUnit {
[CmdletBinding()]param()

log "xUnit tests are currently disabled pending fixes due to API and AssemblyLoadContext changes - @andschwa"
return

if ($Environment.IsWindows) {
throw "xUnit tests are only currently supported on Linux / OS X"
}

if ($Environment.IsMacOS) {
log "Not yet supported on OS X, pretending they passed..."
return
}
[CmdletBinding()]param(
[string] $TestResultsFile = "XUnitResults.xml"
)

# Add .NET CLI tools to PATH
Find-Dotnet

$Arguments = "--configuration", "Linux", "-parallel", "none"
if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
$Arguments += "-verbose"
}

$Content = Split-Path -Parent (Get-PSOutput)
if (-not (Test-Path $Content)) {
throw "PowerShell must be built before running tests!"
}

if(Test-Path $TestResultsFile)
{
Remove-Item $TestResultsFile -Force -ErrorAction SilentlyContinue
}

try {
Push-Location $PSScriptRoot/test/csharp

# Path manipulation to obtain test project output directory
$Output = Join-Path $pwd ((Split-Path -Parent (Get-PSOutput)) -replace (New-PSOptions).Top)
Write-Verbose "Output is $Output"
dotnet restore

Copy-Item -ErrorAction SilentlyContinue -Recurse -Path $Content/* -Include Modules,libpsl-native* -Destination $Output
Start-NativeExecution { dotnet test $Arguments }
# --fx-version workaround required due to https://github.com/dotnet/cli/issues/7901#issuecomment-343323674
if($Environment.IsWindows)
{
dotnet xunit --fx-version 2.0.0 -xml $TestResultsFile
}
else
{
if($Environment.IsMacOS)
{
$nativeLib = "$Content/libpsl-native.dylib"
}
else
{
$nativeLib = "$Content/libpsl-native.so"
}

$requiredDependencies = @(
$nativeLib,
"$Content/Microsoft.Management.Infrastructure.dll",
"$Content/System.Text.Encoding.CodePages.dll"
)

if((Test-Path $requiredDependencies) -notcontains $false)
{
$options = New-PSOptions
$Destination = "bin/$($options.configuration)/$($options.framework)"
New-Item $Destination -ItemType Directory -Force > $null
Copy-Item -Path $requiredDependencies -Destination $Destination -Force
}
else
{
throw "Dependencies $requiredDependencies not met."
}

if ($LASTEXITCODE -ne 0) {
throw "$LASTEXITCODE xUnit tests failed"
dotnet xunit --fx-version 2.0.0 -configuration $Options.configuration -xml $TestResultsFile
}
} finally {
}
finally {
Pop-Location
}
}
Expand Down
6 changes: 3 additions & 3 deletions docs/learning-powershell/using-vscode.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ If you wish to use a specific installation of PowerShell with Visual Studio Code

```json
// On Windows:
"powershell.powerShellExePath": "c:/Program Files/PowerShell/<version>/powershell.exe"
"powershell.powerShellExePath": "c:/Program Files/PowerShell/<version>/pwsh.exe"

// On Linux:
"powershell.powerShellExePath": "/opt/microsoft/powershell/<version>/powershell"
"powershell.powerShellExePath": "/opt/microsoft/powershell/<version>/pwsh"

// On macOS:
"powershell.powerShellExePath": "/usr/local/microsoft/powershell/<version>/powershell"
"powershell.powerShellExePath": "/usr/local/microsoft/powershell/<version>/pwsh"
```

3. Replace the setting with the path to the desired PowerShell executable
Expand Down
19 changes: 9 additions & 10 deletions src/Microsoft.PowerShell.Security/security/CatalogCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,24 @@ protected override void ProcessRecord()
{
foreach (PathInfo tempPath in SessionState.Path.GetResolvedPSPathFromPSPath(p))
{
if (ShouldProcess(tempPath.ProviderPath))
if (ShouldProcess("Including path " + tempPath.ProviderPath, "", ""))
{
paths.Add(tempPath.ProviderPath);
}
}
}
}

// We add 'paths.Count > 0' to support 'ShouldProcess()'
if (paths.Count > 0 )
{
string drive = null;
string drive = null;

// resolve catalog destination Path
if (!SessionState.Path.IsPSAbsolute(catalogFilePath, out drive) && !System.IO.Path.IsPathRooted(catalogFilePath))
{
catalogFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(catalogFilePath);
}
// resolve catalog destination Path
if (!SessionState.Path.IsPSAbsolute(catalogFilePath, out drive) && !System.IO.Path.IsPathRooted(catalogFilePath))
{
catalogFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(catalogFilePath);
}

if (ShouldProcess(catalogFilePath))
{
PerformAction(paths, catalogFilePath);
}
}
Expand Down
Loading