提交 911faded 编写于 作者: S Sam Harwell

Enable nullable reference types for Microsoft.Build.Tasks.CodeAnalysis.UnitTests

上级 5b295cc6
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Linq;
using Microsoft.Build.Framework;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using Xunit;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.IO;
using Roslyn.Test.Utilities;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
......@@ -9,6 +11,7 @@
using System.Linq;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.BuildTasks.UnitTests
......@@ -16,7 +19,7 @@ namespace Microsoft.CodeAnalysis.BuildTasks.UnitTests
public class IntegrationTests : TestBase
{
private static readonly string s_msbuildDirectory;
private static readonly string s_msbuildExecutable;
private static readonly string? s_msbuildExecutable;
static IntegrationTests()
{
......@@ -43,7 +46,7 @@ public IntegrationTests()
_buildTaskDll = typeof(ManagedCompiler).Assembly.Location;
}
private IEnumerable<KeyValuePair<string, string>> AddForLoggingEnvironmentVars(IEnumerable<KeyValuePair<string, string>> vars)
private IEnumerable<KeyValuePair<string, string>> AddForLoggingEnvironmentVars(IEnumerable<KeyValuePair<string, string>>? vars)
{
vars = vars ?? new KeyValuePair<string, string>[] { };
if (!vars.Where(kvp => kvp.Key == "RoslynCommandLineLogFile").Any())
......@@ -61,7 +64,7 @@ public IntegrationTests()
string compilerPath,
string arguments,
string currentDirectory,
IEnumerable<KeyValuePair<string, string>> additionalEnvironmentVars = null)
IEnumerable<KeyValuePair<string, string>>? additionalEnvironmentVars = null)
{
return ProcessUtilities.Run(
compilerPath,
......@@ -75,7 +78,7 @@ public IntegrationTests()
string arguments,
TempDirectory currentDirectory,
IEnumerable<KeyValuePair<string, string>> filesInDirectory,
IEnumerable<KeyValuePair<string, string>> additionalEnvironmentVars = null)
IEnumerable<KeyValuePair<string, string>>? additionalEnvironmentVars = null)
{
foreach (var pair in filesInDirectory)
{
......@@ -406,6 +409,8 @@ End Class
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/1445")]
public void SimpleMSBuild()
{
RoslynDebug.Assert(s_msbuildExecutable is object);
string arguments = string.Format(@"/m /nr:false /t:Rebuild /p:UseSharedCompilation=false /p:UseRoslyn=1 HelloSolution.sln");
var result = RunCommandLineCompiler(s_msbuildExecutable, arguments, _tempDirectory, SimpleMsBuildFiles);
......@@ -605,6 +610,8 @@ End Class
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/16301")]
public void ReportAnalyzerMSBuild()
{
RoslynDebug.Assert(s_msbuildExecutable is object);
string arguments = string.Format(@"/m /nr:false /t:Rebuild /p:UseSharedCompilation=false /p:UseRoslyn=1 HelloSolution.sln");
var result = RunCommandLineCompiler(s_msbuildExecutable, arguments, _tempDirectory, ReportAnalyzerMsBuildFiles,
new Dictionary<string, string>
......@@ -617,6 +624,8 @@ public void ReportAnalyzerMSBuild()
[Fact(Skip = "failing msbuild")]
public void SolutionWithPunctuation()
{
RoslynDebug.Assert(s_msbuildExecutable is object);
var testDir = _tempDirectory.CreateDirectory(@"SLN;!@(goo)'^1");
var slnFile = testDir.CreateFile("Console;!@(goo)'^(Application1.sln").WriteAllText(
@"
......
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.BuildTasks.UnitTests
......@@ -52,6 +55,7 @@ public void BasicMapping()
bool result = task.Execute();
AssertEx.AssertEqualToleratingWhitespaceDifferences("", engine.Log);
RoslynDebug.Assert(task.MappedSourceRoots is object);
Assert.Equal(4, task.MappedSourceRoots.Length);
Assert.Equal(Utilities.FixFilePath(@"c:\packages\SourcePackage1\"), task.MappedSourceRoots[0].ItemSpec);
......@@ -100,6 +104,7 @@ public void InvalidChars()
bool result = task.Execute();
AssertEx.AssertEqualToleratingWhitespaceDifferences("", engine.Log);
RoslynDebug.Assert(task.MappedSourceRoots is object);
Assert.Equal(3, task.MappedSourceRoots.Length);
Assert.Equal(Utilities.FixFilePath(@"!@#:;$%^&*()_+|{}\"), task.MappedSourceRoots[0].ItemSpec);
......@@ -176,6 +181,7 @@ public void NestedRoots_Separators()
bool result = task.Execute();
AssertEx.AssertEqualToleratingWhitespaceDifferences("", engine.Log);
RoslynDebug.Assert(task.MappedSourceRoots is object);
Assert.Equal(4, task.MappedSourceRoots.Length);
Assert.Equal(Utilities.FixFilePath(@"c:\MyProjects\MyProject\"), task.MappedSourceRoots[0].ItemSpec);
......@@ -213,6 +219,7 @@ public void SourceRootCaseSensitive()
bool result = task.Execute();
AssertEx.AssertEqualToleratingWhitespaceDifferences("", engine.Log);
RoslynDebug.Assert(task.MappedSourceRoots is object);
Assert.Equal(3, task.MappedSourceRoots.Length);
Assert.Equal(Utilities.FixFilePath(@"c:\packages\SourcePackage1\"), task.MappedSourceRoots[0].ItemSpec);
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Linq;
using Microsoft.Build.Framework;
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.IO;
......@@ -21,9 +24,9 @@ public sealed class DotNetSdkAvailable : ExecutionCondition
}
private static readonly string s_dotnetExeName;
private static readonly string s_dotnetInstallDir;
private static readonly string? s_dotnetInstallDir;
private static readonly string s_dotnetSdkVersion;
private static readonly string s_dotnetSdkPath;
private static readonly string? s_dotnetSdkPath;
private static string s_projectSource =
@"<Project Sdk='Microsoft.NET.Sdk'>
......@@ -86,7 +89,7 @@ bool isMatchingDotNetInstance(string dotnetDir)
private static void EmitTestHelperProps(
string objDirectory,
string projectFileName,
string content)
string? content)
{
// Common.props automatically import {project-name}.*.props files from MSBuildProjectExtensionsPath directory,
// which is by default set to the IntermediateOutputPath:
......@@ -101,7 +104,7 @@ bool isMatchingDotNetInstance(string dotnetDir)
string outputFile,
string projectFileName,
IEnumerable<string> expressions,
string additionalContent)
string? additionalContent)
{
// Common.targets automatically import {project-name}.*.targets files from MSBuildProjectExtensionsPath directory,
// which is by defautl set to the IntermediateOutputPath:
......@@ -180,7 +183,7 @@ public DotNetSdkTestBase()
Assert.True(File.Exists(Path.Combine(ObjDir.Path, ProjectFileName + ".nuget.g.targets")));
}
protected void VerifyValues(string customProps, string customTargets, string[] targets, string[] expressions, string[] expectedResults)
protected void VerifyValues(string? customProps, string? customTargets, string[] targets, string[] expressions, string[] expectedResults)
{
var evaluationResultsFile = Path.Combine(OutDir.Path, "EvaluationResult.txt");
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis.BuildTasks.UnitTests
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using Microsoft.Build.Framework;
using Moq;
using System;
......
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#nullable enable
using System;
using System.Collections;
using System.Text;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using Microsoft.CodeAnalysis.BuildTasks;
using Roslyn.Test.Utilities;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册