Skip to content

Commit

Permalink
Add the test verifying build check template (#11047)
Browse files Browse the repository at this point in the history
* Add the test verifying build check template

* Make generating packages needed for e2e testing for BootstrapFull or BootstrapNetCore
  • Loading branch information
GangWang01 authored Dec 3, 2024
1 parent c5aadfd commit bedf60d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion eng/TestAssets.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</Target>

<Target Name="MSBuildPackagesForTests"
AfterTargets="BootstrapFull"
AfterTargets="$(BootstrapDependsOn)"
DependsOnTargets="GetSourceFilesForPacking"
Inputs="@(ProjectsToPack);@(SourceFilesForPacking)"
Outputs="$(ArtifactsNonShippingPackagesDir)\Microsoft.Build.$(Version).nupkg;$(ArtifactsNonShippingPackagesDir)\Microsoft.Build.Framework.$(Version).nupkg;$(ArtifactsNonShippingPackagesDir)\Microsoft.NET.StringTools.$(Version).nupkg">
Expand Down
29 changes: 29 additions & 0 deletions src/BuildCheck.UnitTests/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,35 @@ public void DoesNotRunOnRestore(bool buildInOutOfProcessNode)
output.ShouldNotContain("BC0103");
}

#if NET
[Fact]
public void TestBuildCheckTemplate()
{
TransientTestFolder workFolder = _env.CreateFolder(createFolder: true);
var nugetTemplateName = "nugetTemplate.config";
var nugetTemplatePath = Path.Combine(TestAssetsRootPath, "CheckCandidate", nugetTemplateName);
File.Copy(nugetTemplatePath, Path.Combine(workFolder.Path, nugetTemplateName));
AddCustomDataSourceToNugetConfig(workFolder.Path);

var ExecuteDotnetCommand = (string parameters) =>
{
string output = RunnerUtilities.RunProcessAndGetOutput("dotnet", parameters, out bool success);
return output;
};

var buildCheckTemplatePath = Path.Combine(BuildCheckUnitTestsConstants.RepoRoot, "template_feed", "content", "Microsoft.CheckTemplate");
var templateShortName = "msbuildcheck";
var projectName = "BuildCheck";
var installLog = ExecuteDotnetCommand($"new install {buildCheckTemplatePath}");
installLog.ShouldContain($"Success: {buildCheckTemplatePath} installed the following templates:");
var creationLog = ExecuteDotnetCommand($"new {templateShortName} -n {projectName} --MicrosoftBuildVersion {BuildCheckUnitTestsConstants.MicrosoftBuildPackageVersion} -o {workFolder.Path} ");
creationLog.ShouldContain("The template \"MSBuild custom check skeleton project.\" was created successfully.");
var buildLog = ExecuteDotnetCommand($"build {workFolder.Path}");
buildLog.ShouldContain("Build succeeded.");
ExecuteDotnetCommand($"new -u {buildCheckTemplatePath}");
}
#endif

private void AddCustomDataSourceToNugetConfig(string checkCandidatePath)
{
var nugetTemplatePath = Path.Combine(checkCandidatePath, "nugetTemplate.config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,27 @@
<Compile Include="..\Shared\IsExternalInit.cs" />
</ItemGroup>

<Target Name="AddGeneratedFile" BeforeTargets="BeforeCompile;CoreCompile" Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)BuildCheckUnitTestsConstants.cs">
<PropertyGroup>
<GeneratedText>
<![CDATA[
namespace Microsoft.Build.BuildCheck.UnitTests
{
internal sealed class BuildCheckUnitTestsConstants
{
public const string MicrosoftBuildPackageVersion = @"$(Version)"%3B
public const string RepoRoot = @"$(RepoRoot)"%3B
}
}
]]>
</GeneratedText>
<GeneratedFilePath>$(IntermediateOutputPath)BuildCheckUnitTestsConstants.cs</GeneratedFilePath>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(GeneratedFilePath)" />
<FileWrites Include="$(GeneratedFilePath)" />
</ItemGroup>
<WriteLinesToFile Lines="$(GeneratedText)" File="$(GeneratedFilePath)" WriteOnlyWhenDifferent="true" Overwrite="true" />
</Target>

</Project>

0 comments on commit bedf60d

Please sign in to comment.