|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +namespace Microsoft.NET.Build.Tests |
| 5 | +{ |
| 6 | + public class EvaluatorFastPathTests : SdkTest |
| 7 | + { |
| 8 | + public EvaluatorFastPathTests(ITestOutputHelper log) : base(log) |
| 9 | + { |
| 10 | + |
| 11 | + } |
| 12 | + |
| 13 | + [Fact] |
| 14 | + public void FastPathDoesNotNeedReflection() |
| 15 | + { |
| 16 | + var testAsset = _testAssetsManager |
| 17 | + .CopyTestAsset("MSBuildBareBonesProject") |
| 18 | + .WithSource(); |
| 19 | + var command = new MSBuildCommand(testAsset, string.Empty); |
| 20 | + command |
| 21 | + .WithEnvironmentVariable("MSBuildLogPropertyFunctionsRequiringReflection", "true") |
| 22 | + .WithWorkingDirectory(testAsset.Path); |
| 23 | + command |
| 24 | + .ExecuteWithoutRestore() |
| 25 | + .Should() |
| 26 | + .Pass(); |
| 27 | + |
| 28 | + var logPath = Path.Combine(testAsset.Path, "PropertyFunctionsRequiringReflection"); |
| 29 | + File.Exists(logPath).Should().BeFalse(); |
| 30 | + } |
| 31 | + |
| 32 | + [Theory] |
| 33 | + [InlineData("console")] |
| 34 | + [InlineData("webapp")] |
| 35 | + public void EnsureDotnetCommonProjectPropertyFunctionsOnFastPath(string alias) |
| 36 | + { |
| 37 | + var testDir = _testAssetsManager.CreateTestDirectory().Path; |
| 38 | + |
| 39 | + new DotnetNewCommand(Log, alias) |
| 40 | + .WithoutCustomHive() |
| 41 | + .WithWorkingDirectory(testDir) |
| 42 | + .Execute() |
| 43 | + .Should() |
| 44 | + .Pass(); |
| 45 | + |
| 46 | + new DotnetBuildCommand(Log) |
| 47 | + .WithWorkingDirectory(testDir) |
| 48 | + .WithEnvironmentVariable("MSBuildLogPropertyFunctionsRequiringReflection", "true") |
| 49 | + .Execute() |
| 50 | + .Should() |
| 51 | + .Pass(); |
| 52 | + |
| 53 | + var logPath = Path.Combine(testDir, "PropertyFunctionsRequiringReflection"); |
| 54 | + // Functions from Microsoft.Build.Utilities.ToolLocationHelper are pending to add fast path, tracked by https://github.com/dotnet/msbuild/issues/10411. |
| 55 | + // This verification should be changed to no log file created once it is done. |
| 56 | + var toolLocationHelper_GetPlatformSDKLocation = "ReceiverType=Microsoft.Build.Utilities.ToolLocationHelper; ObjectInstanceType=; MethodName=GetPlatformSDKLocation(String, String)"; |
| 57 | + var toolLocationHelper_GetPlatformSDKDisplayName = "ReceiverType=Microsoft.Build.Utilities.ToolLocationHelper; ObjectInstanceType=; MethodName=GetPlatformSDKDisplayName(String, String)"; |
| 58 | + var lines = File.ReadAllLines(logPath); |
| 59 | + var allOnFastPathWithExceptions = lines.All(l => (toolLocationHelper_GetPlatformSDKLocation.Equals(l) || toolLocationHelper_GetPlatformSDKDisplayName.Equals(l))); |
| 60 | + allOnFastPathWithExceptions.Should().BeTrue(); |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments