diff --git a/.editorconfig b/.editorconfig index f48fb56461..b78e7a35b8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -312,8 +312,8 @@ csharp_prefer_simple_default_expression = true:suggestion csharp_style_deconstructed_variable_declaration = true:suggestion csharp_style_inlined_variable_declaration = true:suggestion csharp_style_prefer_local_over_anonymous_function = false:suggestion # not default, default is true, avoided because we use anonymous functions in multiple places and it does not make the code clearer -csharp_style_prefer_index_operator = true:suggestion -csharp_style_prefer_range_operator = true:suggestion +csharp_style_prefer_index_operator = false:warning # not default, default is true, disabled because Index operator is not supported in all the TFMs we support. (supported on .Net Core 3.0+) +csharp_style_prefer_range_operator = false:warning # not default, default is true, disabled because Range operator is not supported in all the TFMs we support. (supported on .Net Core 3.0+) csharp_style_throw_expression = true:suggestion csharp_style_unused_value_assignment_preference = discard_variable:suggestion csharp_style_unused_value_expression_statement_preference = discard_variable:silent @@ -331,6 +331,9 @@ csharp_style_prefer_parameter_null_checking = false # not default, disabled as n # IDE0055: Fix formatting - Set the severity of all .NET and C# formatting rules (https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules) dotnet_diagnostic.IDE0055.severity = warning # ensure all formatting rules are enforced on build +# IDE0057: Use range operator +dotnet_diagnostic.IDE0057.severity = none # Range operator is not supported in some TFMs. + #### C# Formatting Rules #### # New line preferences diff --git a/playground/MSTest1/MSTest1.csproj b/playground/MSTest1/MSTest1.csproj index 2f0ced5017..1ffb127333 100644 --- a/playground/MSTest1/MSTest1.csproj +++ b/playground/MSTest1/MSTest1.csproj @@ -6,7 +6,7 @@ - $(TargetFrameworks);net472;net5.0 + $(TargetFrameworks);net472;net5.0;net6.0;net7.0 false false diff --git a/samples/UnitTestProject/UnitTestProject.csproj b/samples/UnitTestProject/UnitTestProject.csproj index 06b3b010e9..30d3885a17 100644 --- a/samples/UnitTestProject/UnitTestProject.csproj +++ b/samples/UnitTestProject/UnitTestProject.csproj @@ -2,7 +2,7 @@ - $(TargetNetFxVersion);$(TargetNetCoreVersion) + $(TargetNetFxVersion);$(TargetNetCoreVersion);net7.0;net6.0; $(TargetNetCoreVersion) Exe UnitTestProject diff --git a/scripts/build.sh b/scripts/build.sh index ea8f8e28ec..4f862c933d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -156,7 +156,7 @@ TPB_BRANCH="$(git -C "." rev-parse --abbrev-ref HEAD 2>/dev/null)" || TPB_BRANCH TPB_COMMIT="$(git -C "." rev-parse HEAD 2>/dev/null)" || TPB_COMMIT="LOCALBUILD" # detached HEAD if [[ $TP_USE_REPO_API = 1 ]]; then - TPB_TargetFrameworkCore="net6.0" + TPB_TargetFrameworkCore="net7.0" fi # @@ -220,7 +220,7 @@ function install_cli() # # Runtime versions installed usually need to be kept in sync with the ones installed in common.lib.ps1 $install_script --runtime dotnet --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64 --channel "2.1" --version "2.1.30" - $install_script --runtime dotnet --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64 --channel "3.1" --version "3.1.25" + $install_script --runtime dotnet --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64 --channel "3.1" --version "3.1.27" $install_script --runtime dotnet --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64 --channel "5.0" --version "5.0.17" $install_script --runtime dotnet --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64 --channel "6.0" --version "6.0.5" @@ -346,8 +346,8 @@ function publish_package() cp -r src/testhost/bin/$TPB_Configuration/$TPB_TargetFramework/win7-x64/* $testhost cp -r src/testhost.x86/bin/$TPB_Configuration/$TPB_TargetFramework/win7-x86/* $testhost else - cp -r src/testhost/bin/$TPB_Configuration/net6.0/* $testhost - cp -r src/testhost.x86/bin/$TPB_Configuration/net6.0/* $testhost + cp -r src/testhost/bin/$TPB_Configuration/net7.0/* $testhost + cp -r src/testhost.x86/bin/$TPB_Configuration/net7.0/* $testhost fi # Copy over the logger assemblies to the Extensions folder. @@ -355,7 +355,7 @@ function publish_package() if [[ $TP_USE_REPO_API = 1 ]]; then log ".. Package: mv (Source Build)" - local current_tfn="net6.0" + local current_tfn="net7.0" else log ".. Package: mv" local current_tfn="netstandard2.0" diff --git a/scripts/common.lib.ps1 b/scripts/common.lib.ps1 index f8f097a8a1..d0e0a01599 100644 --- a/scripts/common.lib.ps1 +++ b/scripts/common.lib.ps1 @@ -110,13 +110,13 @@ function Install-DotNetCli # # Runtime versions installed usually need to be kept in sync with the ones installed in build.sh & $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Channel '2.1' -Architecture x64 -NoPath -Version '2.1.30' - & $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Channel '3.1' -Architecture x64 -NoPath -Version '3.1.25' + & $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Channel '3.1' -Architecture x64 -NoPath -Version '3.1.27' & $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Channel '5.0' -Architecture x64 -NoPath -Version '5.0.17' & $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Channel '6.0' -Architecture x64 -NoPath -Version '6.0.5' & $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Channel '7.0' -Architecture x64 -NoPath -Version $env:DOTNET_CLI_VERSION & $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Channel '2.1' -Architecture x86 -NoPath -Version '2.1.30' - & $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Channel '3.1' -Architecture x86 -NoPath -Version '3.1.25' + & $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Channel '3.1' -Architecture x86 -NoPath -Version '3.1.27' & $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Channel '5.0' -Architecture x86 -NoPath -Version '5.0.17' & $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Channel '6.0' -Architecture x86 -NoPath -Version '6.0.5' & $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Channel '7.0' -Architecture x86 -NoPath -Version $env:DOTNET_CLI_VERSION diff --git a/shared/NullableAttributes.cs b/shared/NullableAttributes.cs index 64e73a48dd..ded53a2c9f 100644 --- a/shared/NullableAttributes.cs +++ b/shared/NullableAttributes.cs @@ -3,9 +3,6 @@ // 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. - -#pragma warning disable CA1019 // Define accessors for attribute arguments - namespace System.Diagnostics.CodeAnalysis; #if NETFRAMEWORK || NETSTANDARD && !NETSTANDARD2_1 || NETCOREAPP && !NETCOREAPP3_0_OR_GREATER @@ -149,11 +146,3 @@ public MemberNotNullWhenAttribute(bool returnValue, params string[] members) } #endif - -/// -/// Secret attribute that tells the CA1062 validate arguments rule that this method validates the argument is not null. -/// -[AttributeUsage(AttributeTargets.Parameter)] -internal sealed class ValidatedNotNullAttribute : Attribute -{ -} diff --git a/src/AttachVS/AttachVS.csproj b/src/AttachVS/AttachVS.csproj index 69b747e2a9..37fcc745f1 100644 --- a/src/AttachVS/AttachVS.csproj +++ b/src/AttachVS/AttachVS.csproj @@ -7,7 +7,7 @@ Exe - net472 + net7;net472 AttachVS diff --git a/src/AttachVS/AttachVs.cs b/src/AttachVS/AttachVs.cs index 1d712c0d5f..978ec61b49 100644 --- a/src/AttachVS/AttachVs.cs +++ b/src/AttachVS/AttachVs.cs @@ -133,9 +133,9 @@ private static bool AttachVs(Process vs, int pid) { try { - dbg = dte.GetType().InvokeMember("Debugger", BindingFlags.GetProperty, null, dte, null, CultureInfo.InvariantCulture); - lps = dbg.GetType().InvokeMember("LocalProcesses", BindingFlags.GetProperty, null, dbg, null, CultureInfo.InvariantCulture); - var lpn = (System.Collections.IEnumerator)lps.GetType().InvokeMember("GetEnumerator", BindingFlags.InvokeMethod, null, lps, null, CultureInfo.InvariantCulture); + dbg = dte.GetType().InvokeMember("Debugger", BindingFlags.GetProperty, null, dte, null, CultureInfo.InvariantCulture)!; + lps = dbg.GetType().InvokeMember("LocalProcesses", BindingFlags.GetProperty, null, dbg, null, CultureInfo.InvariantCulture)!; + var lpn = (System.Collections.IEnumerator)lps.GetType().InvokeMember("GetEnumerator", BindingFlags.InvokeMethod, null, lps, null, CultureInfo.InvariantCulture)!; while (lpn.MoveNext()) { diff --git a/src/DataCollectors/DumpMinitool.arm64/DumpMinitool.arm64.csproj b/src/DataCollectors/DumpMinitool.arm64/DumpMinitool.arm64.csproj index f571dc4af9..d206b4ff00 100644 --- a/src/DataCollectors/DumpMinitool.arm64/DumpMinitool.arm64.csproj +++ b/src/DataCollectors/DumpMinitool.arm64/DumpMinitool.arm64.csproj @@ -6,8 +6,8 @@ - $(TargetNetFxVersion) - net6.0 + net7.0;net6.0;$(TargetNetFxVersion) + net7.0 AnyCPU false Exe diff --git a/src/DataCollectors/DumpMinitool.x86/DumpMinitool.x86.csproj b/src/DataCollectors/DumpMinitool.x86/DumpMinitool.x86.csproj index d640b294fc..a7ff13ab40 100644 --- a/src/DataCollectors/DumpMinitool.x86/DumpMinitool.x86.csproj +++ b/src/DataCollectors/DumpMinitool.x86/DumpMinitool.x86.csproj @@ -6,8 +6,8 @@ - $(TargetNetFxVersion) - net6.0 + net7.0;$(TargetNetFxVersion) + net7.0 AnyCPU true Exe diff --git a/src/DataCollectors/DumpMinitool/DumpMinitool.csproj b/src/DataCollectors/DumpMinitool/DumpMinitool.csproj index ae03c84fcf..61b77b74af 100644 --- a/src/DataCollectors/DumpMinitool/DumpMinitool.csproj +++ b/src/DataCollectors/DumpMinitool/DumpMinitool.csproj @@ -6,8 +6,8 @@ - $(TargetNetFxVersion) - net6.0 + net7.0;net6.0;$(TargetNetFxVersion) + net7.0 AnyCPU false Exe diff --git a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs index 04f3f78b25..6d93832971 100644 --- a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs +++ b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs @@ -335,7 +335,7 @@ private static ISet ParseCommaSeparatedList(string commaSeparatedList) return strings; } - private void OnSessionStart(object sender, SessionStartEventArgs e) + private void OnSessionStart(object? sender, SessionStartEventArgs e) { ValidateArg.NotNull(e, nameof(e)); ValidateArg.NotNull(e.Context, "SessionStartEventArgs.Context"); @@ -345,7 +345,7 @@ private void OnSessionStart(object sender, SessionStartEventArgs e) StartCollectionForContext(e.Context); } - private void OnSessionEnd(object sender, SessionEndEventArgs e) + private void OnSessionEnd(object? sender, SessionEndEventArgs e) { ValidateArg.NotNull(e, nameof(e)); ValidateArg.NotNull(e.Context, "SessionEndEventArgs.Context"); @@ -355,7 +355,7 @@ private void OnSessionEnd(object sender, SessionEndEventArgs e) WriteCollectedEventLogEntries(e.Context, true, TimeSpan.MaxValue, DateTime.UtcNow); } - private void OnTestCaseStart(object sender, TestCaseStartEventArgs e) + private void OnTestCaseStart(object? sender, TestCaseStartEventArgs e) { ValidateArg.NotNull(e, nameof(e)); ValidateArg.NotNull(e.Context, "TestCaseStartEventArgs.Context"); @@ -371,7 +371,7 @@ private void OnTestCaseStart(object sender, TestCaseStartEventArgs e) StartCollectionForContext(e.Context); } - private void OnTestCaseEnd(object sender, TestCaseEndEventArgs e) + private void OnTestCaseEnd(object? sender, TestCaseEndEventArgs e) { ValidateArg.NotNull(e, nameof(e)); TPDebug.Assert(e.Context != null, "Context is null"); @@ -446,7 +446,7 @@ private void StartCollectionForContext(DataCollectionContext dataCollectionConte var fileName = WriteEventLogs(eventLogEntries, isSessionEnd ? int.MaxValue : MaxEntries, dataCollectionContext, requestedDuration, timeRequestReceived); // Add the directory to the list - _eventLogDirectories.Add(Path.GetDirectoryName(fileName)); + _eventLogDirectories.Add(Path.GetDirectoryName(fileName)!); lock (ContextMap) { @@ -568,23 +568,19 @@ private void ConfigureMaxEntries(CollectorNameValueConfigurationManager collecto private EventLogSessionContext GetEventLogSessionContext(DataCollectionContext dataCollectionContext) { - EventLogSessionContext eventLogSessionContext; - bool eventLogContainerFound; lock (ContextMap) { - eventLogContainerFound = ContextMap.TryGetValue(dataCollectionContext, out eventLogSessionContext); + if (ContextMap.TryGetValue(dataCollectionContext, out var eventLogSessionContext)) + { + return eventLogSessionContext; + } } - if (!eventLogContainerFound) - { - string msg = string.Format( + string msg = string.Format( CultureInfo.CurrentCulture, Resource.ContextNotFoundException, dataCollectionContext.ToString()); - throw new EventLogCollectorException(msg, null); - } - - return eventLogSessionContext; + throw new EventLogCollectorException(msg, null); } } diff --git a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Microsoft.TestPlatform.Extensions.EventLogCollector.csproj b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Microsoft.TestPlatform.Extensions.EventLogCollector.csproj index e63a69b94a..5534492c44 100644 --- a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Microsoft.TestPlatform.Extensions.EventLogCollector.csproj +++ b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Microsoft.TestPlatform.Extensions.EventLogCollector.csproj @@ -6,18 +6,12 @@ Microsoft.TestPlatform.Extensions.EventLogCollector - $(TargetNetFxVersion) - net6.0 + net7.0;$(TargetNetFxVersion) + net7.0 false true - - - - - - - + diff --git a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs b/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs index 1066730e5b..f7c42c9f42 100644 --- a/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs +++ b/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs @@ -193,7 +193,7 @@ private static void GetManagedNameAndHierarchy(MethodBase method, bool useClosed hierarchyValues[HierarchyConstants.Levels.TestGroupIndex] = managedMethodName.Substring(0, methodNameEndIndex); hierarchyValues[HierarchyConstants.Levels.ClassIndex] = managedTypeName.Substring(hierarchyPos[1] + 1, hierarchyPos[2] - hierarchyPos[1] - 1); hierarchyValues[HierarchyConstants.Levels.NamespaceIndex] = managedTypeName.Substring(hierarchyPos[0], hierarchyPos[1] - hierarchyPos[0]); - hierarchyValues[HierarchyConstants.Levels.ContainerIndex] = method.DeclaringType.GetTypeInfo().Assembly.GetName().Name; + hierarchyValues[HierarchyConstants.Levels.ContainerIndex] = method.DeclaringType?.GetTypeInfo()?.Assembly?.GetName()?.Name ?? string.Empty; } /// @@ -411,7 +411,11 @@ private static void AppendMethodString(StringBuilder methodBuilder, string name, if (arity > 0 && methodArity == arity) { - methodBuilder.Append($"`{arity}"); + methodBuilder.Append( +#if NET6_0_OR_GREATER + System.Globalization.CultureInfo.InvariantCulture, +#endif + $"`{arity}"); } } diff --git a/src/Microsoft.TestPlatform.AdapterUtilities/Microsoft.TestPlatform.AdapterUtilities.csproj b/src/Microsoft.TestPlatform.AdapterUtilities/Microsoft.TestPlatform.AdapterUtilities.csproj index c0e44807a5..2131752716 100644 --- a/src/Microsoft.TestPlatform.AdapterUtilities/Microsoft.TestPlatform.AdapterUtilities.csproj +++ b/src/Microsoft.TestPlatform.AdapterUtilities/Microsoft.TestPlatform.AdapterUtilities.csproj @@ -5,8 +5,8 @@ - netstandard2.0;$(TargetNetFxVersion) - net6.0 + net6.0;net7.0;netstandard2.0;$(TargetNetFxVersion) + net7.0 Microsoft.TestPlatform.AdapterUtilities Microsoft.TestPlatform.AdapterUtilities diff --git a/src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.Build.csproj b/src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.Build.csproj index 10857dfd35..7abfd2e6fd 100644 --- a/src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.Build.csproj +++ b/src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.Build.csproj @@ -7,8 +7,8 @@ 2.0.0 Microsoft.TestPlatform.Build - netstandard2.0 - net6.0 + net7.0;netstandard2.0 + net7.0 false true diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestEventsRegistrar.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestEventsRegistrar.cs index 100d58aac8..3a2f773b45 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestEventsRegistrar.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestEventsRegistrar.cs @@ -52,7 +52,7 @@ public void UnregisterTestRunEvents(ITestRunRequest testRunRequest) /// /// /// RawMessage from the testhost - private void OnRawMessageReceived(object sender, string rawMessage) + private void OnRawMessageReceived(object? sender, string rawMessage) { // Directly send the data to translation layer instead of de-serializing it here _designModeClient.SendRawMessage(rawMessage); diff --git a/src/Microsoft.TestPlatform.Client/Microsoft.TestPlatform.Client.csproj b/src/Microsoft.TestPlatform.Client/Microsoft.TestPlatform.Client.csproj index b37d45bed0..628557e922 100644 --- a/src/Microsoft.TestPlatform.Client/Microsoft.TestPlatform.Client.csproj +++ b/src/Microsoft.TestPlatform.Client/Microsoft.TestPlatform.Client.csproj @@ -6,8 +6,8 @@ Microsoft.VisualStudio.TestPlatform.Client - netstandard2.0;$(TargetNetFxVersion) - net6.0 + net7.0;netstandard2.0;$(TargetNetFxVersion) + net7.0 false diff --git a/src/Microsoft.TestPlatform.Client/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.Client/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Client/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Client/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.Client/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Client/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Client/TestPlatform.cs b/src/Microsoft.TestPlatform.Client/TestPlatform.cs index 39100ed5ad..17da54ad1b 100644 --- a/src/Microsoft.TestPlatform.Client/TestPlatform.cs +++ b/src/Microsoft.TestPlatform.Client/TestPlatform.cs @@ -242,7 +242,7 @@ private void AddLoggerAssembliesFromSource(IEnumerable sources, TestAdap foreach (string source in sources) { - string sourceDirectory = Path.GetDirectoryName(source); + var sourceDirectory = Path.GetDirectoryName(source); if (!string.IsNullOrEmpty(sourceDirectory) && _fileHelper.DirectoryExists(sourceDirectory)) { SearchOption searchOption = GetSearchOption(strategy, SearchOption.TopDirectoryOnly); @@ -291,7 +291,9 @@ private static void AddExtensionAssembliesFromExtensionDirectory() .Union(defaultExtensionPaths); } - string extensionsFolder = Path.Combine(Path.GetDirectoryName(typeof(TestPlatform).GetTypeInfo().Assembly.GetAssemblyLocation()), "Extensions"); + string extensionsFolder = Path.Combine( + Path.GetDirectoryName(typeof(TestPlatform).GetTypeInfo().Assembly.GetAssemblyLocation())!, + "Extensions"); if (!fileHelper.DirectoryExists(extensionsFolder)) { // TODO: Since we no-longer run from \vstest.console\vstest.conosle.exe in Playground, the relative @@ -299,7 +301,7 @@ private static void AddExtensionAssembliesFromExtensionDirectory() // should come up with a better way of fixing this. // NOTE: This is specific to Playground which references vstest.console from a location that doesn't contain // the Extensions folder. Normal projects shouldn't have this issue. - extensionsFolder = Path.Combine(Path.GetDirectoryName(extensionsFolder), "vstest.console", "Extensions"); + extensionsFolder = Path.Combine(Path.GetDirectoryName(extensionsFolder)!, "vstest.console", "Extensions"); } if (fileHelper.DirectoryExists(extensionsFolder)) diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs index 99e5e982a5..242600db5a 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs @@ -290,7 +290,12 @@ private void AddNewFileTransfer(FileTransferInformation fileTransferInfo, AsyncC ex.ToString(), uri, friendlyName, - Guid.Parse(testCaseId)); + Guid.Parse(testCaseId +#if NET7_0_OR_GREATER + , CultureInfo.InvariantCulture +#endif + ) + ); throw; } diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionTelemetryManager.cs b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionTelemetryManager.cs index 66c1facc50..54a4c945e9 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionTelemetryManager.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionTelemetryManager.cs @@ -20,7 +20,7 @@ internal class DataCollectionTelemetryManager : IDataCollectionTelemetryManager private const string ClrIeInstrumentationMethodConfigurationPrefix32Variable = "MicrosoftInstrumentationEngine_ConfigPath32_"; private const string ClrIeInstrumentationMethodConfigurationPrefix64Variable = "MicrosoftInstrumentationEngine_ConfigPath64_"; - private static readonly Guid ClrIeProfilerGuid = Guid.Parse("{324f817a-7420-4e6d-b3c1-143fbed6d855}"); + private static readonly Guid ClrIeProfilerGuid = new("{324f817a-7420-4e6d-b3c1-143fbed6d855}"); private const string OverwrittenProfilerName = "overwritten"; private readonly IRequestData _requestData; diff --git a/src/Microsoft.TestPlatform.Common/Microsoft.TestPlatform.Common.csproj b/src/Microsoft.TestPlatform.Common/Microsoft.TestPlatform.Common.csproj index 418848e7d8..f30e942145 100644 --- a/src/Microsoft.TestPlatform.Common/Microsoft.TestPlatform.Common.csproj +++ b/src/Microsoft.TestPlatform.Common/Microsoft.TestPlatform.Common.csproj @@ -6,8 +6,8 @@ Microsoft.VisualStudio.TestPlatform.Common - net6.0;netstandard2.0;$(TargetNetFxVersion) - net6.0 + net7.0;net6.0;netstandard2.0;$(TargetNetFxVersion) + net7.0 false true diff --git a/src/Microsoft.TestPlatform.Common/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.Common/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Common/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Common/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.Common/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Common/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj b/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj index 56e0dd1eba..9f3fe059aa 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj @@ -5,8 +5,8 @@ Microsoft.TestPlatform.CommunicationUtilities - net6.0;netstandard2.0;$(TargetNetFxVersion) - net6.0 + net7.0;net6.0;netstandard2.0;$(TargetNetFxVersion) + net7.0 false diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.CommunicationUtilities/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.CommunicationUtilities/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestCaseConverter.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestCaseConverter.cs index 49906b0008..8b9064fccc 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestCaseConverter.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestCaseConverter.cs @@ -73,7 +73,13 @@ public override bool CanConvert(Type objectType) switch (testProperty.Id) { case "TestCase.Id": - testCase.Id = Guid.Parse(propertyData!); break; + testCase.Id = +#if NET7_0_OR_GREATER + Guid.Parse(propertyData!, CultureInfo.InvariantCulture); +#else + Guid.Parse(propertyData!); +#endif + break; case "TestCase.ExecutorUri": testCase.ExecutorUri = new Uri(propertyData!); break; case "TestCase.FullyQualifiedName": diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj b/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj index a7f4acaf91..354e7b4be8 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj +++ b/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj @@ -6,8 +6,8 @@ Microsoft.TestPlatform.CoreUtilities - $(TargetNetFxVersion);$(TargetNetCoreVersion);netstandard2.0;net6.0 - net6.0 + net7.0;net6.0;netstandard2.0;$(TargetNetFxVersion);$(TargetNetCoreVersion) + net7.0; false @@ -62,8 +62,11 @@ - - + + + + + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0_and_net7.0/PublicAPI.Shipped.txt similarity index 100% rename from src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0/PublicAPI.Shipped.txt rename to src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0_and_net7.0/PublicAPI.Shipped.txt diff --git a/src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0_and_net7.0/PublicAPI.Unshipped.txt similarity index 100% rename from src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0/PublicAPI.Unshipped.txt rename to src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0_and_net7.0/PublicAPI.Unshipped.txt diff --git a/src/Microsoft.TestPlatform.CoreUtilities/ValidateArg.cs b/src/Microsoft.TestPlatform.CoreUtilities/ValidateArg.cs index 31f28f1abb..7b3cd47e13 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/ValidateArg.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/ValidateArg.cs @@ -34,7 +34,7 @@ public static class ValidateArg /// Type of argument. /// [DebuggerStepThrough] - public static T NotNull([ValidatedNotNull] T? arg, string parameterName) + public static T NotNull([NotNull] T? arg, string parameterName) { return arg ?? throw new ArgumentNullException(parameterName); } @@ -55,7 +55,7 @@ public static T NotNull([ValidatedNotNull] T? arg, string parameterName) /// Thrown if the input string is null or empty. /// [DebuggerStepThrough] - public static string NotNullOrEmpty([ValidatedNotNull] string? arg, string parameterName) + public static string NotNullOrEmpty([NotNull] string? arg, string parameterName) { return arg.IsNullOrEmpty() ? throw new ArgumentNullException(parameterName) : arg; } @@ -76,7 +76,7 @@ public static string NotNullOrEmpty([ValidatedNotNull] string? arg, string param /// Thrown if the input string is null, empty or consists only of white-space characters. /// [DebuggerStepThrough] - public static string NotNullOrWhiteSpace([ValidatedNotNull] string? arg, string parameterName) + public static string NotNullOrWhiteSpace([NotNull] string? arg, string parameterName) { return arg.IsNullOrWhiteSpace() ? throw new ArgumentNullException(parameterName) : arg; } @@ -118,7 +118,7 @@ public static void NotNegative(long arg, string parameterName) /// The argument to check. /// The parameter name of the argument. [DebuggerStepThrough] - public static void NotNullOrEmpty([ValidatedNotNull] IEnumerable? arg, string parameterName) + public static void NotNullOrEmpty([NotNull] IEnumerable? arg, string parameterName) { NotNull(arg, parameterName); @@ -136,7 +136,7 @@ public static void NotNullOrEmpty([ValidatedNotNull] IEnumerable? arg, str /// The parameter name of the argument. /// The type of the expected argument. [DebuggerStepThrough] - public static void TypeOf([ValidatedNotNull] object? arg, string parameterName) + public static void TypeOf([NotNull] object? arg, string parameterName) where T : class { NotNull(arg, parameterName); @@ -161,7 +161,7 @@ public static class ValidateArgProperty /// The parameter name of the argument. /// The property name of the argument. [DebuggerStepThrough] - public static void NotNull([ValidatedNotNull] object? arg, string parameterName, string propertyName) + public static void NotNull([NotNull] object? arg, string parameterName, string propertyName) { if (arg == null) { @@ -193,7 +193,7 @@ public static void NotNegative(int arg, string parameterName, string propertyNam /// The parameter name of the argument. /// The property name of the argument. [DebuggerStepThrough] - public static void NotNullOrEmpty([ValidatedNotNull] string? arg, string parameterName, string propertyName) + public static void NotNullOrEmpty([NotNull] string? arg, string parameterName, string propertyName) { NotNull(arg, parameterName, propertyName); @@ -212,7 +212,7 @@ public static void NotNullOrEmpty([ValidatedNotNull] string? arg, string paramet /// The property name of the argument. /// The type of the expected argument. [DebuggerStepThrough] - public static void TypeOf([ValidatedNotNull] object? arg, string parameterName, string propertyName) + public static void TypeOf([NotNull] object? arg, string parameterName, string propertyName) where T : class { NotNull(arg, parameterName, propertyName); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Microsoft.TestPlatform.CrossPlatEngine.csproj b/src/Microsoft.TestPlatform.CrossPlatEngine/Microsoft.TestPlatform.CrossPlatEngine.csproj index 33748b0113..3edd07c71f 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Microsoft.TestPlatform.CrossPlatEngine.csproj +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Microsoft.TestPlatform.CrossPlatEngine.csproj @@ -6,8 +6,8 @@ Microsoft.TestPlatform.CrossPlatEngine - net6.0;netstandard2.0;$(TargetNetFxVersion) - net6.0 + net7.0;net6.0;netstandard2.0;$(TargetNetFxVersion) + net7.0; false diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.CrossPlatEngine/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.CrossPlatEngine/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Execution.Shared/DebuggerBreakpoint.cs b/src/Microsoft.TestPlatform.Execution.Shared/DebuggerBreakpoint.cs index 3d859427df..b765acc1f8 100644 --- a/src/Microsoft.TestPlatform.Execution.Shared/DebuggerBreakpoint.cs +++ b/src/Microsoft.TestPlatform.Execution.Shared/DebuggerBreakpoint.cs @@ -43,7 +43,14 @@ internal static void AttachVisualStudioDebugger(string environmentVariable) } else { - ConsoleOutput.Instance.WriteLine($"Attaching Visual Studio with PID {vsPid} to the process '{Process.GetCurrentProcess().ProcessName}({Process.GetCurrentProcess().Id})'...", OutputLevel.Information); + var processId = +#if NET6_0_OR_GREATER + Environment.ProcessId; +#else + Process.GetCurrentProcess().Id; +#endif + + ConsoleOutput.Instance.WriteLine($"Attaching Visual Studio with PID {vsPid} to the process '{Process.GetCurrentProcess().ProcessName}({processId})'...", OutputLevel.Information); } AttachVs(Process.GetCurrentProcess(), vsPid); diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameCollector.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameCollector.cs index 2125f418fb..81de903e3c 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameCollector.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameCollector.cs @@ -543,7 +543,7 @@ private void SessionEndedHandler(object? sender, SessionEndEventArgs args) /// /// Sender /// TestHostLaunchedEventArgs - private void TestHostLaunchedHandler(object sender, TestHostLaunchedEventArgs args) + private void TestHostLaunchedHandler(object? sender, TestHostLaunchedEventArgs args) { ResetInactivityTimer(); _testHostProcessId = args.TestHostProcessId; @@ -637,7 +637,7 @@ private string GetDumpDirectory() var dumpDirectoryOverrideHasValue = !dumpDirectoryOverride.IsNullOrWhiteSpace(); _uploadDumpFiles = !dumpDirectoryOverrideHasValue; - var dumpDirectory = dumpDirectoryOverrideHasValue ? dumpDirectoryOverride : GetTempDirectory(); + var dumpDirectory = dumpDirectoryOverrideHasValue ? dumpDirectoryOverride! : GetTempDirectory(); Directory.CreateDirectory(dumpDirectory); var dumpPath = Path.Combine(Path.GetFullPath(dumpDirectory)); diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs index 63e9f0aacf..f139bb90f2 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs @@ -78,7 +78,7 @@ public void Initialize(TestLoggerEvents events, string? testRunDictionary) /// /// Sender /// TestRunCompleteEventArgs - private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) + private void TestRunCompleteHandler(object? sender, TestRunCompleteEventArgs e) { ValidateArg.NotNull(sender, nameof(sender)); ValidateArg.NotNull(e, nameof(e)); diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/InactivityTimer.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/InactivityTimer.cs index 31470107a4..5c9e374ab2 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/InactivityTimer.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/InactivityTimer.cs @@ -17,7 +17,7 @@ public class InactivityTimer : IInactivityTimer /// Function to callback once the timer times out. public InactivityTimer(Action timerCallback) { - _timer = new Timer((object state) => timerCallback()); + _timer = new Timer((object? state) => timerCallback()); } /// diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Interfaces/INativeMethodsHelper.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Interfaces/INativeMethodsHelper.cs index c011f79f47..ad739c9eeb 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Interfaces/INativeMethodsHelper.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Interfaces/INativeMethodsHelper.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; - namespace Microsoft.TestPlatform.Extensions.BlameDataCollector; public interface INativeMethodsHelper @@ -12,5 +10,5 @@ public interface INativeMethodsHelper /// /// Process Handle /// Bool for Is64Bit - bool Is64Bit(IntPtr processHandle); + bool Is64Bit(nint processHandle); } diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Microsoft.TestPlatform.Extensions.BlameDataCollector.csproj b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Microsoft.TestPlatform.Extensions.BlameDataCollector.csproj index 381466d689..defead0b96 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Microsoft.TestPlatform.Extensions.BlameDataCollector.csproj +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Microsoft.TestPlatform.Extensions.BlameDataCollector.csproj @@ -19,8 +19,8 @@ Microsoft.TestPlatform.Extensions.BlameDataCollector - netstandard2.0;net472 - net6.0 + net7.0;netstandard2.0;net472 + net7.0; false true diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpArgsBuilder.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpArgsBuilder.cs index 34b24548c4..d7e17ca50a 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpArgsBuilder.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpArgsBuilder.cs @@ -50,10 +50,19 @@ public string BuildTriggerBasedProcDumpArgs(int processId, string filename, IEnu foreach (var exceptionFilter in procDumpExceptionsList) { - procDumpArgument.Append($"-f {exceptionFilter} "); + procDumpArgument.Append( +#if NET7_0_OR_GREATER + System.Globalization.CultureInfo.InvariantCulture, +#endif + $"-f {exceptionFilter} "); } - procDumpArgument.Append($"{processId} {filename}.dmp"); + procDumpArgument.Append( +#if NET7_0_OR_GREATER + System.Globalization.CultureInfo.InvariantCulture, +#endif + $"{processId} {filename}.dmp"); + var argument = procdumpArgumentsFromEnv.IsNullOrWhiteSpace() ? procDumpArgument.ToString() : $"-accepteula {procdumpArgumentsFromEnv} {processId} {filename}.dmp"; @@ -78,7 +87,11 @@ public string BuildHangBasedProcDumpArgs(int processId, string filename, bool is procDumpArgument.Append(" -ma"); } - procDumpArgument.Append($" {processId} {filename}.dmp"); + procDumpArgument.Append( +#if NET7_0_OR_GREATER + System.Globalization.CultureInfo.InvariantCulture, +#endif + $" {processId} {filename}.dmp"); var argument = procDumpArgument.ToString(); return argument; diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs index a8295236f1..0752e9a95a 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs @@ -168,8 +168,7 @@ public IEnumerable GetDumpFiles(bool processCrashed) // There can be more dumps in the crash folder from the child processes that were .NET5 or newer and crashed // get only the ones that match the path we provide to procdump. And get the last one created. var allTargetProcessDumps = allDumps - .Where(dump => Path.GetFileNameWithoutExtension(dump) - .StartsWith(_outputFilePrefix)) + .Where(dump => Path.GetFileNameWithoutExtension(dump).StartsWith(_outputFilePrefix ?? string.Empty)) .Select(dump => new FileInfo(dump)) .OrderBy(dump => dump.LastWriteTime).ThenBy(dump => dump.Name) .ToList(); @@ -285,7 +284,7 @@ private bool TryGetProcDumpExecutable(int processId, out string path) if (!searchPath) { - var candidatePath = Path.Combine(procdumpDirectory, filename); + var candidatePath = Path.Combine(procdumpDirectory!, filename); if (File.Exists(candidatePath)) { EqtTrace.Verbose($"ProcDumpDumper.GetProcDumpExecutable: Path to ProcDump '{candidatePath}' exists, using that."); @@ -311,7 +310,7 @@ private bool TryGetProcDumpExecutable(int processId, out string path) private bool TryGetExecutablePath(string executable, out string executablePath) { executablePath = string.Empty; - var pathString = Environment.GetEnvironmentVariable("PATH"); + var pathString = Environment.GetEnvironmentVariable("PATH") ?? string.Empty; foreach (string path in pathString.Split(Path.PathSeparator)) { string exeFullPath = Path.Combine(path.Trim(), executable); diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/PublicAPI/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/PublicAPI/PublicAPI.Shipped.txt index c06ec39dd6..a5ac44b058 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/PublicAPI/PublicAPI.Shipped.txt +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/PublicAPI/PublicAPI.Shipped.txt @@ -51,7 +51,7 @@ Microsoft.TestPlatform.Extensions.BlameDataCollector.InactivityTimer.Dispose() - Microsoft.TestPlatform.Extensions.BlameDataCollector.InactivityTimer.InactivityTimer(System.Action! timerCallback) -> void Microsoft.TestPlatform.Extensions.BlameDataCollector.InactivityTimer.ResetTimer(System.TimeSpan inactivityTimespan) -> void Microsoft.TestPlatform.Extensions.BlameDataCollector.INativeMethodsHelper -Microsoft.TestPlatform.Extensions.BlameDataCollector.INativeMethodsHelper.Is64Bit(System.IntPtr processHandle) -> bool +Microsoft.TestPlatform.Extensions.BlameDataCollector.INativeMethodsHelper.Is64Bit(nint processHandle) -> bool Microsoft.TestPlatform.Extensions.BlameDataCollector.IProcDumpArgsBuilder Microsoft.TestPlatform.Extensions.BlameDataCollector.IProcDumpArgsBuilder.BuildHangBasedProcDumpArgs(int processId, string! filename, bool isFullDump) -> string! Microsoft.TestPlatform.Extensions.BlameDataCollector.IProcDumpArgsBuilder.BuildTriggerBasedProcDumpArgs(int processId, string! filename, System.Collections.Generic.IEnumerable! procDumpExceptionsList, bool isFullDump) -> string! diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/WindowsHangDumper.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/WindowsHangDumper.cs index 67097bd268..c5783adc54 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/WindowsHangDumper.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/WindowsHangDumper.cs @@ -131,17 +131,17 @@ internal static void CollectDump(IProcessHelper processHelper, Process process, PlatformArchitecture.X86 => "DumpMinitool.x86.exe", PlatformArchitecture.X64 => "DumpMinitool.exe", PlatformArchitecture.ARM64 => "DumpMinitool.arm64.exe", - _ => null + _ => string.Empty }; - if (dumpMinitoolName == null) + if (dumpMinitoolName == string.Empty) { EqtTrace.Verbose($"WindowsHangDumper.CollectDump: The target process architecture is {targetProcessArchitecture}, we don't have a DumpMinitool for that, falling back to using PInvoke directly."); MiniDumpWriteDump.CollectDumpUsingMiniDumpWriteDump(process, outputFile, FromDumpType(type)); } var args = $"--file \"{outputFile}\" --processId {process.Id} --dumpType {type}"; - var dumpMinitoolPath = Path.Combine(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location), "dump", dumpMinitoolName); + var dumpMinitoolPath = Path.Combine(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location)!, "dump", dumpMinitoolName); EqtTrace.Verbose($"WindowsHangDumper.CollectDump: The target process architecture is {targetProcessArchitecture}, dumping it via {dumpMinitoolName}."); if (!File.Exists(dumpMinitoolPath)) diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/XmlReaderWriter.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/XmlReaderWriter.cs index 069977f2b1..fa12724d96 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/XmlReaderWriter.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/XmlReaderWriter.cs @@ -120,15 +120,25 @@ public List ReadTestSequence(string filePath) } var root = xmlDocument.LastChild; + if (root == null) + { + return testCaseList; + } + foreach (XmlNode node in root) { + if (node?.Attributes == null) + { + continue; + } + var testCase = new BlameTestObject { FullyQualifiedName = - node.Attributes[Constants.TestNameAttribute].Value, - Source = node.Attributes[Constants.TestSourceAttribute].Value, - DisplayName = node.Attributes[Constants.TestDisplayNameAttribute].Value, - IsCompleted = node.Attributes[Constants.TestCompletedAttribute].Value == "True" + node.Attributes[Constants.TestNameAttribute]?.Value, + Source = node.Attributes[Constants.TestSourceAttribute]?.Value, + DisplayName = node.Attributes[Constants.TestDisplayNameAttribute]?.Value, + IsCompleted = node.Attributes[Constants.TestCompletedAttribute]?.Value == "True" }; testCaseList.Add(testCase); } diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs index bf92b662b8..6d979825b5 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs @@ -290,13 +290,13 @@ public void TestRunCompleteHandler(object? sender, TestRunCompleteEventArgs e) } logFilePrefixValue = logFilePrefixValue + DateTime.Now.ToString("_yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo) + $".{HtmlLoggerConstants.HtmlFileExtension}"; - HtmlFilePath = Path.Combine(TestResultsDirPath, logFilePrefixValue); + HtmlFilePath = Path.Combine(TestResultsDirPath!, logFilePrefixValue); } else { if (_parametersDictionary.TryGetValue(HtmlLoggerConstants.LogFileNameKey, out string? logFileNameValue) && !logFileNameValue.IsNullOrWhiteSpace()) { - HtmlFilePath = Path.Combine(TestResultsDirPath, logFileNameValue); + HtmlFilePath = Path.Combine(TestResultsDirPath!, logFileNameValue); } } @@ -351,7 +351,7 @@ private string GenerateUniqueFilePath(string fileName, string fileExtension) for (short i = 0; i < short.MaxValue; i++) { var fileNameWithIter = i == 0 ? fileName : Path.GetFileNameWithoutExtension(fileName) + $"[{i}]"; - fullFilePath = Path.Combine(TestResultsDirPath, $"TestResult_{fileNameWithIter}.{fileExtension}"); + fullFilePath = Path.Combine(TestResultsDirPath!, $"TestResult_{fileNameWithIter}.{fileExtension}"); lock (FileCreateLockObject) { if (!File.Exists(fullFilePath)) diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Microsoft.TestPlatform.Extensions.HtmlLogger.csproj b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Microsoft.TestPlatform.Extensions.HtmlLogger.csproj index 31b103cb77..935cd5af48 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Microsoft.TestPlatform.Extensions.HtmlLogger.csproj +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Microsoft.TestPlatform.Extensions.HtmlLogger.csproj @@ -6,8 +6,8 @@ Microsoft.VisualStudio.TestPlatform.Extensions.Html.TestLogger - netstandard2.0;$(TargetNetFxVersion) - net6.0 + net7.0;netstandard2.0;$(TargetNetFxVersion) + net7.0; false true diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Microsoft.TestPlatform.Extensions.TrxLogger.csproj b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Microsoft.TestPlatform.Extensions.TrxLogger.csproj index 16e5eda699..95b58f7d57 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Microsoft.TestPlatform.Extensions.TrxLogger.csproj +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Microsoft.TestPlatform.Extensions.TrxLogger.csproj @@ -6,8 +6,8 @@ Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger - net6.0;netstandard2.0;$(TargetNetFxVersion) - net6.0 + net7.0;net6.0;netstandard2.0;$(TargetNetFxVersion) + net7.0; false diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.Extensions.TrxLogger/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.Extensions.TrxLogger/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/EqtAssert.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/EqtAssert.cs index d12662bf64..1dd4ee85b6 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/EqtAssert.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/EqtAssert.cs @@ -42,7 +42,7 @@ public static void IsTrue(bool expression, string comment) /// /// Parameter to check /// String - parameter name - public static void ParameterNotNull([ValidatedNotNull] object? parameter, [ValidatedNotNull] string parameterName) + public static void ParameterNotNull([NotNull] object? parameter, [NotNull] string parameterName) { AssertParameterNameNotNullOrEmpty(parameterName); TPDebug.Assert(parameter != null, $"'{nameof(parameterName)}' is null"); @@ -57,7 +57,7 @@ public static void ParameterNotNull([ValidatedNotNull] object? parameter, [Valid /// /// Parameter to check /// String - parameter name - public static void StringNotNullOrEmpty([ValidatedNotNull] string? parameter, [ValidatedNotNull] string parameterName) + public static void StringNotNullOrEmpty([NotNull] string? parameter, [NotNull] string parameterName) { AssertParameterNameNotNullOrEmpty(parameterName); TPDebug.Assert(!parameter.IsNullOrEmpty(), $"'{nameof(parameterName)}' is null or empty"); @@ -72,7 +72,7 @@ public static void StringNotNullOrEmpty([ValidatedNotNull] string? parameter, [V /// /// The parameter name to verify [Conditional("DEBUG")] - private static void AssertParameterNameNotNullOrEmpty([ValidatedNotNull] string? parameterName) + private static void AssertParameterNameNotNullOrEmpty([NotNull] string? parameterName) { TPDebug.Assert(!parameterName.IsNullOrEmpty(), "'parameterName' is null or empty"); } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj b/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj index 0464996fcb..dcab739485 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj +++ b/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj @@ -7,8 +7,8 @@ Microsoft.VisualStudio.TestPlatform.ObjectModel - $(TargetNetFxVersion);$(TargetNetCoreVersion);netstandard2.0 - net6.0 + net7.0;$(TargetNetFxVersion);$(TargetNetCoreVersion);netstandard2.0; + net7.0; Microsoft.TestPlatform.ObjectModel diff --git a/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..2ceb9ba877 --- /dev/null +++ b/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1,4 @@ +#nullable enable +static Microsoft.VisualStudio.TestPlatform.ObjectModel.EqtTrace.TraceLevel.get -> Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformTraceLevel (forwarded, contained in Microsoft.TestPlatform.CoreUtilities) +static Microsoft.VisualStudio.TestPlatform.ObjectModel.EqtTrace.TraceLevel.set -> void (forwarded, contained in Microsoft.TestPlatform.CoreUtilities) +static Microsoft.VisualStudio.TestPlatform.ObjectModel.Framework.DefaultFramework.get -> Microsoft.VisualStudio.TestPlatform.ObjectModel.Framework! diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/net6.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/net7.0/PublicAPI.Unshipped.txt similarity index 100% rename from src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/net6.0/PublicAPI.Unshipped.txt rename to src/Microsoft.TestPlatform.ObjectModel/PublicAPI/net7.0/PublicAPI.Unshipped.txt diff --git a/src/Microsoft.TestPlatform.ObjectModel/TestCase.cs b/src/Microsoft.TestPlatform.ObjectModel/TestCase.cs index 5de3ce721a..fef61efea6 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/TestCase.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/TestCase.cs @@ -3,6 +3,9 @@ using System; using System.Collections.Generic; +#if NET7_0_OR_GREATER +using System.Globalization; +#endif using System.IO; using System.Linq; using System.Runtime.Serialization; @@ -261,7 +264,23 @@ protected override void ProtectedSetPropertyValue(TestProperty property, object? return; case "TestCase.Id": - Id = value is Guid guid ? guid : Guid.Parse((value as string)!); + if (value is Guid guid) + { + Id = guid; + } + else if (value is string guidString) + { +#if NET7_0_OR_GREATER + Id = Guid.Parse(guidString, CultureInfo.InvariantCulture); +#else + Id = Guid.Parse(guidString); +#endif + } + else + { + Id = Guid.Empty; + } + return; case "TestCase.LineNumber": diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs index 28e99e1d99..6d468d0dd2 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs @@ -116,5 +116,5 @@ public interface IProcessHelper /// /// process id /// Process Handle - IntPtr GetProcessHandle(int processId); + nint GetProcessHandle(int processId); } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/Microsoft.TestPlatform.PlatformAbstractions.csproj b/src/Microsoft.TestPlatform.PlatformAbstractions/Microsoft.TestPlatform.PlatformAbstractions.csproj index 60907b8ca2..fbc3b7888f 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/Microsoft.TestPlatform.PlatformAbstractions.csproj +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/Microsoft.TestPlatform.PlatformAbstractions.csproj @@ -7,8 +7,8 @@ Microsoft.TestPlatform.PlatformAbstractions Microsoft.TestPlatform.PlatformAbstractions - $(TargetNetFxVersion);$(TargetNetCoreVersion);netstandard2.0;net6.0 - net6.0 + net7.0;$(TargetNetFxVersion);$(TargetNetCoreVersion);netstandard2.0;net6.0 + net7.0; false $(NoWarn);NU1605 @@ -36,8 +36,11 @@ - - + + + + + diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/PublicAPI.Shipped.txt index 5fb1f3356d..696ed76517 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/PublicAPI.Shipped.txt +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/PublicAPI.Shipped.txt @@ -47,7 +47,7 @@ Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IProcessHelp Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IProcessHelper.GetCurrentProcessId() -> int Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IProcessHelper.GetCurrentProcessLocation() -> string! Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IProcessHelper.GetNativeDllDirectory() -> string! -Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IProcessHelper.GetProcessHandle(int processId) -> System.IntPtr +Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IProcessHelper.GetProcessHandle(int processId) -> nint Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IProcessHelper.GetProcessId(object? process) -> int Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IProcessHelper.GetProcessName(int processId) -> string! Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IProcessHelper.GetTestEngineDirectory() -> string? @@ -102,7 +102,7 @@ Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.GetCurren Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.GetCurrentProcessId() -> int Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.GetCurrentProcessLocation() -> string! Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.GetNativeDllDirectory() -> string! -Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.GetProcessHandle(int processId) -> System.IntPtr +Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.GetProcessHandle(int processId) -> nint Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.GetProcessId(object? process) -> int Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.GetProcessName(int processId) -> string! Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.GetTestEngineDirectory() -> string? diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/net6.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/net6.0_and_net7.0/PublicAPI.Shipped.txt similarity index 100% rename from src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/net6.0/PublicAPI.Shipped.txt rename to src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/net6.0_and_net7.0/PublicAPI.Shipped.txt diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/net6.0_and_net7.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/net6.0_and_net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..ab058de62d --- /dev/null +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/PublicAPI/net6.0_and_net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/net462/System/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/net462/System/ProcessHelper.cs index e0553562cb..cc65454857 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/net462/System/ProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/net462/System/ProcessHelper.cs @@ -21,7 +21,7 @@ public string GetCurrentProcessLocation() => Path.GetDirectoryName(GetCurrentProcessFileName()); /// - public IntPtr GetProcessHandle(int processId) => + public nint GetProcessHandle(int processId) => processId == _currentProcess.Id ? _currentProcess.Handle : Process.GetProcessById(processId).Handle; diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/netcore/System/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/netcore/System/ProcessHelper.cs index 5d7b528081..6cf4b0f91b 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/netcore/System/ProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/netcore/System/ProcessHelper.cs @@ -22,7 +22,7 @@ public string GetCurrentProcessLocation() } /// - public IntPtr GetProcessHandle(int processId) + public nint GetProcessHandle(int processId) { // An IntPtr representing the value of the handle field. // If the handle has been marked invalid with SetHandleAsInvalid, this method still returns the original handle value, which can be a stale value. diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Microsoft.TestPlatform.TestHostProvider.csproj b/src/Microsoft.TestPlatform.TestHostProvider/Microsoft.TestPlatform.TestHostProvider.csproj index b1a10b8ac4..7e25baa267 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Microsoft.TestPlatform.TestHostProvider.csproj +++ b/src/Microsoft.TestPlatform.TestHostProvider/Microsoft.TestPlatform.TestHostProvider.csproj @@ -6,8 +6,8 @@ Microsoft.TestPlatform.TestHostRuntimeProvider - net6.0;netstandard2.0;$(TargetNetFxVersion) - net6.0 + net7.0;net6.0;netstandard2.0;$(TargetNetFxVersion) + net7.0; $(DefineConstants);DOTNET_BUILD_FROM_SOURCE false true diff --git a/src/Microsoft.TestPlatform.TestHostProvider/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.TestHostProvider/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.TestHostProvider/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.TestHostProvider/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.TestHostProvider/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.TestHostProvider/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs b/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs index d637998729..0bbef70c71 100644 --- a/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs +++ b/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs @@ -29,7 +29,7 @@ public static void FixRelativePathsInRunSettings(XmlDocument xmlDocument, string ValidateArg.NotNull(xmlDocument, nameof(xmlDocument)); ValidateArg.NotNullOrEmpty(path, nameof(path)); - string root = Path.GetDirectoryName(path); + var root = Path.GetDirectoryName(path)!; AddRunSettingsDirectoryNode(xmlDocument, root); @@ -56,7 +56,7 @@ private static void AddRunSettingsDirectoryNode(XmlDocument doc, string path) { var node = doc.CreateNode(XmlNodeType.Element, RunsettingsDirectory, string.Empty); node.InnerXml = path; - doc.DocumentElement.AppendChild(node); + doc.DocumentElement!.AppendChild(node); } private static void FixNodeFilePath(XmlNode node, string root) diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index 83a82545c0..be25c77976 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -122,14 +122,16 @@ public async Task> ProcessAttachmentSetsAsync(XmlElem private static async Task?> MergeCodeCoverageFilesAsync(IList files, CancellationToken cancellationToken) { + TPDebug.Assert(s_mergeOperationEnumValues != null); + cancellationToken.ThrowIfCancellationRequested(); // Invoke methods LoadCodeCoverageAssembly(); - var task = (Task)s_mergeMethodInfo.Invoke(s_classInstance, new object[] { files[0], files, s_mergeOperationEnumValues.GetValue(0), true, cancellationToken }); + var task = (Task)s_mergeMethodInfo.Invoke(s_classInstance, new object[] { files[0], files, s_mergeOperationEnumValues.GetValue(0)!, true, cancellationToken })!; await task.ConfigureAwait(false); - if (task.GetType().GetProperty("Result").GetValue(task, null) is not IList mergedResults) + if (task.GetType().GetProperty("Result")!.GetValue(task, null) is not IList mergedResults) { EqtTrace.Error("CodeCoverageDataCollectorAttachmentsHandler: Failed to merge code coverage files."); return files; @@ -163,15 +165,16 @@ private static void LoadCodeCoverageAssembly() return; } - var assemblyPath = Path.Combine(Path.GetDirectoryName(typeof(CodeCoverageDataAttachmentsHandler).GetTypeInfo().Assembly.GetAssemblyLocation()), CodeCoverageIoAssemblyName + ".dll"); + var dataAttachmentAssemblyLocation = typeof(CodeCoverageDataAttachmentsHandler).GetTypeInfo().Assembly.GetAssemblyLocation()!; + var assemblyPath = Path.Combine(Path.GetDirectoryName(dataAttachmentAssemblyLocation)!, CodeCoverageIoAssemblyName + ".dll"); s_codeCoverageAssembly = new PlatformAssemblyLoadContext().LoadAssemblyFromPath(assemblyPath); - var classType = s_codeCoverageAssembly.GetType($"{CodeCoverageIoAssemblyName}.{CoverageFileUtilityTypeName}"); - s_classInstance = Activator.CreateInstance(classType); + var classType = s_codeCoverageAssembly.GetType($"{CodeCoverageIoAssemblyName}.{CoverageFileUtilityTypeName}")!; + s_classInstance = Activator.CreateInstance(classType)!; var types = s_codeCoverageAssembly.GetTypes(); - var mergeOperationEnum = Array.Find(types, d => d.Name == CoverageMergeOperationName); + var mergeOperationEnum = Array.Find(types, d => d.Name == CoverageMergeOperationName)!; s_mergeOperationEnumValues = Enum.GetValues(mergeOperationEnum); - s_mergeMethodInfo = classType.GetMethod(MergeMethodName, new[] { typeof(string), typeof(IList), mergeOperationEnum, typeof(bool), typeof(CancellationToken) }); + s_mergeMethodInfo = classType.GetMethod(MergeMethodName, new[] { typeof(string), typeof(IList), mergeOperationEnum, typeof(bool), typeof(CancellationToken) })!; } } diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageRunSettingsProcessor.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageRunSettingsProcessor.cs index 4b958a2416..05fc9b3fba 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageRunSettingsProcessor.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageRunSettingsProcessor.cs @@ -188,11 +188,13 @@ public CodeCoverageRunSettingsProcessor(XmlNode defaultSettingsRootNode) // default settings node and bail out. if (tempNode == null) { - var defaultNode = ExtractNode( - defaultRootNode, - partialPath.ToString()); + var defaultNode = ExtractNode(defaultRootNode, partialPath.ToString()); + if (defaultNode == null) + { + return null; + } - var importedChild = currentNode.OwnerDocument.ImportNode(defaultNode, true); + var importedChild = currentNode.OwnerDocument!.ImportNode(defaultNode, true); currentNode.AppendChild(importedChild); return null; @@ -219,6 +221,11 @@ private static bool ShouldProcessCurrentExclusion(XmlNode node) { const string attributeName = "mergeDefaults"; + if (node.Attributes == null) + { + return true; + } + foreach (XmlAttribute attribute in node.Attributes) { // If the attribute is present and set on 'false' we skip processing for the @@ -298,7 +305,7 @@ private static void MergeNodes(XmlNode currentNode, XmlNode? defaultNode) } // Import missing default exclusions. - var importedChild = currentNode.OwnerDocument.ImportNode(child, true); + var importedChild = currentNode.OwnerDocument!.ImportNode(child, true); currentNode.AppendChild(importedChild); } } diff --git a/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs b/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs index 5901e1c666..f5494460a4 100644 --- a/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs +++ b/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs @@ -95,7 +95,7 @@ public class InferRunSettingsHelper var document = new XmlDocument(); document.Load(reader); - var runSettingsNavigator = document.CreateNavigator(); + var runSettingsNavigator = document.CreateNavigator()!; // Move navigator to RunConfiguration node if (!runSettingsNavigator.MoveToChild(RunSettingsNodeName, string.Empty) || @@ -155,7 +155,7 @@ public class InferRunSettingsHelper /// The results directory. public static void UpdateRunSettingsWithUserProvidedSwitches(XmlDocument runSettingsDocument, Architecture architecture, Framework framework, string? resultsDirectory) { - var runSettingsNavigator = runSettingsDocument.CreateNavigator(); + var runSettingsNavigator = runSettingsDocument.CreateNavigator()!; ValidateRunConfiguration(runSettingsNavigator); @@ -325,7 +325,7 @@ public static bool TryGetLegacySettingElements(string runsettingsXml, out Dictio using var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings); var document = new XmlDocument(); document.Load(reader); - var runSettingsNavigator = document.CreateNavigator(); + var runSettingsNavigator = document.CreateNavigator()!; var node = runSettingsNavigator.SelectSingleNode(@"/RunSettings/LegacySettings"); if (node == null) @@ -338,7 +338,7 @@ public static bool TryGetLegacySettingElements(string runsettingsXml, out Dictio var legacySettingElements = new List(); while (childNodes.MoveNext()) { - legacySettingElements.Add(childNodes.Current.Name); + legacySettingElements.Add(childNodes.Current!.Name); } foreach (var executionNodePath in ExecutionNodesPaths) @@ -414,7 +414,7 @@ public static bool TryGetLegacySettingElements(string runsettingsXml, out Dictio using var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings); var document = new XmlDocument(); document.Load(reader); - var runSettingsNavigator = document.CreateNavigator(); + var runSettingsNavigator = document.CreateNavigator()!; var node = runSettingsNavigator.SelectSingleNode(EnvironmentVariablesNodePath); if (node == null) @@ -456,7 +456,7 @@ public static bool TryGetDeviceXml(XPathNavigator runSettingsNavigator, [NotNull ValidateArg.NotNull(runSettingsNavigator, nameof(runSettingsNavigator)); deviceXml = null; - XPathNavigator targetDeviceNode = runSettingsNavigator.SelectSingleNode(MsTestTargetDeviceNodePath); + var targetDeviceNode = runSettingsNavigator.SelectSingleNode(MsTestTargetDeviceNodePath); if (targetDeviceNode != null) { deviceXml = targetDeviceNode.InnerXml; @@ -483,7 +483,7 @@ public static bool IsTestSettingsEnabled(string? runsettingsXml) var document = new XmlDocument(); document.Load(reader); - var runSettingsNavigator = document.CreateNavigator(); + var runSettingsNavigator = document.CreateNavigator()!; // Move navigator to MSTest node if (!runSettingsNavigator.MoveToChild(RunSettingsNodeName, string.Empty) || @@ -512,9 +512,9 @@ private static void AddNodeIfNotPresent(XmlDocument xmlDocument, string nodeP // Navigator should be at Root of runsettings xml, attempt to move to /RunSettings/RunConfiguration var root = xmlDocument.DocumentElement; - if (root.SelectSingleNode(RunConfigurationNodePath) == null) + if (root?.SelectSingleNode(RunConfigurationNodePath) == null) { - if (root.Name == RunSettingsNodeName) + if (root?.Name == RunSettingsNodeName) { // When just is provided in the runsettings string, then this will add the common RunConfiguration inner node. XmlUtilities.AppendOrModifyChild(xmlDocument, RunConfigurationNodePath, RunConfigurationNodeName, innerXml: null); @@ -705,12 +705,8 @@ public static IEnumerable FilterCompatibleSources(Architecture chosenPla /// private static bool IsPlatformIncompatible(Architecture sourcePlatform, Architecture targetPlatform) { - if (sourcePlatform is Architecture.Default or Architecture.AnyCPU) - { - return false; - } - - return targetPlatform == Architecture.X64 && !Is64BitOperatingSystem() || sourcePlatform != targetPlatform; + return sourcePlatform is not Architecture.Default and not Architecture.AnyCPU + && (targetPlatform == Architecture.X64 && !Is64BitOperatingSystem() || sourcePlatform != targetPlatform); static bool Is64BitOperatingSystem() { diff --git a/src/Microsoft.TestPlatform.Utilities/MSTestSettingsUtilities.cs b/src/Microsoft.TestPlatform.Utilities/MSTestSettingsUtilities.cs index 78637752b6..0d94b7de48 100644 --- a/src/Microsoft.TestPlatform.Utilities/MSTestSettingsUtilities.cs +++ b/src/Microsoft.TestPlatform.Utilities/MSTestSettingsUtilities.cs @@ -35,7 +35,7 @@ public static XmlDocument Import(string settingsFile, XmlDocument defaultRunSett throw new XmlException(string.Format(CultureInfo.CurrentCulture, UtilitiesResources.UnExpectedSettingsFile)); } - var navigator = defaultRunSettings.CreateNavigator(); + var navigator = defaultRunSettings.CreateNavigator()!; if (!navigator.MoveToChild(Constants.RunSettingsName, string.Empty)) { @@ -44,7 +44,7 @@ public static XmlDocument Import(string settingsFile, XmlDocument defaultRunSett var settingsNode = GenerateMsTestXml(settingsFile); - defaultRunSettings.DocumentElement.PrependChild(defaultRunSettings.ImportNode(settingsNode, true)); + defaultRunSettings.DocumentElement!.PrependChild(defaultRunSettings.ImportNode(settingsNode, true)); // Adding RunConfig if (!navigator.MoveToChild(Constants.RunConfigurationSettingsName, string.Empty)) diff --git a/src/Microsoft.TestPlatform.Utilities/Microsoft.TestPlatform.Utilities.csproj b/src/Microsoft.TestPlatform.Utilities/Microsoft.TestPlatform.Utilities.csproj index 271cdf21a6..60c5ac5ed7 100644 --- a/src/Microsoft.TestPlatform.Utilities/Microsoft.TestPlatform.Utilities.csproj +++ b/src/Microsoft.TestPlatform.Utilities/Microsoft.TestPlatform.Utilities.csproj @@ -6,11 +6,11 @@ Microsoft.TestPlatform.Utilities - netstandard2.0;$(TargetNetFxVersion) - net6.0 + net7.0;netstandard2.0;$(TargetNetFxVersion) + net7.0; false - + diff --git a/src/Microsoft.TestPlatform.Utilities/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.Utilities/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Utilities/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Utilities/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.Utilities/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.Utilities/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs b/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs index 263122930b..b9bf379981 100644 --- a/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs +++ b/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs @@ -63,7 +63,15 @@ internal static bool IsValidNodeXmlValue(string xmlNodeValue, Func var secureInnerXml = SecurityElement.Escape(innerXml); #else // fixing manually as we currently target to netcore 1.1 and we don't have default implementation for Escape functionality - var secureInnerXml = innerXml.IsNullOrEmpty() ? innerXml : innerXml.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'"); + string secureInnerXml; + if (innerXml.IsNullOrEmpty()) + { + secureInnerXml = string.Empty; + } + else + { + secureInnerXml = innerXml.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'"); + } #endif if (childNode == null) { diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj index 604fd9e646..42db158dc2 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj @@ -6,8 +6,8 @@ Microsoft.TestPlatform.VsTestConsole.TranslationLayer - net6.0;netstandard2.0;$(TargetNetFxVersion) - net6.0 + net7.0;net6.0;netstandard2.0;$(TargetNetFxVersion) + net7.0; false diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/SettingsMigrator/Migrator.cs b/src/SettingsMigrator/Migrator.cs index bd0f02bd3d..e2edb5c224 100644 --- a/src/SettingsMigrator/Migrator.cs +++ b/src/SettingsMigrator/Migrator.cs @@ -101,8 +101,7 @@ private static void MigrateRunSettings(string oldRunSettingsPath, string newRunS runSettingsXmlDoc.Load(reader); var root = runSettingsXmlDoc.DocumentElement; - var testSettingsNode = root.SelectSingleNode(@"/RunSettings/MSTest/SettingsFile"); - + var testSettingsNode = root?.SelectSingleNode(@"/RunSettings/MSTest/SettingsFile"); if (testSettingsNode != null) { testSettingsPath = testSettingsNode.InnerText; @@ -113,7 +112,7 @@ private static void MigrateRunSettings(string oldRunSettingsPath, string newRunS // Expand path relative to runSettings location. if (!Path.IsPathRooted(testSettingsPath)) { - testSettingsPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(oldRunSettingsPath), testSettingsPath)); + testSettingsPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(oldRunSettingsPath)!, testSettingsPath)); } // Remove the embedded testSettings node if it exists. @@ -153,36 +152,42 @@ private static void MigrateTestSettings(string oldTestSettingsPath, string newRu /// Runsettings Xml private static void MigrateTestSettingsNodesToRunSettings(string testSettingsPath, XmlDocument runSettingsXmlDoc) { - var testSettingsNodes = ReadTestSettingsNodes(testSettingsPath); + TestSettingsNodes testSettingsNodes = ReadTestSettingsNodes(testSettingsPath); string? testTimeout = null; - if (testSettingsNodes.Timeout != null && testSettingsNodes.Timeout.Attributes[TestTimeoutAttributeName] != null) - { - testTimeout = testSettingsNodes.Timeout.Attributes[TestTimeoutAttributeName].Value; - } - string? runTimeout = null; - if (testSettingsNodes.Timeout != null && testSettingsNodes.Timeout.Attributes[RunTimeoutAttributeName] != null) + if (testSettingsNodes.Timeout is not null) { - runTimeout = testSettingsNodes.Timeout.Attributes[RunTimeoutAttributeName].Value; - } + if (testSettingsNodes.Timeout.Attributes?[TestTimeoutAttributeName] is XmlAttribute testTimeoutAttribute) + { + testTimeout = testTimeoutAttribute.Value; + } - string? parallelTestCount = null; - if (testSettingsNodes.Execution != null && testSettingsNodes.Execution.Attributes[ParallelTestCountAttributeName] != null) - { - parallelTestCount = testSettingsNodes.Execution.Attributes[ParallelTestCountAttributeName].Value; + if (testSettingsNodes.Timeout.Attributes?[RunTimeoutAttributeName] is XmlAttribute runTimeoutAttribute) + { + runTimeout = runTimeoutAttribute.Value; + } } + string? parallelTestCount = null; string? hostProcessPlatform = null; - if (testSettingsNodes.Execution != null && testSettingsNodes.Execution.Attributes[HostProcessPlatformAttributeName] != null) + if (testSettingsNodes.Execution is not null) { - hostProcessPlatform = testSettingsNodes.Execution.Attributes[HostProcessPlatformAttributeName].Value; + if (testSettingsNodes.Execution.Attributes?[ParallelTestCountAttributeName] is XmlAttribute parallelTestCountAttribute) + { + parallelTestCount = parallelTestCountAttribute.Value; + } + + if (testSettingsNodes.Execution.Attributes?[HostProcessPlatformAttributeName] is XmlAttribute hostProcessPlatformAttribute) + { + hostProcessPlatform = hostProcessPlatformAttribute.Value; + } } // WebTestRunConfiguration node. if (testSettingsNodes.WebSettings != null) { - runSettingsXmlDoc.DocumentElement.AppendChild(runSettingsXmlDoc.ImportNode(testSettingsNodes.WebSettings, deep: true)); + runSettingsXmlDoc.DocumentElement?.AppendChild(runSettingsXmlDoc.ImportNode(testSettingsNodes.WebSettings, deep: true)); } // LegacySettings node. @@ -191,11 +196,11 @@ private static void MigrateTestSettingsNodesToRunSettings(string testSettingsPat // TestSessionTimeout node. if (!runTimeout.IsNullOrEmpty()) { - AddRunTimeoutNode(runTimeout, runSettingsXmlDoc); + AddRunTimeoutNode(runTimeout, runSettingsXmlDoc!); } // DataCollectors node. - if (testSettingsNodes.Datacollectors != null && testSettingsNodes.Datacollectors.Count > 0) + if (testSettingsNodes?.Datacollectors != null && testSettingsNodes.Datacollectors.Count > 0) { AddDataCollectorNodes(testSettingsNodes.Datacollectors, runSettingsXmlDoc); } @@ -203,7 +208,7 @@ private static void MigrateTestSettingsNodesToRunSettings(string testSettingsPat private static TestSettingsNodes ReadTestSettingsNodes(string testSettingsPath) { - var testSettingsNodes = new TestSettingsNodes(); + TestSettingsNodes testSettingsNodes = new(); using (XmlTextReader reader = new(testSettingsPath)) { @@ -211,7 +216,7 @@ private static TestSettingsNodes ReadTestSettingsNodes(string testSettingsPath) var testSettingsXmlDoc = new XmlDocument(); testSettingsXmlDoc.Load(reader); - var testSettingsRoot = testSettingsXmlDoc.DocumentElement; + var testSettingsRoot = testSettingsXmlDoc.DocumentElement!; // Select the interesting nodes from the xml. testSettingsNodes.Deployment = testSettingsRoot.SelectSingleNode(@"/TestSettings/Deployment"); @@ -223,14 +228,16 @@ private static TestSettingsNodes ReadTestSettingsNodes(string testSettingsPath) testSettingsNodes.Hosts = testSettingsRoot.SelectSingleNode(@"/TestSettings/Execution/Hosts"); testSettingsNodes.Execution = testSettingsRoot.SelectSingleNode(@"/TestSettings/Execution"); - if (testSettingsNodes.Timeout != null && (testSettingsNodes.Timeout.Attributes[AgentNotRespondingTimeoutAttribute] != null || - testSettingsNodes.Timeout.Attributes[DeploymentTimeoutAttribute] != null || testSettingsNodes.Timeout.Attributes[ScriptTimeoutAttribute] != null)) + if (testSettingsNodes.Timeout != null + && (testSettingsNodes.Timeout.Attributes?[AgentNotRespondingTimeoutAttribute] != null + || testSettingsNodes.Timeout.Attributes?[DeploymentTimeoutAttribute] != null + || testSettingsNodes.Timeout.Attributes?[ScriptTimeoutAttribute] != null)) { Console.WriteLine(CommandLineResources.UnsupportedAttributes); } } - return testSettingsNodes; + return testSettingsNodes!; } /// @@ -239,10 +246,10 @@ private static TestSettingsNodes ReadTestSettingsNodes(string testSettingsPath) /// Xml doc to process private static void RemoveEmbeddedTestSettings(XmlDocument newXmlDoc) { - var testSettingsNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest/SettingsFile"); + var testSettingsNode = newXmlDoc.DocumentElement?.SelectSingleNode(@"/RunSettings/MSTest/SettingsFile"); if (testSettingsNode != null) { - testSettingsNode.ParentNode.RemoveChild(testSettingsNode); + testSettingsNode.ParentNode?.RemoveChild(testSettingsNode); } } @@ -267,9 +274,13 @@ private static void AddLegacyNodes(TestSettingsNodes testSettingsNodes, string? return; } + if (newXmlDoc.DocumentElement == null) + { + return; + } + // Add ForcedLegacy node. var mstestNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest"); - XmlNode forcedLegacyNode; if (mstestNode == null) { mstestNode = newXmlDoc.CreateNode(XmlNodeType.Element, MSTestNodeName, null); @@ -277,19 +288,24 @@ private static void AddLegacyNodes(TestSettingsNodes testSettingsNodes, string? mstestNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest"); } - forcedLegacyNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest/ForcedLegacyMode"); + if (mstestNode == null) + { + return; + } + + var forcedLegacyNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest/ForcedLegacyMode"); if (forcedLegacyNode == null) { forcedLegacyNode = newXmlDoc.CreateNode(XmlNodeType.Element, ForcedLegacyModeName, null); mstestNode.AppendChild(newXmlDoc.ImportNode(forcedLegacyNode, deep: true)); - forcedLegacyNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest/ForcedLegacyMode"); + forcedLegacyNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest/ForcedLegacyMode")!; } forcedLegacyNode.InnerText = "true"; // Remove if the legacy node already exists. var legacyNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/LegacySettings"); - if (legacyNode != null) + if (legacyNode?.ParentNode != null) { Console.WriteLine(CommandLineResources.IgnoringLegacySettings); legacyNode.ParentNode.RemoveChild(legacyNode); @@ -310,28 +326,28 @@ private static void AddLegacyNodes(TestSettingsNodes testSettingsNodes, string? // Execution node. if (testSettingsNodes.UnitTestConfig != null || !parallelTestCount.IsNullOrEmpty() || !testTimeout.IsNullOrEmpty() || testSettingsNodes.Hosts != null) { - var newExecutionNode = newXmlDoc.CreateNode(XmlNodeType.Element, ExecutionNodeName, null); + XmlNode newExecutionNode = newXmlDoc.CreateNode(XmlNodeType.Element, ExecutionNodeName, null); if (!parallelTestCount.IsNullOrEmpty()) { - var paralellAttribute = newXmlDoc.CreateAttribute(ParallelTestCountAttributeName); - paralellAttribute.Value = parallelTestCount; - newExecutionNode.Attributes.Append(paralellAttribute); + var parallelAttribute = newXmlDoc.CreateAttribute(ParallelTestCountAttributeName); + parallelAttribute.Value = parallelTestCount; + newExecutionNode.Attributes?.Append(parallelAttribute); } if (!hostProcessPlatform.IsNullOrEmpty()) { var hostProcessPlatformAttribute = newXmlDoc.CreateAttribute(HostProcessPlatformAttributeName); hostProcessPlatformAttribute.Value = hostProcessPlatform; - newExecutionNode.Attributes.Append(hostProcessPlatformAttribute); + newExecutionNode.Attributes?.Append(hostProcessPlatformAttribute); } if (!testTimeout.IsNullOrEmpty()) { var newTimeoutsNode = newXmlDoc.CreateNode(XmlNodeType.Element, TimeoutsNodeName, null); - var testtimeoutattribute = newXmlDoc.CreateAttribute(TestTimeoutAttributeName); - testtimeoutattribute.Value = testTimeout; - newTimeoutsNode.Attributes.Append(testtimeoutattribute); + var testTimeoutAttribute = newXmlDoc.CreateAttribute(TestTimeoutAttributeName); + testTimeoutAttribute.Value = testTimeout; + newTimeoutsNode.Attributes?.Append(testTimeoutAttribute); newExecutionNode.AppendChild(newXmlDoc.ImportNode(newTimeoutsNode, deep: true)); } @@ -354,12 +370,17 @@ private static void AddLegacyNodes(TestSettingsNodes testSettingsNodes, string? } /// - /// Adds the datacollector nodes to the runSettings xml. + /// Adds the dataCollector nodes to the runSettings xml. /// - /// Datacollector Nodes + /// Datacollector Nodes /// Xml doc to process - private static void AddDataCollectorNodes(XmlNodeList oldDatacollectorNodes, XmlDocument newXmlDoc) + private static void AddDataCollectorNodes(XmlNodeList oldDataCollectorNodes, XmlDocument? newXmlDoc) { + if (newXmlDoc?.DocumentElement == null) + { + return; + } + var dataCollectionRunSettingsNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/DataCollectionRunSettings"); dataCollectionRunSettingsNode ??= newXmlDoc.CreateNode(XmlNodeType.Element, DataCollectionRunSettingsNodeName, null); @@ -369,12 +390,12 @@ private static void AddDataCollectorNodes(XmlNodeList oldDatacollectorNodes, Xml dataCollectorsNode = newXmlDoc.CreateNode(XmlNodeType.Element, DataCollectorsNodeName, null); dataCollectionRunSettingsNode.AppendChild(newXmlDoc.ImportNode(dataCollectorsNode, deep: true)); newXmlDoc.DocumentElement.AppendChild(dataCollectionRunSettingsNode); - dataCollectorsNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/DataCollectionRunSettings/DataCollectors"); + dataCollectorsNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/DataCollectionRunSettings/DataCollectors")!; } - foreach (XmlNode datacollector in oldDatacollectorNodes) + foreach (XmlNode dataCollector in oldDataCollectorNodes) { - dataCollectorsNode.AppendChild(newXmlDoc.ImportNode(datacollector, deep: true)); + dataCollectorsNode.AppendChild(newXmlDoc.ImportNode(dataCollector, deep: true)); } } @@ -385,6 +406,11 @@ private static void AddDataCollectorNodes(XmlNodeList oldDatacollectorNodes, Xml /// Xml doc to process private static void AddRunTimeoutNode(string runTimeout, XmlDocument newXmlDoc) { + if (newXmlDoc.DocumentElement == null) + { + return; + } + var runConfigurationNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/RunConfiguration"); runConfigurationNode ??= newXmlDoc.CreateNode(XmlNodeType.Element, RunConfigurationNodeName, null); diff --git a/src/SettingsMigrator/PathResolver.cs b/src/SettingsMigrator/PathResolver.cs index 8a4fb15d59..cb197a3241 100644 --- a/src/SettingsMigrator/PathResolver.cs +++ b/src/SettingsMigrator/PathResolver.cs @@ -33,7 +33,7 @@ public class PathResolver { var oldFilePath = args[0]; var newFileName = string.Concat(Path.GetFileNameWithoutExtension(oldFilePath), "_", DateTime.Now.ToString("MM-dd-yyyy_hh-mm-ss", CultureInfo.CurrentCulture), RunSettingsExtension); - newFilePath = Path.Combine(Path.GetDirectoryName(oldFilePath), newFileName); + newFilePath = Path.Combine(Path.GetDirectoryName(oldFilePath)!, newFileName); } else if (args.Length == 2) { diff --git a/src/SettingsMigrator/SettingsMigrator.csproj b/src/SettingsMigrator/SettingsMigrator.csproj index 82f634edfc..ab06081b04 100644 --- a/src/SettingsMigrator/SettingsMigrator.csproj +++ b/src/SettingsMigrator/SettingsMigrator.csproj @@ -6,8 +6,8 @@ SettingsMigrator - $(TargetNetFxVersion) - net6.0 + net7.0;$(TargetNetFxVersion) + net7.0; Exe AnyCPU false diff --git a/src/datacollector/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/datacollector/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/datacollector/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/datacollector/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/datacollector/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/datacollector/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/datacollector/datacollector.csproj b/src/datacollector/datacollector.csproj index 7a6bf8e0f8..88b2c2557a 100644 --- a/src/datacollector/datacollector.csproj +++ b/src/datacollector/datacollector.csproj @@ -14,7 +14,8 @@ $(TargetNetCoreVersion) $(TargetFrameworks);net472 $(TargetFrameworks);$(TargetNetFxVersion) - net6.0 + $(TargetFrameworks);net7.0;net6.0; + net7.0 AnyCPU Exe Major diff --git a/src/package/nuspec/Microsoft.TestPlatform.Build.csproj b/src/package/nuspec/Microsoft.TestPlatform.Build.csproj index 6f3480e8ab..909ce2c73c 100644 --- a/src/package/nuspec/Microsoft.TestPlatform.Build.csproj +++ b/src/package/nuspec/Microsoft.TestPlatform.Build.csproj @@ -2,7 +2,7 @@ Exe netstandard2.0 - net6.0 + net7.0 false TestPlatform.Build.nuspec BranchName=$(BranchName);CommitId=$(CommitId);Version=$(Version);TargetFramework=$(TargetFramework) diff --git a/src/package/nuspec/Microsoft.TestPlatform.CLI.csproj b/src/package/nuspec/Microsoft.TestPlatform.CLI.csproj index db9fbdba03..852b7e97cd 100644 --- a/src/package/nuspec/Microsoft.TestPlatform.CLI.csproj +++ b/src/package/nuspec/Microsoft.TestPlatform.CLI.csproj @@ -2,7 +2,7 @@ Exe $(TargetNetCoreVersion) - net6.0 + net7.0 false TestPlatform.CLI.nuspec BranchName=$(BranchName);CommitId=$(CommitId);Version=$(Version);TargetFramework=$(TargetFramework) diff --git a/src/package/package/package.csproj b/src/package/package/package.csproj index 9ec1f8e390..0ad3344694 100644 --- a/src/package/package/package.csproj +++ b/src/package/package/package.csproj @@ -6,7 +6,7 @@ $(TargetNetFxVersion);$(TargetNetCoreVersion) - net6.0 + net7.0 package false false diff --git a/src/package/sign/sign.proj b/src/package/sign/sign.proj index 553e090587..0b4bb9855e 100644 --- a/src/package/sign/sign.proj +++ b/src/package/sign/sign.proj @@ -27,9 +27,6 @@ $(ArtifactsBaseDirectory)netstandard2.0\ - - $(ArtifactsBaseDirectory)uap10.0\ - $(ArtifactsBaseDirectory)obj\$(BuildConfiguration)\$(TargetFramework)\$(TargetRuntime)\ diff --git a/src/testhost.arm64/testhost.arm64.csproj b/src/testhost.arm64/testhost.arm64.csproj index b23e53ecbb..a6f863b722 100644 --- a/src/testhost.arm64/testhost.arm64.csproj +++ b/src/testhost.arm64/testhost.arm64.csproj @@ -11,13 +11,13 @@ testhost.arm64 - $(TargetNetCoreVersion);$(TargetNetFxVersion);net47;net471;net472;net48 - net6.0 + net7.0;$(TargetNetCoreVersion);$(TargetNetFxVersion);net47;net471;net472;net48 + net7.0; Exe false app.manifest - + win10-arm64 false $(AssemblyName.Replace('.arm64', '')).$(TargetFramework).arm64 diff --git a/src/testhost.x86/TestHostTraceListener.cs b/src/testhost.x86/TestHostTraceListener.cs index 3be97db76a..0832b07d6d 100644 --- a/src/testhost.x86/TestHostTraceListener.cs +++ b/src/testhost.x86/TestHostTraceListener.cs @@ -33,12 +33,12 @@ public static void Setup() EqtTrace.Verbose("TestPlatformTraceListener.Setup: Added test platform trace listener."); } - public override void Fail(string message) + public override void Fail(string? message) { throw GetException(message); } - public override void Fail(string message, string detailMessage) + public override void Fail(string? message, string? detailMessage) { throw GetException((message + Environment.NewLine + detailMessage)); } diff --git a/src/testhost.x86/testhost.x86.csproj b/src/testhost.x86/testhost.x86.csproj index b14f562d5b..440075d394 100644 --- a/src/testhost.x86/testhost.x86.csproj +++ b/src/testhost.x86/testhost.x86.csproj @@ -11,15 +11,15 @@ testhost.x86 - $(TargetNetCoreVersion);$(TargetNetFxVersion);net47;net471;net472;net48 - net6.0 + net7.0;$(TargetNetCoreVersion);$(TargetNetFxVersion);net47;net471;net472;net48 + net7.0; AnyCPU true Exe false app.manifest - + win7-x86 false $(AssemblyName.Replace('.x86', '')).$(TargetFramework).x86 diff --git a/src/testhost/testhost.csproj b/src/testhost/testhost.csproj index ce52d0ac90..01d3621971 100644 --- a/src/testhost/testhost.csproj +++ b/src/testhost/testhost.csproj @@ -11,13 +11,13 @@ testhost - $(TargetNetCoreVersion);$(TargetNetFxVersion);net47;net471;net472;net48 - net6.0 + net7.0;$(TargetNetCoreVersion);$(TargetNetFxVersion);net47;net471;net472;net48 + net7.0; Exe false app.manifest - + win7-x64 false $(AssemblyName).$(TargetFramework) diff --git a/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs b/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs index fef3e315db..8a1e47df5f 100644 --- a/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs +++ b/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs @@ -58,7 +58,17 @@ public Architecture GetArchitecture(string assemblyPath) { // AssemblyName won't load the assembly into current domain. var assemblyName = AssemblyName.GetAssemblyName(assemblyPath); - archType = MapToArchitecture(assemblyName.ProcessorArchitecture, assemblyPath); + + var processorArchitecture = +#if NET7_0_OR_GREATER + // AssemblyName doesn't include ProcessorArchitecture in net7. + // It will always be ProcessorArchitecture.None. + ProcessorArchitecture.None; +#else + assemblyName.ProcessorArchitecture; +#endif + + archType = MapToArchitecture(processorArchitecture, assemblyPath); } catch (Exception ex) { @@ -102,15 +112,9 @@ private Architecture GetArchitectureFromAssemblyMetadata(string path) // to Run image that flag is not "updated" and ignored. So we check if the module is IL only or not. // If it's not IL only it means that is a R2R (Ready to Run) and we're already in the correct architecture x86. // In all other cases the architecture will end inside the correct switch branch. - var corflags = peReader.PEHeaders.CorHeader.Flags; - if ((corflags & CorFlags.Requires32Bit) != 0 || (corflags & CorFlags.ILOnly) == 0) - { - return Architecture.X86; - } - else - { - return Architecture.AnyCPU; - } + var corflags = peReader.PEHeaders.CorHeader?.Flags; + return (corflags & CorFlags.Requires32Bit) != 0 || (corflags & CorFlags.ILOnly) == 0 + ? Architecture.X86 : Architecture.AnyCPU; default: { EqtTrace.Error($"AssemblyMetadataProvider.GetArchitecture: Unhandled architecture '{peReader.PEHeaders.CoffHeader.Machine}'."); @@ -206,7 +210,6 @@ public Architecture GetArchitectureForSource(string imagePath) const int imageFileMachineThumb = 0x01c2; // ARM Thumb/Thumb-2 Little-Endian const int imageFileMachineArmnt = 0x01c4; // ARM Thumb-2 Little-Endian - try { //get the input stream diff --git a/src/vstest.console/InProcessVsTestConsoleWrapper.cs b/src/vstest.console/InProcessVsTestConsoleWrapper.cs index 624aed1ea8..b8c71d4934 100644 --- a/src/vstest.console/InProcessVsTestConsoleWrapper.cs +++ b/src/vstest.console/InProcessVsTestConsoleWrapper.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Globalization; using System.Linq; using System.Threading; @@ -81,7 +80,12 @@ public InProcessVsTestConsoleWrapper(ConsoleParameters consoleParameters) } // Fill the parameters. - consoleParameters.ParentProcessId = Process.GetCurrentProcess().Id; + consoleParameters.ParentProcessId = +#if NET7_0_OR_GREATER + Environment.ProcessId; +#else + System.Diagnostics.Process.GetCurrentProcess().Id; +#endif consoleParameters.PortNumber = port; // Start vstest.console. diff --git a/src/vstest.console/Internal/ConsoleLogger.cs b/src/vstest.console/Internal/ConsoleLogger.cs index 1775159c6a..a687280755 100644 --- a/src/vstest.console/Internal/ConsoleLogger.cs +++ b/src/vstest.console/Internal/ConsoleLogger.cs @@ -701,115 +701,118 @@ private void TestRunCompleteHandler(object? sender, TestRunCompleteEventArgs e) } } - var leafTestResultsPerSource = LeafTestResults.Select(p => p.Value).GroupBy(r => r.TestCase.Source); - foreach (var sd in leafTestResultsPerSource) + var leafTestResultsPerSource = LeafTestResults?.Select(p => p.Value)?.GroupBy(r => r.TestCase.Source); + if (leafTestResultsPerSource is not null) { - var source = sd.Key; - var sourceSummary = new SourceSummary(); - - var results = sd.ToArray(); - // duration of the whole source is the difference between the test that ended last and the one that started first - sourceSummary.Duration = !results.Any() ? TimeSpan.Zero : results.Max(r => r.EndTime) - results.Min(r => r.StartTime); - foreach (var result in results) + foreach (var sd in leafTestResultsPerSource) { - switch (result.Outcome) - { - case TestOutcome.Passed: - sourceSummary.TotalTests++; - sourceSummary.PassedTests++; - break; - case TestOutcome.Failed: - sourceSummary.TotalTests++; - sourceSummary.FailedTests++; - break; - case TestOutcome.Skipped: - sourceSummary.TotalTests++; - sourceSummary.SkippedTests++; - break; - default: - break; - } - } + var source = sd.Key; + var sourceSummary = new SourceSummary(); - if (VerbosityLevel is Verbosity.Quiet or Verbosity.Minimal) - { - TestOutcome sourceOutcome = TestOutcome.None; - if (sourceSummary.FailedTests > 0) + var results = sd.ToArray(); + // duration of the whole source is the difference between the test that ended last and the one that started first + sourceSummary.Duration = !results.Any() ? TimeSpan.Zero : results.Max(r => r.EndTime) - results.Min(r => r.StartTime); + foreach (var result in results) { - sourceOutcome = TestOutcome.Failed; - } - else if (sourceSummary.PassedTests > 0) - { - sourceOutcome = TestOutcome.Passed; - } - else if (sourceSummary.SkippedTests > 0) - { - sourceOutcome = TestOutcome.Skipped; + switch (result.Outcome) + { + case TestOutcome.Passed: + sourceSummary.TotalTests++; + sourceSummary.PassedTests++; + break; + case TestOutcome.Failed: + sourceSummary.TotalTests++; + sourceSummary.FailedTests++; + break; + case TestOutcome.Skipped: + sourceSummary.TotalTests++; + sourceSummary.SkippedTests++; + break; + default: + break; + } } - string resultString = sourceOutcome switch - { - TestOutcome.Failed => (CommandLineResources.FailedTestIndicator + "!").PadRight(LongestResultIndicator), - TestOutcome.Passed => (CommandLineResources.PassedTestIndicator + "!").PadRight(LongestResultIndicator), - TestOutcome.Skipped => (CommandLineResources.SkippedTestIndicator + "!").PadRight(LongestResultIndicator), - _ => CommandLineResources.None.PadRight(LongestResultIndicator), - }; - var failed = sourceSummary.FailedTests.ToString(CultureInfo.CurrentCulture).PadLeft(5); - var passed = sourceSummary.PassedTests.ToString(CultureInfo.CurrentCulture).PadLeft(5); - var skipped = sourceSummary.SkippedTests.ToString(CultureInfo.CurrentCulture).PadLeft(5); - var total = sourceSummary.TotalTests.ToString(CultureInfo.CurrentCulture).PadLeft(5); - - - var frameworkString = _targetFramework.IsNullOrEmpty() - ? string.Empty - : $"({_targetFramework})"; - - var duration = GetFormattedDurationString(sourceSummary.Duration); - var sourceName = Path.GetFileName(sd.Key); - - var outputLine = string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary, - resultString, - failed, - passed, - skipped, - total, - duration, - sourceName, - frameworkString); - - - ConsoleColor? color = null; - if (sourceOutcome == TestOutcome.Failed) - { - color = ConsoleColor.Red; - } - else if (sourceOutcome == TestOutcome.Passed) + if (VerbosityLevel is Verbosity.Quiet or Verbosity.Minimal) { - color = ConsoleColor.Green; - } - else if (sourceOutcome == TestOutcome.Skipped) - { - color = ConsoleColor.Yellow; - } + TestOutcome sourceOutcome = TestOutcome.None; + if (sourceSummary.FailedTests > 0) + { + sourceOutcome = TestOutcome.Failed; + } + else if (sourceSummary.PassedTests > 0) + { + sourceOutcome = TestOutcome.Passed; + } + else if (sourceSummary.SkippedTests > 0) + { + sourceOutcome = TestOutcome.Skipped; + } - if (color != null) - { - Output.Write(outputLine, OutputLevel.Information, color.Value); - } - else - { - Output.Write(outputLine, OutputLevel.Information); + string resultString = sourceOutcome switch + { + TestOutcome.Failed => (CommandLineResources.FailedTestIndicator + "!").PadRight(LongestResultIndicator), + TestOutcome.Passed => (CommandLineResources.PassedTestIndicator + "!").PadRight(LongestResultIndicator), + TestOutcome.Skipped => (CommandLineResources.SkippedTestIndicator + "!").PadRight(LongestResultIndicator), + _ => CommandLineResources.None.PadRight(LongestResultIndicator), + }; + var failed = sourceSummary.FailedTests.ToString(CultureInfo.CurrentCulture).PadLeft(5); + var passed = sourceSummary.PassedTests.ToString(CultureInfo.CurrentCulture).PadLeft(5); + var skipped = sourceSummary.SkippedTests.ToString(CultureInfo.CurrentCulture).PadLeft(5); + var total = sourceSummary.TotalTests.ToString(CultureInfo.CurrentCulture).PadLeft(5); + + + var frameworkString = _targetFramework.IsNullOrEmpty() + ? string.Empty + : $"({_targetFramework})"; + + var duration = GetFormattedDurationString(sourceSummary.Duration); + var sourceName = Path.GetFileName(sd.Key); + + var outputLine = string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary, + resultString, + failed, + passed, + skipped, + total, + duration, + sourceName, + frameworkString); + + + ConsoleColor? color = null; + if (sourceOutcome == TestOutcome.Failed) + { + color = ConsoleColor.Red; + } + else if (sourceOutcome == TestOutcome.Passed) + { + color = ConsoleColor.Green; + } + else if (sourceOutcome == TestOutcome.Skipped) + { + color = ConsoleColor.Yellow; + } + + if (color != null) + { + Output.Write(outputLine, OutputLevel.Information, color.Value); + } + else + { + Output.Write(outputLine, OutputLevel.Information); + } + + Output.Information(false, CommandLineResources.TestRunSummaryAssemblyAndFramework, + sourceName, + frameworkString); } - Output.Information(false, CommandLineResources.TestRunSummaryAssemblyAndFramework, - sourceName, - frameworkString); + passedTests += sourceSummary.PassedTests; + failedTests += sourceSummary.FailedTests; + skippedTests += sourceSummary.SkippedTests; + totalTests += sourceSummary.TotalTests; } - - passedTests += sourceSummary.PassedTests; - failedTests += sourceSummary.FailedTests; - skippedTests += sourceSummary.SkippedTests; - totalTests += sourceSummary.TotalTests; } if (VerbosityLevel is Verbosity.Quiet or Verbosity.Minimal) diff --git a/src/vstest.console/Internal/ProgressIndicator.cs b/src/vstest.console/Internal/ProgressIndicator.cs index 0821ca4b69..1b21b1e15b 100644 --- a/src/vstest.console/Internal/ProgressIndicator.cs +++ b/src/vstest.console/Internal/ProgressIndicator.cs @@ -100,7 +100,7 @@ public void Stop() } } - private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e) { if (IsRunning) { diff --git a/src/vstest.console/Processors/EnableBlameArgumentProcessor.cs b/src/vstest.console/Processors/EnableBlameArgumentProcessor.cs index 91bbb29359..639cf95b8a 100644 --- a/src/vstest.console/Processors/EnableBlameArgumentProcessor.cs +++ b/src/vstest.console/Processors/EnableBlameArgumentProcessor.cs @@ -188,7 +188,7 @@ private void InitializeBlame(bool enableCrashDump, bool enableHangDump, Dictiona var settings = _runSettingsManager.ActiveRunSettings?.SettingsXml; // Get results directory from RunSettingsManager - var resultsDirectory = GetResultsDirectory(settings); + var resultsDirectory = GetResultsDirectory(settings)!; // Get data collection run settings. Create if not present. var dataCollectionRunSettings = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settings); @@ -205,8 +205,9 @@ private void InitializeBlame(bool enableCrashDump, bool enableHangDump, Dictiona if (enableCrashDump) { var dumpParameters = collectDumpParameters - .Where(p => new[] { "CollectAlways", "DumpType" }.Contains(p.Key, StringComparer.OrdinalIgnoreCase)) - .ToDictionary(p => p.Key, p => p.Value, StringComparer.OrdinalIgnoreCase); + ?.Where(p => new[] { "CollectAlways", "DumpType" }.Contains(p.Key, StringComparer.OrdinalIgnoreCase)) + .ToDictionary(p => p.Key, p => p.Value, StringComparer.OrdinalIgnoreCase) + ?? new Dictionary(); if (!dumpParameters.ContainsKey("DumpType")) { @@ -220,8 +221,9 @@ private void InitializeBlame(bool enableCrashDump, bool enableHangDump, Dictiona if (enableHangDump) { var hangDumpParameters = collectDumpParameters - .Where(p => new[] { "TestTimeout", "HangDumpType" }.Contains(p.Key, StringComparer.OrdinalIgnoreCase)) - .ToDictionary(p => p.Key, p => p.Value, StringComparer.OrdinalIgnoreCase); + ?.Where(p => new[] { "TestTimeout", "HangDumpType" }.Contains(p.Key, StringComparer.OrdinalIgnoreCase)) + .ToDictionary(p => p.Key, p => p.Value, StringComparer.OrdinalIgnoreCase) + ?? new Dictionary(); if (!hangDumpParameters.ContainsKey("TestTimeout")) { @@ -281,7 +283,7 @@ private void InitializeBlame(bool enableCrashDump, bool enableHangDump, Dictiona /// Parameters. /// Xml document. /// Outer node. - private static void AddCollectDumpNode(Dictionary parameters, XmlDocument xmlDocument, XmlElement outernode) + private static void AddCollectDumpNode(Dictionary? parameters, XmlDocument xmlDocument, XmlElement outernode) { var dumpNode = xmlDocument.CreateElement(Constants.BlameCollectDumpKey); if (parameters != null && parameters.Count > 0) diff --git a/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs b/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs index 5b297ed38a..f2b01b973f 100644 --- a/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs +++ b/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs @@ -211,8 +211,7 @@ private void UpdateWithCodeCoverageSettingsIfNotConfigured() runSettingsDocument = document; } - var runSettingsNavigator = runSettingsDocument.CreateNavigator(); - + var runSettingsNavigator = runSettingsDocument.CreateNavigator()!; if (ContainsDataCollectorWithFriendlyName(runSettingsNavigator, FriendlyName)) { // runsettings already has Code coverage data collector, just enable it. @@ -244,15 +243,15 @@ private void UpdateWithCodeCoverageSettingsIfNotConfigured() XPathNavigator dataCollectorsNavigator; if (existingPath.Equals(xpaths[2]) == false) { - dataCollectorsNavigator = runSettingsNavigator.SelectSingleNode(existingPath); + dataCollectorsNavigator = runSettingsNavigator.SelectSingleNode(existingPath)!; var missingNodesText = GetMissingNodesTextIfAny(existingPath, xpaths[2]); dataCollectorsNavigator.AppendChild(missingNodesText); } - dataCollectorsNavigator = runSettingsNavigator.SelectSingleNode(xpaths[2]); + dataCollectorsNavigator = runSettingsNavigator.SelectSingleNode(xpaths[2])!; dataCollectorsNavigator.AppendChild(CodeCoverageCollectorSettingsTemplate); - _runSettingsManager.UpdateRunSettings(runSettingsDocument.CreateNavigator().OuterXml); + _runSettingsManager.UpdateRunSettings(runSettingsDocument.CreateNavigator()!.OuterXml); } } @@ -283,7 +282,7 @@ private static bool ContainsDataCollectorWithFriendlyName(IXPathNavigable runSet _ = runSettingDocument ?? throw new ArgumentNullException(nameof(runSettingDocument)); _ = dataCollectorFriendlyName ?? throw new ArgumentNullException(nameof(dataCollectorFriendlyName)); - var navigator = runSettingDocument.CreateNavigator(); + var navigator = runSettingDocument.CreateNavigator()!; var nodes = navigator.Select("/RunSettings/DataCollectionRunSettings/DataCollectors/DataCollector"); foreach (XPathNavigator? dataCollectorNavigator in nodes) diff --git a/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs b/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs index dfed7542a0..f6580388e6 100644 --- a/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs +++ b/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs @@ -222,7 +222,7 @@ private void DiscoveryRequest_OnDiscoveredTests(object? sender, DiscoveredTestsE // Initializing the test case filter here because the filter value is read late. TestCaseFilter.Initialize(_options.TestCaseFilterValue); - var discoveredTests = args.DiscoveredTestCases.ToList(); + var discoveredTests = args.DiscoveredTestCases!.ToList(); var filteredTests = TestCaseFilter.FilterTests(discoveredTests).ToList(); // remove any duplicate tests diff --git a/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs b/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs index fb39297d34..dde4d55320 100644 --- a/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs +++ b/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs @@ -272,6 +272,7 @@ private void ExecuteSelectedTests() private void DiscoveryRequest_OnDiscoveredTests(object? sender, DiscoveredTestsEventArgs args) { TPDebug.Assert(_selectedTestNames != null, "Initialize should have been called"); + TPDebug.Assert(args.DiscoveredTestCases != null); _discoveredTestCount += args.DiscoveredTestCases.Count(); foreach (var testCase in args.DiscoveredTestCases!) diff --git a/src/vstest.console/PublicAPI/net7.0/PublicAPI.Shipped.txt b/src/vstest.console/PublicAPI/net7.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/vstest.console/PublicAPI/net7.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/vstest.console/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/vstest.console/PublicAPI/net7.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/vstest.console/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index ee1f67b6e1..642e36bb9e 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -671,7 +671,7 @@ protected virtual void Dispose(bool disposing) XmlRunSettingsUtilities.ReaderSettings); var document = new XmlDocument(); document.Load(reader); - var navigator = document.CreateNavigator(); + var navigator = document.CreateNavigator()!; var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml); var loggerRunSettings = XmlRunSettingsUtilities.GetLoggerRunSettings(runsettingsXml) ?? new LoggerRunSettings(); diff --git a/src/vstest.console/vstest.console.csproj b/src/vstest.console/vstest.console.csproj index d7a3d0567b..5a186f01ab 100644 --- a/src/vstest.console/vstest.console.csproj +++ b/src/vstest.console/vstest.console.csproj @@ -8,8 +8,8 @@ vstest.console vstest.console.arm64 - $(TargetNetFxVersion);$(TargetNetCoreVersion) - net6.0 + net7.0;$(TargetNetFxVersion);$(TargetNetCoreVersion) + net7.0; Exe Major false @@ -22,6 +22,10 @@ (e.g. System.Runtime 4.1.2 instead of 4.0.0) --> false + + + $(MSBuildWarningsAsMessages);MSB3276; + win7-x64;win10-arm64 diff --git a/test/TestAssets/ArchitectureSwitch/ArchitectureSwitch.csproj b/test/TestAssets/ArchitectureSwitch/ArchitectureSwitch.csproj index 96466b21a1..4330294307 100644 --- a/test/TestAssets/ArchitectureSwitch/ArchitectureSwitch.csproj +++ b/test/TestAssets/ArchitectureSwitch/ArchitectureSwitch.csproj @@ -1,7 +1,7 @@ - net6.0;net5.0 - net6.0;netcoreapp3.1 + net7.0;net6.0;net5.0 + net7.0;net6.0;netcoreapp3.1 false diff --git a/test/TestAssets/Tools/Tools.csproj b/test/TestAssets/Tools/Tools.csproj index 5981f1c93c..f135d9a66d 100644 --- a/test/TestAssets/Tools/Tools.csproj +++ b/test/TestAssets/Tools/Tools.csproj @@ -9,7 +9,7 @@ - net5.0 + net7.0;net6.0;net5.0 Exe hanging_child diff --git a/test/TestAssets/child-crash/child-crash.csproj b/test/TestAssets/child-crash/child-crash.csproj index e0221378ae..79103e1d8f 100644 --- a/test/TestAssets/child-crash/child-crash.csproj +++ b/test/TestAssets/child-crash/child-crash.csproj @@ -9,7 +9,7 @@ - net5.0 + net7.0;net6.0;net5.0 child_crash false diff --git a/test/TestAssets/child-hang/child-hang.csproj b/test/TestAssets/child-hang/child-hang.csproj index ccb65b2dbf..fd2070c4b2 100644 --- a/test/TestAssets/child-hang/child-hang.csproj +++ b/test/TestAssets/child-hang/child-hang.csproj @@ -8,7 +8,7 @@ - $(TargetNetFxVersion);net472;net48;$(TargetNetCoreVersion);net5.0 + $(TargetNetFxVersion);net472;net48;$(TargetNetCoreVersion);net7.0;net6.0;net5.0 netcoreapp3.1 child_hang false diff --git a/test/TestAssets/crash/crash.csproj b/test/TestAssets/crash/crash.csproj index 40e2ee46c6..1cf0041859 100644 --- a/test/TestAssets/crash/crash.csproj +++ b/test/TestAssets/crash/crash.csproj @@ -8,7 +8,7 @@ - $(TargetNetFxVersion);net472;net48;$(TargetNetCoreVersion);net5.0 + $(TargetNetFxVersion);net472;net48;$(TargetNetCoreVersion);net7.0;net6.0;net5.0 netcoreapp3.1 false diff --git a/test/TestAssets/hanging-child/hanging-child.csproj b/test/TestAssets/hanging-child/hanging-child.csproj index 0b4db786aa..29462503aa 100644 --- a/test/TestAssets/hanging-child/hanging-child.csproj +++ b/test/TestAssets/hanging-child/hanging-child.csproj @@ -9,7 +9,7 @@ - net5.0 + net7.0;net6.0;net5.0 Exe hanging_child diff --git a/test/TestAssets/performance/Perfy.TestAdapter/Perfy.TestAdapter.csproj b/test/TestAssets/performance/Perfy.TestAdapter/Perfy.TestAdapter.csproj index c1613de05a..f21b3c90af 100644 --- a/test/TestAssets/performance/Perfy.TestAdapter/Perfy.TestAdapter.csproj +++ b/test/TestAssets/performance/Perfy.TestAdapter/Perfy.TestAdapter.csproj @@ -2,7 +2,7 @@ - net6.0;net48;net472;net471;net5.0 + net7.0;net6.0;net48;net472;net471;net5.0 netcoreapp3.1 false false diff --git a/test/TestAssets/problematic-child/problematic-child.csproj b/test/TestAssets/problematic-child/problematic-child.csproj index cd12b0cde9..83be57c2d8 100644 --- a/test/TestAssets/problematic-child/problematic-child.csproj +++ b/test/TestAssets/problematic-child/problematic-child.csproj @@ -9,7 +9,7 @@ - net5.0 + net7.0;net6.0;net5.0 Exe problematic_child diff --git a/test/TestAssets/timeout/timeout.csproj b/test/TestAssets/timeout/timeout.csproj index 20818da131..4f9b22714d 100644 --- a/test/TestAssets/timeout/timeout.csproj +++ b/test/TestAssets/timeout/timeout.csproj @@ -9,7 +9,7 @@ - $(TargetNetFxVersion);net472;net48;$(TargetNetCoreVersion);net5.0 + $(TargetNetFxVersion);net472;net48;$(TargetNetCoreVersion);net7.0;net6.0;net5.0 netcoreapp3.1 false