-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run all cohosting tests with FUSE on and off #11330
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6013045
Create test infra for running all tests on fuse and non-fuse
davidwengier 1a8a188
Run all cohost tests with FUSE and non-FUSE
davidwengier 21b055b
Automatically compile Razor files in tests.
davidwengier 0aff97d
Skip folding range tests due to whitespace differences
davidwengier dec3b3c
Skip semantic tokens test on FUSE due to differences
davidwengier 115eca9
Fix ExtractToCodeBehind tests
davidwengier ec8615f
Output semi-colon before switching back to hidden line directives
davidwengier a5c9f5d
Add extra test to validate the things that don't need to get skipped …
davidwengier a123a9b
PR feedback
davidwengier 1403312
Merge remote-tracking branch 'upstream/main' into CohostTestsOnFuse
davidwengier 36068f6
Merge remote-tracking branch 'upstream/main' into CohostTestsOnFuse
davidwengier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Fuse/FuseFactAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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 Xunit; | ||
using Xunit.Sdk; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Test.Common; | ||
|
||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | ||
[XunitTestCaseDiscoverer($"Microsoft.AspNetCore.Razor.Test.Common.{nameof(FuseFactDiscoverer)}", "Microsoft.AspNetCore.Razor.Test.Common")] | ||
internal sealed class FuseFactAttribute : FactAttribute | ||
{ | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Fuse/FuseFactDiscoverer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Test.Common; | ||
|
||
internal sealed class FuseFactDiscoverer(IMessageSink diagnosticMessageSink) | ||
: FactDiscoverer(diagnosticMessageSink) | ||
{ | ||
public override IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) | ||
{ | ||
return CreateTestCases(discoveryOptions, testMethod, DiagnosticMessageSink); | ||
} | ||
|
||
public static IEnumerable<IXunitTestCase> CreateTestCases(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IMessageSink messageSink, object[]? dataRow = null) | ||
{ | ||
yield return CreateTestCase(forceRuntimeCodeGeneration: false); | ||
yield return CreateTestCase(forceRuntimeCodeGeneration: true); | ||
|
||
FuseTestCase CreateTestCase(bool forceRuntimeCodeGeneration) | ||
{ | ||
return new FuseTestCase(forceRuntimeCodeGeneration, messageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, dataRow); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Fuse/FuseTestCase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// 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.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Test.Common; | ||
|
||
internal sealed class FuseTestCase : XunitTestCase | ||
{ | ||
private bool _forceRuntimeCodeGeneration; | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] | ||
public FuseTestCase() { } | ||
|
||
public FuseTestCase(bool forceRuntimeCodeGeneration, IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod, object[]? testMethodArguments = null) | ||
: base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments) | ||
{ | ||
_forceRuntimeCodeGeneration = forceRuntimeCodeGeneration; | ||
} | ||
|
||
protected override string GetDisplayName(IAttributeInfo factAttribute, string displayName) | ||
{ | ||
return base.GetDisplayName(factAttribute, displayName) + (_forceRuntimeCodeGeneration ? " (FUSE)" : ""); | ||
} | ||
|
||
protected override string GetSkipReason(IAttributeInfo factAttribute) | ||
{ | ||
if (_forceRuntimeCodeGeneration && TestMethod.TestClass.TestCollection.TestAssembly.Assembly.Name.StartsWith("Microsoft.AspNetCore.Razor.LanguageServer")) | ||
{ | ||
return "Language server cannot run FUSE tests"; | ||
} | ||
|
||
return base.GetSkipReason(factAttribute); | ||
} | ||
|
||
public override Task<RunSummary> RunAsync(IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) | ||
{ | ||
Debug.Assert(constructorArguments.Length >= 1 && constructorArguments[0] is FuseTestContext, $"{TestMethod.TestClass.Class.Name}.{TestMethod.Method.Name} uses a formatting test attribute in a class without a FuseTestContext parameter?"); | ||
constructorArguments[0] = new FuseTestContext | ||
{ | ||
ForceRuntimeCodeGeneration = _forceRuntimeCodeGeneration | ||
}; | ||
return base.RunAsync(diagnosticMessageSink, messageBus, constructorArguments, aggregator, cancellationTokenSource); | ||
} | ||
|
||
public override void Deserialize(IXunitSerializationInfo data) | ||
{ | ||
_forceRuntimeCodeGeneration = data.GetValue<bool>(nameof(_forceRuntimeCodeGeneration)); | ||
base.Deserialize(data); | ||
} | ||
|
||
public override void Serialize(IXunitSerializationInfo data) | ||
{ | ||
data.AddValue(nameof(_forceRuntimeCodeGeneration), _forceRuntimeCodeGeneration); | ||
base.Serialize(data); | ||
} | ||
|
||
protected override string GetUniqueID() | ||
{ | ||
return base.GetUniqueID() + (_forceRuntimeCodeGeneration ? "FUSE" : "NOFUSE"); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Fuse/FuseTestContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Razor.Test.Common; | ||
|
||
public sealed class FuseTestContext | ||
{ | ||
public required bool ForceRuntimeCodeGeneration { get; init; } | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Fuse/FuseTheoryAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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 Xunit; | ||
using Xunit.Sdk; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Test.Common; | ||
|
||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | ||
[XunitTestCaseDiscoverer($"Microsoft.AspNetCore.Razor.Test.Common.{nameof(FuseTheoryDiscoverer)}", "Microsoft.AspNetCore.Razor.Test.Common")] | ||
internal sealed class FuseTheoryAttribute : TheoryAttribute | ||
{ | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Fuse/FuseTheoryDiscoverer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Collections.Generic; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Test.Common; | ||
|
||
internal sealed class FuseTheoryDiscoverer(IMessageSink diagnosticMessageSink) | ||
: TheoryDiscoverer(diagnosticMessageSink) | ||
{ | ||
public override IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) | ||
{ | ||
// We have to force pre-enumeration of theories for this discoverer to work correctly. Normally its true in VS, | ||
// but false in command line/CI. Since we're injecting "fake" data rows, we rely on it everywhere. Without this | ||
// set to true, the method below that we override doesn't get called. | ||
discoveryOptions.SetValue("xunit.discovery.PreEnumerateTheories", true); | ||
return base.Discover(discoveryOptions, testMethod, theoryAttribute); | ||
} | ||
|
||
protected override IEnumerable<IXunitTestCase> CreateTestCasesForDataRow(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute, object[] dataRow) | ||
{ | ||
return FuseFactDiscoverer.CreateTestCases(discoveryOptions, testMethod, DiagnosticMessageSink, dataRow); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we know that a formatting test attribute is getting used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking, we don't, but instances of this test case are only created by the discoverer for those attributes. If we could actually know for sure, then this assert wouldn't be needed.