Skip to content
Open
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
50 changes: 50 additions & 0 deletions eng/testing/xunit/xunit.console.v3.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<Project>

<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<TestResultsName>testResults.xml</TestResultsName>
<UseXunitExcludesTxtFile Condition="'$(TargetOS)' == 'android' or '$(TargetOS)' == 'ios' or '$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'tvos' or '$(TargetOS)' == 'tvossimulator' or '$(TargetOS)' == 'maccatalyst'">true</UseXunitExcludesTxtFile>
</PropertyGroup>

<ItemGroup>
<!-- Configures xunit to not print out passing tests with output when diagnostic messages are enabled. -->
<SetScriptCommands Include="$(EnvVarCommand) XUNIT_HIDE_PASSING_OUTPUT_DIAGNOSTICS=1" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetsMobile)' != 'true' and '$(TestSingleFile)' != 'true'">
<_depsFileArgument Condition="'$(GenerateDependencyFile)' == 'true'">--depsfile $(AssemblyName).deps.json</_depsFileArgument>
<RunScriptCommand Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">"$(RunScriptHost)" exec --runtimeconfig $(AssemblyName).runtimeconfig.json $(_depsFileArgument) $(TargetFileName)</RunScriptCommand>
<RunScriptCommand Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(RunScriptWindowsCmd)' != 'true'">./$(AssemblyName)</RunScriptCommand>
<RunScriptCommand Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(RunScriptWindowsCmd)' == 'true'">$(AssemblyName).exe</RunScriptCommand>

<RunScriptCommand>$(RunScriptCommand) -xml $(TestResultsName)</RunScriptCommand>
<RunScriptCommand>$(RunScriptCommand) -noLogo</RunScriptCommand>
<RunScriptCommand Condition="'$(ArchiveTests)' == 'true'">$(RunScriptCommand) -noColor</RunScriptCommand>
<RunScriptCommand Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(TestDisableAppDomain)' == 'true'">$(RunScriptCommand) -noappdomain</RunScriptCommand>
<RunScriptCommand Condition="'$(TestDisableParallelization)' == 'true'">$(RunScriptCommand) -maxThreads 1</RunScriptCommand>
<RunScriptCommand Condition="'$(XUnitShowProgress)' == 'true'">$(RunScriptCommand) -reporter verbose</RunScriptCommand>
</PropertyGroup>

<PropertyGroup Condition="'$(UseXunitExcludesTxtFile)' != 'true'">
<!-- Add local and global options to the argument stack. -->
<RunScriptCommand Condition="'$(XUnitMethodName)' != ''">$(RunScriptCommand) -method $(XUnitMethodName)</RunScriptCommand>
<RunScriptCommand Condition="'$(XUnitClassName)' != ''">$(RunScriptCommand) -class $(XUnitClassName)</RunScriptCommand>

<!-- Add to run argument string -->
<RunScriptCommand>$(RunScriptCommand)$(_withCategories.Replace(';', ' -trait category='))</RunScriptCommand>
<RunScriptCommand>$(RunScriptCommand)$(_withoutCategories.Replace(';', ' -trait- category='))</RunScriptCommand>

<!-- User passed in options. -->
<RunScriptCommand Condition="'$(XUnitOptions)' != ''">$(RunScriptCommand) $(XUnitOptions)</RunScriptCommand>
</PropertyGroup>

<PropertyGroup Condition="'$(UseXunitExcludesTxtFile)' == 'true'">
<XunitExcludesTxtFileContent>$(_withoutCategories.Replace(';', '%0dcategory='))</XunitExcludesTxtFileContent>
</PropertyGroup>

<PropertyGroup Condition="'$(TestSingleFile)' == 'true' and '$(TargetsAppleMobile)' != 'true'">
<!-- Pass the results file -->
<RunScriptCommand>$(RunScriptCommand) -xml $(TestResultsName)</RunScriptCommand>
</PropertyGroup>

</Project>
12 changes: 8 additions & 4 deletions eng/testing/xunit/xunit.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
<!-- Microsoft.Net.Test.Sdk brings a lot of satellite assemblies in. -->
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<TestRunnerConfigPath>$(MSBuildThisFileDirectory)xunit.runner.json</TestRunnerConfigPath>
<OutputType Condition="'$(UseXUnitV3)' == 'true' and '$(TargetsMobile)' != 'true'">Exe</OutputType>
<!-- xUnit1051 recommends TestContext.Current.CancellationToken (v3 pattern) which
is not yet adopted; suppress until a full v3 migration is performed. -->
<NoWarn>$(NoWarn);xUnit1051</NoWarn>
</PropertyGroup>

<ItemGroup>
<!-- Excluding xunit.core/build as it enables deps file generation. -->
<PackageReference Include="xunit.core" Version="$(XUnitVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" ExcludeAssets="build" />
<PackageReference Include="xunit.core" Version="$(XUnitVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" ExcludeAssets="build" Condition="'$(UseXUnitV3)' != 'true'" />
<PackageReference Include="xunit.v3.core" Version="$(XUnitV3Version)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" ExcludeAssets="build" Condition="'$(UseXUnitV3)' == 'true'" />
<PackageReference Include="xunit.analyzers" Version="$(XUnitAnalyzersVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" />

<PackageReference Include="xunit.assert" Version="$(XUnitVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
<PackageReference Include="Microsoft.DotNet.XUnitAssert" Version="$(MicrosoftDotNetXUnitAssertVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
<PackageReference Include="xunit.assert" Version="$(XUnitVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp' and '$(UseXUnitV3)' != 'true'" />
<PackageReference Include="xunit.v3.assert" Version="$(XUnitV3Version)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" Condition="'$(UseXUnitV3)' == 'true'" />
<PackageReference Include="Microsoft.DotNet.XUnitAssert" Version="$(MicrosoftDotNetXUnitAssertVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(UseXUnitV3)' != 'true'" />

<PackageReference Include="Microsoft.DotNet.XUnitExtensions" Version="$(MicrosoftDotNetXUnitExtensionsVersion)" />
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" Version="$(MicrosoftDotNetXUnitExtensionsVersion)" Condition="'$(UseXUnitV3)' != 'true'" />
<PackageReference Include="Microsoft.DotNet.XUnitV3Extensions" Version="$(MicrosoftDotNetXUnitExtensionsVersion)" Condition="'$(UseXUnitV3)' == 'true'" />
<PackageReference Include="Microsoft.DotNet.RemoteExecutor" Version="$(MicrosoftDotNetRemoteExecutorVersion)" Condition="'$(IncludeRemoteExecutor)' == 'true'" />

<!--
Expand Down
14 changes: 13 additions & 1 deletion eng/testing/xunit/xunit.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,17 @@
<RunArguments>$(TargetPath) --settings:$(OutDir).runsettings</RunArguments>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)xunit.console.targets" />
<PropertyGroup Condition="'$(UseXUnitV3)' == 'true' and '$(TestSingleFile)' != 'true'">
<UseAppHost>false</UseAppHost>
</PropertyGroup>

<Target Name="_XunitValidateBuild"
BeforeTargets="BeforeBuild"
Condition="'$(UseXUnitV3)' == 'true' and '$(TargetFramework)' != ''">
<Error Text="xUnit.net v3 test projects must be executable (set project property '&lt;OutputType&gt;Exe&lt;/OutputType&gt;'). If this is not a test project, reference xunit.v3.extensibility.core instead."
Condition="'$(OutputType)' != 'Exe'" />
</Target>

<Import Project="$(MSBuildThisFileDirectory)xunit.console.targets" Condition="'$(UseXUnitV3)' != 'true'" />
<Import Project="$(MSBuildThisFileDirectory)xunit.console.v3.targets" Condition="'$(UseXUnitV3)' == 'true'" />
</Project>
10 changes: 10 additions & 0 deletions src/libraries/Common/tests/TestUtilities/RandomTestCaseOrderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
#if XUNIT_V3
using Xunit.v3;
#else
using Xunit.Abstractions;
#endif
using Xunit.Sdk;

namespace TestUtilities;
Expand Down Expand Up @@ -42,6 +46,12 @@ public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> t
? randomizedTests
: testCases;

public IReadOnlyCollection<TTestCase> OrderTestCases<TTestCase>(IReadOnlyCollection<TTestCase> testCases)
where TTestCase : notnull, ITestCase
=> TryRandomize(testCases.ToList(), _diagnosticMessageSink, out List<TTestCase>? randomizedTests)
? randomizedTests
: testCases;

public static bool TryRandomize<T>(List<T> tests, IMessageSink messageSink, [NotNullWhen(true)] out List<T>? randomizedTests)
{
randomizedTests = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
using System.Collections.Generic;
using System.Linq;
using Xunit;
#if XUNIT_V3
using Xunit.v3;
#else
using Xunit.Abstractions;
#endif
using Xunit.Sdk;

namespace TestUtilities;
Expand All @@ -24,4 +28,10 @@ public IEnumerable<ITestCollection> OrderTestCollections(IEnumerable<ITestCollec
=> RandomTestCaseOrderer.TryRandomize(testCollections.ToList(), _diagnosticMessageSink, out List<ITestCollection>? randomizedTests)
? randomizedTests
: testCollections;

public IReadOnlyCollection<TTestCollection> OrderTestCollections<TTestCollection>(IReadOnlyCollection<TTestCollection> testCollections)
where TTestCollection : ITestCollection
=> RandomTestCaseOrderer.TryRandomize(testCollections.ToList(), _diagnosticMessageSink, out List<TTestCollection>? randomizedTests)
? randomizedTests
: testCollections;
}
4 changes: 4 additions & 0 deletions src/libraries/Common/tests/TestUtilities/TestEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
using System.Diagnostics.Tracing;
using System.IO;
using System.Text;
#if XUNIT_V3
using Xunit;
#else
using Xunit.Abstractions;
#endif

namespace TestUtilities;

Expand Down
117 changes: 117 additions & 0 deletions src/libraries/Common/tests/TestUtilities/TestUtilities.Shared.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<Project>
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppMinimum);$(NetFrameworkCurrent)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- For some reason, xunit.core.props isn't excluded in VS and sets this to true. -->
<IsTestProject>false</IsTestProject>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)ILLink.Substitutions.AggressiveTrimming.xml"
LogicalName="ILLink.Substitutions.xml"
Condition="'$(EnableAggressiveTrimming)' == 'true'" />

<Compile Include="System\AdminHelpers.cs" />
<Compile Include="System\AssertExtensions.cs" />
<Compile Include="System\IO\StreamExtensions.cs" />
<Compile Include="System\IO\PathGenerator.cs" />
<Compile Include="System\RetryHelper.cs" />
<Compile Include="System\Buffers\BoundedMemory.cs" />
<Compile Include="System\Buffers\BoundedMemory.Creation.cs" />
<Compile Include="System\Buffers\BoundedMemory.Unix.cs" />
<Compile Include="System\Buffers\BoundedMemory.Windows.cs" />
<Compile Include="System\Buffers\BoundedMemory.Default.cs" />
<Compile Include="System\Buffers\PoisonPagePlacement.cs" />
<Compile Include="System\Runtime\InteropServices\SafeBufferUtil.cs" />
<Compile Include="System\IO\FileCleanupTestBase.cs" />
<Compile Include="System\LineEndingsHelper.cs" />
<Compile Include="System\TestEnvironment.cs" />
<Compile Include="System\ThreadCultureChange.cs" />
<Compile Include="System\AssemblyPathHelper.cs" />
<!-- We don't compile per but and instead use runtime platform checks. -->
<Compile Include="System\PlatformDetection.cs" />
<Compile Include="System\PlatformDetection.Unix.cs" />
<Compile Include="System\PlatformDetection.Windows.cs" />
<Compile Include="System\WindowsIdentityFixture.cs" />

<Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
Link="Common\System\Text\ValueStringBuilder.cs" />
<!--
Interop.Library is not designed to support runtime checks therefore we are picking the Windows
variant from the Common folder and adding the missing members manually.
-->
<Compile Include="Interop\Interop.Libraries.cs" />

<Compile Include="RandomTestCaseOrderer.cs" />
<Compile Include="RandomTestCollectionOrderer.cs" />

<Compile Include="TestEventListener.cs" />
</ItemGroup>

<!-- Windows imports -->
<ItemGroup>
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.CreateFile.cs"
Link="Common\Interop\Windows\Kernel32\Interop.CreateFile.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.FileOperations.cs"
Link="Common\Interop\Windows\Kernel32\Interop.FileOperations.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GetCurrentProcess.cs"
Link="Common\Interop\Windows\Kernel32\Interop.GetCurrentProcess.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GetFinalPathNameByHandle.cs"
Link="Common\Interop\Windows\Kernel32\Interop.GetFinalPathNameByHandle.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.SECURITY_ATTRIBUTES.cs"
Link="Common\Interop\Windows\Kernel32\Interop.SECURITY_ATTRIBUTES.cs" />
<Compile Include="$(CommonPath)Interop\Windows\NtDll\Interop.RtlGetVersion.cs"
Link="Common\Interop\Windows\NtDll\Interop.RtlGetVersion.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.OpenProcessToken.cs"
Link="Common\Interop\Windows\Advapi32\Interop.OpenProcessToken.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.CloseHandle.cs"
Link="Common\Interop\Windows\Kernel32\Interop.CloseHandle.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.TOKEN_INFORMATION_CLASS.cs"
Link="Common\Interop\Windows\Advapi32\Interop.TOKEN_INFORMATION_CLASS.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.GetTokenInformation_void.cs"
Link="Common\Interop\Windows\Advapi32\Interop.GetTokenInformation_void.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.TOKEN_ELEVATION.cs"
Link="Common\Interop\Windows\Advapi32\Interop.TOKEN_ELEVATION.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.BOOL.cs"
Link="Common\Interop\Windows\Interop.BOOL.cs" />

<Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\SafeTokenHandle.cs"
Link="Common\Microsoft\Win32\SafeHandles\SafeTokenHandle.cs"/>
<Compile Include="$(CommonPath)System\IO\PathInternal.Windows.cs"
Link="Common\System\IO\PathInternal.Windows.cs" />
</ItemGroup>

<!-- Unix imports -->
<ItemGroup>
<Compile Include="$(CommonPath)Interop\Unix\System.Security.Cryptography.Native\Interop.Initialization.cs"
Link="Common\Interop\Unix\System.Security.Cryptography.Native\Interop.Initialization.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslAvailable.cs"
Link="Common\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslAvailable.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslVersion.cs"
Link="Common\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslVersion.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslGetProtocolSupport.cs"
Link="Common\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslGetProtocolSupport.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetEUid.cs"
Link="Common\Interop\Unix\Interop.GetEUid.cs" />
</ItemGroup>

<!-- Android imports -->
<ItemGroup>
<Compile Include="$(CommonPath)Interop\Android\Interop.Libraries.cs"
Link="Common\Interop\Android\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Android\System.Security.Cryptography.Native.Android\Interop.Ssl.ProtocolSupport.cs"
Link="Common\Interop\Android\System.Security.Cryptography.Native.Android\Interop.Ssl.ProtocolSupport.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\CallerArgumentExpressionAttribute.cs"
Link="Common\System\Runtime\CompilerServices\CallerArgumentExpressionAttribute.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>TestUtilities</AssemblyName>
<RootNamespace>TestUtilities</RootNamespace>
<DefineConstants>$(DefineConstants);XUNIT_V3</DefineConstants>
</PropertyGroup>

<Import Project="TestUtilities.Shared.props" />

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.XUnitV3Extensions" Version="$(MicrosoftDotNetXUnitExtensionsVersion)" />
<PackageReference Include="xunit.v3.assert" Version="$(XUnitV3Version)" />
<PackageReference Include="xunit.v3.extensibility.core" Version="$(XUnitV3Version)" ExcludeAssets="build" />
</ItemGroup>

</Project>
Loading
Loading