Skip to content

Commit cd44ea7

Browse files
committed
Clean up #nullable disable from test directory
1 parent 110f80a commit cd44ea7

File tree

8 files changed

+32
-40
lines changed

8 files changed

+32
-40
lines changed

test/ArgumentForwarding.Tests/ArgumentForwardingTests.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#nullable disable
5-
64
using System.Diagnostics;
75
using Microsoft.DotNet.Cli.CommandFactory;
86

@@ -13,14 +11,14 @@ public class ArgumentForwardingTests : SdkTest
1311
private static readonly string s_reflectorDllName = "ArgumentsReflector.dll";
1412
private static readonly string s_reflectorCmdName = "reflector_cmd";
1513

16-
private string ReflectorPath { get; set; }
17-
private string ReflectorCmdPath { get; set; }
14+
private string ReflectorPath { get; set; } = string.Empty;
15+
private string ReflectorCmdPath { get; set; } = string.Empty;
1816

1917
public ArgumentForwardingTests(ITestOutputHelper log) : base(log)
2018
{
2119
// This test has a dependency on an argument reflector
2220
// Make sure it's been binplaced properly
23-
FindAndEnsureReflectorPresent();
21+
FindAndEnsureReflectorPresent();
2422
}
2523

2624
private void FindAndEnsureReflectorPresent()
@@ -203,9 +201,9 @@ private string[] EscapeAndEvaluateArgumentStringCmd(string[] rawEvaluatedArgumen
203201
/// </summary>
204202
/// <param name="reflectorOutput"></param>
205203
/// <returns></returns>
206-
private string[] ParseReflectorOutput(string reflectorOutput)
204+
private string[] ParseReflectorOutput(string? reflectorOutput)
207205
{
208-
return reflectorOutput.TrimEnd('\r', '\n').Split(',');
206+
return reflectorOutput?.TrimEnd('\r', '\n').Split(',') ?? Array.Empty<string>();
209207
}
210208

211209
/// <summary>
@@ -215,9 +213,9 @@ private string[] ParseReflectorOutput(string reflectorOutput)
215213
/// </summary>
216214
/// <param name="reflectorOutput"></param>
217215
/// <returns></returns>
218-
private string[] ParseReflectorCmdOutput(string reflectorOutput)
216+
private string[] ParseReflectorCmdOutput(string? reflectorOutput)
219217
{
220-
var args = reflectorOutput.Split(new string[] { "," }, StringSplitOptions.None);
218+
var args = reflectorOutput?.Split(new string[] { "," }, StringSplitOptions.None) ?? Array.Empty<string>();
221219
args[args.Length - 1] = args[args.Length - 1].TrimEnd('\r', '\n');
222220

223221
// To properly pass args to cmd, quotes inside a parameter are doubled

test/Microsoft.NET.TestFramework/NuGetConfigWriter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ public static class NuGetConfigWriter
77
{
88
public static readonly string AspNetCoreDevFeed = "https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json";
99

10-
public static void Write(string folder, params string[] nugetSources)
10+
public static void Write(string folder, params string?[] nugetSources)
1111
{
1212
Write(folder, nugetSources.ToList());
1313
}
14-
public static void Write(string folder, List<string> nugetSources)
14+
public static void Write(string folder, List<string?> nugetSources)
1515
{
1616
string configFilePath = Path.Combine(folder, "NuGet.Config");
1717
var root = new XElement("configuration");
@@ -23,7 +23,7 @@ public static void Write(string folder, List<string> nugetSources)
2323
{
2424
packageSources.Add(new XElement("add",
2525
new XAttribute("key", Guid.NewGuid().ToString()),
26-
new XAttribute("value", nugetSources[i])
26+
new XAttribute("value", nugetSources[i] ?? string.Empty)
2727
));
2828
}
2929

test/Microsoft.NET.TestFramework/TestAssetsManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public TestAsset CopyTestAsset(
6161
public TestAsset CreateTestProject(
6262
TestProject testProject,
6363
[CallerMemberName] string callingMethod = "",
64-
string identifier = "",
64+
string? identifier = "",
6565
string targetExtension = ".csproj")
6666
{
6767
var testDestinationDirectory =

test/crossgen.Tests/crossgen.Tests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#nullable disable
5-
64
using System.Reflection.PortableExecutable;
75

86
namespace Microsoft.DotNet.Tests
@@ -22,7 +20,7 @@ public void CLI_SDK_assemblies_must_be_crossgened()
2220
// TODO: Update method of finding cliPath (right now it's finding a ref path in stage 0
2321
string dotnetDir = FindDotnetDirInPath();
2422
string cliPath = Directory.EnumerateFiles(dotnetDir, "dotnet.dll", SearchOption.AllDirectories).First();
25-
cliPath = Path.GetDirectoryName(cliPath);
23+
cliPath = Path.GetDirectoryName(cliPath) ?? string.Empty;
2624
CheckDirectoryIsCrossgened(cliPath);
2725
}
2826

@@ -32,7 +30,7 @@ public void Shared_Fx_assemblies_must_be_crossgened()
3230
// TODO: Update method of finding sharedFxPath
3331
string dotnetDir = FindDotnetDirInPath();
3432
string sharedFxPath = Directory.EnumerateFiles(dotnetDir, "mscorlib*.dll", SearchOption.AllDirectories).First();
35-
sharedFxPath = Path.GetDirectoryName(sharedFxPath);
33+
sharedFxPath = Path.GetDirectoryName(sharedFxPath) ?? string.Empty;
3634
CheckDirectoryIsCrossgened(sharedFxPath);
3735
}
3836

@@ -68,7 +66,11 @@ private static string FindDotnetDirInPath()
6866
string dotnetPath = Path.Combine(path, dotnetExecutable);
6967
if (File.Exists(dotnetPath))
7068
{
71-
return Path.GetDirectoryName(dotnetPath);
69+
var directoryName = Path.GetDirectoryName(dotnetPath);
70+
if (directoryName is not null)
71+
{
72+
return directoryName;
73+
}
7274
}
7375
}
7476

test/dotnet-add-package.Tests/GivenDotnetPackageAdd.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#nullable disable
5-
64
using System.Runtime.CompilerServices;
75

86
namespace Microsoft.DotNet.Cli.Package.Add.Tests
@@ -243,7 +241,7 @@ private static TestProject GetProject(string targetFramework, string referencePr
243241
return project;
244242
}
245243

246-
private string GetPackagePath(string targetFramework, string packageName, string version, [CallerMemberName] string callingMethod = "", string identifier = null)
244+
private string GetPackagePath(string targetFramework, string packageName, string version, [CallerMemberName] string callingMethod = "", string? identifier = null)
247245
{
248246
var project = GetProject(targetFramework, packageName, version);
249247
var packCommand = new PackCommand(_testAssetsManager.CreateTestProject(project, callingMethod: callingMethod, identifier: identifier));

test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#nullable disable
5-
64
using Msbuild.Tests.Utilities;
75

86
namespace Microsoft.DotNet.Cli.Add.Reference.Tests
@@ -65,7 +63,7 @@ private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string
6563
return new ProjDir(_testAssetsManager.CreateTestDirectory(testName: callingMethod, identifier: identifier).Path);
6664
}
6765

68-
private ProjDir NewLib(string dir = null, [System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
66+
private ProjDir NewLib(string? dir = null, [System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
6967
{
7068
var projDir = dir == null ? NewDir(callingMethod: callingMethod, identifier: identifier) : new ProjDir(dir);
7169

@@ -92,7 +90,7 @@ private static void SetTargetFrameworks(ProjDir proj, string[] frameworks)
9290
csproj.Save();
9391
}
9492

95-
private ProjDir NewLibWithFrameworks(string dir = null, [System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
93+
private ProjDir NewLibWithFrameworks(string? dir = null, [System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
9694
{
9795
var ret = NewLib(dir, callingMethod: callingMethod, identifier: identifier);
9896
SetTargetFrameworks(ret, DefaultFrameworks);
@@ -708,7 +706,7 @@ public void WhenDirectoryContainingProjectIsGivenReferenceIsAdded()
708706

709707
var result = new DotnetCommand(Log, "add", lib.CsProjPath, "reference")
710708
.WithWorkingDirectory(setup.TestRoot)
711-
.Execute(Path.GetDirectoryName(setup.ValidRefCsprojPath));
709+
.Execute(Path.GetDirectoryName(setup.ValidRefCsprojPath) ?? string.Empty);
712710

713711
result.Should().Pass();
714712
result.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ReferenceAddedToTheProject, @"ValidRef\ValidRef.csproj"));

test/dotnet-back-compat.Tests/GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#nullable disable
5-
64
namespace Microsoft.DotNet.Cli.Build.Tests
75
{
86
public class GivenThatWeWantToBeBackwardsCompatibleWith1xProjects : SdkTest
@@ -87,10 +85,10 @@ public void ItRunsABackwardsVersionedTool()
8785
void ChangeProjectTargetFramework(string projectFile, string target)
8886
{
8987
var projectXml = XDocument.Load(projectFile);
90-
var ns = projectXml.Root.Name.Namespace;
91-
var propertyGroup = projectXml.Root.Elements(ns + "PropertyGroup").First();
92-
var rootNamespaceElement = propertyGroup.Element(ns + "TargetFramework");
93-
rootNamespaceElement.SetValue(target);
88+
var ns = projectXml.Root?.Name.Namespace ?? string.Empty;
89+
var propertyGroup = projectXml.Root?.Elements(ns + "PropertyGroup").First();
90+
var rootNamespaceElement = propertyGroup?.Element(ns + "TargetFramework");
91+
rootNamespaceElement?.SetValue(target);
9492
projectXml.Save(projectFile.ToString());
9593
}
9694

test/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#nullable disable
5-
64
using System.CommandLine;
75
using Microsoft.DotNet.Configurer;
86

@@ -217,7 +215,7 @@ public void It_does_not_warn_on_rid_with_self_contained_set_in_project()
217215
var testInstance = _testAssetsManager.CreateTestProject(testProject);
218216

219217
new DotnetBuildCommand(Log)
220-
.WithWorkingDirectory(Path.Combine(testInstance.Path, testProject.Name))
218+
.WithWorkingDirectory(Path.Combine(testInstance.Path, testProject.Name ?? string.Empty))
221219
.Execute("-r", "win-x64")
222220
.Should()
223221
.Pass()
@@ -276,7 +274,7 @@ public void It_builds_with_implicit_rid_with_SelfContained(string executeOptions
276274
var testAsset = _testAssetsManager.CreateTestProject(testProject);
277275

278276

279-
new DotnetBuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name))
277+
new DotnetBuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name ?? string.Empty))
280278
.Execute(executeOptions)
281279
.Should()
282280
.Pass()
@@ -308,7 +306,7 @@ public void It_builds_referenced_exe_with_self_contained_specified_via_command_l
308306
var testAsset = _testAssetsManager.CreateTestProject(testProject);
309307

310308
new DotnetCommand(Log)
311-
.WithWorkingDirectory(Path.Combine(testAsset.Path, testProject.Name))
309+
.WithWorkingDirectory(Path.Combine(testAsset.Path, testProject.Name ?? string.Empty))
312310
.Execute("build", "-r", EnvironmentInfo.GetCompatibleRid(), "--self-contained")
313311
.Should()
314312
.Pass()
@@ -337,7 +335,7 @@ public void It_resolves_analyzers_targeting_mulitple_roslyn_versions(string comp
337335
<PackageReference Include=""Library.ContainsAnalyzer2"" Version=""1.0.0"" />
338336
</ItemGroup>");
339337

340-
project.Root.Add(itemGroup);
338+
project.Root?.Add(itemGroup);
341339
});
342340

343341
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: compilerApiVersion);
@@ -377,7 +375,7 @@ public void It_resolves_analyzers_targeting_mulitple_roslyn_versions(string comp
377375
}
378376
}
379377

380-
static readonly List<string> nugetRoots = new()
378+
static readonly List<string?> nugetRoots = new()
381379
{
382380
TestContext.Current.NuGetCachePath,
383381
Path.Combine(CliFolderPathCalculator.DotnetHomePath, ".dotnet", "NuGetFallbackFolder")
@@ -387,7 +385,7 @@ static string RelativeNuGetPath(string absoluteNuGetPath)
387385
{
388386
foreach (var nugetRoot in nugetRoots)
389387
{
390-
if (absoluteNuGetPath.StartsWith(nugetRoot + Path.DirectorySeparatorChar))
388+
if (nugetRoot is not null && absoluteNuGetPath.StartsWith(nugetRoot + Path.DirectorySeparatorChar))
391389
{
392390
return absoluteNuGetPath.Substring(nugetRoot.Length + 1)
393391
.Replace(Path.DirectorySeparatorChar, '/');

0 commit comments

Comments
 (0)