Merge pull request #690 from PowerShell/travis-xunit
Run xUnit tests on Travis
This commit is contained in:
commit
ed14e45b94
14 changed files with 56 additions and 9 deletions
|
@ -19,6 +19,7 @@ before_install:
|
||||||
script:
|
script:
|
||||||
- powershell -c "Import-Module ./PowerShellGitHubDev.psm1; Start-PSBuild"
|
- powershell -c "Import-Module ./PowerShellGitHubDev.psm1; Start-PSBuild"
|
||||||
- ./pester.sh
|
- ./pester.sh
|
||||||
|
- ./xunit.sh
|
||||||
notifications:
|
notifications:
|
||||||
slack:
|
slack:
|
||||||
secure: sKYd4n61+ZFzGZuWGUl8V1kN0NM16wRVOFVlNhlFCwnkrEsKROb++EvXf5uwnKuzxkhEjvPWO+UFgeshQDoR93y4s5YLfhC5JupK4nUzjPzWs208KTrh8u/x9MY8X6Ojxi85EEAiku5GzMoMlkucSStZUYwbIfnelzqdw8uoRwmm2MW4XCPwsuEuDUVghyiva0Mdx1G6MopCrK8T96WywJXT3chhfZQgVt+sQCBt9g+2kjDaObKrzG0P07IVK43ZpDgnu6AoxlyBzIx9mJH2Oa/tki3/kTO72Wcp3ps3qvmiStADamzVKR9p1VlWCLWAd6VOehxuByCGEyujpzk135Wud2DZYO+8LD6inZVhFe3Wt5pCU9BDXZppiATfMCqgXEH7nK54pEn79yHcjthRJ2+Z9ot7As2fu3RSBmTAi8nRP0fxRyX/jctR3S6P0qt0y1ynx9nzBfhmhPQW0PMVazWS/nruQIvK/3iiYXjZxM5bBwIvabmwV00EYeTdbL6ufXWNgQcG1ZWkDsi2I3vst/ytUbHwaFYg83bXWpxg9DCzJeWLVUvE5/3NfBxRAuCTot/fgTEA9IYScvrlL7Q/bT0cOt0vEM98MPf1UO+WP85uxhsRgHtwDEo+jMaL6ZFkPhlV6mmmED4NdY2//a571cLNXdnuMAze5O3TWGBG53g=
|
secure: sKYd4n61+ZFzGZuWGUl8V1kN0NM16wRVOFVlNhlFCwnkrEsKROb++EvXf5uwnKuzxkhEjvPWO+UFgeshQDoR93y4s5YLfhC5JupK4nUzjPzWs208KTrh8u/x9MY8X6Ojxi85EEAiku5GzMoMlkucSStZUYwbIfnelzqdw8uoRwmm2MW4XCPwsuEuDUVghyiva0Mdx1G6MopCrK8T96WywJXT3chhfZQgVt+sQCBt9g+2kjDaObKrzG0P07IVK43ZpDgnu6AoxlyBzIx9mJH2Oa/tki3/kTO72Wcp3ps3qvmiStADamzVKR9p1VlWCLWAd6VOehxuByCGEyujpzk135Wud2DZYO+8LD6inZVhFe3Wt5pCU9BDXZppiATfMCqgXEH7nK54pEn79yHcjthRJ2+Z9ot7As2fu3RSBmTAi8nRP0fxRyX/jctR3S6P0qt0y1ynx9nzBfhmhPQW0PMVazWS/nruQIvK/3iiYXjZxM5bBwIvabmwV00EYeTdbL6ufXWNgQcG1ZWkDsi2I3vst/ytUbHwaFYg83bXWpxg9DCzJeWLVUvE5/3NfBxRAuCTot/fgTEA9IYScvrlL7Q/bT0cOt0vEM98MPf1UO+WP85uxhsRgHtwDEo+jMaL6ZFkPhlV6mmmED4NdY2//a571cLNXdnuMAze5O3TWGBG53g=
|
||||||
|
|
13
test/csharp/README.md
Normal file
13
test/csharp/README.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# xUnit Tests
|
||||||
|
|
||||||
|
This tests are completely Linux specific.
|
||||||
|
|
||||||
|
Every test class *must* belong to
|
||||||
|
`[Collection("AssemblyLoadContext")]`. This ensures that PowerShell's
|
||||||
|
AssemblyLoadContext is initialized before any other code is executed.
|
||||||
|
When this is not the case, late initialization fails with
|
||||||
|
`System.InvalidOperationException : Binding model is already locked
|
||||||
|
for the AppDomain and cannot be reset.`
|
||||||
|
|
||||||
|
Having every class in the same collection is as close to an xUnit
|
||||||
|
global init hook as can be done.
|
26
test/csharp/fixture_AssemblyLoadContext.cs
Normal file
26
test/csharp/fixture_AssemblyLoadContext.cs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
using Xunit;
|
||||||
|
using System;
|
||||||
|
using System.Management.Automation;
|
||||||
|
using Microsoft.PowerShell.Linux.Host;
|
||||||
|
|
||||||
|
// This collection fixture initializes Core PowerShell's AssemblyLoadContext once and only
|
||||||
|
// once. Attempting to initialize in a class level fixture will cause multiple
|
||||||
|
// initializations, resulting in test failure due to "Binding model is already locked for
|
||||||
|
// the AppDomain and cannot be reset".
|
||||||
|
namespace PSTests
|
||||||
|
{
|
||||||
|
public class AssemblyLoadContextFixture
|
||||||
|
{
|
||||||
|
public AssemblyLoadContextFixture()
|
||||||
|
{
|
||||||
|
// Initialize the Core PowerShell AssemblyLoadContext
|
||||||
|
PowerShellAssemblyLoadContextInitializer.SetPowerShellAssemblyLoadContext(AppContext.BaseDirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[CollectionDefinition("AssemblyLoadContext")]
|
||||||
|
public class AssemblyLoadContextCollection : ICollectionFixture<AssemblyLoadContextFixture>
|
||||||
|
{
|
||||||
|
// nothing to do but satisfy the interface
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ using System.Management.Automation.Language;
|
||||||
|
|
||||||
namespace PSTests
|
namespace PSTests
|
||||||
{
|
{
|
||||||
|
[Collection("AssemblyLoadContext")]
|
||||||
public static class PSEnumerableBinderTests
|
public static class PSEnumerableBinderTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Management.Automation;
|
||||||
|
|
||||||
namespace PSTests
|
namespace PSTests
|
||||||
{
|
{
|
||||||
|
[Collection("AssemblyLoadContext")]
|
||||||
public static class CorePsExtensionsTests
|
public static class CorePsExtensionsTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
@ -6,6 +6,7 @@ using System.Management.Automation;
|
||||||
|
|
||||||
namespace PSTests
|
namespace PSTests
|
||||||
{
|
{
|
||||||
|
[Collection("AssemblyLoadContext")]
|
||||||
public static class PlatformTests
|
public static class PlatformTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Management.Automation;
|
||||||
|
|
||||||
namespace PSTests
|
namespace PSTests
|
||||||
{
|
{
|
||||||
|
[Collection("AssemblyLoadContext")]
|
||||||
public static class PSTypeExtensionsTests
|
public static class PSTypeExtensionsTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
@ -5,6 +5,7 @@ using Microsoft.PowerShell.Commands;
|
||||||
|
|
||||||
namespace PSTests
|
namespace PSTests
|
||||||
{
|
{
|
||||||
|
[Collection("AssemblyLoadContext")]
|
||||||
public static class FileSystemProviderTests
|
public static class FileSystemProviderTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Management.Automation;
|
||||||
namespace PSTests
|
namespace PSTests
|
||||||
{
|
{
|
||||||
// Not static because a test requires non-const variables
|
// Not static because a test requires non-const variables
|
||||||
|
[Collection("AssemblyLoadContext")]
|
||||||
public class MshSnapinInfoTests
|
public class MshSnapinInfoTests
|
||||||
{
|
{
|
||||||
// Test that it does not throw an exception
|
// Test that it does not throw an exception
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Management.Automation;
|
||||||
|
|
||||||
namespace PSTests
|
namespace PSTests
|
||||||
{
|
{
|
||||||
|
[Collection("AssemblyLoadContext")]
|
||||||
public static class PSVersionInfoTests
|
public static class PSVersionInfoTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
@ -9,17 +9,12 @@ namespace PSTests
|
||||||
// NOTE: do not call AddCommand("out-host") after invoking or MergeMyResults,
|
// NOTE: do not call AddCommand("out-host") after invoking or MergeMyResults,
|
||||||
// otherwise Invoke will not return any objects
|
// otherwise Invoke will not return any objects
|
||||||
|
|
||||||
|
[Collection("AssemblyLoadContext")]
|
||||||
public class RunspaceTests
|
public class RunspaceTests
|
||||||
{
|
{
|
||||||
private static int count = 3;
|
private static int count = 3;
|
||||||
private static string script = String.Format($"get-process | select-object -first {count}");
|
private static string script = String.Format($"get-process | select-object -first {count}");
|
||||||
|
|
||||||
// Initialize the Core PowerShell AssemblyLoadContext
|
|
||||||
public RunspaceTests()
|
|
||||||
{
|
|
||||||
PowerShellAssemblyLoadContextInitializer.SetPowerShellAssemblyLoadContext(AppContext.BaseDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestRunspaceWithPipeline()
|
public void TestRunspaceWithPipeline()
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Management.Automation;
|
||||||
|
|
||||||
namespace PSTests
|
namespace PSTests
|
||||||
{
|
{
|
||||||
|
[Collection("AssemblyLoadContext")]
|
||||||
public static class SecuritySupportTests
|
public static class SecuritySupportTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Management.Automation;
|
||||||
|
|
||||||
namespace PSTests
|
namespace PSTests
|
||||||
{
|
{
|
||||||
|
[Collection("AssemblyLoadContext")]
|
||||||
public static class UtilsTests
|
public static class UtilsTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
9
xunit.sh
9
xunit.sh
|
@ -20,9 +20,12 @@ popd
|
||||||
# Run xUnit tests
|
# Run xUnit tests
|
||||||
pushd test/csharp
|
pushd test/csharp
|
||||||
## Build
|
## Build
|
||||||
dotnet build
|
dotnet build -c Linux
|
||||||
## Work-around dotnet/cli#753
|
## Work-around dotnet/cli#753
|
||||||
cp -r ../../src/Microsoft.PowerShell.Linux.Host/{Modules,*ps1xml} bin/Debug/netstandardapp1.5/ubuntu.14.04-x64
|
cp -r ../../src/Microsoft.PowerShell.Linux.Host/{Modules,*ps1xml} bin/Linux/netstandardapp1.5/ubuntu.14.04-x64
|
||||||
## Test
|
## Test
|
||||||
dotnet test
|
dotnet test -c Linux
|
||||||
|
result=$?
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
exit $result
|
||||||
|
|
Loading…
Reference in a new issue