Skip to content

Commit

Permalink
Merge pull request #28707 from JanKrivanek/template-verifier
Browse files Browse the repository at this point in the history
Template verifier adoption in CommonTemplateTests
  • Loading branch information
JanKrivanek authored Nov 25, 2022
2 parents 28a1b03 + 2b1b74a commit 8f2f52e
Show file tree
Hide file tree
Showing 131 changed files with 1,896 additions and 893 deletions.
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<!-- test dependencies -->
<MicrosoftTemplateEngineMocksPackageVersion>$(MicrosoftTemplateEngineAbstractionsPackageVersion)</MicrosoftTemplateEngineMocksPackageVersion>
<MicrosoftTemplateEngineTestHelperPackageVersion>$(MicrosoftTemplateEngineAbstractionsPackageVersion)</MicrosoftTemplateEngineTestHelperPackageVersion>
<MicrosoftTemplateEngineAuthoringTemplateVerifierVersion>$(MicrosoftTemplateEngineAbstractionsPackageVersion)</MicrosoftTemplateEngineAuthoringTemplateVerifierVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/Microsoft/visualfsharp -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Class1
{
FileName = exePath
};
TestContext.Current.AddTestEnvironmentVariables(toolCommandSpec);
TestContext.Current.AddTestEnvironmentVariables(toolCommandSpec.Environment);

ICommand toolCommand = toolCommandSpec.ToCommand().CaptureStdOut();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private CommandResult GenerateDepsAndRunTool(TestProject toolProject, [CallerMem
FileName = TestContext.Current.ToolsetUnderTest.DotNetHostPath,
Arguments = dotnetArgs
};
TestContext.Current.AddTestEnvironmentVariables(toolCommandSpec);
TestContext.Current.AddTestEnvironmentVariables(toolCommandSpec.Environment);

ICommand toolCommand = toolCommandSpec.ToCommand().CaptureStdOut();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override SdkCommandSpec CreateCommand(IEnumerable<string> args)
Arguments = args.ToList(),
WorkingDirectory = WorkingDirectory
};
TestContext.Current.AddTestEnvironmentVariables(sdkCommandSpec);
TestContext.Current.AddTestEnvironmentVariables(sdkCommandSpec.Environment);
return sdkCommandSpec;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected override SdkCommandSpec CreateCommand(IEnumerable<string> args)
Arguments = newArgs
};

TestContext.Current.AddTestEnvironmentVariables(ret);
TestContext.Current.AddTestEnvironmentVariables(ret.Environment);

return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override SdkCommandSpec CreateCommand(IEnumerable<string> args)
Arguments = args.ToList(),
WorkingDirectory = WorkingDirectory,
};
TestContext.Current.AddTestEnvironmentVariables(sdkCommandSpec);
TestContext.Current.AddTestEnvironmentVariables(sdkCommandSpec.Environment);
return sdkCommandSpec;
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/Tests/Microsoft.NET.TestFramework/TestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.DotNet.Cli.Utils;
using Microsoft.NET.TestFramework.Commands;
using System.Globalization;
using System.Collections.Generic;

namespace Microsoft.NET.TestFramework
{
Expand Down Expand Up @@ -51,20 +52,20 @@ public static TestContext Current

public const string LatestRuntimePatchForNetCoreApp2_0 = "2.0.9";

public void AddTestEnvironmentVariables(SdkCommandSpec command)
public void AddTestEnvironmentVariables(IDictionary<string, string> environment)
{
command.Environment["DOTNET_MULTILEVEL_LOOKUP"] = "0";
environment["DOTNET_MULTILEVEL_LOOKUP"] = "0";

// Set NUGET_PACKAGES environment variable to match value from build.ps1
command.Environment["NUGET_PACKAGES"] = NuGetCachePath;
environment["NUGET_PACKAGES"] = NuGetCachePath;

command.Environment["GenerateResourceMSBuildArchitecture"] = "CurrentArchitecture";
command.Environment["GenerateResourceMSBuildRuntime"] = "CurrentRuntime";
environment["GenerateResourceMSBuildArchitecture"] = "CurrentArchitecture";
environment["GenerateResourceMSBuildRuntime"] = "CurrentRuntime";

// Prevent test MSBuild nodes from persisting
command.Environment["MSBUILDDISABLENODEREUSE"] = "1";
environment["MSBUILDDISABLENODEREUSE"] = "1";

ToolsetUnderTest.AddTestEnvironmentVariables(command);
ToolsetUnderTest.AddTestEnvironmentVariables(environment);
}


Expand Down
22 changes: 11 additions & 11 deletions src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,29 @@ public string GetMicrosoftNETBuildExtensionsPath()
}
}

public void AddTestEnvironmentVariables(SdkCommandSpec command)
public void AddTestEnvironmentVariables(IDictionary<string, string> environment)
{
if (ShouldUseFullFrameworkMSBuild)
{
string sdksPath = Path.Combine(DotNetRoot, "sdk", SdkVersion, "Sdks");

// Use stage 2 MSBuild SDK resolver
command.Environment["MSBUILDADDITIONALSDKRESOLVERSFOLDER"] = SdkResolverPath;
environment["MSBUILDADDITIONALSDKRESOLVERSFOLDER"] = SdkResolverPath;

// Avoid using stage 0 dotnet install dir
command.Environment["DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR"] = "";
environment["DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR"] = "";

// Put stage 2 on the Path (this is how the MSBuild SDK resolver finds dotnet)
command.Environment["Path"] = DotNetRoot + ";" + Environment.GetEnvironmentVariable("Path");
environment["Path"] = DotNetRoot + ";" + Environment.GetEnvironmentVariable("Path");

if (!string.IsNullOrEmpty(MicrosoftNETBuildExtensionsPathOverride))
{
var microsoftNETBuildExtensionsPath = GetMicrosoftNETBuildExtensionsPath();
command.Environment["MicrosoftNETBuildExtensionsTargets"] = Path.Combine(microsoftNETBuildExtensionsPath, "Microsoft.NET.Build.Extensions.targets");
environment["MicrosoftNETBuildExtensionsTargets"] = Path.Combine(microsoftNETBuildExtensionsPath, "Microsoft.NET.Build.Extensions.targets");

if (UsingFullMSBuildWithoutExtensionsTargets())
{
command.Environment["CustomAfterMicrosoftCommonTargets"] = Path.Combine(sdksPath, "Microsoft.NET.Build.Extensions",
environment["CustomAfterMicrosoftCommonTargets"] = Path.Combine(sdksPath, "Microsoft.NET.Build.Extensions",
"msbuildExtensions-ver", "Microsoft.Common.targets", "ImportAfter", "Microsoft.NET.Build.Extensions.targets");
}
}
Expand All @@ -185,21 +185,21 @@ public void AddTestEnvironmentVariables(SdkCommandSpec command)

if (Environment.Is64BitProcess)
{
command.Environment.Add("DOTNET_ROOT", DotNetRoot);
environment.Add("DOTNET_ROOT", DotNetRoot);
}
else
{
command.Environment.Add("DOTNET_ROOT(x86)", DotNetRoot);
environment.Add("DOTNET_ROOT(x86)", DotNetRoot);
}

if (!string.IsNullOrEmpty(CliHomePath))
{
command.Environment.Add("DOTNET_CLI_HOME", CliHomePath);
environment.Add("DOTNET_CLI_HOME", CliHomePath);
}

// We set this environment variable for in-process tests, but we don't want it to flow to out of process tests
// (especially if we're trying to run on full Framework MSBuild)
command.Environment[DotNet.Cli.Utils.Constants.MSBUILD_EXE_PATH] = "";
environment[DotNet.Cli.Utils.Constants.MSBUILD_EXE_PATH] = "";

}

Expand Down Expand Up @@ -236,7 +236,7 @@ private SdkCommandSpec CreateCommand(params string[] args)
ret.Arguments = newArgs;
}

TestContext.Current.AddTestEnvironmentVariables(ret);
TestContext.Current.AddTestEnvironmentVariables(ret.Environment);

return ret;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": 1,
"isRoot": true,
"tools": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The template "%TEMPLATE_NAME%" was created successfully.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
root = true

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The template "%TEMPLATE_NAME%" was created successfully.
Loading

0 comments on commit 8f2f52e

Please sign in to comment.