Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions 2 .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,10 @@ dotnet_diagnostic.VSTHRD105.severity = none # VSTHRD105: Avoid metho
dotnet_diagnostic.MSTESTEXP.severity = none # MSTESTEXP: Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
dotnet_diagnostic.TPEXP.severity = none # TPEXP: Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

dotnet_diagnostic.SA1108.severity = none # SA1108: Block statements must not contain embedded comments
dotnet_diagnostic.SA1600.severity = none # SA1600: Elements should be documented
dotnet_diagnostic.SA1601.severity = none # SA1601: Partial elements should be documented
dotnet_diagnostic.SA1602.severity = none # SA1602: Enumeration items should be documented

#### Naming styles ####

Expand Down
2 changes: 2 additions & 0 deletions 2 Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<PackageVersion Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
Comment thread
Evangelink marked this conversation as resolved.
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.Diagnostics.NETCore.Client" Version="0.2.553101" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="$(MicrosoftTestingExtensionsCodeCoverageVersion)" />
Expand Down Expand Up @@ -75,6 +76,7 @@
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<!-- CVE-2024-0057 / Transitive deps of code analysis testing packages -->
<PackageVersion Include="NuGet.Packaging" Version="6.12.1" />
<PackageVersion Include="NuGet.Protocol" Version="6.12.1" />
<PackageVersion Include="Polly" Version="8.5.0" />
<PackageVersion Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageVersion Include="StreamJsonRpc" Version="2.20.20" />
Expand Down
28 changes: 28 additions & 0 deletions 28 TestFx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Testing.Extension
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTest.GlobalConfigsGenerator", "src\Analyzers\MSTest.GlobalConfigsGenerator\MSTest.GlobalConfigsGenerator.csproj", "{A85AA656-6DB6-4A0B-AA80-CBB4058B3DDB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTest.Engine", "src\Adapter\MSTest.Engine\MSTest.Engine.csproj", "{82881535-7E40-80D9-F086-A3847775F2E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTest.SourceGeneration", "src\Analyzers\MSTest.SourceGeneration\MSTest.SourceGeneration.csproj", "{7BA0E74E-798E-4399-2EDE-A23BD5DA78CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTest.Engine.UnitTests", "test\UnitTests\MSTest.Engine.UnitTests\MSTest.Engine.UnitTests.csproj", "{2C0DFAC0-5D58-D172-ECE4-CBB78AD03435}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTest.SourceGeneration.UnitTests", "test\UnitTests\MSTest.SourceGeneration.UnitTests\MSTest.SourceGeneration.UnitTests.csproj", "{E6C0466E-BE8D-C04F-149A-FD98438F1413}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -500,6 +508,22 @@ Global
{A85AA656-6DB6-4A0B-AA80-CBB4058B3DDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A85AA656-6DB6-4A0B-AA80-CBB4058B3DDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A85AA656-6DB6-4A0B-AA80-CBB4058B3DDB}.Release|Any CPU.Build.0 = Release|Any CPU
{82881535-7E40-80D9-F086-A3847775F2E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{82881535-7E40-80D9-F086-A3847775F2E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82881535-7E40-80D9-F086-A3847775F2E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82881535-7E40-80D9-F086-A3847775F2E7}.Release|Any CPU.Build.0 = Release|Any CPU
{7BA0E74E-798E-4399-2EDE-A23BD5DA78CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BA0E74E-798E-4399-2EDE-A23BD5DA78CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BA0E74E-798E-4399-2EDE-A23BD5DA78CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BA0E74E-798E-4399-2EDE-A23BD5DA78CA}.Release|Any CPU.Build.0 = Release|Any CPU
{2C0DFAC0-5D58-D172-ECE4-CBB78AD03435}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C0DFAC0-5D58-D172-ECE4-CBB78AD03435}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C0DFAC0-5D58-D172-ECE4-CBB78AD03435}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C0DFAC0-5D58-D172-ECE4-CBB78AD03435}.Release|Any CPU.Build.0 = Release|Any CPU
{E6C0466E-BE8D-C04F-149A-FD98438F1413}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6C0466E-BE8D-C04F-149A-FD98438F1413}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6C0466E-BE8D-C04F-149A-FD98438F1413}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6C0466E-BE8D-C04F-149A-FD98438F1413}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -587,6 +611,10 @@ Global
{53EBA540-F6CF-0715-1F62-241A53F537EC} = {6AEE1440-FDF0-4729-8196-B24D0E333550}
{FB4ED3AA-A12E-4192-861F-4B025876AA0F} = {6AEE1440-FDF0-4729-8196-B24D0E333550}
{A85AA656-6DB6-4A0B-AA80-CBB4058B3DDB} = {E7F15C9C-3928-47AD-8462-64FD29FFCA54}
{82881535-7E40-80D9-F086-A3847775F2E7} = {24088844-2107-4DB2-8F3F-CBCA94FC4B28}
{7BA0E74E-798E-4399-2EDE-A23BD5DA78CA} = {E7F15C9C-3928-47AD-8462-64FD29FFCA54}
{2C0DFAC0-5D58-D172-ECE4-CBB78AD03435} = {BB874DF1-44FE-415A-B634-A6B829107890}
{E6C0466E-BE8D-C04F-149A-FD98438F1413} = {BB874DF1-44FE-415A-B634-A6B829107890}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {31E0F4D5-975A-41CC-933E-545B2201FAF9}
Expand Down
2 changes: 2 additions & 0 deletions 2 src/Adapter/MSTest.Engine/.editorconfig
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
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
Comment thread
Evangelink marked this conversation as resolved.
public AssertFailedException(string message, Exception ex)
: base(message, ex)
{
}

private AssertFailedException(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
}
}
6 changes: 6 additions & 0 deletions 6 src/Adapter/MSTest.Engine/BannedSymbols.txt
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
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
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];
}
9 changes: 9 additions & 0 deletions 9 src/Adapter/MSTest.Engine/Configurations/IConfiguration.cs
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; }
}
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;
}
122 changes: 122 additions & 0 deletions 122 src/Adapter/MSTest.Engine/Engine/BFSTestNodeVisitor.cs
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);
}
13 changes: 13 additions & 0 deletions 13 src/Adapter/MSTest.Engine/Engine/ITestArgumentsEntry.cs
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; }
}
11 changes: 11 additions & 0 deletions 11 src/Adapter/MSTest.Engine/Engine/ITestArgumentsManager.cs
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);
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.