From fc79ea25df2cdeb3cf29af0ce302a99e0bc00294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 17 Jun 2022 16:33:32 +0200 Subject: [PATCH] Enable missed nullables on already handled projects (#3773) --- .../Microsoft.TestPlatform.Client.csproj | 3 +++ .../Microsoft.TestPlatform.Common.csproj | 1 - src/Microsoft.TestPlatform.CoreUtilities/Friends.cs | 1 + .../Helpers/CommandLineArgumentsHelper.cs | 3 +-- .../Helpers/DotnetHostHelper.cs | 10 +++++----- .../Helpers/EnvironmentVariableHelper.cs | 2 +- .../Helpers/FileHelper.cs | 6 +++--- .../Helpers/Interfaces/IDotnetHostHelper.cs | 4 +--- .../Interfaces/IEnvironmentVariableHelper.cs | 4 +--- .../Helpers/Interfaces/IFileHelper.cs | 9 ++++----- .../Microsoft.TestPlatform.CoreUtilities.csproj | 6 +++++- .../PublicAPI/net6.0/PublicAPI.Shipped.txt | 13 ++++++++++++- .../Tracing/EqtTrace.cs | 4 ++-- .../PostProcessing/ArtifactProcessingManager.cs | 7 ++++++- .../Friends.cs | 9 --------- .../Hosting/DefaultTestHostManager.cs | 2 +- .../Hosting/DotnetTestHostManager.cs | 2 +- .../Microsoft.TestPlatform.AcceptanceTests.csproj | 3 +++ .../Helpers/DotnetHostHelperTest.cs | 2 +- ...t.TestPlatform.TestHostProvider.UnitTests.csproj | 3 --- .../Microsoft.TestPlatform.TestUtilities.csproj | 3 +++ test/vstest.ProgrammerTests/Fakes/FakeFileHelper.cs | 8 +++++--- .../Processors/EnableDiagArgumentProcessorTests.cs | 2 +- 23 files changed, 60 insertions(+), 47 deletions(-) delete mode 100644 src/Microsoft.TestPlatform.PlatformAbstractions/Friends.cs diff --git a/src/Microsoft.TestPlatform.Client/Microsoft.TestPlatform.Client.csproj b/src/Microsoft.TestPlatform.Client/Microsoft.TestPlatform.Client.csproj index 38f7e83900..e100e5c959 100644 --- a/src/Microsoft.TestPlatform.Client/Microsoft.TestPlatform.Client.csproj +++ b/src/Microsoft.TestPlatform.Client/Microsoft.TestPlatform.Client.csproj @@ -54,5 +54,8 @@ + + + diff --git a/src/Microsoft.TestPlatform.Common/Microsoft.TestPlatform.Common.csproj b/src/Microsoft.TestPlatform.Common/Microsoft.TestPlatform.Common.csproj index f986553113..9c9018c74d 100644 --- a/src/Microsoft.TestPlatform.Common/Microsoft.TestPlatform.Common.csproj +++ b/src/Microsoft.TestPlatform.Common/Microsoft.TestPlatform.Common.csproj @@ -13,7 +13,6 @@ - diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Friends.cs b/src/Microsoft.TestPlatform.CoreUtilities/Friends.cs index d39fb25c14..95374f0881 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Friends.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Friends.cs @@ -7,5 +7,6 @@ [assembly: InternalsVisibleTo("vstest.console.arm64, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("Microsoft.TestPlatform.CommunicationUtilities, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.ObjectModel, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.Common, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("vstest.ProgrammerTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/CommandLineArgumentsHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/CommandLineArgumentsHelper.cs index 216db267a1..6d59b3b1e9 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/CommandLineArgumentsHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/CommandLineArgumentsHelper.cs @@ -72,8 +72,7 @@ public static bool TryGetIntArgFromDict(IDictionary argsDiction return false; } - value = int.Parse(optionValue); - return true; + return int.TryParse(optionValue, out value); } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs index abd4b03361..79bfdd578d 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs @@ -105,7 +105,7 @@ private bool TryGetExecutablePath(string executableBaseName, out string executab } executablePath = string.Empty; - var pathString = Environment.GetEnvironmentVariable("PATH"); + var pathString = Environment.GetEnvironmentVariable("PATH")!; foreach (string path in pathString.Split(Path.PathSeparator)) { string exeFullPath = Path.Combine(path.Trim(), executableBaseName); @@ -149,7 +149,7 @@ public bool TryGetDotnetPathByArchitecture(PlatformArchitecture targetArchitectu string envKey = $"DOTNET_ROOT_{targetArchitecture.ToString().ToUpperInvariant()}"; // Try on arch specific env var - string envVar = _environmentVariableHelper.GetEnvironmentVariable(envKey); + string? envVar = _environmentVariableHelper.GetEnvironmentVariable(envKey); // Try on non virtualized x86 var(should happen only on non-x86 architecture) if ((envVar == null || !_fileHelper.DirectoryExists(envVar)) && @@ -233,14 +233,14 @@ public bool TryGetDotnetPathByArchitecture(PlatformArchitecture targetArchitectu if ((_environment.Architecture == PlatformArchitecture.X64 || _environment.Architecture == PlatformArchitecture.ARM64) && targetArchitecture == PlatformArchitecture.X86) { - muxerPath = Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles(x86)"), "dotnet", _muxerName); + muxerPath = Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles(x86)")!, "dotnet", _muxerName); } else { // If we're on ARM and target is x64 we expect correct installation inside x64 folder muxerPath = _environment.Architecture == PlatformArchitecture.ARM64 && targetArchitecture == PlatformArchitecture.X64 - ? Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles"), "dotnet", "x64", _muxerName) - : Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles"), "dotnet", _muxerName); + ? Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles")!, "dotnet", "x64", _muxerName) + : Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles")!, "dotnet", _muxerName); } } else diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/EnvironmentVariableHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/EnvironmentVariableHelper.cs index d7457292ea..39a127b74c 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/EnvironmentVariableHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/EnvironmentVariableHelper.cs @@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers; internal class EnvironmentVariableHelper : IEnvironmentVariableHelper { /// - public string GetEnvironmentVariable(string variable) + public string? GetEnvironmentVariable(string variable) => Environment.GetEnvironmentVariable(variable); /// diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs index 4c144d9e96..40242708fd 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs @@ -29,11 +29,11 @@ public string GetCurrentDirectory() => Directory.GetCurrentDirectory(); /// - public bool Exists(string path) + public bool Exists(string? path) => File.Exists(path); /// - public bool DirectoryExists(string path) + public bool DirectoryExists(string? path) => Directory.Exists(path); /// @@ -48,7 +48,7 @@ public Stream GetStream(string filePath, FileMode mode, FileAccess access, FileS public IEnumerable EnumerateFiles( string directory, SearchOption searchOption, - params string[] endsWithSearchPatterns) + params string[]? endsWithSearchPatterns) { if (endsWithSearchPatterns == null || endsWithSearchPatterns.Length == 0) { diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs index dd190eeeff..d81c2f690d 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs @@ -3,8 +3,6 @@ using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; /// @@ -31,5 +29,5 @@ public interface IDotnetHostHelper /// Specific architecture /// Path to the muxer /// True if native muxer is found - bool TryGetDotnetPathByArchitecture(PlatformArchitecture targetArchitecture, out string muxerPath); + bool TryGetDotnetPathByArchitecture(PlatformArchitecture targetArchitecture, out string? muxerPath); } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IEnvironmentVariableHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IEnvironmentVariableHelper.cs index 2d7cd021a8..79aeee6434 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IEnvironmentVariableHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IEnvironmentVariableHelper.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. -#nullable disable - using System; namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; @@ -14,7 +12,7 @@ internal interface IEnvironmentVariableHelper /// /// The name of the environment variable. /// The value of the environment variable specified by variable, or null if the environment variable is not found. - string GetEnvironmentVariable(string variable); + string? GetEnvironmentVariable(string variable); /// /// Retrieves the value of an environment variable from the current process and converts it to the given type. diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs index 9f70076ed1..0fb176db09 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs @@ -2,13 +2,12 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Diagnostics.CodeAnalysis; #if !NETSTANDARD1_0 using System.Collections.Generic; using System.IO; #endif -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; /// @@ -36,14 +35,14 @@ public interface IFileHelper /// /// The path of file. /// True if file exists . - bool Exists(string path); + bool Exists([NotNullWhen(true)] string? path); /// /// Exists utility to check if directory exists (case sensitive). /// /// The path of file. /// True if directory exists . - bool DirectoryExists(string path); + bool DirectoryExists([NotNullWhen(true)] string? path); #if !NETSTANDARD1_0 /// @@ -72,7 +71,7 @@ public interface IFileHelper /// for directory. /// Patterns used to select files using String.EndsWith /// List of files matching the pattern. - IEnumerable EnumerateFiles(string directory, SearchOption searchOption, params string[] endsWithSearchPatterns); + IEnumerable EnumerateFiles(string directory, SearchOption searchOption, params string[]? endsWithSearchPatterns); /// /// Gets attributes of a file. diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj b/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj index a47d0f305e..6b3f2ce418 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj +++ b/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj @@ -6,7 +6,7 @@ Microsoft.TestPlatform.CoreUtilities - netstandard2.0;netstandard1.3;net451;net45 + net6.0;netstandard2.0;netstandard1.3;net451;net45 false $(TargetFrameworks);uap10.0;netstandard1.0 net6.0 @@ -84,6 +84,10 @@ + + + + NullableHelpers.cs diff --git a/src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0/PublicAPI.Shipped.txt index 5f282702bb..9d88848572 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0/PublicAPI.Shipped.txt +++ b/src/Microsoft.TestPlatform.CoreUtilities/PublicAPI/net6.0/PublicAPI.Shipped.txt @@ -1 +1,12 @@ - \ No newline at end of file +Microsoft.VisualStudio.TestPlatform.Utilities.ConsoleOutput +Microsoft.VisualStudio.TestPlatform.Utilities.ConsoleOutput.Write(string message, Microsoft.VisualStudio.TestPlatform.Utilities.OutputLevel level) -> void +Microsoft.VisualStudio.TestPlatform.Utilities.ConsoleOutput.WriteLine(string message, Microsoft.VisualStudio.TestPlatform.Utilities.OutputLevel level) -> void +Microsoft.VisualStudio.TestPlatform.Utilities.OutputExtensions +static Microsoft.VisualStudio.TestPlatform.ObjectModel.EqtTrace.TraceLevel.get -> Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformTraceLevel +static Microsoft.VisualStudio.TestPlatform.ObjectModel.EqtTrace.TraceLevel.set -> void +static Microsoft.VisualStudio.TestPlatform.Utilities.ConsoleOutput.Instance.get -> Microsoft.VisualStudio.TestPlatform.Utilities.ConsoleOutput +static Microsoft.VisualStudio.TestPlatform.Utilities.OutputExtensions.Error(this Microsoft.VisualStudio.TestPlatform.Utilities.IOutput output, bool appendPrefix, string format, params object[] args) -> void +static Microsoft.VisualStudio.TestPlatform.Utilities.OutputExtensions.Information(this Microsoft.VisualStudio.TestPlatform.Utilities.IOutput output, bool appendPrefix, string format, params object[] args) -> void +static Microsoft.VisualStudio.TestPlatform.Utilities.OutputExtensions.Information(this Microsoft.VisualStudio.TestPlatform.Utilities.IOutput output, bool appendPrefix, System.ConsoleColor foregroundColor, string format, params object[] args) -> void +static Microsoft.VisualStudio.TestPlatform.Utilities.OutputExtensions.Warning(this Microsoft.VisualStudio.TestPlatform.Utilities.IOutput output, bool appendPrefix, string format, params object[] args) -> void +static Microsoft.VisualStudio.TestPlatform.Utilities.OutputExtensions.Write(this Microsoft.VisualStudio.TestPlatform.Utilities.IOutput output, string message, Microsoft.VisualStudio.TestPlatform.Utilities.OutputLevel level, System.ConsoleColor foregroundColor) -> void diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/EqtTrace.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/EqtTrace.cs index 1b74ef4720..ea8d3305dd 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/EqtTrace.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/EqtTrace.cs @@ -180,7 +180,7 @@ public static bool InitializeTrace(string? customLogFile, PlatformTraceLevel tra [Conditional("TRACE")] public static void Fail(string message) { - Fail(message, null); + Fail(message, new object[0]); } /// @@ -190,7 +190,7 @@ public static void Fail(string message) /// The formatted error message /// Arguments to the format [Conditional("TRACE")] - public static void Fail(string format, params object?[]? args) + public static void Fail(string format, params object?[] args) { string message = string.Format(CultureInfo.InvariantCulture, format, args); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/PostProcessing/ArtifactProcessingManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/PostProcessing/ArtifactProcessingManager.cs index d53a561be3..9449ce97a5 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/PostProcessing/ArtifactProcessingManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/PostProcessing/ArtifactProcessingManager.cs @@ -93,6 +93,7 @@ public void CollectArtifacts(TestRunCompleteEventArgs testRunCompleteEventArgs, { EqtTrace.Verbose($"ArtifactProcessingManager.CollectArtifacts: Saving data collectors artifacts for post process into {_processArtifactFolder}"); Stopwatch watch = Stopwatch.StartNew(); + TPDebug.Assert(_testSessionProcessArtifactFolder is not null, "_testSessionProcessArtifactFolder is null"); _fileHelper.CreateDirectory(_testSessionProcessArtifactFolder); EqtTrace.Verbose($"ArtifactProcessingManager.CollectArtifacts: Persist runsettings \n{runSettingsXml}"); _fileHelper.WriteAllTextToFile(Path.Combine(_testSessionProcessArtifactFolder, RunsettingsFileName), runSettingsXml); @@ -213,11 +214,15 @@ await _testRunAttachmentsProcessingManager.ProcessTestRunAttachmentsAsync(runset } - private TestArtifacts[] LoadTestArtifacts() => _fileHelper.GetFiles(_processArtifactFolder, "*.*", SearchOption.AllDirectories) + private TestArtifacts[] LoadTestArtifacts() + { + TPDebug.Assert(_processArtifactFolder is not null, "_processArtifactFolder is null"); + return _fileHelper.GetFiles(_processArtifactFolder, "*.*", SearchOption.AllDirectories) .Select(file => new { TestSessionId = Path.GetFileName(Path.GetDirectoryName(file)), Artifact = file }) .GroupBy(grp => grp.TestSessionId) .Select(testSessionArtifact => new TestArtifacts(testSessionArtifact.Key, testSessionArtifact.Select(x => ParseArtifact(x.Artifact)).Where(x => x is not null).ToArray()!)) // Bang because null dataflow doesn't yet backport learning from the `Where` clause .ToArray(); + } private static Artifact? ParseArtifact(string fileName) { diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/Friends.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/Friends.cs deleted file mode 100644 index ded0266d5d..0000000000 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/Friends.cs +++ /dev/null @@ -1,9 +0,0 @@ -// 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.Runtime.CompilerServices; - -#region Product Assemblies -[assembly: InternalsVisibleTo("Microsoft.TestPlatform.TestHostRuntimeProvider, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] -[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CoreUtilities, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] -#endregion diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index 8d9ca315c1..6b9a56e853 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -282,7 +282,7 @@ public IEnumerable GetTestPlatformExtensions(IEnumerable? source { if (sources != null && sources.Any()) { - extensions = extensions.Concat(sources.SelectMany(s => _fileHelper.EnumerateFiles(Path.GetDirectoryName(s), SearchOption.TopDirectoryOnly, TestAdapterEndsWithPattern))); + extensions = extensions.Concat(sources.SelectMany(s => _fileHelper.EnumerateFiles(Path.GetDirectoryName(s)!, SearchOption.TopDirectoryOnly, TestAdapterEndsWithPattern))); } extensions = FilterExtensionsBasedOnVersion(extensions); diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 88825066a4..1a4f787198 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -434,7 +434,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( } PlatformArchitecture finalTargetArchitecture = forceToX64 ? PlatformArchitecture.X64 : targetArchitecture; - if (!_dotnetHostHelper.TryGetDotnetPathByArchitecture(finalTargetArchitecture, out string muxerPath)) + if (!_dotnetHostHelper.TryGetDotnetPathByArchitecture(finalTargetArchitecture, out string? muxerPath)) { string message = string.Format(Resources.NoDotnetMuxerFoundForArchitecture, $"dotnet{(_platformEnvironment.OperatingSystem == PlatformOperatingSystem.Windows ? ".exe" : string.Empty)}", finalTargetArchitecture.ToString()); EqtTrace.Error(message); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/Microsoft.TestPlatform.AcceptanceTests.csproj b/test/Microsoft.TestPlatform.AcceptanceTests/Microsoft.TestPlatform.AcceptanceTests.csproj index 5910cccd71..9488029108 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/Microsoft.TestPlatform.AcceptanceTests.csproj +++ b/test/Microsoft.TestPlatform.AcceptanceTests/Microsoft.TestPlatform.AcceptanceTests.csproj @@ -23,6 +23,9 @@ + + + diff --git a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Helpers/DotnetHostHelperTest.cs b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Helpers/DotnetHostHelperTest.cs index 4a7e074033..141ec72976 100644 --- a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Helpers/DotnetHostHelperTest.cs +++ b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Helpers/DotnetHostHelperTest.cs @@ -89,7 +89,7 @@ public void GetDotnetPathByArchitecture_EnvVars(PlatformArchitecture targetArchi _fileHelper.Setup(x => x.Exists(envVars[envVar])).Returns(true); if (found) { - _fileHelper.Setup(x => x.GetStream(envVars[envVar], FileMode.Open, FileAccess.Read)).Returns(File.OpenRead(envVars[envVar]!)); + _fileHelper.Setup(x => x.GetStream(envVars[envVar]!, FileMode.Open, FileAccess.Read)).Returns(File.OpenRead(envVars[envVar]!)); } // Act & Assert diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj index ad9826155d..ac6ed32f77 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj @@ -12,9 +12,6 @@ netcoreapp3.1 Exe - - - diff --git a/test/Microsoft.TestPlatform.TestUtilities/Microsoft.TestPlatform.TestUtilities.csproj b/test/Microsoft.TestPlatform.TestUtilities/Microsoft.TestPlatform.TestUtilities.csproj index 056a13875c..9ae3c0949a 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/Microsoft.TestPlatform.TestUtilities.csproj +++ b/test/Microsoft.TestPlatform.TestUtilities/Microsoft.TestPlatform.TestUtilities.csproj @@ -17,6 +17,9 @@ + + + diff --git a/test/vstest.ProgrammerTests/Fakes/FakeFileHelper.cs b/test/vstest.ProgrammerTests/Fakes/FakeFileHelper.cs index 645e905c26..62ec8daa99 100644 --- a/test/vstest.ProgrammerTests/Fakes/FakeFileHelper.cs +++ b/test/vstest.ProgrammerTests/Fakes/FakeFileHelper.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; namespace vstest.ProgrammerTests.Fakes; @@ -40,14 +41,15 @@ public void DeleteEmptyDirectroy(string directoryPath) throw new NotImplementedException(); } - public bool DirectoryExists(string path) + public bool DirectoryExists(string? path) { + TPDebug.Assert(path is not null, "path is null"); // TODO: Check if any file has the directory in name. This will improve. var directoryExists = Files.Select(f => Path.GetDirectoryName(f.Path)).Any(p => p != null && p.StartsWith(path)); return directoryExists; } - public IEnumerable EnumerateFiles(string directory, SearchOption searchOption, params string[] endsWithSearchPatterns) + public IEnumerable EnumerateFiles(string directory, SearchOption searchOption, params string[]? endsWithSearchPatterns) { Func predicate = searchOption == SearchOption.TopDirectoryOnly ? (f, dir) => Path.GetDirectoryName(f.Path) == dir @@ -57,7 +59,7 @@ public IEnumerable EnumerateFiles(string directory, SearchOption searchO return files; } - public bool Exists(string path) + public bool Exists(string? path) { throw new NotImplementedException(); } diff --git a/test/vstest.console.UnitTests/Processors/EnableDiagArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/EnableDiagArgumentProcessorTests.cs index 29d243bb68..f17ce830f4 100644 --- a/test/vstest.console.UnitTests/Processors/EnableDiagArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/EnableDiagArgumentProcessorTests.cs @@ -156,7 +156,7 @@ public void EnableDiagArgumentProcessorExecutorShouldCreateDirectoryOfLogFileIfN _diagProcessor.Executor!.Value.Initialize(_dummyFilePath); - _mockFileHelper.Verify(fh => fh.CreateDirectory(Path.GetDirectoryName(_dummyFilePath)), Times.Once); + _mockFileHelper.Verify(fh => fh.CreateDirectory(Path.GetDirectoryName(_dummyFilePath)!), Times.Once); } [TestMethod]