Skip to content

Commit 855ac86

Browse files
authored
Add the test verifying property functions used in dotnet console/webapp don't need a reflection (#48475)
1 parent 91c916c commit 855ac86

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
}

test/TestAssets/TestProjects/MSBuildBareBonesProject/BareBones.proj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

4+
<PropertyGroup>
5+
<MajorMinorVersion>$([System.Version]::Parse('17.12.11.10').ToString(2))</MajorMinorVersion>
6+
<String_Replace>$([System.Text.RegularExpressions.Regex]::Replace('abc123def', 'abc', ''))</String_Replace>
7+
<String_Equals>$([System.String]::new('Hi').Equals('Hi'))</String_Equals>
8+
<FileName>$([System.IO.Path]::GetFileNameWithoutExtension('C:\folder\file.txt'))</FileName>
9+
<NumberToString>$([System.Int32]::new(123).ToString('mm')</NumberToString>
10+
<Directory>$([Microsoft.Build.Evaluation.IntrinsicFunctions]::NormalizeDirectory('C:/folder1/./folder2/'))</Directory>
11+
<IsWindows>$([Microsoft.Build.Evaluation.IntrinsicFunctions]::IsOSPlatform('Windows'))</IsWindows>
12+
<!-- Functions from Microsoft.Build.Utilities.ToolLocationHelper are pending to add fast path, tracked by https://github.com/dotnet/msbuild/issues/10411.
13+
Comment out this for testing once it's done.
14+
<PlatformSdkLocation>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKLocation('Windows', ''))</PlatformSdkLocation>
15+
<PlatformDisplayName>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKDisplayName('Windows', ''))</PlatformDisplayName>
16+
-->
17+
</PropertyGroup>
18+
419
<Target Name="SayHello">
520
<Message Importance="high" Text="Hello, from MSBuild!" />
621
</Target>

0 commit comments

Comments
 (0)