Skip to content

Commit

Permalink
Fix tests to workaround MSBuild searching the PATH itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerhardt committed Jul 24, 2023
1 parent 4d64983 commit 214cb7b
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -40,7 +41,23 @@ public static void AssertCommandLine(

var message = engine.BuildMessages.OfType<TaskCommandLineEventArgs>().Single();
var commandLine = message.CommandLine.Replace(" ", " ").Trim();
Assert.Equal($@"{RuntimeHostInfo.GetDotNetPathOrDefault()} exec ""{task.PathToManagedTool}"" {line}", commandLine);

var dotnetPath = RuntimeHostInfo.GetDotNetPathOrDefault();
var expectedCommandLine = $@"{dotnetPath} exec ""{task.PathToManagedTool}"" {line}";

bool isOnlyFileName = Path.GetFileName(dotnetPath).Length == dotnetPath.Length;
if (isOnlyFileName)
{
// When ToolTask.GenerateFullPathToTool() returns only a file name (not a path to a file), MSBuild's ToolTask
// will search the %PATH% (see https://github.com/dotnet/msbuild/blob/5410bf323451e04e99e79bcffd158e6d8d378149/src/Utilities/ToolTask.cs#L494-L513)
// and log the full path to the exe. In this case, only assert that the commandLine ends with the expected
// command line, and ignore the full path at the beginning.
Assert.EndsWith(expectedCommandLine, commandLine);
}
else
{
Assert.Equal(expectedCommandLine, commandLine);
}

compilerTask.NoConfig = true;
Assert.Equal("/noconfig", compilerTask.GenerateToolArguments());
Expand Down

0 comments on commit 214cb7b

Please sign in to comment.