-
Notifications
You must be signed in to change notification settings - Fork 307
Add SourceGen + Engine #4966
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
Merged
Merged
Add SourceGen + Engine #4966
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,2 @@ | ||
| [*.{cs,vb}] | ||
| file_header_template = Copyright (c) Microsoft Corporation. All rights reserved.\nLicensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information. |
88 changes: 88 additions & 0 deletions
88
src/Adapter/MSTest.Engine/Assertions/AssertFailedException.cs
This file contains hidden or 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,88 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information. | ||
|
|
||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Microsoft.Testing.Framework; | ||
|
|
||
| /// <summary> | ||
| /// AssertFailedException class. Used to indicate failure for a test case. | ||
| /// </summary> | ||
| [Serializable] | ||
| public sealed class AssertFailedException : Exception | ||
| { | ||
| /// <summary> | ||
| /// Creates AssertFailedException with a given message and metadata. | ||
| /// </summary> | ||
| /// <param name="message">Message to be reported to the user.</param> | ||
| /// <returns>AssertFailedException.</returns> | ||
| internal static AssertFailedException Create(string message) => CreateInternal(message, expected: null, actual: null); | ||
|
|
||
| /// <summary> | ||
| /// Creates AssertFailedException with a given message and metadata. | ||
| /// </summary> | ||
| /// <param name="message">Message to be reported to the user, it may, or may not include the values that were compared. If values are not included provide them to 'expected' and 'actual'.</param> | ||
| /// <param name="expected">The expected value, when that value is complex, and diffing it to actual makes it easier for user to see the difference.</param> | ||
| /// <param name="actual">The actual value, when that value is complex, and diffing it to expected makes it easier for user to see the difference.</param> | ||
| /// <returns>AssertFailedException.</returns> | ||
| internal static AssertFailedException Create(string message, string expected, string actual) => CreateInternal(message, expected, actual); | ||
|
|
||
| private static AssertFailedException CreateInternal(string message, string? expected, string? actual) | ||
| { | ||
| #pragma warning disable SYSLIB0051 // Type or member is obsolete | ||
| var ex = new AssertFailedException(message); | ||
| #pragma warning restore SYSLIB0051 // Type or member is obsolete | ||
|
|
||
| if (expected != null) | ||
| { | ||
| ex.Data["assert.expected"] = expected; | ||
| } | ||
|
|
||
| if (actual != null) | ||
| { | ||
| ex.Data["assert.actual"] = actual; | ||
| } | ||
|
|
||
| return ex; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AssertFailedException"/> class. | ||
| /// </summary> | ||
| #if NET8_0_OR_GREATER | ||
| [Obsolete("Use Create instead", DiagnosticId = "SYSLIB0051")] | ||
| #endif | ||
| public AssertFailedException() | ||
| : base() | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AssertFailedException"/> class. | ||
| /// </summary> | ||
| /// <param name="message">The exception message.</param> | ||
| #if NET8_0_OR_GREATER | ||
| [Obsolete("Use Create instead", DiagnosticId = "SYSLIB0051")] | ||
| #endif | ||
| public AssertFailedException(string message) | ||
| : base(message) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AssertFailedException"/> class. | ||
| /// </summary> | ||
| /// <param name="message">The exception message.</param> | ||
| /// <param name="ex">The inner exception.</param> | ||
| #if NET8_0_OR_GREATER | ||
| [Obsolete("Use Create instead", DiagnosticId = "SYSLIB0051")] | ||
| #endif | ||
|
Evangelink marked this conversation as resolved.
|
||
| public AssertFailedException(string message, Exception ex) | ||
| : base(message, ex) | ||
| { | ||
| } | ||
|
|
||
| private AssertFailedException(SerializationInfo serializationInfo, StreamingContext streamingContext) | ||
| { | ||
| } | ||
| } |
This file contains hidden or 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,6 @@ | ||
| M:System.Threading.Tasks.Task.Run(System.Action,System.Threading.CancellationToken); Use 'ITask' instead | ||
| M:System.Threading.Tasks.Task.Run(System.Func{System.Threading.Tasks.Task},System.Threading.CancellationToken); Use 'ITask' instead | ||
| M:System.String.IsNullOrEmpty(System.String); Use 'RoslynString.IsNullOrEmpty' instead | ||
| M:System.String.IsNullOrWhiteSpace(System.String); Use 'RoslynString.IsNullOrWhiteSpace' instead | ||
| M:System.Diagnostics.Debug.Assert(System.Boolean); Use 'RoslynDebug.Assert' instead | ||
| M:System.Diagnostics.Debug.Assert(System.Boolean,System.String); Use 'RoslynDebug.Assert' instead |
17 changes: 17 additions & 0 deletions
17
src/Adapter/MSTest.Engine/Configurations/ConfigurationExtensions.cs
This file contains hidden or 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,17 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information. | ||
|
|
||
| using Microsoft.Testing.Platform.Configurations; | ||
|
|
||
| namespace Microsoft.Testing.Framework.Configurations; | ||
|
|
||
| public static class ConfigurationExtensions | ||
| { | ||
| public static string GetTestResultDirectory(this IConfiguration configuration) | ||
| => GetConfigurationWrapper(configuration).WrappedConfiguration.GetTestResultDirectory(); | ||
|
|
||
| private static ConfigurationWrapper GetConfigurationWrapper(IConfiguration configuration) | ||
| => configuration is not ConfigurationWrapper configurationWrapper | ||
| ? throw new ArgumentException("Current configuration is not of expected type", nameof(configuration)) | ||
| : configurationWrapper; | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/Adapter/MSTest.Engine/Configurations/ConfigurationWrapper.cs
This file contains hidden or 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,20 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information. | ||
|
|
||
| using PlatformIConfiguration = Microsoft.Testing.Platform.Configurations.IConfiguration; | ||
|
|
||
| namespace Microsoft.Testing.Framework.Configurations; | ||
|
|
||
| /// <summary> | ||
| /// Wraps a platform IConfiguration instance. This is preferable as it allows us to avoid being dependent | ||
| /// on Platform if we need some specific API change. | ||
| /// </summary> | ||
| internal sealed class ConfigurationWrapper : IConfiguration | ||
| { | ||
| public ConfigurationWrapper(PlatformIConfiguration configuration) | ||
| => WrappedConfiguration = configuration; | ||
|
|
||
| internal PlatformIConfiguration WrappedConfiguration { get; } | ||
|
|
||
| public string? this[string key] => WrappedConfiguration[key]; | ||
| } |
This file contains hidden or 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 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.Testing.Framework.Configurations; | ||
|
|
||
| public interface IConfiguration | ||
| { | ||
| string? this[string key] { get; } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/Adapter/MSTest.Engine/Configurations/TestFrameworkConfiguration.cs
This file contains hidden or 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 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.Testing.Framework.Configurations; | ||
|
|
||
| public sealed class TestFrameworkConfiguration(int maxParallelTests = int.MaxValue) | ||
| { | ||
| public int MaxParallelTests { get; } = maxParallelTests; | ||
| } |
This file contains hidden or 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,122 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information. | ||
|
|
||
| using System.Web; | ||
|
|
||
| using Microsoft.Testing.Framework.Helpers; | ||
| using Microsoft.Testing.Platform.Extensions.Messages; | ||
| using Microsoft.Testing.Platform.Requests; | ||
|
|
||
| namespace Microsoft.Testing.Framework; | ||
|
|
||
| #pragma warning disable TPEXP // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
| internal sealed class BFSTestNodeVisitor | ||
| { | ||
| private readonly IEnumerable<TestNode> _rootTestNodes; | ||
| private readonly ITestExecutionFilter _testExecutionFilter; | ||
| private readonly TestArgumentsManager _testArgumentsManager; | ||
|
|
||
| public BFSTestNodeVisitor(IEnumerable<TestNode> rootTestNodes, ITestExecutionFilter testExecutionFilter, | ||
| TestArgumentsManager testArgumentsManager) | ||
| { | ||
| if (testExecutionFilter is not TreeNodeFilter and not TestNodeUidListFilter and not NopFilter) | ||
| { | ||
| throw new ArgumentOutOfRangeException(nameof(testExecutionFilter)); | ||
| } | ||
|
|
||
| _rootTestNodes = rootTestNodes; | ||
| _testExecutionFilter = testExecutionFilter; | ||
| _testArgumentsManager = testArgumentsManager; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Process a test node found during tree traversal. | ||
| /// </summary> | ||
| /// <param name="node">The test node found.</param> | ||
| /// <param name="parentNodeUid">The UID of the node's parent.</param> | ||
| /// <param name="nodeFullPath">The tree full path to get to the node.</param> | ||
| /// <returns>A collection of additional test nodes to visit resulting from the processing of the node.</returns> | ||
| internal delegate ICollection<TestNode> TestNodeProcessor(TestNode node, TestNodeUid? parentNodeUid, string nodeFullPath); | ||
|
|
||
| internal KeyValuePair<TestNodeUid, List<TestNode>>[] DuplicatedNodes { get; private set; } = Array.Empty<KeyValuePair<TestNodeUid, List<TestNode>>>(); | ||
|
|
||
| public async Task VisitAsync(Func<TestNode, TestNodeUid?, Task> onIncludedTestNodeAsync) | ||
| { | ||
| // This is case sensitive, and culture insensitive, to keep UIDs unique, and comparable between different system. | ||
| Dictionary<TestNodeUid, List<TestNode>> testNodesByUid = new(); | ||
| Queue<(TestNode CurrentNode, TestNodeUid? ParentNodeUid, StringBuilder NodeFullPath)> queue = new(); | ||
| foreach (TestNode node in _rootTestNodes) | ||
| { | ||
| queue.Enqueue((node, null, new())); | ||
| } | ||
|
|
||
| while (queue.Count > 0) | ||
| { | ||
| (TestNode currentNode, TestNodeUid? parentNodeUid, StringBuilder nodeFullPath) = queue.Dequeue(); | ||
|
|
||
| if (!testNodesByUid.TryGetValue(currentNode.StableUid, out List<TestNode>? testNodes)) | ||
| { | ||
| testNodes = new(); | ||
| testNodesByUid.Add(currentNode.StableUid, testNodes); | ||
| } | ||
|
|
||
| testNodes.Add(currentNode); | ||
|
|
||
| StringBuilder nodeFullPathForChildren = new StringBuilder().Append(nodeFullPath); | ||
|
|
||
| if (nodeFullPathForChildren.Length == 0 | ||
| || nodeFullPathForChildren[^1] != TreeNodeFilter.PathSeparator) | ||
| { | ||
| nodeFullPathForChildren.Append(TreeNodeFilter.PathSeparator); | ||
| } | ||
|
|
||
| // We want to encode the path fragment to avoid conflicts with the separator. We are using URL encoding because it is | ||
| // a well-known proven standard encoding that is reversible. | ||
| nodeFullPathForChildren.Append(EncodeString(currentNode.OverriddenEdgeName ?? currentNode.DisplayName)); | ||
| string currentNodeFullPath = nodeFullPathForChildren.ToString(); | ||
|
|
||
| // When we are filtering as tree filter and the current node does not match the filter, we skip the node and its children. | ||
| if (_testExecutionFilter is TreeNodeFilter treeNodeFilter) | ||
| { | ||
| if (!treeNodeFilter.MatchesFilter(currentNodeFullPath, CreatePropertyBagForFilter(currentNode.Properties))) | ||
| { | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| // If the node is expandable, we expand it (replacing the original node) | ||
| if (TestArgumentsManager.IsExpandableTestNode(currentNode)) | ||
| { | ||
| currentNode = await _testArgumentsManager.ExpandTestNodeAsync(currentNode); | ||
| } | ||
|
|
||
| // If the node is not filtered out by the test execution filter, we call the callback with the node. | ||
| if (_testExecutionFilter is not TestNodeUidListFilter listFilter | ||
| || listFilter.TestNodeUids.Any(uid => currentNode.StableUid.ToPlatformTestNodeUid() == uid)) | ||
| { | ||
| await onIncludedTestNodeAsync(currentNode, parentNodeUid); | ||
| } | ||
|
|
||
| foreach (TestNode childNode in currentNode.Tests) | ||
| { | ||
| queue.Enqueue((childNode, currentNode.StableUid, nodeFullPathForChildren)); | ||
| } | ||
| } | ||
|
|
||
| DuplicatedNodes = testNodesByUid.Where(x => x.Value.Count > 1).ToArray(); | ||
| } | ||
|
|
||
| private static PropertyBag CreatePropertyBagForFilter(IProperty[] properties) | ||
| { | ||
| PropertyBag propertyBag = new(); | ||
| foreach (IProperty property in properties) | ||
| { | ||
| propertyBag.Add(property); | ||
| } | ||
|
|
||
| return propertyBag; | ||
| } | ||
|
|
||
| private static string EncodeString(string value) | ||
| => HttpUtility.UrlEncode(value); | ||
| } |
This file contains hidden or 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,13 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.Testing.Framework; | ||
|
|
||
| internal interface ITestArgumentsEntry | ||
| { | ||
| string UidFragment { get; } | ||
|
|
||
| string? DisplayNameFragment { get; } | ||
|
|
||
| object? Arguments { get; } | ||
| } |
This file contains hidden or 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,11 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.Testing.Framework; | ||
|
|
||
| internal interface ITestArgumentsManager | ||
| { | ||
| void RegisterTestArgumentsEntryProvider<TArguments>( | ||
| TestNodeUid testNodeStableUid, | ||
| Func<TestArgumentsContext, InternalUnsafeTestArgumentsEntry<TArguments>> argumentsEntryProviderCallback); | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.