Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1bbfc9c
Add a basic xunit runner generator that generates a top-level-stateme…
jkoritzinsky Oct 22, 2021
6523a11
Fix some bugs in the generator. Convert the Interop/PInvoke/Vector2_3…
jkoritzinsky Oct 22, 2021
6143a48
Implement support for [Fact] methods that are instance methods on IDi…
jkoritzinsky Oct 22, 2021
9b9ae95
Import enum sources from XUnitExtensions and hook up support for some…
jkoritzinsky Oct 25, 2021
54e93eb
Add one more newline
jkoritzinsky Oct 25, 2021
14ca067
Add preliminary support for building an IL test runner using the sour…
jkoritzinsky Oct 25, 2021
149ffe2
Rename to make the logic clearer.
jkoritzinsky Oct 25, 2021
23b7975
Update src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs
jkoritzinsky Oct 25, 2021
623cc48
Add support for extern-alias with references (to handle conflicting n…
jkoritzinsky Oct 26, 2021
a20864e
Apply suggestions from code review
jkoritzinsky Nov 2, 2021
4a7ebe9
Merge branch 'main' of github.com:dotnet/runtime into xunit-runner-ge…
jkoritzinsky Nov 2, 2021
f5009c8
Update src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs
jkoritzinsky Nov 2, 2021
59960aa
Add the XUnit wrapper generator to the list of ambient project depend…
trylek Nov 2, 2021
191ac42
Fix nullability bug in XUnitWrapperGenerator
trylek Nov 2, 2021
a2bdb78
Merge branch 'main' of github.com:dotnet/runtime into xunit-runner-ge…
jkoritzinsky Nov 3, 2021
e597fec
Merge branch 'main' of github.com:dotnet/runtime into xunit-runner-ge…
jkoritzinsky Nov 8, 2021
e783f9e
Write out the exception that caused the test to fail to the console.
jkoritzinsky Nov 8, 2021
c978193
Convert the Castable test to use the generator
jkoritzinsky Nov 8, 2021
270144b
Support running the xunit wrapper generator in "standalone" mode for …
jkoritzinsky Nov 8, 2021
4c73d6f
Add first draft of result reporting infrastructure.
jkoritzinsky Nov 8, 2021
e81deda
Fix IL .assembly directive to be the assembly name that can be resolv…
jkoritzinsky Nov 9, 2021
4f9dcbb
Add test reporting for "merged test runner" assemblies.
jkoritzinsky Nov 10, 2021
d5961f6
Add Microsoft.DotNet.XUnitExtensions to the targetting pack.
jkoritzinsky Nov 10, 2021
4d412d0
Add support for the rest of ActiveIssueAttribute
jkoritzinsky Nov 10, 2021
377b8a0
Add support for more attributes and clean up code.
jkoritzinsky Nov 10, 2021
835f56d
Add support for SkipOnCoreClrAttribute.
jkoritzinsky Nov 10, 2021
c84c5d1
Merge branch 'main' of github.com:dotnet/runtime into xunit-runner-ge…
jkoritzinsky Nov 10, 2021
b7fb243
Support running tests with the [Fact] attribute that return 100 for s…
jkoritzinsky Nov 10, 2021
d49c1f4
Fix failures and update comment
jkoritzinsky Nov 10, 2021
1b19bed
Update src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs
jkoritzinsky Nov 11, 2021
040877c
Fix handling of SkipOnCoreClrAttribute and SkipOnMonoAttribute with R…
jkoritzinsky Nov 11, 2021
d736995
Add support for running tests marked with <RequiresProcessIsolation>t…
jkoritzinsky Nov 12, 2021
a77d13c
Merge branch 'main' into xunit-runner-generator
jkoritzinsky Nov 12, 2021
04650fd
Add support for substring-based test filtering and add infrastructure…
jkoritzinsky Nov 15, 2021
8ef73bd
Integrate work from #61224 with some modifications based on offline d…
jkoritzinsky Nov 15, 2021
5881fa1
Fix Castable.csproj and fix SkipOnMono/SkipOnCoreCLR attribute support.
jkoritzinsky Nov 15, 2021
eccf29a
Work around tests that hit compiler limits. Move tests that used Xuni…
jkoritzinsky Nov 16, 2021
ccd08a2
Rewrite how superpmicollect sets up its testing to make it more frien…
jkoritzinsky Nov 16, 2021
db68ce4
Add back the _BuildSpmiTestProjectScripts target since I'm not sure w…
jkoritzinsky Nov 17, 2021
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
Add support for substring-based test filtering and add infrastructure…
… (but not actual support since I don't feel like writing a parser right now) for the full dotnet test --filter syntax.
  • Loading branch information
jkoritzinsky committed Nov 15, 2021
commit 04650fdf63fc9a0bdeba5ce90f6c0b1f79c04d7f
20 changes: 19 additions & 1 deletion src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace XUnitWrapperGenerator;
interface ITestInfo
{
string TestNameExpression { get; }
string DisplayNameForFiltering { get; }
string Method { get; }
string ContainingType { get; }

Expand All @@ -33,6 +34,7 @@ public BasicTestMethod(IMethodSymbol method, string externAlias, ImmutableArray<
var args = arguments.IsDefaultOrEmpty ? "" : string.Join(", ", arguments);
ContainingType = method.ContainingType.ToDisplayString(XUnitWrapperGenerator.FullyQualifiedWithoutGlobalNamespace);
Method = method.Name;
DisplayNameForFiltering = $"{ContainingType}.{Method}({args})";
TestNameExpression = displayNameExpression ?? $"\"{externAlias}::{ContainingType}.{Method}({args})\"";
if (method.IsStatic)
{
Expand All @@ -45,6 +47,7 @@ public BasicTestMethod(IMethodSymbol method, string externAlias, ImmutableArray<
}

public string TestNameExpression { get; }
public string DisplayNameForFiltering { get; }
public string Method { get; }
public string ContainingType { get; }
private string ExecutionStatement { get; }
Expand All @@ -69,10 +72,13 @@ public LegacyStandaloneEntryPointTestMethod(IMethodSymbol method, string externA
ContainingType = method.ContainingType.ToDisplayString(XUnitWrapperGenerator.FullyQualifiedWithoutGlobalNamespace);
Method = method.Name;
TestNameExpression = $"\"{externAlias}::{ContainingType}.{Method}()\"";
DisplayNameForFiltering = $"{ContainingType}.{Method}()";
ExecutionStatement = $"Xunit.Assert.Equal(100, {externAlias}::{ContainingType}.{Method}());";
}

public string TestNameExpression { get; }
public string DisplayNameForFiltering { get; }

public string Method { get; }
public string ContainingType { get; }
private string ExecutionStatement { get; }
Expand Down Expand Up @@ -100,6 +106,7 @@ public ConditionalTest(ITestInfo innerTest, string condition)
_innerTest = innerTest;
_condition = condition;
TestNameExpression = innerTest.TestNameExpression;
DisplayNameForFiltering = innerTest.DisplayNameForFiltering;
Method = innerTest.Method;
ContainingType = innerTest.ContainingType;
}
Expand All @@ -110,6 +117,9 @@ public ConditionalTest(ITestInfo innerTest, Xunit.TestPlatforms platform)
}

public string TestNameExpression { get; }

public string DisplayNameForFiltering { get; }

public string Method { get; }
public string ContainingType { get; }

Expand Down Expand Up @@ -193,6 +203,7 @@ public MemberDataTest(ISymbol referencedMember, ITestInfo innerTest, string exte
TestNameExpression = innerTest.TestNameExpression;
Method = innerTest.Method;
ContainingType = innerTest.ContainingType;
DisplayNameForFiltering = $"{ContainingType}.{Method}(...)";
_innerTest = innerTest;
_loopVarIdentifier = argumentLoopVarIdentifier;

Expand All @@ -206,6 +217,7 @@ public MemberDataTest(ISymbol referencedMember, ITestInfo innerTest, string exte
}

public string TestNameExpression { get; }
public string DisplayNameForFiltering { get; }
public string Method { get; }
public string ContainingType { get; }

Expand Down Expand Up @@ -234,12 +246,15 @@ sealed class OutOfProcessTest : ITestInfo
public OutOfProcessTest(string displayName, string relativeAssemblyPath)
{
Method = displayName;
DisplayNameForFiltering = displayName;
TestNameExpression = $"@\"{displayName}\"";
ExecutionStatement = $@"TestLibrary.OutOfProcessTest.RunOutOfProcessTest(typeof(Program).Assembly.Location, @""{relativeAssemblyPath}"");";
}

public string TestNameExpression { get; }

public string DisplayNameForFiltering { get; }

public string Method { get; }

public string ContainingType => "OutOfProcessTest";
Expand All @@ -259,15 +274,18 @@ sealed class NoTestReporting : ITestReporterWrapper
sealed class WrapperLibraryTestSummaryReporting : ITestReporterWrapper
{
private string _summaryLocalIdentifier;
private readonly string _filterLocalIdentifier;

public WrapperLibraryTestSummaryReporting(string summaryLocalIdentifier)
public WrapperLibraryTestSummaryReporting(string summaryLocalIdentifier, string filterLocalIdentifier)
{
_summaryLocalIdentifier = summaryLocalIdentifier;
_filterLocalIdentifier = filterLocalIdentifier;
}

public string WrapTestExecutionWithReporting(string testExecutionExpression, ITestInfo test)
{
StringBuilder builder = new();
builder.AppendLine($"if ({_filterLocalIdentifier} is null || {_filterLocalIdentifier}.ShouldRunTest(@\"{test.ContainingType}.{test.Method}\", {test.TestNameExpression}))");
builder.AppendLine("{");

builder.AppendLine($"TimeSpan testStart = stopwatch.Elapsed;");
Expand Down
3 changes: 3 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/OptionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class OptionsHelper
private const string PriorityOption = "build_property.Priority";
private const string RuntimeFlavorOption = "build_property.RuntimeFlavor";
private const string IsOutOfProcessTestAssemblyOption = "build_metadata.AdditionalFiles.IsOutOfProcessTestAssembly";
private const string TestFilterOption = "build_metadata.AdditionalFiles.TestFilter";
private const string TestAssemblyRelativePathOption = "build_metadata.AdditionalFiles.TestAssemblyRelativePath";
private const string TestDisplayNameOption = "build_metadata.AdditionalFiles.TestDisplayName";

Expand Down Expand Up @@ -38,6 +39,8 @@ private static bool GetBoolOption(this AnalyzerConfigOptions options, string key

internal static bool IsOutOfProcessTestAssembly(this AnalyzerConfigOptions options) => options.GetBoolOption(IsOutOfProcessTestAssemblyOption);

internal static string? TestFilter(this AnalyzerConfigOptions options) => options.TryGetValue(TestFilterOption, out string? filter) ? filter : null;

internal static string? TestAssemblyRelativePath(this AnalyzerConfigOptions options) => options.TryGetValue(TestAssemblyRelativePathOption, out string? flavor) ? flavor : null;

internal static string? TestDisplayName(this AnalyzerConfigOptions options) => options.TryGetValue(TestDisplayNameOption, out string? flavor) ? flavor : null;
Expand Down
13 changes: 10 additions & 3 deletions src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
.Collect()
.Combine(outOfProcessTests.Collect())
.Select((tests, ct) => tests.Left.AddRange(tests.Right))
.Combine(aliasMap)
.Combine(context.AnalyzerConfigOptionsProvider)
.Select((data, ct) =>
{
var (tests, options) = data;
var filter = new XUnitWrapperLibrary.TestFilter(options.GlobalOptions.TestFilter() ?? "");
return (ImmutableArray.CreateRange(tests.Where(test => filter.ShouldRunTest($"{test.ContainingType}.{test.Method}", test.DisplayNameForFiltering, Array.Empty<string>()))), options);
})
.Combine(aliasMap)
.Combine(assemblyName),
static (context, data) =>
{
var (((methods, aliasMap), configOptions), assemblyName) = data;
var (((methods, configOptions), aliasMap), assemblyName) = data;

bool referenceCoreLib = configOptions.GlobalOptions.ReferenceSystemPrivateCoreLib();

Expand All @@ -103,9 +109,10 @@ private static string GenerateFullTestRunner(ImmutableArray<ITestInfo> testInfos
{
// For simplicity, we'll use top-level statements for the generated Main method.
StringBuilder builder = new();
ITestReporterWrapper reporter = new WrapperLibraryTestSummaryReporting("summary");
ITestReporterWrapper reporter = new WrapperLibraryTestSummaryReporting("summary", "filter");
builder.AppendLine(string.Join("\n", aliasMap.Values.Where(alias => alias != "global").Select(alias => $"extern alias {alias};")));

builder.AppendLine("XUnitWrapperLibrary.TestFilter filter = args.Length != 0 ? new XUnitWrapperLibrary.TestFilter(args[0]) : null;");
builder.AppendLine("XUnitWrapperLibrary.TestSummary summary = new();");
builder.AppendLine("System.Diagnostics.Stopwatch stopwatch = new();");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersion)" />
</ItemGroup>

<ItemGroup>
<Compile Include="../XUnitWrapperLibrary/TestFilter.cs" Link="TestFilter.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<!-- Properties that influence test harness generation -->
<CompilerVisibleProperty Include="ReferenceSystemPrivateCoreLib" />
<CompilerVisibleProperty Include="IsMergedTestRunnerAssembly" />
<CompilerVisibleProperty Include="TestFilter" />
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="IsOutOfProcessTestAssembly" />
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="TestAssemblyRelativePath" />
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="TestDisplayName" />
Expand Down
103 changes: 103 additions & 0 deletions src/tests/Common/XUnitWrapperLibrary/TestFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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 System.Text;
namespace XUnitWrapperLibrary;

public class TestFilter
{
interface ISearchClause
{
bool IsMatch(string fullyQualifiedName, string displayName, string[] traits);
}

enum TermKind
{
FullyQualifiedName,
DisplayName
}
sealed class NameClause : ISearchClause
{
public NameClause(TermKind kind, string filter, bool substring)
{
Kind = kind;
Filter = filter;
Substring = substring;
}
public TermKind Kind { get; }
public string Filter { get; }
public bool Substring { get; }

public bool IsMatch(string fullyQualifiedName, string displayName, string[] traits)
{
string stringToSearch = Kind switch
{
TermKind.FullyQualifiedName => fullyQualifiedName,
TermKind.DisplayName => displayName,
_ => throw new InvalidOperationException()
};

if (Substring)
{
return stringToSearch.Contains(Filter);
}
return stringToSearch == Filter;
}
}

sealed class AndClause : ISearchClause
{
private ISearchClause _left;
private ISearchClause _right;

public AndClause(ISearchClause left, ISearchClause right)
{
_left = left;
_right = right;
}

public bool IsMatch(string fullyQualifiedName, string displayName, string[] traits) => _left.IsMatch(fullyQualifiedName, displayName, traits) && _right.IsMatch(fullyQualifiedName, displayName, traits);
}

sealed class OrClause : ISearchClause
{
private ISearchClause _left;
private ISearchClause _right;

public OrClause(ISearchClause left, ISearchClause right)
{
_left = left;
_right = right;
}

public bool IsMatch(string fullyQualifiedName, string displayName, string[] traits) => _left.IsMatch(fullyQualifiedName, displayName, traits) || _right.IsMatch(fullyQualifiedName, displayName, traits);
}

sealed class NotClause : ISearchClause
{
private ISearchClause _inner;

public NotClause(ISearchClause inner)
{
_inner = inner;
}

public bool IsMatch(string fullyQualifiedName, string displayName, string[] traits) => !_inner.IsMatch(fullyQualifiedName, displayName, traits);
}

private ISearchClause? _filter;

public TestFilter(string filterString)
{
if (filterString.IndexOfAny(new[] { '!', '(', ')', '~', '=' }) != -1)
{
throw new ArgumentException("Complex test filter expressions are not supported today. The only filters supported today are the simple form supported in 'dotnet test --filter' (substrings of the test's fully qualified name). If further filtering options are desired, file an issue on dotnet/runtime for support.", nameof(filterString));
}
_filter = new NameClause(TermKind.FullyQualifiedName, filterString, substring: true);
}

public bool ShouldRunTest(string fullyQualifiedName, string displayName, string[]? traits = null) => _filter is null ? true : _filter.IsMatch(fullyQualifiedName, displayName, traits ?? Array.Empty<string>());
}