Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add build script logic to facilitate the test switchover to [Fact] style
This change is based on Jeremy's POC PR; I have modified the build
scripts to minimize the changes to the individual test build scripts.
In the simplest case the conversion requires just replacing the Main
method with a [Fact]-marked test entrypoint and removing the
OutputType property from the project file.

Empty OutputType property gets automatically replaced with the Library
default in the SDK scripts; this is not a huge deal but I had to
remove the pre-existing hack of OutputType=Library + CLRTestKind=""
implying SharedLibrary. According to my search most Library projects
already have the SharedLibrary CLRTestKind set, for the rest I plan
to set it using a bulk project modification; I think I should be able
to adapt the ILTransform analyzer for this purpose.

Thanks

Tomas
  • Loading branch information
trylek committed Nov 4, 2021
commit e23a75b73bad943f6dcf19e4aef44005e1fb0466
4 changes: 4 additions & 0 deletions src/tests/Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<Compile Include="Utilities.cs" />
<Compile Include="HostPolicyMock.cs" />
<Compile Include="XPlatformUtils.cs" />

<!-- xUnit-style attribute support -->
<Compile Include="SkipOnPlatformAttribute.cs" />
<Compile Include="TestPlatforms.cs" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions src/tests/Common/CoreCLRTestLibrary/SkipOnPlatformAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

using System;

namespace Xunit
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class SkipOnPlatformAttribute : Attribute
{
internal SkipOnPlatformAttribute() { }
public SkipOnPlatformAttribute(TestPlatforms testPlatforms, string reason) { }
}
}
27 changes: 27 additions & 0 deletions src/tests/Common/CoreCLRTestLibrary/TestPlatforms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

using System;

namespace Xunit
{
[Flags]
public enum TestPlatforms
{
Windows = 1,
Linux = 2,
OSX = 4,
FreeBSD = 8,
NetBSD = 16,
illumos= 32,
Solaris = 64,
iOS = 128,
tvOS = 256,
Android = 512,
Browser = 1024,
MacCatalyst = 2048,
AnyUnix = FreeBSD | Linux | NetBSD | OSX | illumos | Solaris | iOS | tvOS | MacCatalyst | Android | Browser,
Any = ~0
}
}
14 changes: 13 additions & 1 deletion src/tests/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@

<!-- Default priority building values. -->
<PropertyGroup>
<CLRTestKind Condition="'$(CLRTestKind)' == '' and '$(OutputType)' == 'Library'">SharedLibrary</CLRTestKind>
<CLRTestKind Condition="'$(CLRTestKind)' == ''">BuildAndRun</CLRTestKind>
<CLRTestPriority Condition="'$(CLRTestPriority)' == ''">0</CLRTestPriority>

<IsFactStyleTest>false</IsFactStyleTest>
<IsFactStyleTest Condition="'$(OutputType)' == 'Library' and '$(CLRTestKind)' == 'BuildAndRun'">true</IsFactStyleTest>

<!-- Switch OutputType to exe, otherwise Roslyn fails to compile the Main method in the generated wrapper -->
<OutputType Condition="$(IsFactStyleTest)">exe</OutputType>
</PropertyGroup>

<!-- All CLRTests need to be of a certain "kind". These kinds are enumerated below.
Expand Down Expand Up @@ -74,6 +79,13 @@
</ProjectReference>
</ItemGroup>

<!-- Inject the XUnit wrapper generator into test build for [Fact]-style tests -->
<ItemGroup Condition="$(IsFactStyleTest)">
<ProjectReference Include="$(MSBuildThisFileDirectory)/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<Import Project="Common/XUnitWrapperGenerator/XUnitWrapperGenerator.props" Condition="$(IsFactStyleTest)" />

Comment on lines +82 to +88
Copy link
Member

Choose a reason for hiding this comment

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

We can reference the generator and import the MSBuild file for all tests. The generator should be a no-op for non-Fact-style tests. If it isn't, I can make changes to the generator to fix that.

<!-- Determine if this project should be built or not -->
<PropertyGroup>
<BuildAllProjects Condition="'$(BuildAllProjects)' == ''">false</BuildAllProjects>
Expand Down
29 changes: 0 additions & 29 deletions src/tests/Interop/PInvoke/Decimal/DecimalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,6 @@
using TestLibrary;
using FactAttribute = Xunit.FactAttribute;

namespace Xunit
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class SkipOnPlatformAttribute : Attribute
{
internal SkipOnPlatformAttribute() { }
public SkipOnPlatformAttribute(TestPlatforms testPlatforms, string reason) { }
}

[Flags]
public enum TestPlatforms
{
Windows = 1,
Linux = 2,
OSX = 4,
FreeBSD = 8,
NetBSD = 16,
illumos= 32,
Solaris = 64,
iOS = 128,
tvOS = 256,
Android = 512,
Browser = 1024,
MacCatalyst = 2048,
AnyUnix = FreeBSD | Linux | NetBSD | OSX | illumos | Solaris | iOS | tvOS | MacCatalyst | Android | Browser,
Any = ~0
}
}

public class DecimalTest
{
private const int StartingIntValue = 42;
Expand Down
6 changes: 0 additions & 6 deletions src/tests/Interop/PInvoke/Decimal/DecimalTest.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Include="*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="CMakeLists.txt" />
<ProjectReference Include="$(RepoRoot)/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<Import Project="$(RepoRoot)/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.props" />
</Project>