提交 e4584e21 编写于 作者: A Ashley Hauck

Add tests for empty csctoolexe/csctoolpath

上级 641e07aa
......@@ -192,9 +192,11 @@ private DotnetHost DotnetHostInfo
var commandLine = commandLineBuilder.ToString();
// ToolExe delegates back to ToolName if the override is not
// set. So, if ToolExe != ToolName, we know ToolExe is
// explicitly overriden - so use it as a native invocation.
if (string.IsNullOrEmpty(ToolPath) || ToolExe == ToolName)
// set. So, if ToolExe == ToolName, we know ToolExe is not
// explicitly overriden. So, if both ToolPath is unset and
// ToolExe == ToolName, we know nothing is overridden, and
// we can use our own csc.
if (string.IsNullOrEmpty(ToolPath) && ToolExe == ToolName)
{
_dotnetHostInfo = DotnetHost.CreateManagedInvocationTool(ToolName, commandLine);
}
......@@ -202,7 +204,7 @@ private DotnetHost DotnetHostInfo
{
// Explicitly provided ToolPath or ToolExe, don't try to
// figure anything out
_dotnetHostInfo = DotnetHost.CreateNativeInvocationTool(Path.Combine(ToolPath, ToolExe), commandLine);
_dotnetHostInfo = DotnetHost.CreateNativeInvocationTool(Path.Combine(ToolPath ?? "", ToolExe), commandLine);
}
}
return _dotnetHostInfo;
......
......@@ -421,9 +421,11 @@ private DotnetHost DotnetHostInfo
var commandLine = commandLineBuilder.ToString();
// ToolExe delegates back to ToolName if the override is not
// set. So, if ToolExe != ToolName, we know ToolExe is
// explicitly overriden - so use it as a native invocation.
if (string.IsNullOrEmpty(ToolPath) || ToolExe == ToolName)
// set. So, if ToolExe == ToolName, we know ToolExe is not
// explicitly overriden. So, if both ToolPath is unset and
// ToolExe == ToolName, we know nothing is overridden, and
// we can use our own csc.
if (string.IsNullOrEmpty(ToolPath) && ToolExe == ToolName)
{
_dotnetHostInfo = DotnetHost.CreateManagedInvocationTool(ToolName, commandLine);
}
......@@ -431,7 +433,7 @@ private DotnetHost DotnetHostInfo
{
// Explicitly provided ToolPath or ToolExe, don't try to
// figure anything out
_dotnetHostInfo = DotnetHost.CreateNativeInvocationTool(Path.Combine(ToolPath, ToolExe), commandLine);
_dotnetHostInfo = DotnetHost.CreateNativeInvocationTool(Path.Combine(ToolPath ?? "", ToolExe), commandLine);
}
}
return _dotnetHostInfo;
......@@ -455,6 +457,14 @@ protected sealed override string ToolName
}
}
/// <summary>
/// Method for testing only
/// </summary>
public string GeneratePathToTool()
{
return GenerateFullPathToTool();
}
/// <summary>
/// Return the path to the tool to execute.
/// </summary>
......@@ -486,7 +496,7 @@ protected override int ExecuteTool(string pathToTool, string responseFileCommand
try
{
if (!UseSharedCompilation ||
!DotnetHostInfo.IsManagedTool ||
!DotnetHostInfo.IsManagedInvocation ||
!BuildServerConnection.IsCompilerServerSupported)
{
return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
......@@ -705,6 +715,14 @@ protected override string GenerateResponseFileCommands()
return commandLineBuilder.ToString();
}
/// <summary>
/// Method for testing only
/// </summary>
public string GenerateCommandLine()
{
return GenerateCommandLineCommands();
}
protected override string GenerateCommandLineCommands()
{
return DotnetHostInfo.CommandLineArgs;
......
......@@ -6,6 +6,7 @@
using Microsoft.CodeAnalysis.BuildTasks;
using Xunit;
using Moq;
using System.IO;
namespace Microsoft.CodeAnalysis.BuildTasks.UnitTests
{
......@@ -334,5 +335,40 @@ public void SharedCompilationId()
csc.SharedCompilationId = "testPipeName";
Assert.Equal("/out:test.exe test.cs", csc.GenerateResponseFileContents());
}
[Fact]
public void EmptyCscToolPath()
{
var csc = new Csc();
csc.ToolPath = "";
csc.ToolExe = Path.Combine("path", "to", "custom_csc");
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
Assert.Equal("", csc.GenerateCommandLine());
Assert.Equal(Path.Combine("path", "to", "custom_csc"), csc.GeneratePathToTool());
csc = new Csc();
csc.ToolExe = Path.Combine("path", "to", "custom_csc");
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
Assert.Equal("", csc.GenerateCommandLine());
Assert.Equal(Path.Combine("path", "to", "custom_csc"), csc.GeneratePathToTool());
}
[Fact]
public void EmptyCscToolExe()
{
var csc = new Csc();
csc.ToolPath = Path.Combine("path", "to", "custom_csc");
csc.ToolExe = "";
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
Assert.Equal("", csc.GenerateCommandLine());
// StartsWith because it can be csc.exe or csc.dll
Assert.StartsWith(Path.Combine("path", "to", "custom_csc", "csc."), csc.GeneratePathToTool());
csc = new Csc();
csc.ToolPath = Path.Combine("path", "to", "custom_csc");
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
Assert.Equal("", csc.GenerateCommandLine());
Assert.StartsWith(Path.Combine("path", "to", "custom_csc", "csc."), csc.GeneratePathToTool());
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册