Skip to content

Commit

Permalink
Sdk Preprocessor output test
Browse files Browse the repository at this point in the history
  • Loading branch information
rainersigwald committed Nov 30, 2016
1 parent e30f3d3 commit 350e21b
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/XMakeBuildEngine/UnitTests/Evaluation/Preprocessor_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -844,5 +844,96 @@ public void ProjectMetadata()

Helpers.VerifyAssertLineByLine(expected, writer.ToString());
}

[Fact]
public void SdkImportsAreInPreprocessedOutput()
{
var testSdkRoot = Path.Combine(Path.GetTempPath(), "MSBuildUnitTest");
var testSdkDirectory = Path.Combine(testSdkRoot, "MSBuildUnitTestSdk", "Sdk");

try
{
Directory.CreateDirectory(testSdkDirectory);

string sdkPropsPath = Path.Combine(testSdkDirectory, "Sdk.props");
string sdkTargetsPath = Path.Combine(testSdkDirectory, "Sdk.targets");

File.WriteAllText(sdkPropsPath, @"<Project>
<PropertyGroup>
<SdkPropsImported>true</SdkPropsImported>
</PropertyGroup>
</Project>");
File.WriteAllText(sdkTargetsPath, @"<Project>
<PropertyGroup>
<SdkTargetsImported>true</SdkTargetsImported>
</PropertyGroup>
</Project>");

using (new Helpers.TemporaryEnvironment("MSBuildSDKsPath", testSdkRoot))
{
string content = @"<Project Sdk='MSBuildUnitTestSdk'>
<PropertyGroup>
<p>v1</p>
</PropertyGroup>
</Project>";

var project = new Project(ProjectRootElement.Create(XmlReader.Create(new StringReader(content))));

StringWriter writer = new StringWriter();

project.SaveLogicalProject(writer);

string expected = ObjectModelHelpers.CleanupFileContents(
$@"<?xml version=""1.0"" encoding=""utf-16""?>
<Project Sdk=""MSBuildUnitTestSdk"">
<!--
============================================================================================================================================
Import of ""{sdkPropsPath}"" from Sdk ""MSBuildUnitTestSdk"" was implied by the Project element's Sdk attribute.
{sdkPropsPath}
============================================================================================================================================
-->
<PropertyGroup>
<SdkPropsImported>true</SdkPropsImported>
</PropertyGroup>
<!--
============================================================================================================================================
</Import>
============================================================================================================================================
-->
<PropertyGroup>
<p>v1</p>
</PropertyGroup>
<!--
============================================================================================================================================
Import of ""{sdkTargetsPath}"" from Sdk ""MSBuildUnitTestSdk"" was implied by the Project element's Sdk attribute.
{sdkTargetsPath}
============================================================================================================================================
-->
<PropertyGroup>
<SdkTargetsImported>true</SdkTargetsImported>
</PropertyGroup>
<!--
============================================================================================================================================
</Import>
============================================================================================================================================
-->
</Project>");
Helpers.VerifyAssertLineByLine(expected, writer.ToString());
}
}
finally
{
if (Directory.Exists(testSdkDirectory))
{
FileUtilities.DeleteWithoutTrailingBackslash(testSdkDirectory, true);
}
}
}
}
}

0 comments on commit 350e21b

Please sign in to comment.