Skip to content
Open
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
20 changes: 10 additions & 10 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@
<TestRunnerName>Microsoft.Testing.Platform</TestRunnerName>
</PropertyGroup>

<!-- Polyfill config -->
<PropertyGroup>
<PolyEnsure>true</PolyEnsure>
<!-- PolyGuard is temporary until the binary compat with VSTestBridge
https://github.com/microsoft/testfx/pull/7064#issuecomment-3623472023
https://github.com/microsoft/testfx/pull/6977 -->
<PolyGuard>true</PolyGuard>
<PolyStringInterpolation>true</PolyStringInterpolation>
<PolyUseEmbeddedAttribute>true</PolyUseEmbeddedAttribute>
</PropertyGroup>

<ItemGroup>
<Using Include="System.Collections" />
Expand All @@ -103,4 +93,14 @@
<Using Include="System.Xml.XPath" />
</ItemGroup>

<!-- Shared polyfills for older target frameworks.
CS0436 is suppressed because InternalsVisibleTo causes the same internal polyfill types
to be visible from referenced assemblies; the local copy is intentionally preferred. -->
<PropertyGroup Condition="'$(Language)' != 'F#'">
<NoWarn>$(NoWarn);CS0436</NoWarn>
</PropertyGroup>
<ItemGroup Condition="'$(Language)' != 'F#'">
<Compile Include="$(MSBuildThisFileDirectory)eng\Polyfills.cs" Link="Polyfills.cs" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.8.251003001" />
<PackageVersion Include="OpenTelemetry" Version="1.14.0" />
<PackageVersion Include="Polyfill" Version="9.7.3" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="$(SystemThreadingTasksExtensionsVersion)" />
</ItemGroup>
<ItemGroup Label="Test dependencies">
Expand Down
971 changes: 971 additions & 0 deletions eng/Polyfills.cs

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions src/Adapter/MSTest.Engine/MSTest.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ This package provides a new experimental engine for MSTest test framework.]]>
<ProjectReference Include="$(RepoRoot)src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Polyfill" PrivateAssets="all" />
</ItemGroup>

<!-- NuGet package layout -->
<!-- NuGet folders https://learn.microsoft.com/nuget/create-packages/creating-a-package#from-a-convention-based-working-directory -->
<ItemGroup>
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@
<AdditionalFiles Include="PublicAPI\PublicAPI.Unshipped.txt" Condition=" '$(TargetFramework)' != '$(UwpMinimum)' AND '$(TargetFramework)' != '$(ModernUwpMinimum)' " />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Polyfill" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Label="NuGet">
<NuspecProperty Include="ArtifactsBinDir=$(ArtifactsBinDir)" />
<NuspecProperty Include="Configuration=$(Configuration)" />
Expand All @@ -90,7 +86,6 @@
</ItemGroup>

<ItemGroup>
<Using Include="Polyfills" />
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope" Alias="ExecutionScope" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETFRAMEWORK
namespace Microsoft.CodeAnalysis;

internal sealed partial class EmbeddedAttribute : Attribute
{
}
#endif
// EmbeddedAttribute is now provided by eng/Polyfills.cs.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ private static bool IsValueTask(this MethodInfo method)

private static void InferGenerics(Type parameterType, Type argumentType, List<(Type ParameterType, Type Substitution)> result)
{
if (parameterType.IsGenericMethodParameter())
#if NET5_0_OR_GREATER
if (parameterType.IsGenericMethodParameter)
#else
if (parameterType.IsGenericParameter && parameterType.DeclaringMethod is not null)
#endif
{
// We found a generic parameter. The argument type should be the substitution for it.
result.Add((parameterType, argumentType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" />
<PackageReference Include="Polyfill" PrivateAssets="all" />
<PackageReference Include="System.Threading.Tasks.Extensions" Condition=" '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == '$(NetFrameworkMinimum)' OR '$(TargetFramework)' == '$(UwpMinimum)' " />
</ItemGroup>

Expand All @@ -55,7 +54,6 @@
</ItemGroup>

<ItemGroup>
<Using Include="Polyfills" />
<Using Include="$(RootNamespace).Resources" />
</ItemGroup>

Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ private static void SetParallelSettings(XmlReader reader, MSTestSettings setting
CultureInfo.CurrentCulture,
Resource.InvalidParallelScopeValue,
value,
string.Join(", ", Enum.GetNames<ExecutionScope>())));
string.Join(", ", Enum.GetNames(typeof(ExecutionScope)))));

break;
}
Expand All @@ -740,7 +740,7 @@ private static void SetParallelSettings(XmlReader reader, MSTestSettings setting
private static bool TryParseEnum<T>(string value, out T result)
where T : struct, Enum
=> Enum.TryParse(value, true, out result)
&& Enum.IsDefined(result);
&& Enum.IsDefined(typeof(T), result);

private static void SetGlobalSettings(
[StringSyntax(StringSyntaxAttribute.Xml, nameof(runsettingsXml))] string runsettingsXml,
Expand Down Expand Up @@ -902,7 +902,7 @@ internal static void SetSettingsFromConfig(IConfiguration configuration, IMessag
CultureInfo.CurrentCulture,
Resource.InvalidParallelScopeValue,
value,
string.Join(", ", Enum.GetNames<ExecutionScope>())));
string.Join(", ", Enum.GetNames(typeof(ExecutionScope)))));
}

settings.ParallelizationScope = scope;
Expand Down
72 changes: 72 additions & 0 deletions src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

// Polyfill extension methods for the Adapter projects which target
// net462 and need APIs not available on .NET Framework.
#if !NET5_0_OR_GREATER

internal static class AdapterPolyfillExtensions
{
public static bool Contains(this string s, char c) => s.IndexOf(c) >= 0;

public static bool StartsWith(this string s, char c) => s.Length > 0 && s[0] == c;

public static bool EndsWith(this string s, char c) => s.Length > 0 && s[s.Length - 1] == c;

public static bool IsAssignableTo(this System.Type type, System.Type? targetType)
=> targetType?.IsAssignableFrom(type) ?? false;

public static bool TryAdd<TKey, TValue>(this System.Collections.Generic.Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
where TKey : notnull
{
if (!dictionary.ContainsKey(key))
{
dictionary.Add(key, value);
return true;
}

return false;
}

public static System.Text.StringBuilder AppendJoin(this System.Text.StringBuilder sb, string separator, System.Collections.Generic.IEnumerable<string> values)
{
bool first = true;
foreach (string value in values)
{
if (!first)
{
sb.Append(separator);
}

sb.Append(value);
first = false;
}

return sb;
}

public static System.Text.StringBuilder AppendJoin(this System.Text.StringBuilder sb, char separator, System.Collections.Generic.IEnumerable<string> values) =>
sb.AppendJoin(separator.ToString(), values);

public static TValue GetOrAdd<TKey, TValue, TArg>(this System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> dictionary, TKey key, System.Func<TKey, TArg, TValue> valueFactory, TArg factoryArgument)
where TKey : notnull
=> dictionary.GetOrAdd(key, k => valueFactory(k, factoryArgument));

public static string[] Split(this string s, char separator, System.StringSplitOptions options) =>
s.Split([separator], options);
}

#endif

#if !NET8_0_OR_GREATER

internal static class AdapterCancellationTokenSourcePolyfill
{
public static System.Threading.Tasks.Task CancelAsync(this System.Threading.CancellationTokenSource cts)
{
cts.Cancel();
return System.Threading.Tasks.Task.CompletedTask;
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private static void GetConnectionProperties(DataSourceAttribute dataSourceAttrib
providerNameInvariant = ConfigurationManager.ConnectionStrings[element.ConnectionString].ProviderName;
connectionString = ConfigurationManager.ConnectionStrings[element.ConnectionString].ConnectionString;
tableName = element.DataTableName;
dataAccessMethod = Enum.Parse<DataAccessMethod>(element.DataAccessMethod);
dataAccessMethod = (DataAccessMethod)Enum.Parse(typeof(DataAccessMethod), element.DataAccessMethod);
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void SetupHost()

if (PlatformServiceProvider.Instance.AdapterTraceLogger.IsInfoEnabled)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.Info("DesktopTestSourceHost.SetupHost(): Creating assembly resolver with resolution paths {0}.", string.Join(',', resolutionPaths));
PlatformServiceProvider.Instance.AdapterTraceLogger.Info("DesktopTestSourceHost.SetupHost(): Creating assembly resolver with resolution paths {0}.", string.Join(",", resolutionPaths));
}

// NOTE: These 2 lines are super important, see https://github.com/microsoft/testfx/issues/2922
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public override void AddDeploymentItemsBasedOnMsTestSetting(string testSourceHan
/// <returns>Root deployment directory.</returns>
public override string GetRootDeploymentDirectory(string baseDirectory)
{
string dateTimeSuffix = $"{DateTime.Now.ToString("yyyyMMddTHHmmss", DateTimeFormatInfo.InvariantInfo)}_{Environment.ProcessId}";
using var currentProcess = Process.GetCurrentProcess();
string dateTimeSuffix = $"{DateTime.Now.ToString("yyyyMMddTHHmmss", DateTimeFormatInfo.InvariantInfo)}_{currentProcess.Id}";
string directoryName = string.Format(CultureInfo.InvariantCulture, Resource.TestRunName, DeploymentFolderPrefix,
#if NETFRAMEWORK
Environment.UserName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<PackageReference Include="Polyfill" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" />
<PackageReference Include="Polyfill" PrivateAssets="all" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

// Polyfill extension methods specific to the Analyzers project (which targets netstandard2.0
// only and does not reference Microsoft.Testing.Platform).

internal static class AnalyzerPolyfillExtensions
{
public static bool IsAssignableTo(this System.Type type, System.Type? targetType)
=> targetType?.IsAssignableFrom(type) ?? false;

public static void Deconstruct<TKey, TValue>(this System.Collections.Generic.KeyValuePair<TKey, TValue> pair, out TKey key, out TValue value)
{
key = pair.Key;
value = pair.Value;
}

public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
where TKey : notnull
=> dictionary.TryGetValue(key, out TValue? value) ? value : defaultValue;

public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Immutable.IImmutableDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
where TKey : notnull
=> dictionary.TryGetValue(key, out TValue? value) ? value : defaultValue;

public static bool Contains(this string s, char c) => s.IndexOf(c) >= 0;

public static bool StartsWith(this string s, char c) => s.Length > 0 && s[0] == c;

public static bool EndsWith(this string s, char c) => s.Length > 0 && s[s.Length - 1] == c;
}
35 changes: 2 additions & 33 deletions src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information.

#if !NETCOREAPP
#pragma warning disable SA1403 // File may only contain a single namespace
#pragma warning disable SA1642 // Constructor summary documentation should begin with standard text
#pragma warning disable SA1623 // Property summary documentation should match accessors

using System.ComponentModel;

namespace System.Runtime.CompilerServices
{
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit;
}

// This was copied from https://github.com/dotnet/coreclr/blob/60f1e6265bd1039f023a82e0643b524d6aaf7845/src/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
// and updated to have the scope of the attributes be internal.
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter will not be null even if the corresponding type allows it.</summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class NotNullWhenAttribute : Attribute
{
/// <summary>Initializes the attribute with the specified return value condition.</summary>
/// <param name="returnValue">
/// The return value condition. If the method returns this value, the associated parameter will not be null.
/// </param>
public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;

/// <summary>Gets the return value condition.</summary>
public bool ReturnValue { get; }
}
}

#endif
// Polyfills for IsExternalInit and NotNullWhenAttribute are provided by eng/Polyfills.cs.
// This file is kept for reference but no longer defines those types.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ This package extends Microsoft Testing Platform to provide a Azure DevOps report
<Compile Include="$(RepoRoot)\test\Utilities\Microsoft.Testing.TestInfrastructure\RootFinder.cs" Link="RootFinder.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Polyfill" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform\Microsoft.Testing.Platform.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
<PackageReference Include="Polyfill" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ This package extends Microsoft Testing Platform to provide a crash dump function
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.TrxReport.Abstractions\Microsoft.Testing.Extensions.TrxReport.Abstractions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Polyfill" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Microsoft.Testing.Extensions.VSTestBridge" Key="$(VsPublicKey)" />
<InternalsVisibleTo Include="Microsoft.Testing.Extensions.HangDump" Key="$(VsPublicKey)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
<RootNamespace>Microsoft.Testing.Extensions.Diagnostics</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Polyfill" PrivateAssets="all" />
</ItemGroup>

<!-- NuGet properties -->
<PropertyGroup>
<PackageDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ This package extends Microsoft Testing Platform to provide Hot Reload support.]]
<AdditionalFiles Include="PublicAPI/PublicAPI.Unshipped.txt" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Polyfill" PrivateAssets="all" />
</ItemGroup>

<!-- NuGet package layout -->
<!-- NuGet folders https://learn.microsoft.com/nuget/create-packages/creating-a-package#from-a-convention-based-working-directory -->
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
<AdditionalFiles Include="PublicAPI.Unshipped.txt" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Polyfill" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Microsoft.Testing.Platform.MSBuild.UnitTests" Key="$(VsPublicKey)" />
</ItemGroup>
Expand Down
Loading