Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template verifier adoption in CommonTemplateTests #28707

Merged
merged 30 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5530578
Adopt TemplateEngine.Authoring.TemplateVerifier in CommonTestTemplates
JanKrivanek Oct 19, 2022
eeb5585
Convert TopLevelProgramSupport test
JanKrivanek Oct 19, 2022
acabaa3
Covert remaining unit tests in CommonTemplatesTests
JanKrivanek Oct 21, 2022
77e5fde
Udpate dotnet-new.IntegrationTests.csproj to use internal feed package
JanKrivanek Oct 21, 2022
939ee0a
Merge remote-tracking branch 'upstream/main' into template-verifier
JanKrivanek Oct 21, 2022
d360677
Fix version mismatches
JanKrivanek Oct 21, 2022
fdc5cb2
Adjust snapshots build exclusion
JanKrivanek Oct 25, 2022
0924684
Merge remote-tracking branch 'upstream/main' into template-verifier
Nov 8, 2022
3b04a69
Update tests
JanKrivanek Nov 8, 2022
1b7a2dd
Inject test environment
JanKrivanek Nov 8, 2022
c0a3f32
Bugfix
JanKrivanek Nov 8, 2022
b5b7e0b
Fix Verify change in handling newlines
JanKrivanek Nov 9, 2022
be0236d
Consolidate integration tests
JanKrivanek Nov 10, 2022
d5959c2
Consolidate tests further
JanKrivanek Nov 10, 2022
ddd24ab
Add directory separators unixification
JanKrivanek Nov 11, 2022
9909a94
Fix issues in consolidated tests
JanKrivanek Nov 11, 2022
66fbd7a
Build fix
JanKrivanek Nov 11, 2022
ddd9510
Test fix
JanKrivanek Nov 11, 2022
fd264d2
Test fix 2
JanKrivanek Nov 11, 2022
3ff162c
Workaround Verify limitation with .config files
JanKrivanek Nov 11, 2022
7be7c25
Upgrade EmptyFiles
JanKrivanek Nov 21, 2022
23b8c80
Reflect PR comments
JanKrivanek Nov 23, 2022
000c28f
Adjust item test to net8 changes
JanKrivanek Nov 23, 2022
12026d3
Testfix - snapshots update
JanKrivanek Nov 23, 2022
ed7874c
Merge remote-tracking branch 'upstream/main' into template-verifier
JanKrivanek Nov 23, 2022
8854670
Update default TFM to net8.0
JanKrivanek Nov 23, 2022
3ccb7ba
Add and modify test scenarios for net8
JanKrivanek Nov 24, 2022
b2a3c66
Remove net6 templates from test matrix for now, to workaround issues …
JanKrivanek Nov 24, 2022
c5fa669
Update test to reflect 5.0 EOL
JanKrivanek Nov 24, 2022
2b1b74a
Readd net6.0 to test matrix, skipping buggy cases
JanKrivanek Nov 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"version": 1,
"isRoot": true,
"tools": {}
Expand Down
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.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
root = true
root = true

# All files
[*]
Expand Down
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 @@
The template "%TEMPLATE_NAME%" was created successfully.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand Down
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 @@
The template "%TEMPLATE_NAME%" was created successfully.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Ignore Visual Studio temporary files, build results, and
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
Expand Down
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
@@ -1,4 +1,4 @@
{
{
"sdk": {
"rollForward": "major",
"version": "5.0.200"
Expand Down
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
@@ -1,4 +1,4 @@
{
{
"sdk": {
"version": "5.0.200"
}
Expand Down
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
@@ -1,4 +1,4 @@
{
{
"sdk": {
"version": "%CURRENT-VER%"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The template "%TEMPLATE_NAME%" was created successfully.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

48 changes: 29 additions & 19 deletions src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,41 @@ public CommonTemplatesTests(SharedHomeDirectory fixture, ITestOutputHelper log)

[Theory]
[InlineData("dotnet gitignore file", "gitignore", null)]
[InlineData("dotnet gitignore file", ".gitignore", null)]
[InlineData("global.json file", "globaljson", null)]
[InlineData("global.json file", "globaljson", new[] { "--sdk-version", "5.0.200" })]
[InlineData("global.json file", "globaljson", new[] { "--sdk-version", "5.0.200", "--roll-forward", "major" })]
[InlineData("global.json file", "global.json", null)]
[InlineData("global.json file", "global.json", new[] { "--sdk-version", "5.0.200" })]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove .NET 5 here (EOL), can be done in another PR

[InlineData("global.json file", "global.json", new[] { "--sdk-version", "5.0.200", "--roll-forward", "major" })]
[InlineData("NuGet Config", "nugetconfig", null)]
[InlineData("NuGet Config", "nuget.config", null)]
[InlineData("Solution File", "sln", null)]
[InlineData("Solution File", "solution", null)]
[InlineData("Dotnet local tool manifest file", "tool-manifest", null)]
[InlineData("Web Config", "webconfig", null)]
[InlineData("EditorConfig file", "editorconfig", null)]
[InlineData("EditorConfig file", "editorconfig", new[] { "--empty" })]
[InlineData("EditorConfig file", ".editorconfig", null)]
[InlineData("EditorConfig file", ".editorconfig", new[] { "--empty" })]
public async void AllCommonItemsCreate(string expectedTemplateName, string templateShortName, string[]? args)
{
Dictionary<string, string> environmentUnderTest = new() { ["DOTNET_NOLOGO"] = false.ToString() };
TestContext.Current.AddTestEnvironmentVariables(environmentUnderTest);

string itemName = expectedTemplateName.Replace(' ', '-').Replace('.', '-');

TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName)
{
TemplateSpecificArgs = args,
// squeshing snapshots by creating output unique for template (but not alias) and preventing item to have name by alias
TemplateSpecificArgs = new[] { "-o", itemName, "-n", "item" }.Concat(args ?? Enumerable.Empty<string>()),
SnapshotsDirectory = "Approvals",
VerifyCommandOutput = true,
VerificationExcludePatterns = new[] { "*/stderr.txt", "*\\stderr.txt" },
vlada-shubina marked this conversation as resolved.
Show resolved Hide resolved
SettingsDirectory = _fixture.HomeDirectory,
DotnetExecutablePath = TestContext.Current.ToolsetUnderTest.DotNetHostPath,
UniqueFor = templateShortName.Equals("nugetconfig") ? UniqueForOption.OsPlatform : null,
DoNotPrependTemplateNameToScenarioName = true,
UniqueFor = expectedTemplateName.Equals("NuGet Config") ? UniqueForOption.OsPlatform : null,
}
.WithCustomEnvironment(environmentUnderTest)
.WithCustomScrubbers(
Expand All @@ -72,7 +83,7 @@ public async void AllCommonItemsCreate(string expectedTemplateName, string templ

// globaljson is appending current sdk version. Due to the 'base' dotnet used to run test this version differs
// on dev and CI runs and possibly from the version within test host. Easiest is just to scrub it away
if (templateShortName.Equals("globaljson") && args == null)
if (expectedTemplateName.Equals("global.json file") && args == null)
{
string sdkVersionUnderTest = await new SdkInfoProvider().GetCurrentVersionAsync(default).ConfigureAwait(false);
options.CustomScrubbers?.AddScrubber(sb => sb.Replace(sdkVersionUnderTest, "%CURRENT-VER%"), "json");
Expand Down Expand Up @@ -162,24 +173,24 @@ public void NuGetConfigPermissions()

var templatesToTest = new[]
{
new { Template = consoleTemplateShortname, Frameworks = new[] { null, "net7.0" } },
new { Template = "classlib", Frameworks = new[] { null, "net7.0", "netstandard2.0", "netstandard2.1" } }
new { Template = consoleTemplateShortname, Frameworks = new[] { null, "net6.0", "net7.0", "net8.0" } },
new { Template = "classlib", Frameworks = new[] { null, "net6.0", "net7.0", "net8.0", "netstandard2.0", "netstandard2.1" } }
};

//features: top-level statements; nullables; implicit usings; filescoped namespaces

string[] unsupportedLanguageVersions = { "1", "ISO-1" };
string[] unsupportedFrameworkVersions = { "net5.0", "netcoreapp3.1" };
string?[] supportedLanguageVersions = { null, "ISO-2", "2", "3", "4", "5", "6", "7", "7.1", "7.2", "7.3", "8.0", "9.0", "10.0", "11.0", "11", "latest", "latestMajor", "default", "preview" };
//C# 12 is not supported yet - https://github.com/dotnet/sdk/issues/29195
string?[] supportedLanguageVersions = { null, "ISO-2", "2", "3", "4", "5", "6", "7", "7.1", "7.2", "7.3", "8.0", "9.0", "10.0", "11.0", "11", /*"12",*/ "latest", "latestMajor", "default", "preview" };

string?[] nullableSupportedInFrameworkByDefault = { null, "net7.0", "netstandard2.1" };
string?[] implicitUsingsSupportedInFramework = { null, "net7.0" };
string?[] fileScopedNamespacesSupportedFrameworkByDefault = { null, "net7.0" };
string?[] nullableSupportedInFrameworkByDefault = { null, "net7.0", "net8.0", "netstandard2.1" };
string?[] implicitUsingsSupportedInFramework = { null, "net6.0", "net7.0", "net8.0" };
vlada-shubina marked this conversation as resolved.
Show resolved Hide resolved
string?[] fileScopedNamespacesSupportedFrameworkByDefault = { null, "net7.0", "net8.0" };

string?[] nullableSupportedLanguages = { "8.0", "9.0", "10.0", "11.0", "11", "latest", "latestMajor", "default", "preview" };
string?[] topLevelStatementSupportedLanguages = { null, "9.0", "10.0", "11", "11.0", "latest", "latestMajor", "default", "preview" };
string?[] implicitUsingsSupportedLanguages = { null, "10.0", "11.0", "11", "latest", "latestMajor", "default", "preview" };
string?[] fileScopedNamespacesSupportedLanguages = { "10.0", "11.0", "11", "latest", "latestMajor", "default", "preview" };
string?[] nullableSupportedLanguages = { "8.0", "9.0", "10.0", "11.0", "11", /*"12",*/ "latest", "latestMajor", "default", "preview" };
string?[] topLevelStatementSupportedLanguages = { null, "9.0", "10.0", "11", "11.0", /*"12",*/ "latest", "latestMajor", "default", "preview" };
string?[] implicitUsingsSupportedLanguages = { null, "10.0", "11.0", "11", /*"12",*/ "latest", "latestMajor", "default", "preview" };
string?[] fileScopedNamespacesSupportedLanguages = { "10.0", "11.0", "11", /*"12",*/ "latest", "latestMajor", "default", "preview" };

string?[] supportedLangs = { null, "C#", "F#", "VB" };

Expand All @@ -191,7 +202,6 @@ public void NuGetConfigPermissions()
IEnumerable<string?> langs = new string?[] { null };
if (langVersion == null)
{
frameworks = frameworks.Concat(unsupportedFrameworkVersions);
langs = supportedLangs;
}

Expand All @@ -212,7 +222,7 @@ public void NuGetConfigPermissions()

object?[]? CreateParams(string templateName, string? langVersion, string? lang, string? framework, bool forceDisableTopLevel)
{
bool supportsTopLevel = topLevelStatementSupportedLanguages.Contains(langVersion) && !unsupportedFrameworkVersions.Contains(framework);
bool supportsTopLevel = topLevelStatementSupportedLanguages.Contains(langVersion);

// If forceDisableTopLevel is requested - then generate params only if it makes sense - for C# console project of a version that
// supports top level statements. Otherwise it doesn't make sense to test this overwritting functionality
Expand All @@ -225,7 +235,7 @@ public void NuGetConfigPermissions()
{
templateName,
// buildPass
supportedLanguageVersions.Contains(langVersion) && !unsupportedFrameworkVersions.Contains(framework),
supportedLanguageVersions.Contains(langVersion),
framework,
langVersion,
// langVersionUnsupported
Expand Down Expand Up @@ -263,8 +273,8 @@ public async void FeaturesSupport(
bool supportsImplicitUsings,
bool supportsFileScopedNs)
{
const string currentDefaultFramework = "net8.0";
//string currentDefaultFramework = $"net{Environment.Version.Major}.{Environment.Version.Minor}";
// "net8.0";
string currentDefaultFramework = $"net{Environment.Version.Major}.{Environment.Version.Minor}";

string workingDir = CreateTemporaryFolder(folderName: $"{name}-{langVersion ?? "null"}-{framework ?? "null"}");
string outputDir = "MyProject";
Expand Down