Skip to content
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

Don't reference MTP in UWP #4402

Merged
merged 2 commits into from
Dec 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,12 @@ private void ExecuteTestsInSource(IEnumerable<TestCase> tests, IRunContext? runC
ExecuteTestsWithTestRunner(testsToRun, frameworkHandle, source, sourceLevelParameters, testRunner);
}

#if !WINDOWS_UWP
if (MSTestGracefulStopTestExecutionCapability.Instance.IsStopRequested)
{
testRunner.ForceCleanup();
}
#endif

PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("Executed tests belonging to source {0}", source);
}
Expand All @@ -426,10 +428,12 @@ private void ExecuteTestsWithTestRunner(
foreach (TestCase currentTest in orderedTests)
{
_testRunCancellationToken?.ThrowIfCancellationRequested();
#if !WINDOWS_UWP
if (MSTestGracefulStopTestExecutionCapability.Instance.IsStopRequested)
{
break;
}
#endif

// If it is a fixture test, add it to the list of fixture tests and do not execute it.
// It is executed by test itself.
Expand Down
3 changes: 2 additions & 1 deletion src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Adapter\MSTestAdapter.PlatformServices\MSTestAdapter.PlatformServices.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.VSTestBridge\Microsoft.Testing.Extensions.VSTestBridge.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.VSTestBridge\Microsoft.Testing.Extensions.VSTestBridge.csproj"
Condition=" '$(TargetFramework)' != '$(UwpMinimum)' " />
<ProjectReference Include="$(RepoRoot)src\Analyzers\MSTest.Internal.Analyzers\MSTest.Internal.Analyzers.csproj">
<OutputItemType>Analyzer</OutputItemType>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
Expand Down
24 changes: 21 additions & 3 deletions src/Adapter/MSTest.TestAdapter/MSTestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

using Microsoft.Testing.Platform.Configurations;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
#if !WINDOWS_UWP
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
#endif
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
Expand Down Expand Up @@ -263,7 +265,9 @@ public static void PopulateSettings(MSTestSettings settings)
[Obsolete("this function will be removed in v4.0.0")]
public static void PopulateSettings(IDiscoveryContext? context) => PopulateSettings(context, null, null);

private static bool IsRunSettingsFileHasMSTestSettings(string? runSettingsXml) => IsRunSettingsFileHasSettingName(runSettingsXml, SettingsName) || IsRunSettingsFileHasSettingName(runSettingsXml, SettingsNameAlias);
#if !WINDOWS_UWP
private static bool IsRunSettingsFileHasMSTestSettings(string? runSettingsXml)
=> IsRunSettingsFileHasSettingName(runSettingsXml, SettingsName) || IsRunSettingsFileHasSettingName(runSettingsXml, SettingsNameAlias);

private static bool IsRunSettingsFileHasSettingName(string? runSettingsXml, string SettingName)
{
Expand All @@ -288,6 +292,7 @@ private static bool IsRunSettingsFileHasSettingName(string? runSettingsXml, stri

return !reader.EOF;
}
#endif

/// <summary>
/// Populate adapter settings from the context.
Expand All @@ -298,16 +303,25 @@ private static bool IsRunSettingsFileHasSettingName(string? runSettingsXml, stri
/// </param>
internal static void PopulateSettings(IDiscoveryContext? context, IMessageLogger? logger, IConfiguration? configuration)
{
if (configuration?["mstest"] != null && context?.RunSettings != null && IsRunSettingsFileHasMSTestSettings(context.RunSettings.SettingsXml))
#if !WINDOWS_UWP
if (configuration?["mstest"] != null
&& context?.RunSettings != null
&& IsRunSettingsFileHasMSTestSettings(context.RunSettings.SettingsXml))
{
throw new InvalidOperationException(Resource.DuplicateConfigurationError);
}
#endif

// This will contain default adapter settings
var settings = new MSTestSettings();
var runConfigurationSettings = RunConfigurationSettings.PopulateSettings(context);

if (!StringEx.IsNullOrEmpty(context?.RunSettings?.SettingsXml) && configuration?["mstest"] is null)
#if !WINDOWS_UWP
if (!StringEx.IsNullOrEmpty(context?.RunSettings?.SettingsXml)
&& configuration?["mstest"] is null)
#else
if (!StringEx.IsNullOrEmpty(context?.RunSettings?.SettingsXml))
#endif
{
MSTestSettings? aliasSettings = GetSettings(context.RunSettings.SettingsXml, SettingsNameAlias, logger);

Expand All @@ -325,11 +339,13 @@ internal static void PopulateSettings(IDiscoveryContext? context, IMessageLogger

SetGlobalSettings(context.RunSettings.SettingsXml, settings, logger);
}
#if !WINDOWS_UWP
else if (configuration?["mstest"] is not null)
{
RunConfigurationSettings.SetRunConfigurationSettingsFromConfig(configuration, runConfigurationSettings);
SetSettingsFromConfig(configuration, logger, settings);
}
#endif

CurrentSettings = settings;
RunConfigurationSettings = runConfigurationSettings;
Expand Down Expand Up @@ -877,6 +893,7 @@ private static void SetGlobalSettings(
}
}

#if !WINDOWS_UWP
private static void ParseBooleanSetting(IConfiguration configuration, string key, IMessageLogger? logger, Action<bool> setSetting)
{
if (configuration[$"mstest:{key}"] is not string value)
Expand Down Expand Up @@ -1033,4 +1050,5 @@ internal static void SetSettingsFromConfig(IConfiguration configuration, IMessag

MSTestSettingsProvider.Load(configuration);
}
#endif
}
8 changes: 7 additions & 1 deletion src/Adapter/MSTest.TestAdapter/RunConfigurationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Xml;

#if !WINDOWS_UWP
using System.Globalization;

Evangelink marked this conversation as resolved.
Show resolved Hide resolved
using Microsoft.Testing.Platform.Configurations;
#endif

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
Expand Down Expand Up @@ -166,6 +170,7 @@ private static RunConfigurationSettings ToSettings(XmlReader reader)
return settings;
}

#if !WINDOWS_UWP
internal static RunConfigurationSettings SetRunConfigurationSettingsFromConfig(IConfiguration configuration, RunConfigurationSettings settings)
{
// Expected format of the json is: -
Expand Down Expand Up @@ -195,4 +200,5 @@ internal static RunConfigurationSettings SetRunConfigurationSettingsFromConfig(I

return settings;
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if !WINDOWS_UWP
using Microsoft.Testing.Platform.Capabilities.TestFramework;

namespace Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -23,3 +24,4 @@ public Task StopTestExecutionAsync(CancellationToken cancellationToken)
return Task.CompletedTask;
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if WINDOWS_UWP
namespace Microsoft.Testing.Platform.Configurations;

internal interface IConfiguration
{
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project>
<Project>

<!-- SDK top import -->
<Import Project="Sdk.props" Sdk="MSBuild.Sdk.Extras" Condition=" '$(OS)' == 'Windows_NT' " />
Expand Down Expand Up @@ -31,14 +31,16 @@

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\TestFramework\TestFramework.Extensions\TestFramework.Extensions.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.VSTestBridge\Microsoft.Testing.Extensions.VSTestBridge.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.VSTestBridge\Microsoft.Testing.Extensions.VSTestBridge.csproj"
Condition=" '$(TargetFramework)' != '$(UwpMinimum)' " />
<ProjectReference Include="$(RepoRoot)src\Analyzers\MSTest.Internal.Analyzers\MSTest.Internal.Analyzers.csproj">
<OutputItemType>Analyzer</OutputItemType>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Condition=" '$(TargetFramework)' == '$(UwpMinimum)' " />
<PackageReference Include="System.Diagnostics.TextWriterTraceListener" Condition=" '$(TargetFramework)' == '$(WinUiMinimum)' " />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#nullable enable
#nullable enable