diff --git a/test/Microsoft.NET.Build.Tests/EvaluatorFastPathTests.cs b/test/Microsoft.NET.Build.Tests/EvaluatorFastPathTests.cs new file mode 100644 index 000000000000..702a7f464dab --- /dev/null +++ b/test/Microsoft.NET.Build.Tests/EvaluatorFastPathTests.cs @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.NET.Build.Tests +{ + public class EvaluatorFastPathTests : SdkTest + { + public EvaluatorFastPathTests(ITestOutputHelper log) : base(log) + { + + } + + [Fact] + public void FastPathDoesNotNeedReflection() + { + var testAsset = _testAssetsManager + .CopyTestAsset("MSBuildBareBonesProject") + .WithSource(); + var command = new MSBuildCommand(testAsset, string.Empty); + command + .WithEnvironmentVariable("MSBuildLogPropertyFunctionsRequiringReflection", "true") + .WithWorkingDirectory(testAsset.Path); + command + .ExecuteWithoutRestore() + .Should() + .Pass(); + + var logPath = Path.Combine(testAsset.Path, "PropertyFunctionsRequiringReflection"); + File.Exists(logPath).Should().BeFalse(); + } + + [Theory] + [InlineData("console")] + [InlineData("webapp")] + public void EnsureDotnetCommonProjectPropertyFunctionsOnFastPath(string alias) + { + var testDir = _testAssetsManager.CreateTestDirectory().Path; + + new DotnetNewCommand(Log, alias) + .WithoutCustomHive() + .WithWorkingDirectory(testDir) + .Execute() + .Should() + .Pass(); + + new DotnetBuildCommand(Log) + .WithWorkingDirectory(testDir) + .WithEnvironmentVariable("MSBuildLogPropertyFunctionsRequiringReflection", "true") + .Execute() + .Should() + .Pass(); + + var logPath = Path.Combine(testDir, "PropertyFunctionsRequiringReflection"); + // Functions from Microsoft.Build.Utilities.ToolLocationHelper are pending to add fast path, tracked by https://github.com/dotnet/msbuild/issues/10411. + // This verification should be changed to no log file created once it is done. + var toolLocationHelper_GetPlatformSDKLocation = "ReceiverType=Microsoft.Build.Utilities.ToolLocationHelper; ObjectInstanceType=; MethodName=GetPlatformSDKLocation(String, String)"; + var toolLocationHelper_GetPlatformSDKDisplayName = "ReceiverType=Microsoft.Build.Utilities.ToolLocationHelper; ObjectInstanceType=; MethodName=GetPlatformSDKDisplayName(String, String)"; + var lines = File.ReadAllLines(logPath); + var allOnFastPathWithExceptions = lines.All(l => (toolLocationHelper_GetPlatformSDKLocation.Equals(l) || toolLocationHelper_GetPlatformSDKDisplayName.Equals(l))); + allOnFastPathWithExceptions.Should().BeTrue(); + } + } +} diff --git a/test/TestAssets/TestProjects/MSBuildBareBonesProject/BareBones.proj b/test/TestAssets/TestProjects/MSBuildBareBonesProject/BareBones.proj index e0b8706444cb..88dff20e531a 100644 --- a/test/TestAssets/TestProjects/MSBuildBareBonesProject/BareBones.proj +++ b/test/TestAssets/TestProjects/MSBuildBareBonesProject/BareBones.proj @@ -1,6 +1,21 @@ + + $([System.Version]::Parse('17.12.11.10').ToString(2)) + $([System.Text.RegularExpressions.Regex]::Replace('abc123def', 'abc', '')) + $([System.String]::new('Hi').Equals('Hi')) + $([System.IO.Path]::GetFileNameWithoutExtension('C:\folder\file.txt')) + $([System.Int32]::new(123).ToString('mm') + $([Microsoft.Build.Evaluation.IntrinsicFunctions]::NormalizeDirectory('C:/folder1/./folder2/')) + $([Microsoft.Build.Evaluation.IntrinsicFunctions]::IsOSPlatform('Windows')) + + +