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
21 changes: 15 additions & 6 deletions test/csharp/csharp.tests.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\Test.Common.props"/>
<Import Project="../Test.Common.props"/>

<PropertyGroup>
<Description>PowerShell On Linux xUnit Tests</Description>
<Description>PowerShell xUnit Tests</Description>
<AssemblyName>powershell-tests</AssemblyName>
<RuntimeIdentifiers>win7-x86;win7-x64;osx.10.12-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>

<PropertyGroup>
<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>../../src/signing/visualstudiopublic.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\System.Management.Automation\System.Management.Automation.csproj" />
<ProjectReference Include="../../src/Microsoft.PowerShell.SDK/Microsoft.PowerShell.SDK.csproj"/>
<ProjectReference Include="../../src/Microsoft.PowerShell.Commands.Diagnostics/Microsoft.PowerShell.Commands.Diagnostics.csproj"/>
<ProjectReference Include="../../src/Microsoft.WSMan.Management/Microsoft.WSMan.Management.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.3.0" />
<!-- DotNetCliToolReference element specifies the CLI tool that the user wants to restore in the context of the project. -->
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0" />
<PackageReference Include="Xunit.SkippableFact" Version="1.3.3" />
</ItemGroup>

</Project>
25 changes: 0 additions & 25 deletions test/csharp/fixture_AssemblyLoadContext.cs

This file was deleted.

7 changes: 3 additions & 4 deletions test/csharp/test_Binders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

namespace PSTests
{
[Collection("AssemblyLoadContext")]
public static class PSEnumerableBinderTests
{
[Fact]
public static void TestIsComObject()
public static void TestIsStaticTypePossiblyEnumerable()
{
// It just needs an arbitrary object
Assert.False(PSEnumerableBinder.IsComObject(42));
// It just needs an arbitrary type
Assert.False(PSEnumerableBinder.IsStaticTypePossiblyEnumerable(42.GetType()));
}
}
}
9 changes: 5 additions & 4 deletions test/csharp/test_CorePsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace PSTests
{
[Collection("AssemblyLoadContext")]
public static class PlatformTests
{
[Fact]
Expand All @@ -15,6 +14,7 @@ public static void TestIsCoreCLR()
Assert.True(Platform.IsCoreCLR);
}

#if Unix
[Fact]
public static void TestGetUserName()
{
Expand All @@ -38,7 +38,7 @@ public static void TestGetUserName()
}
}

[Fact(Skip="Bad arguments for macOS")]
[Fact]
public static void TestGetMachineName()
{
var startInfo = new ProcessStartInfo
Expand All @@ -61,7 +61,7 @@ public static void TestGetMachineName()
}
}

[Fact(Skip="Bad arguments for macOS")]
[Fact]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe that this is still not good for MacOS. hostname --fqdn is an error. Will this run on Mac?

public static void TestGetFQDN()
{
var startInfo = new ProcessStartInfo
Expand All @@ -84,7 +84,7 @@ public static void TestGetFQDN()
}
}

[Fact(Skip="Bad arguments for macOS")]
[Fact]
public static void TestGetDomainName()
{
var startInfo = new ProcessStartInfo
Expand Down Expand Up @@ -255,5 +255,6 @@ public static void TestFileIsSymLink()
File.Delete(path);
File.Delete(link);
}
#endif
}
}
6 changes: 2 additions & 4 deletions test/csharp/test_ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

namespace PSTests
{
[Collection("AssemblyLoadContext")]
public static class PSTypeExtensionsTests
{
[Fact]
public static void TestIsComObject()
public static void TestIsNumeric()
{
// It just needs an arbitrary type
Assert.False(PSTypeExtensions.IsComObject(42.GetType()));
Assert.True(PSTypeExtensions.IsNumeric(42.GetType()));
}
}
}
44 changes: 32 additions & 12 deletions test/csharp/test_FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
using System.Management.Automation.Runspaces;
using Microsoft.PowerShell;
using Microsoft.PowerShell.Commands;
using System.Reflection;

namespace PSTests
{
[Collection("AssemblyLoadContext")]
public class FileSystemProviderTests: IDisposable
{
private string testPath;
Expand All @@ -37,9 +37,8 @@ private ExecutionContext GetExecutionContext()
{
CultureInfo currentCulture = CultureInfo.CurrentCulture;
PSHost hostInterface = new DefaultHost(currentCulture,currentCulture);
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
InitialSessionState iss = InitialSessionState.CreateDefault2();
AutomationEngine engine = new AutomationEngine(hostInterface, runspaceConfiguration, iss);
AutomationEngine engine = new AutomationEngine(hostInterface, iss);
ExecutionContext executionContext = new ExecutionContext(engine, hostInterface, iss);
return executionContext;
}
Expand All @@ -58,7 +57,14 @@ private ProviderInfo GetProvider()
[Fact]
public void TestCreateJunctionFails()
{
Assert.False(InternalSymbolicLinkLinkCodeMethods.CreateJunction("",""));
if(!Platform.IsWindows)
{
Assert.False(InternalSymbolicLinkLinkCodeMethods.CreateJunction("",""));
}
else
{
Assert.Throws<System.ArgumentNullException>(delegate { InternalSymbolicLinkLinkCodeMethods.CreateJunction("",""); });
}
}

[Fact]
Expand All @@ -74,12 +80,26 @@ public void TestGetHelpMaml()
public void TestMode()
{
Assert.Equal(FileSystemProvider.Mode(null),String.Empty);
FileSystemInfo directoryObject = new DirectoryInfo(@"/");
FileSystemInfo fileObject = new FileInfo(@"/etc/hosts");
FileSystemInfo executableObject = new FileInfo(@"/bin/echo");
Assert.Equal(FileSystemProvider.Mode(PSObject.AsPSObject(directoryObject)).Replace("r","-"),"d-----");
Assert.Equal(FileSystemProvider.Mode(PSObject.AsPSObject(fileObject)).Replace("r","-"),"------");
Assert.Equal(FileSystemProvider.Mode(PSObject.AsPSObject(executableObject)).Replace("r","-"),"------");
FileSystemInfo directoryObject = null;
FileSystemInfo fileObject = null;
FileSystemInfo executableObject = null;

if(!Platform.IsWindows)
{
directoryObject = new DirectoryInfo(@"/");
fileObject = new FileInfo(@"/etc/hosts");
executableObject = new FileInfo(@"/bin/echo");
}
else
{
directoryObject = new DirectoryInfo(System.Environment.CurrentDirectory);
fileObject = new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location);
executableObject = new FileInfo(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
}

Assert.Equal("d-----", FileSystemProvider.Mode(PSObject.AsPSObject(directoryObject)).Replace("r","-"));
Assert.Equal("------", FileSystemProvider.Mode(PSObject.AsPSObject(fileObject)).Replace("r","-").Replace("a","-"));
Assert.Equal("------", FileSystemProvider.Mode(PSObject.AsPSObject(executableObject)).Replace("r","-").Replace("a","-"));
}

[Fact]
Expand All @@ -99,7 +119,7 @@ public void TestGetProperty()
{
if(property.Name == "IsReadOnly")
{
Assert.Equal(property.Value,false);
Assert.False((bool)property.Value);
}
}
}
Expand All @@ -118,7 +138,7 @@ public void TestSetProperty()
{
if(property.Name == "Name")
{
Assert.Equal(property.Value,"test");
Assert.Equal("test", property.Value);
}
}
}
Expand Down
Loading