Skip to content

Commit fc79ea2

Browse files
authored
Enable missed nullables on already handled projects (#3773)
1 parent 4c4c336 commit fc79ea2

File tree

23 files changed

+60
-47
lines changed

23 files changed

+60
-47
lines changed

src/Microsoft.TestPlatform.Client/Microsoft.TestPlatform.Client.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,8 @@
5454
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Shipped.txt" />
5555
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt" />
5656
</ItemGroup>
57+
<ItemGroup>
58+
<Compile Include="..\..\shared\NullableAttributes.cs" Link="NullableAttributes.cs" />
59+
</ItemGroup>
5760
<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" />
5861
</Project>

src/Microsoft.TestPlatform.Common/Microsoft.TestPlatform.Common.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
</PropertyGroup>
1414
<ItemGroup>
1515
<Compile Include="..\..\scripts\build\ExternalAssemblyVersions.cs" Link="ExternalAssemblyVersions.cs" />
16-
<Compile Include="..\..\shared\NullableAttributes.cs" Link="NullableAttributes.cs" />
1716
</ItemGroup>
1817
<ItemGroup>
1918
<EmbeddedResource Include="Resources\Resources.resx" />

src/Microsoft.TestPlatform.CoreUtilities/Friends.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
[assembly: InternalsVisibleTo("vstest.console.arm64, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
88
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CommunicationUtilities, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
99
[assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.ObjectModel, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
10+
[assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.Common, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
1011

1112
[assembly: InternalsVisibleTo("vstest.ProgrammerTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]

src/Microsoft.TestPlatform.CoreUtilities/Helpers/CommandLineArgumentsHelper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public static bool TryGetIntArgFromDict(IDictionary<string, string?> argsDiction
7272
return false;
7373
}
7474

75-
value = int.Parse(optionValue);
76-
return true;
75+
return int.TryParse(optionValue, out value);
7776
}
7877

7978

src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private bool TryGetExecutablePath(string executableBaseName, out string executab
105105
}
106106

107107
executablePath = string.Empty;
108-
var pathString = Environment.GetEnvironmentVariable("PATH");
108+
var pathString = Environment.GetEnvironmentVariable("PATH")!;
109109
foreach (string path in pathString.Split(Path.PathSeparator))
110110
{
111111
string exeFullPath = Path.Combine(path.Trim(), executableBaseName);
@@ -149,7 +149,7 @@ public bool TryGetDotnetPathByArchitecture(PlatformArchitecture targetArchitectu
149149
string envKey = $"DOTNET_ROOT_{targetArchitecture.ToString().ToUpperInvariant()}";
150150

151151
// Try on arch specific env var
152-
string envVar = _environmentVariableHelper.GetEnvironmentVariable(envKey);
152+
string? envVar = _environmentVariableHelper.GetEnvironmentVariable(envKey);
153153

154154
// Try on non virtualized x86 var(should happen only on non-x86 architecture)
155155
if ((envVar == null || !_fileHelper.DirectoryExists(envVar)) &&
@@ -233,14 +233,14 @@ public bool TryGetDotnetPathByArchitecture(PlatformArchitecture targetArchitectu
233233
if ((_environment.Architecture == PlatformArchitecture.X64 || _environment.Architecture == PlatformArchitecture.ARM64) &&
234234
targetArchitecture == PlatformArchitecture.X86)
235235
{
236-
muxerPath = Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles(x86)"), "dotnet", _muxerName);
236+
muxerPath = Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles(x86)")!, "dotnet", _muxerName);
237237
}
238238
else
239239
{
240240
// If we're on ARM and target is x64 we expect correct installation inside x64 folder
241241
muxerPath = _environment.Architecture == PlatformArchitecture.ARM64 && targetArchitecture == PlatformArchitecture.X64
242-
? Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles"), "dotnet", "x64", _muxerName)
243-
: Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles"), "dotnet", _muxerName);
242+
? Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles")!, "dotnet", "x64", _muxerName)
243+
: Path.Combine(_environmentVariableHelper.GetEnvironmentVariable("ProgramFiles")!, "dotnet", _muxerName);
244244
}
245245
}
246246
else

src/Microsoft.TestPlatform.CoreUtilities/Helpers/EnvironmentVariableHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
1212
internal class EnvironmentVariableHelper : IEnvironmentVariableHelper
1313
{
1414
/// <inheritdoc />
15-
public string GetEnvironmentVariable(string variable)
15+
public string? GetEnvironmentVariable(string variable)
1616
=> Environment.GetEnvironmentVariable(variable);
1717

1818
/// <inheritdoc />

src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public string GetCurrentDirectory()
2929
=> Directory.GetCurrentDirectory();
3030

3131
/// <inheritdoc/>
32-
public bool Exists(string path)
32+
public bool Exists(string? path)
3333
=> File.Exists(path);
3434

3535
/// <inheritdoc/>
36-
public bool DirectoryExists(string path)
36+
public bool DirectoryExists(string? path)
3737
=> Directory.Exists(path);
3838

3939
/// <inheritdoc/>
@@ -48,7 +48,7 @@ public Stream GetStream(string filePath, FileMode mode, FileAccess access, FileS
4848
public IEnumerable<string> EnumerateFiles(
4949
string directory,
5050
SearchOption searchOption,
51-
params string[] endsWithSearchPatterns)
51+
params string[]? endsWithSearchPatterns)
5252
{
5353
if (endsWithSearchPatterns == null || endsWithSearchPatterns.Length == 0)
5454
{

src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
55

6-
#nullable disable
7-
86
namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces;
97

108
/// <summary>
@@ -31,5 +29,5 @@ public interface IDotnetHostHelper
3129
/// <param name="targetArchitecture">Specific architecture</param>
3230
/// <param name="muxerPath">Path to the muxer</param>
3331
/// <returns>True if native muxer is found</returns>
34-
bool TryGetDotnetPathByArchitecture(PlatformArchitecture targetArchitecture, out string muxerPath);
32+
bool TryGetDotnetPathByArchitecture(PlatformArchitecture targetArchitecture, out string? muxerPath);
3533
}

src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IEnvironmentVariableHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
#nullable disable
5-
64
using System;
75

86
namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
@@ -14,7 +12,7 @@ internal interface IEnvironmentVariableHelper
1412
/// </summary>
1513
/// <param name="variable">The name of the environment variable.</param>
1614
/// <returns>The value of the environment variable specified by variable, or null if the environment variable is not found.</returns>
17-
string GetEnvironmentVariable(string variable);
15+
string? GetEnvironmentVariable(string variable);
1816

1917
/// <summary>
2018
/// Retrieves the value of an environment variable from the current process and converts it to the given type.

src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
#if !NETSTANDARD1_0
67
using System.Collections.Generic;
78
using System.IO;
89
#endif
910

10-
#nullable disable
11-
1211
namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
1312

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

4140
/// <summary>
4241
/// Exists utility to check if directory exists (case sensitive).
4342
/// </summary>
4443
/// <param name="path"> The path of file. </param>
4544
/// <returns>True if directory exists <see cref="bool"/>.</returns>
46-
bool DirectoryExists(string path);
45+
bool DirectoryExists([NotNullWhen(true)] string? path);
4746

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

7776
/// <summary>
7877
/// Gets attributes of a file.

0 commit comments

Comments
 (0)