Skip to content

Commit

Permalink
Enable missed nullables on already handled projects (#3773)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored Jun 17, 2022
1 parent 4c4c336 commit fc79ea2
Show file tree
Hide file tree
Showing 23 changed files with 60 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\shared\NullableAttributes.cs" Link="NullableAttributes.cs" />
</ItemGroup>
<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\scripts\build\ExternalAssemblyVersions.cs" Link="ExternalAssemblyVersions.cs" />
<Compile Include="..\..\shared\NullableAttributes.cs" Link="NullableAttributes.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Resources.resx" />
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.TestPlatform.CoreUtilities/Friends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public static bool TryGetIntArgFromDict(IDictionary<string, string?> argsDiction
return false;
}

value = int.Parse(optionValue);
return true;
return int.TryParse(optionValue, out value);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) &&
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
internal class EnvironmentVariableHelper : IEnvironmentVariableHelper
{
/// <inheritdoc />
public string GetEnvironmentVariable(string variable)
public string? GetEnvironmentVariable(string variable)
=> Environment.GetEnvironmentVariable(variable);

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public string GetCurrentDirectory()
=> Directory.GetCurrentDirectory();

/// <inheritdoc/>
public bool Exists(string path)
public bool Exists(string? path)
=> File.Exists(path);

/// <inheritdoc/>
public bool DirectoryExists(string path)
public bool DirectoryExists(string? path)
=> Directory.Exists(path);

/// <inheritdoc/>
Expand All @@ -48,7 +48,7 @@ public Stream GetStream(string filePath, FileMode mode, FileAccess access, FileS
public IEnumerable<string> EnumerateFiles(
string directory,
SearchOption searchOption,
params string[] endsWithSearchPatterns)
params string[]? endsWithSearchPatterns)
{
if (endsWithSearchPatterns == null || endsWithSearchPatterns.Length == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces;

/// <summary>
Expand All @@ -31,5 +29,5 @@ public interface IDotnetHostHelper
/// <param name="targetArchitecture">Specific architecture</param>
/// <param name="muxerPath">Path to the muxer</param>
/// <returns>True if native muxer is found</returns>
bool TryGetDotnetPathByArchitecture(PlatformArchitecture targetArchitecture, out string muxerPath);
bool TryGetDotnetPathByArchitecture(PlatformArchitecture targetArchitecture, out string? muxerPath);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,7 +12,7 @@ internal interface IEnvironmentVariableHelper
/// </summary>
/// <param name="variable">The name of the environment variable.</param>
/// <returns>The value of the environment variable specified by variable, or null if the environment variable is not found.</returns>
string GetEnvironmentVariable(string variable);
string? GetEnvironmentVariable(string variable);

/// <summary>
/// Retrieves the value of an environment variable from the current process and converts it to the given type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
Expand Down Expand Up @@ -36,14 +35,14 @@ public interface IFileHelper
/// </summary>
/// <param name="path"> The path of file. </param>
/// <returns>True if file exists <see cref="bool"/>.</returns>
bool Exists(string path);
bool Exists([NotNullWhen(true)] string? path);

/// <summary>
/// Exists utility to check if directory exists (case sensitive).
/// </summary>
/// <param name="path"> The path of file. </param>
/// <returns>True if directory exists <see cref="bool"/>.</returns>
bool DirectoryExists(string path);
bool DirectoryExists([NotNullWhen(true)] string? path);

#if !NETSTANDARD1_0
/// <summary>
Expand Down Expand Up @@ -72,7 +71,7 @@ public interface IFileHelper
/// <param name="searchOption"><see cref="SearchOption"/> for directory.</param>
/// <param name="endsWithSearchPatterns">Patterns used to select files using String.EndsWith</param>
/// <returns>List of files matching the pattern.</returns>
IEnumerable<string> EnumerateFiles(string directory, SearchOption searchOption, params string[] endsWithSearchPatterns);
IEnumerable<string> EnumerateFiles(string directory, SearchOption searchOption, params string[]? endsWithSearchPatterns);

/// <summary>
/// Gets attributes of a file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<AssemblyName>Microsoft.TestPlatform.CoreUtilities</AssemblyName>
<TargetFrameworks>netstandard2.0;netstandard1.3;net451;net45</TargetFrameworks>
<TargetFrameworks>net6.0;netstandard2.0;netstandard1.3;net451;net45</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);uap10.0;netstandard1.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFrameworks>
Expand Down Expand Up @@ -84,6 +84,10 @@
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\shared\NullableAttributes.cs" Link="NullableAttributes.cs" />
</ItemGroup>

<ItemGroup>
<None Update="NullableHelpers.tt">
<LastGenOutput>NullableHelpers.cs</LastGenOutput>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@

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
4 changes: 2 additions & 2 deletions src/Microsoft.TestPlatform.CoreUtilities/Tracing/EqtTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/// <summary>
Expand All @@ -190,7 +190,7 @@ public static void Fail(string message)
/// <param name="format">The formatted error message</param>
/// <param name="args">Arguments to the format</param>
[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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
9 changes: 0 additions & 9 deletions src/Microsoft.TestPlatform.PlatformAbstractions/Friends.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public IEnumerable<string> GetTestPlatformExtensions(IEnumerable<string>? 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<ItemGroup>
<AdditionalFiles Include="BannedSymbols.txt" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\shared\NullableAttributes.cs" Link="NullableAttributes.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(TestPlatformRoot)src\Microsoft.TestPlatform.Extensions.HtmlLogger\Microsoft.TestPlatform.Extensions.HtmlLogger.csproj" />
<ProjectReference Include="$(TestPlatformRoot)test\Microsoft.TestPlatform.TestUtilities\Microsoft.TestPlatform.TestUtilities.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">netcoreapp3.1</TargetFrameworks>
<OutputType Condition=" $(TargetFramework.StartsWith('net6')) ">Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\shared\NullableAttributes.cs" Link="NullableAttributes.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.TestHostProvider\Microsoft.TestPlatform.TestHostProvider.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<ItemGroup>
<AdditionalFiles Include="BannedSymbols.txt" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\shared\NullableAttributes.cs" Link="NullableAttributes.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.Common\Microsoft.TestPlatform.Common.csproj" />
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj" />
Expand Down
Loading

0 comments on commit fc79ea2

Please sign in to comment.