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
Next Next commit
Import enum sources from XUnitExtensions and hook up support for some…
… basic cases of OS and runtime-specific filtering.
  • Loading branch information
jkoritzinsky authored and trylek committed Nov 4, 2021
commit 4f53c373b5c842b1ddda5a047c47587a0ab266b0
118 changes: 118 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis;

namespace XUnitWrapperGenerator;

interface ITestInfo
{
string ExecutionStatement { get; }
}

sealed class StaticFactMethod : ITestInfo
{
public StaticFactMethod(IMethodSymbol method)
{
ExecutionStatement = $"{method.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}.{method.Name}();";
}

public string ExecutionStatement { get; }

public override bool Equals(object obj)
{
return obj is StaticFactMethod other && ExecutionStatement == other.ExecutionStatement;
}
}

sealed class InstanceFactMethod : ITestInfo
{
public InstanceFactMethod(IMethodSymbol method)
{
ExecutionStatement = $"using ({method.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)} obj = new()) obj.{method.Name}();";
}

public string ExecutionStatement { get; }

public override bool Equals(object obj)
{
return obj is InstanceFactMethod other && ExecutionStatement == other.ExecutionStatement;
}
}

sealed class ConditionalTest : ITestInfo
{
public ConditionalTest(ITestInfo innerTest, string condition)
{
ExecutionStatement = $"if ({condition}) {{ {innerTest.ExecutionStatement} }}";
}

public string ExecutionStatement { get; }

public override bool Equals(object obj)
{
return obj is ConditionalTest other && ExecutionStatement == other.ExecutionStatement;
}
}

sealed class PlatformSpecificTest : ITestInfo
{
public PlatformSpecificTest(ITestInfo innerTest, Xunit.TestPlatforms platform)
{
List<string> platformCheckConditions = new();
if (platform.HasFlag(Xunit.TestPlatforms.Windows))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsWindows()");
}
if (platform.HasFlag(Xunit.TestPlatforms.Linux))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsLinux()");
}
if (platform.HasFlag(Xunit.TestPlatforms.OSX))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsMacOS()");
}
if (platform.HasFlag(Xunit.TestPlatforms.illumos))
{
platformCheckConditions.Add(@"global::System.OperatingSystem.IsOSPlatform(""illumos"")");
}
if (platform.HasFlag(Xunit.TestPlatforms.Solaris))
{
platformCheckConditions.Add(@"global::System.OperatingSystem.IsOSPlatform(""Solaris"")");
}
if (platform.HasFlag(Xunit.TestPlatforms.Android))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsAndroid()");
}
if (platform.HasFlag(Xunit.TestPlatforms.iOS))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsIOS()");
}
if (platform.HasFlag(Xunit.TestPlatforms.tvOS))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsAndroid()");
}
if (platform.HasFlag(Xunit.TestPlatforms.MacCatalyst))
{
platformCheckConditions.Add(@"global::System.OperatingSystem.IsOSPlatform(""maccatalyst"")");
}
if (platform.HasFlag(Xunit.TestPlatforms.Browser))
{
platformCheckConditions.Add(@"global::System.OperatingSystem.IsOSPlatform(""browser"")");
}
if (platform.HasFlag(Xunit.TestPlatforms.FreeBSD))
{
platformCheckConditions.Add(@"global::System.OperatingSystem.IsFreeBSD()");
}
if (platform.HasFlag(Xunit.TestPlatforms.NetBSD))
{
platformCheckConditions.Add(@"global::System.OperatingSystem.IsOSPlatform(""NetBSD"")");
}
ExecutionStatement = $"if ({string.Join(" || ", platformCheckConditions)}) {{ {innerTest.ExecutionStatement} }}";
}

public string ExecutionStatement { get; }
}

16 changes: 16 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/RuntimeConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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 RuntimeConfiguration
{
Any = ~0,
Checked = 1,
Debug = 1 << 1,
Release = 1 << 2
}
}
38 changes: 38 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/RuntimeTestModes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 RuntimeTestModes
{
// Disable always when using coreclr runtime.
Any = ~0,

// We're running regular tests with no runtime stress modes
RegularRun = 1,

// JitStress, JitStressRegs, JitMinOpts and TailcallStress enable
// various modes in the JIT that cause us to exercise more code paths,
// and generate different kinds of code
JitStress = 1 << 1, // COMPlus_JitStress is set.
JitStressRegs = 1 << 2, // COMPlus_JitStressRegs is set.
JitMinOpts = 1 << 3, // COMPlus_JITMinOpts is set.
TailcallStress = 1 << 4, // COMPlus_TailcallStress is set.

// ZapDisable says to not use NGEN or ReadyToRun images.
// This means we JIT everything.
ZapDisable = 1 << 5, // COMPlus_ZapDisable is set.

// GCStress3 forces a GC at various locations, typically transitions
// to/from the VM from managed code.
GCStress3 = 1 << 6, // COMPlus_GCStress includes mode 0x3.

// GCStressC forces a GC at every JIT-generated code instruction,
// including in NGEN/ReadyToRun code.
GCStressC = 1 << 7, // COMPlus_GCStress includes mode 0xC.
AnyGCStress = GCStress3 | GCStressC // Disable when any GCStress is exercised.
}
}
41 changes: 0 additions & 41 deletions src/tests/Common/XUnitWrapperGenerator/TestMethodInfo.cs

This file was deleted.

26 changes: 26 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/TestPlatforms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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
}
}
15 changes: 15 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/TestRuntimes.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
{
[Flags]
public enum TestRuntimes
{
CoreCLR = 1,
Mono = 2,
Any = ~0
}
}
Loading