From 5530578354f7a22946d129f1c084e610c49d2348 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Wed, 19 Oct 2022 13:19:00 +0200 Subject: [PATCH 01/12] Adopt TemplateEngine.Authoring.TemplateVerifier in CommonTestTemplates --- eng/Versions.props | 1 + .../std-streams/stderr.txt | 1 + .../std-streams/stdout.txt | 1 + .../std-streams/stderr.txt | 1 + .../std-streams/stdout.txt | 7 + .../std-streams/stderr.txt | 1 + .../std-streams/stdout.txt | 1 + .../editorconfig/.editorconfig | 2 + .../std-streams/stderr.txt | 1 + .../std-streams/stdout.txt | 1 + .../globaljson/global.json | 6 + .../std-streams/stderr.txt | 1 + .../std-streams/stdout.txt | 1 + .../globaljson/global.json | 5 + .../std-streams/stderr.txt | 1 + .../std-streams/stdout.txt | 1 + .../dotnet-new.Tests/CommonTemplatesTests.cs | 195 +++++++++++------- .../dotnet-new.Tests/VerifySettingsFixture.cs | 2 +- .../dotnet-new.IntegrationTests.csproj | 16 +- 19 files changed, 170 insertions(+), 75 deletions(-) create mode 100644 src/Tests/dotnet-new.Tests/Approvals/AllCommonItemsCreate._.verified/std-streams/stderr.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/AllCommonItemsCreate._.verified/std-streams/stdout.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreateRestoreAndBuild._.verified/std-streams/stderr.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreateRestoreAndBuild._.verified/std-streams/stdout.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreate_NoRestore._.verified/std-streams/stderr.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreate_NoRestore._.verified/std-streams/stdout.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/editorconfig/.editorconfig create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/std-streams/stderr.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/std-streams/stdout.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/globaljson/global.json create mode 100644 src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/std-streams/stderr.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/std-streams/stdout.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/globaljson/global.json create mode 100644 src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/std-streams/stderr.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/std-streams/stdout.txt diff --git a/eng/Versions.props b/eng/Versions.props index 2a736d29ac97..819e7ad7c0d8 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -133,6 +133,7 @@ $(MicrosoftTemplateEngineAbstractionsPackageVersion) $(MicrosoftTemplateEngineAbstractionsPackageVersion) + $(MicrosoftTemplateEngineAbstractionsPackageVersion) diff --git a/src/Tests/dotnet-new.Tests/Approvals/AllCommonItemsCreate._.verified/std-streams/stderr.txt b/src/Tests/dotnet-new.Tests/Approvals/AllCommonItemsCreate._.verified/std-streams/stderr.txt new file mode 100644 index 000000000000..5f282702bb03 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/AllCommonItemsCreate._.verified/std-streams/stderr.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/AllCommonItemsCreate._.verified/std-streams/stdout.txt b/src/Tests/dotnet-new.Tests/Approvals/AllCommonItemsCreate._.verified/std-streams/stdout.txt new file mode 100644 index 000000000000..70cab17a4b13 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/AllCommonItemsCreate._.verified/std-streams/stdout.txt @@ -0,0 +1 @@ +The template "%TEMPLATE_NAME%" was created successfully. \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreateRestoreAndBuild._.verified/std-streams/stderr.txt b/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreateRestoreAndBuild._.verified/std-streams/stderr.txt new file mode 100644 index 000000000000..5f282702bb03 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreateRestoreAndBuild._.verified/std-streams/stderr.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreateRestoreAndBuild._.verified/std-streams/stdout.txt b/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreateRestoreAndBuild._.verified/std-streams/stdout.txt new file mode 100644 index 000000000000..430a24c2acb9 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreateRestoreAndBuild._.verified/std-streams/stdout.txt @@ -0,0 +1,7 @@ +The template "%TEMPLATE_NAME%" was created successfully. + +Processing post-creation actions... +Restoring %PROJECT_NAME%: + Determining projects to restore... + Restored %PROJECT_NAME% (%DURATION%). +Restore succeeded. \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreate_NoRestore._.verified/std-streams/stderr.txt b/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreate_NoRestore._.verified/std-streams/stderr.txt new file mode 100644 index 000000000000..5f282702bb03 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreate_NoRestore._.verified/std-streams/stderr.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreate_NoRestore._.verified/std-streams/stdout.txt b/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreate_NoRestore._.verified/std-streams/stdout.txt new file mode 100644 index 000000000000..70cab17a4b13 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/AllCommonProjectsCreate_NoRestore._.verified/std-streams/stdout.txt @@ -0,0 +1 @@ +The template "%TEMPLATE_NAME%" was created successfully. \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/editorconfig/.editorconfig b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/editorconfig/.editorconfig new file mode 100644 index 000000000000..6a5db887fd68 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/editorconfig/.editorconfig @@ -0,0 +1,2 @@ +root = true + diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/std-streams/stderr.txt b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/std-streams/stderr.txt new file mode 100644 index 000000000000..5f282702bb03 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/std-streams/stderr.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/std-streams/stdout.txt b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/std-streams/stdout.txt new file mode 100644 index 000000000000..7d111cb75350 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty.editorconfig.--empty.verified/std-streams/stdout.txt @@ -0,0 +1 @@ +The template "EditorConfig file" was created successfully. \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/globaljson/global.json b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/globaljson/global.json new file mode 100644 index 000000000000..7730b087984a --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/globaljson/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "rollForward": "major", + "version": "5.0.200" + } +} \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/std-streams/stderr.txt b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/std-streams/stderr.txt new file mode 100644 index 000000000000..5f282702bb03 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/std-streams/stderr.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/std-streams/stdout.txt b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/std-streams/stdout.txt new file mode 100644 index 000000000000..d8cf40e1cb6b --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200#--roll-forward#major.verified/std-streams/stdout.txt @@ -0,0 +1 @@ +The template "global.json file" was created successfully. \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/globaljson/global.json b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/globaljson/global.json new file mode 100644 index 000000000000..f65450fd2f28 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/globaljson/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "5.0.200" + } +} \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/std-streams/stderr.txt b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/std-streams/stderr.txt new file mode 100644 index 000000000000..5f282702bb03 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/std-streams/stderr.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/std-streams/stdout.txt b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/std-streams/stdout.txt new file mode 100644 index 000000000000..d8cf40e1cb6b --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/GlobalJsonTests.globaljson.--sdk-version#5.0.200.verified/std-streams/stdout.txt @@ -0,0 +1 @@ +The template "global.json file" was created successfully. \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs index 6d7e54013ed7..02b143838c38 100644 --- a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs +++ b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs @@ -6,9 +6,12 @@ using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Xml.Linq; +using FluentAssertions; using Microsoft.DotNet.Cli.Utils; +using Microsoft.Extensions.Logging; using Microsoft.NET.TestFramework.Assertions; using Microsoft.NET.TestFramework.Commands; +using Microsoft.TemplateEngine.Authoring.TemplateVerifier; using Microsoft.TemplateEngine.TestHelper; using Xunit.Abstractions; @@ -18,11 +21,13 @@ public class CommonTemplatesTests : BaseIntegrationTest, IClassFixture "fsproj", "VB" => "vbproj", _ => "csproj" }; - string finalProjectName = Regex.Escape(Path.Combine(workingDir, $"{workingDirName}.{extension}")); + + string projectName = "sample-project-name"; + string projectDir = Path.Combine(workingDir, templateShortName); + string finalProjectName = Path.Combine(projectDir, $"{projectName}.{extension}"); Console.WriteLine($"Expected project location: {finalProjectName}"); - List args = new() { templateShortName }; + List args = new() { "-n", projectName }; if (!string.IsNullOrWhiteSpace(language)) { args.Add("--language"); @@ -78,24 +84,35 @@ public void AllCommonProjectsCreateRestoreAndBuild(string expectedTemplateName, args.Add(langVersion); } - new DotnetNewCommand(_log, args.ToArray()) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr() - .And.HaveStdOutMatching( -$@"The template ""{expectedTemplateName}"" was created successfully\. - -Processing post-creation actions\.\.\. -Restoring {finalProjectName}: -.* -Restore succeeded\.", - RegexOptions.Singleline); + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName) + { + TemplateSpecificArgs = args, + ExpectationsDirectory = "Approvals", + OutputDirectory = workingDir, + VerifyCommandOutput = true, + VerificationExcludePatterns = new[] { "*.cs", "*.fs", "*.vb", "*.*proj" }, + DoNotPrependCallerMethodNameToScenarioName = false, + DoNotAppendParamsToScenarioName = true, + DoNotPrependTemplateToScenarioName = true, + } + .WithCustomScrubbers( + ScrubbersDefinition.Empty + .AddScrubber(sb => + { + const string projectPathTag = "%PROJECT_NAME%"; + sb.Replace(expectedTemplateName, "%TEMPLATE_NAME%").Replace(finalProjectName, projectPathTag); + string pattern = "(^ Restored " + Regex.Escape(projectPathTag) + " \\()(.*)(\\)\\.)"; + string res = sb.ToString(); + res = Regex.Replace(res, pattern, "$1%DURATION%$3", RegexOptions.Multiline); + sb.Clear(); + sb.Append(res); + })); + + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); new DotnetRestoreCommand(_log) - .WithWorkingDirectory(workingDir) + .WithWorkingDirectory(projectDir) .Execute() .Should() .ExitWith(0) @@ -103,7 +120,7 @@ Processing post-creation actions\.\.\. .NotHaveStdErr(); new DotnetBuildCommand(_log) - .WithWorkingDirectory(workingDir) + .WithWorkingDirectory(projectDir) .Execute() .Should() .ExitWith(0) @@ -147,11 +164,9 @@ Processing post-creation actions\.\.\. [InlineData("Class Library", "classlib", "C#", "netstandard2.0")] [InlineData("Class Library", "classlib", "VB", "netstandard2.0")] [InlineData("Class Library", "classlib", "F#", "netstandard2.0")] - public void AllCommonProjectsCreate_NoRestore(string expectedTemplateName, string templateShortName, string? language = null, string? framework = null) + public async void AllCommonProjectsCreate_NoRestore(string expectedTemplateName, string templateShortName, string? language = null, string? framework = null) { - string workingDir = CreateTemporaryFolder(folderName: $"{templateShortName}-{language?.Replace("#", "Sharp") ?? "null"}-{framework ?? "null"}"); - - List args = new() { templateShortName, "--no-restore" }; + List args = new() { "--no-restore" }; if (!string.IsNullOrWhiteSpace(language)) { args.Add("--language"); @@ -163,16 +178,23 @@ public void AllCommonProjectsCreate_NoRestore(string expectedTemplateName, strin args.Add(framework); } - new DotnetNewCommand(_log, args.ToArray()) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr() - .And.HaveStdOut($@"The template ""{expectedTemplateName}"" was created successfully."); + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName) + { + TemplateSpecificArgs = args, + ExpectationsDirectory = "Approvals", + VerifyCommandOutput = true, + VerificationIncludePatterns = new[] { "*.txt" }, + DoNotAppendParamsToScenarioName = true, + SettingsDirectory = _fixture.HomeDirectory, + DoNotPrependTemplateToScenarioName = true, + } + .WithCustomScrubbers( + ScrubbersDefinition.Empty + .AddScrubber(sb => sb.Replace(expectedTemplateName, "%TEMPLATE_NAME%")) + ); - Directory.Delete(workingDir, true); + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); } [Theory] @@ -183,24 +205,28 @@ public void AllCommonProjectsCreate_NoRestore(string expectedTemplateName, strin [InlineData("Solution File", "solution")] [InlineData("Dotnet local tool manifest file", "tool-manifest")] [InlineData("Web Config", "webconfig")] - public void AllCommonItemsCreate(string expectedTemplateName, string templateShortName) + public async void AllCommonItemsCreate(string expectedTemplateName, string templateShortName) { - string workingDir = CreateTemporaryFolder(folderName: $"{templateShortName}"); - - new DotnetNewCommand(_log, templateShortName) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr() - .And.HaveStdOutContaining($@"The template ""{expectedTemplateName}"" was created successfully."); + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName) + { + ExpectationsDirectory = "Approvals", + VerifyCommandOutput = true, + VerificationIncludePatterns = new[] { "*.txt" }, + DoNotAppendParamsToScenarioName = true, + SettingsDirectory = _fixture.HomeDirectory, + DoNotPrependTemplateToScenarioName = true, + } + .WithCustomScrubbers( + ScrubbersDefinition.Empty + .AddScrubber(sb => sb.Replace(expectedTemplateName, "%TEMPLATE_NAME%")) + ); - Directory.Delete(workingDir, true); + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); } [Fact] - public void EditorConfigTests() + public void EditorConfigTests_orig() { string workingDir = CreateTemporaryFolder(); @@ -237,44 +263,67 @@ public void EditorConfigTests() Directory.Delete(workingDir, true); } + [Fact] + public async void EditorConfigTests_Empty() + { + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: "editorconfig") + { + TemplateSpecificArgs = new[] { "--empty" }, + ExpectationsDirectory = "Approvals", + SettingsDirectory = _fixture.HomeDirectory, + VerifyCommandOutput = true, + }; + + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); + } + + [Fact] + public async void EditorConfigTests_Default() + { + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: "editorconfig") + { + ExpectationsDirectory = "Approvals", + SettingsDirectory = _fixture.HomeDirectory, + } + .WithCustomDirectoryVerifier(async (content, contentFetcher) => + { + await foreach (var (filePath, scrubbedContent) in contentFetcher.Value) + { + filePath.Replace(Path.DirectorySeparatorChar, '/').Should().BeEquivalentTo(@"editorconfig/.editorconfig"); + scrubbedContent.Should().Contain("dotnet_naming_rule"); + scrubbedContent.Should().Contain("dotnet_style_"); + scrubbedContent.Should().Contain("dotnet_naming_symbols"); + } + }); + + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); + } + [Theory] [InlineData( -@"{ - ""sdk"": { - ""version"": ""5.0.200"" - } -}", "globaljson", "--sdk-version", "5.0.200")] [InlineData( -@"{ - ""sdk"": { - ""rollForward"": ""major"", - ""version"": ""5.0.200"" - } -}", "globaljson", "--sdk-version", "5.0.200", "--roll-forward", "major")] - public void GlobalJsonTests(string expectedContent, params string[] parameters) + public async void GlobalJsonTests(params string[] parameters) { - string workingDir = CreateTemporaryFolder(); - - new DotnetNewCommand(_log, parameters) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr() - .And.HaveStdOut($@"The template ""global.json file"" was created successfully."); + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: parameters[0]) + { + TemplateSpecificArgs = parameters[1..], + ExpectationsDirectory = "Approvals", + SettingsDirectory = _fixture.HomeDirectory, + VerifyCommandOutput = true, + }; - string globalJsonConent = File.ReadAllText(Path.Combine(workingDir, "global.json")); - Assert.Equal(expectedContent.Replace("\r\n", "\n"), globalJsonConent.Replace("\r\n", "\n")); - Directory.Delete(workingDir, true); + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); } [Fact] diff --git a/src/Tests/dotnet-new.Tests/VerifySettingsFixture.cs b/src/Tests/dotnet-new.Tests/VerifySettingsFixture.cs index 969efcb0f349..6a4c3807b9ac 100644 --- a/src/Tests/dotnet-new.Tests/VerifySettingsFixture.cs +++ b/src/Tests/dotnet-new.Tests/VerifySettingsFixture.cs @@ -8,7 +8,7 @@ public class VerifySettingsFixture : IDisposable { public VerifySettingsFixture() { - VerifierSettings.DerivePathInfo( + Verifier.DerivePathInfo( (_, _, type, method) => new( directory: "Approvals", typeName: type.Name, diff --git a/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj b/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj index d875c3ac63a3..dca0aee2aee1 100644 --- a/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj +++ b/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj @@ -10,15 +10,23 @@ true + + - + + + @@ -66,4 +74,10 @@ namespace Microsoft.DotNet.Cli.New.IntegrationTests + + + + + + From eeb55859341f17704d4d42cf4d274c90344e6248 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Wed, 19 Oct 2022 21:21:49 +0200 Subject: [PATCH 02/12] Convert TopLevelProgramSupport test --- .../MyProject/Program.cs | 12 ++ .../MyProject/console.csproj | 9 ++ .../MyProject/Program.cs | 12 ++ .../MyProject/console.csproj | 10 ++ .../MyProject/Program.cs | 4 + .../MyProject/console.csproj | 10 ++ .../MyProject/Program.cs | 2 + .../MyProject/console.csproj | 10 ++ .../MyProject/Program.cs | 2 + .../MyProject/console.csproj | 11 ++ .../dotnet-new.Tests/CommonTemplatesTests.cs | 107 ++++++------------ 11 files changed, 114 insertions(+), 75 deletions(-) create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/console.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/console.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/console.csproj diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs new file mode 100644 index 000000000000..eb556c611f8f --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace console +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj new file mode 100644 index 000000000000..e90b46d9acdb --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj @@ -0,0 +1,9 @@ + + + + Exe + net7.0 + %LANG% + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs new file mode 100644 index 000000000000..eb556c611f8f --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace console +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj new file mode 100644 index 000000000000..7dfb8ec8ba15 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + %LANG% + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/Program.cs new file mode 100644 index 000000000000..ea0a451f4903 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/Program.cs @@ -0,0 +1,4 @@ +// See https://aka.ms/new-console-template for more information +using System; + +Console.WriteLine("Hello, World!"); diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/console.csproj new file mode 100644 index 000000000000..7dfb8ec8ba15 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/console.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + %LANG% + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/Program.cs new file mode 100644 index 000000000000..3751555cbd32 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/console.csproj new file mode 100644 index 000000000000..780397f26459 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/console.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/Program.cs new file mode 100644 index 000000000000..3751555cbd32 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/console.csproj new file mode 100644 index 000000000000..e8aab907fdf2 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/console.csproj @@ -0,0 +1,11 @@ + + + + Exe + net7.0 + %LANG% + enable + enable + + + diff --git a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs index 02b143838c38..8094bdaa6b5b 100644 --- a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs +++ b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs @@ -225,44 +225,6 @@ public async void AllCommonItemsCreate(string expectedTemplateName, string templ await engine.Execute(options).ConfigureAwait(false); } - [Fact] - public void EditorConfigTests_orig() - { - string workingDir = CreateTemporaryFolder(); - - new DotnetNewCommand(_log, "editorconfig") - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr() - .And.HaveStdOut($@"The template ""EditorConfig file"" was created successfully."); - - string path = Path.Combine(workingDir, ".editorconfig"); - string editorConfigContent = File.ReadAllText(path); - Assert.Contains("dotnet_naming_rule", editorConfigContent); - Assert.Contains("dotnet_style_", editorConfigContent); - Assert.Contains("dotnet_naming_symbols", editorConfigContent); - File.Delete(path); - - new DotnetNewCommand(_log, "editorconfig", "--empty") - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr() - .And.HaveStdOut($@"The template ""EditorConfig file"" was created successfully."); - - editorConfigContent = File.ReadAllText(path); - Assert.DoesNotContain("dotnet_naming_rule", editorConfigContent); - Assert.DoesNotContain("dotnet_style_", editorConfigContent); - Assert.DoesNotContain("dotnet_naming_symbols", editorConfigContent); - Assert.Contains("root = true", editorConfigContent); - Directory.Delete(workingDir, true); - } - [Fact] public async void EditorConfigTests_Empty() { @@ -382,7 +344,9 @@ public void NuGetConfigPermissions() string[] unsupportedLanguageVersions = { "1", "ISO-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", "latest", "latestMajor", "default", "preview" }; + string?[] nullableSupport = { null, "8.0", "9.0", "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; string?[] topLevelStatementSupport = { null, "9.0", "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; + string?[] implicitUsingsSupport = { null, "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; foreach (var template in templatesToTest) { @@ -396,7 +360,9 @@ public void NuGetConfigPermissions() false, //dotnet build should fail framework, langVersion, - topLevelStatementSupport.Contains(langVersion) + nullableSupport.Contains(langVersion), + topLevelStatementSupport.Contains(langVersion), + implicitUsingsSupport.Contains(langVersion), }; } } @@ -410,7 +376,9 @@ public void NuGetConfigPermissions() true, //dotnet build should pass framework, langVersion, - topLevelStatementSupport.Contains(langVersion) + nullableSupport.Contains(langVersion), + topLevelStatementSupport.Contains(langVersion), + implicitUsingsSupport.Contains(langVersion), }; } } @@ -420,11 +388,13 @@ public void NuGetConfigPermissions() [Theory] //creates all possible combinations for supported templates, language versions and frameworks [MemberData(nameof(TopLevelProgramSupport_Data))] - public void TopLevelProgramSupport(string name, bool buildPass, string? framework, string? langVersion, bool supportsFeature) + public async void TopLevelProgramSupport(string name, bool buildPass, string? framework, string? langVersion, bool supportsNullable, bool supportsTopLevel, bool supportsImplicitUsings) { + //features: top-level statements; nullables; implicit usings + string workingDir = CreateTemporaryFolder(folderName: $"{name}-{langVersion ?? "null"}-{framework ?? "null"}"); - List args = new() { name, "-o", "MyProject" }; + List args = new() { "-o", "MyProject" }; if (!string.IsNullOrWhiteSpace(framework)) { args.Add("--framework"); @@ -436,13 +406,26 @@ public void TopLevelProgramSupport(string name, bool buildPass, string? framewor args.Add(langVersion); } - new DotnetNewCommand(_log, args.ToArray()) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr(); + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: name) + { + TemplateSpecificArgs = args, + ExpectationsDirectory = "Approvals", + OutputDirectory = workingDir, + SettingsDirectory = _fixture.HomeDirectory, + DoNotPrependTemplateToScenarioName = true, + DoNotAppendParamsToScenarioName = true, + ScenarioDistinguisher = !buildPass ? + "OutOfSupport" : + $"Nullable-{supportsNullable}#TopLevel-{supportsTopLevel}#ImplicitUsings-{supportsImplicitUsings}" + (langVersion == null ? "#NoLang" : null), + VerificationExcludePatterns = buildPass ? null : new[] { "*" }, + } + .WithCustomScrubbers( + ScrubbersDefinition.Empty + .AddScrubber(sb => sb.Replace($"{langVersion}", "%LANG%")) + ); + + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); CommandResult buildResult = new DotnetBuildCommand(_log, "MyProject") .WithWorkingDirectory(workingDir) @@ -455,32 +438,6 @@ public void TopLevelProgramSupport(string name, bool buildPass, string? framewor else { buildResult.Should().Fail(); - return; - } - - string programFileContent = File.ReadAllText(Path.Combine(workingDir, "MyProject", "Program.cs")); - string unexpectedTopLevelContent = -@"namespace MyProject -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine(""Hello, World!""); - } - } -} -"; - if (supportsFeature) - { - Assert.Contains("Console.WriteLine(\"Hello, World!\")", programFileContent); - Assert.Contains("// See https://aka.ms/new-console-template for more information", programFileContent); - Assert.DoesNotContain(unexpectedTopLevelContent, programFileContent); - } - else - { - Assert.DoesNotContain("// See https://aka.ms/new-console-template for more information", programFileContent); - Assert.Contains(unexpectedTopLevelContent, programFileContent); } } From acabaa39e9fedaec0f40e31c24b1a3675ca1477c Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Fri, 21 Oct 2022 14:46:29 +0200 Subject: [PATCH 03/12] Covert remaining unit tests in CommonTemplatesTests --- .../MyProject/Class1.cs | 9 + .../MyProject/classlib.csproj | 8 + .../MyProject/Class1.cs | 9 + .../MyProject/classlib.csproj | 7 + .../MyProject/Class1.cs | 9 + .../MyProject/classlib.csproj | 9 + .../MyProject/Class1.cs | 9 + .../MyProject/classlib.csproj | 8 + .../MyProject/Class1.cs | 9 + .../MyProject/classlib.csproj | 9 + .../MyProject/Class1.cs | 7 + .../MyProject/classlib.csproj | 9 + .../MyProject/Class1.cs | 5 + .../MyProject/classlib.csproj | 9 + .../MyProject/Class1.cs | 5 + .../MyProject/classlib.csproj | 10 + .../MyProject/Program.cs | 12 + .../MyProject/console.csproj | 9 + .../MyProject/Program.cs | 12 + .../MyProject/console.csproj | 10 + .../MyProject/Program.cs | 4 + .../MyProject/console.csproj | 10 + .../MyProject/Program.cs | 2 + .../MyProject/console.csproj | 10 + .../MyProject/Program.cs | 2 + .../MyProject/console.csproj | 11 + .../MyProject/Program.cs | 8 + .../MyProject/console.csproj | 10 + .../MyProject/Program.cs | 8 + .../MyProject/console.csproj | 11 + .../MyProject/Program.cs | 12 + .../MyProject/console.csproj | 10 + .../dotnet-new.Tests/CommonTemplatesTests.cs | 623 +++++------------- .../DotnetNewInstantiateTests.Approval.cs | 3 +- 34 files changed, 446 insertions(+), 452 deletions(-) create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/Class1.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/classlib.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/Class1.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/classlib.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-True.verified/MyProject/Class1.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-True.verified/MyProject/classlib.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/Class1.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/classlib.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/Class1.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/classlib.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/console.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/console.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console.#NoLang.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console.#NoLang.verified/MyProject/console.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console._.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console._.verified/MyProject/console.csproj create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespaces._.verified/MyProject/Program.cs create mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespaces._.verified/MyProject/console.csproj diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs new file mode 100644 index 000000000000..fc1265d5a13d --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs @@ -0,0 +1,9 @@ +using System; + +namespace classlib +{ + public class Class1 + { + + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj new file mode 100644 index 000000000000..39b7bff66866 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj @@ -0,0 +1,8 @@ + + + + %FRAMEWORK% + %LANG% + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/Class1.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/Class1.cs new file mode 100644 index 000000000000..fc1265d5a13d --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/Class1.cs @@ -0,0 +1,9 @@ +using System; + +namespace classlib +{ + public class Class1 + { + + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/classlib.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/classlib.csproj new file mode 100644 index 000000000000..072df2dcfb54 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-False#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/classlib.csproj @@ -0,0 +1,7 @@ + + + + %FRAMEWORK% + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs new file mode 100644 index 000000000000..fc1265d5a13d --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs @@ -0,0 +1,9 @@ +using System; + +namespace classlib +{ + public class Class1 + { + + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj new file mode 100644 index 000000000000..a968f1b07101 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj @@ -0,0 +1,9 @@ + + + + %FRAMEWORK% + %LANG% + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/Class1.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/Class1.cs new file mode 100644 index 000000000000..fc1265d5a13d --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/Class1.cs @@ -0,0 +1,9 @@ +using System; + +namespace classlib +{ + public class Class1 + { + + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/classlib.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/classlib.csproj new file mode 100644 index 000000000000..089bd557c90e --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False#NoLang.verified/MyProject/classlib.csproj @@ -0,0 +1,8 @@ + + + + %FRAMEWORK% + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs new file mode 100644 index 000000000000..fc1265d5a13d --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Class1.cs @@ -0,0 +1,9 @@ +using System; + +namespace classlib +{ + public class Class1 + { + + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj new file mode 100644 index 000000000000..a968f1b07101 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/classlib.csproj @@ -0,0 +1,9 @@ + + + + %FRAMEWORK% + %LANG% + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-True.verified/MyProject/Class1.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-True.verified/MyProject/Class1.cs new file mode 100644 index 000000000000..ae5e51c9ff8d --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-True.verified/MyProject/Class1.cs @@ -0,0 +1,7 @@ +using System; + +namespace classlib; +public class Class1 +{ + +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-True.verified/MyProject/classlib.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-True.verified/MyProject/classlib.csproj new file mode 100644 index 000000000000..a968f1b07101 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-True.verified/MyProject/classlib.csproj @@ -0,0 +1,9 @@ + + + + %FRAMEWORK% + %LANG% + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/Class1.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/Class1.cs new file mode 100644 index 000000000000..b080d4b67534 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/Class1.cs @@ -0,0 +1,5 @@ +namespace classlib; +public class Class1 +{ + +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/classlib.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/classlib.csproj new file mode 100644 index 000000000000..9ec0fc5f2334 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/classlib.csproj @@ -0,0 +1,9 @@ + + + + %FRAMEWORK% + enable + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/Class1.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/Class1.cs new file mode 100644 index 000000000000..b080d4b67534 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/Class1.cs @@ -0,0 +1,5 @@ +namespace classlib; +public class Class1 +{ + +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/classlib.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/classlib.csproj new file mode 100644 index 000000000000..8af04e6e81c3 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.classlib.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/classlib.csproj @@ -0,0 +1,10 @@ + + + + %FRAMEWORK% + %LANG% + enable + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs new file mode 100644 index 000000000000..eb556c611f8f --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace console +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj new file mode 100644 index 000000000000..77de492bfc70 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-False#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj @@ -0,0 +1,9 @@ + + + + Exe + %FRAMEWORK% + %LANG% + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs new file mode 100644 index 000000000000..eb556c611f8f --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace console +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj new file mode 100644 index 000000000000..2f468dfa8531 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-False#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj @@ -0,0 +1,10 @@ + + + + Exe + %FRAMEWORK% + %LANG% + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs new file mode 100644 index 000000000000..ea0a451f4903 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/Program.cs @@ -0,0 +1,4 @@ +// See https://aka.ms/new-console-template for more information +using System; + +Console.WriteLine("Hello, World!"); diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj new file mode 100644 index 000000000000..2f468dfa8531 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-False#FileScopedNs-False.verified/MyProject/console.csproj @@ -0,0 +1,10 @@ + + + + Exe + %FRAMEWORK% + %LANG% + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/Program.cs new file mode 100644 index 000000000000..3751555cbd32 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/console.csproj new file mode 100644 index 000000000000..2259bce51317 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True#NoLang.verified/MyProject/console.csproj @@ -0,0 +1,10 @@ + + + + Exe + %FRAMEWORK% + enable + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/Program.cs new file mode 100644 index 000000000000..3751555cbd32 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/console.csproj new file mode 100644 index 000000000000..63f76841e653 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/FeaturesSupport.console.Nullable-True#TopLevel-True#ImplicitUsings-True#FileScopedNs-True.verified/MyProject/console.csproj @@ -0,0 +1,11 @@ + + + + Exe + %FRAMEWORK% + %LANG% + enable + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console.#NoLang.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console.#NoLang.verified/MyProject/Program.cs new file mode 100644 index 000000000000..32235d003676 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console.#NoLang.verified/MyProject/Program.cs @@ -0,0 +1,8 @@ +namespace console; +class Program +{ + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console.#NoLang.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console.#NoLang.verified/MyProject/console.csproj new file mode 100644 index 000000000000..780397f26459 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console.#NoLang.verified/MyProject/console.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console._.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console._.verified/MyProject/Program.cs new file mode 100644 index 000000000000..32235d003676 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console._.verified/MyProject/Program.cs @@ -0,0 +1,8 @@ +namespace console; +class Program +{ + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console._.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console._.verified/MyProject/console.csproj new file mode 100644 index 000000000000..e8aab907fdf2 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled.console._.verified/MyProject/console.csproj @@ -0,0 +1,11 @@ + + + + Exe + net7.0 + %LANG% + enable + enable + + + diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespaces._.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespaces._.verified/MyProject/Program.cs new file mode 100644 index 000000000000..eb556c611f8f --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespaces._.verified/MyProject/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace console +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespaces._.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespaces._.verified/MyProject/console.csproj new file mode 100644 index 000000000000..7dfb8ec8ba15 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespaces._.verified/MyProject/console.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + %LANG% + enable + + + diff --git a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs index 8094bdaa6b5b..c7a719a22542 100644 --- a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs +++ b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs @@ -218,7 +218,13 @@ public async void AllCommonItemsCreate(string expectedTemplateName, string templ } .WithCustomScrubbers( ScrubbersDefinition.Empty - .AddScrubber(sb => sb.Replace(expectedTemplateName, "%TEMPLATE_NAME%")) + .AddScrubber((path, content) => + { + if (path.Replace(Path.DirectorySeparatorChar, '/') == "std-streams/stdout.txt") + { + content.Replace(expectedTemplateName, "%TEMPLATE_NAME%"); + } + }) ); VerificationEngine engine = new VerificationEngine(_logger); @@ -331,213 +337,86 @@ public void NuGetConfigPermissions() #region Project templates language features tests - /// - /// Creates all possible combinations for supported templates, language versions and frameworks. - /// - public static IEnumerable TopLevelProgramSupport_Data() - { - var templatesToTest = new[] - { - new { Name = "console", Frameworks = new[] { null, "net7.0" } } - }; - - string[] unsupportedLanguageVersions = { "1", "ISO-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", "latest", "latestMajor", "default", "preview" }; - - string?[] nullableSupport = { null, "8.0", "9.0", "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; - string?[] topLevelStatementSupport = { null, "9.0", "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; - string?[] implicitUsingsSupport = { null, "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; - - foreach (var template in templatesToTest) - { - foreach (string langVersion in unsupportedLanguageVersions) - { - foreach (string? framework in template.Frameworks) - { - yield return new object?[] - { - template.Name, - false, //dotnet build should fail - framework, - langVersion, - nullableSupport.Contains(langVersion), - topLevelStatementSupport.Contains(langVersion), - implicitUsingsSupport.Contains(langVersion), - }; - } - } - foreach (string? langVersion in supportedLanguageVersions) - { - foreach (string? framework in template.Frameworks) - { - yield return new object?[] - { - template.Name, - true, //dotnet build should pass - framework, - langVersion, - nullableSupport.Contains(langVersion), - topLevelStatementSupport.Contains(langVersion), - implicitUsingsSupport.Contains(langVersion), - }; - } - } - } - } - [Theory] - //creates all possible combinations for supported templates, language versions and frameworks - [MemberData(nameof(TopLevelProgramSupport_Data))] - public async void TopLevelProgramSupport(string name, bool buildPass, string? framework, string? langVersion, bool supportsNullable, bool supportsTopLevel, bool supportsImplicitUsings) + [InlineData("11.0")] + [InlineData("11")] + [InlineData("10.0")] + [InlineData("10")] + [InlineData("preview")] + [InlineData("latest")] + [InlineData("default")] + [InlineData("latestMajor")] + [InlineData(null)] + public async void TopLevelProgramSupport_WhenFlagIsEnabled(string? langVersion) { - //features: top-level statements; nullables; implicit usings - - string workingDir = CreateTemporaryFolder(folderName: $"{name}-{langVersion ?? "null"}-{framework ?? "null"}"); + string workingDir = CreateTemporaryFolder(folderName: $"{langVersion ?? "null"}"); - List args = new() { "-o", "MyProject" }; - if (!string.IsNullOrWhiteSpace(framework)) - { - args.Add("--framework"); - args.Add(framework); - } - if (!string.IsNullOrWhiteSpace(langVersion)) + List args = new() { "-o", "MyProject", "--use-program-main" }; + if (!string.IsNullOrEmpty(langVersion)) { args.Add("--langVersion"); args.Add(langVersion); } - TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: name) + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: "console") { TemplateSpecificArgs = args, ExpectationsDirectory = "Approvals", OutputDirectory = workingDir, SettingsDirectory = _fixture.HomeDirectory, - DoNotPrependTemplateToScenarioName = true, + // DoNotPrependTemplateToScenarioName = true, DoNotAppendParamsToScenarioName = true, - ScenarioDistinguisher = !buildPass ? - "OutOfSupport" : - $"Nullable-{supportsNullable}#TopLevel-{supportsTopLevel}#ImplicitUsings-{supportsImplicitUsings}" + (langVersion == null ? "#NoLang" : null), - VerificationExcludePatterns = buildPass ? null : new[] { "*" }, + ScenarioDistinguisher = langVersion == null ? "#NoLang" : null, } .WithCustomScrubbers( ScrubbersDefinition.Empty - .AddScrubber(sb => sb.Replace($"{langVersion}", "%LANG%")) + .AddScrubber(sb => sb.Replace($"{langVersion}", "%LANG%"), "csproj") ); VerificationEngine engine = new VerificationEngine(_logger); await engine.Execute(options).ConfigureAwait(false); - CommandResult buildResult = new DotnetBuildCommand(_log, "MyProject") - .WithWorkingDirectory(workingDir) - .Execute(); - - if (buildPass) - { - buildResult.Should().ExitWith(0).And.NotHaveStdErr(); - } - else - { - buildResult.Should().Fail(); - } - } - - [Theory] - [InlineData("11.0")] - [InlineData("11")] - [InlineData("10.0")] - [InlineData("10")] - [InlineData("preview")] - [InlineData("latest")] - [InlineData("default")] - [InlineData("latestMajor")] - [InlineData(null)] - public void TopLevelProgramSupport_WhenFlagIsEnabled(string? langVersion) - { - string workingDir = CreateTemporaryFolder(folderName: $"{langVersion ?? "null"}"); - - List args = new() { "console", "-o", "MyProject", "--use-program-main" }; - if (!string.IsNullOrEmpty(langVersion)) - { - args.Add("--langVersion"); - args.Add(langVersion); - } - - new DotnetNewCommand(_log, args.ToArray()) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr(); - new DotnetBuildCommand(_log, "MyProject") .WithWorkingDirectory(workingDir) .Execute() .Should().ExitWith(0).And.NotHaveStdErr(); - - string programFileContent = File.ReadAllText(Path.Combine(workingDir, "MyProject", "Program.cs")); - string expectedTopLevelContent = -@"namespace MyProject; -class Program -{ - static void Main(string[] args) - { - Console.WriteLine(""Hello, World!""); - } -} -"; - Assert.DoesNotContain("// See https://aka.ms/new-console-template for more information", programFileContent); - Assert.Contains(expectedTopLevelContent, programFileContent); + Directory.Delete(workingDir, true); } [Theory] [InlineData("9.0")] [InlineData("9")] - public void TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespaces(string? langVersion) + public async void TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespaces(string? langVersion) { - string workingDir = CreateTemporaryFolder(folderName: $"{langVersion ?? "null"}"); - - List args = new() { "console", "-o", "MyProject", "--use-program-main" }; + List args = new() { "-o", "MyProject", "--use-program-main" }; if (!string.IsNullOrEmpty(langVersion)) { args.Add("--langVersion"); args.Add(langVersion); } - new DotnetNewCommand(_log, args.ToArray()) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr(); - - new DotnetBuildCommand(_log, "MyProject") - .WithWorkingDirectory(workingDir) - .Execute() - .Should().ExitWith(0).And.NotHaveStdErr(); + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: "console") + { + TemplateSpecificArgs = args, + ExpectationsDirectory = "Approvals", + SettingsDirectory = _fixture.HomeDirectory, + // DoNotPrependTemplateToScenarioName = true, + DoNotAppendParamsToScenarioName = true, + DoNotPrependTemplateToScenarioName = true, + } + .WithCustomScrubbers( + ScrubbersDefinition.Empty + .AddScrubber(sb => sb.Replace($"{langVersion}", "%LANG%"), "csproj") + ); - string programFileContent = File.ReadAllText(Path.Combine(workingDir, "MyProject", "Program.cs")); - string expectedTopLevelContent = -@"namespace MyProject -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine(""Hello, World!""); - } - } -} -"; - Assert.DoesNotContain("// See https://aka.ms/new-console-template for more information", programFileContent); - Assert.Contains(expectedTopLevelContent, programFileContent); + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); } /// /// Creates all possible combinations for supported templates, language versions and frameworks. /// - public static IEnumerable NullableSupport_Data() + public static IEnumerable FeaturesSupport_Data() { var templatesToTest = new[] { @@ -545,11 +424,19 @@ static void Main(string[] args) new { Template = "classlib", Frameworks = new[] { null, "net7.0", "netstandard2.0", "netstandard2.1" } } }; + //features: top-level statements; nullables; implicit usings; filescoped namespaces + string[] unsupportedLanguageVersions = { "1", "ISO-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", "latest", "latestMajor", "default", "preview" }; - string?[] supportedInFrameworkByDefault = { null, "net7.0", "netstandard2.1" }; - string?[] supportedInLanguageVersion = { "8.0", "9.0", "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; + string?[] nullableSupportedInFrameworkByDefault = { null, "net7.0", "netstandard2.1" }; + string?[] implicitUsingsSupportedInFramework = { null, "net7.0" }; + string?[] fileScopedNamespacesSupportedFrameworkByDefault = { null, "net7.0" }; + + string?[] nullableSupportedLanguages = { "8.0", "9.0", "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; + string?[] topLevelStatementSupportedLanguages = { null, "9.0", "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; + string?[] implicitUsingsSupportedLanguages = { null, "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; + string?[] fileScopedNamespacesSupportedLanguages = { "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; foreach (var template in templatesToTest) { @@ -563,8 +450,12 @@ static void Main(string[] args) false, //dotnet build should fail framework, langVersion, - supportedInLanguageVersion.Contains(langVersion) - || langVersion == null && supportedInFrameworkByDefault.Contains(framework) + nullableSupportedLanguages.Contains(langVersion) + || langVersion == null && nullableSupportedInFrameworkByDefault.Contains(framework), + topLevelStatementSupportedLanguages.Contains(langVersion), + implicitUsingsSupportedLanguages.Contains(langVersion) && implicitUsingsSupportedInFramework.Contains(framework), + fileScopedNamespacesSupportedLanguages.Contains(langVersion) + || langVersion == null && fileScopedNamespacesSupportedFrameworkByDefault.Contains(framework), }; } } @@ -578,8 +469,12 @@ static void Main(string[] args) true, //dotnet build should pass framework, langVersion, - supportedInLanguageVersion.Contains(langVersion) - || langVersion == null && supportedInFrameworkByDefault.Contains(framework) + nullableSupportedLanguages.Contains(langVersion) + || langVersion == null && nullableSupportedInFrameworkByDefault.Contains(framework), + topLevelStatementSupportedLanguages.Contains(langVersion), + implicitUsingsSupportedLanguages.Contains(langVersion) && implicitUsingsSupportedInFramework.Contains(framework), + fileScopedNamespacesSupportedLanguages.Contains(langVersion) + || langVersion == null && fileScopedNamespacesSupportedFrameworkByDefault.Contains(framework), }; } } @@ -588,12 +483,23 @@ static void Main(string[] args) [Theory] //creates all possible combinations for supported templates, language versions and frameworks - [MemberData(nameof(NullableSupport_Data))] - public void NullableSupport(string name, bool buildPass, string? framework, string? langVersion, bool supportsFeature) + [MemberData(nameof(FeaturesSupport_Data))] + public async void FeaturesSupport( + string name, + bool buildPass, + string? framework, + string? langVersion, + bool supportsNullable, + bool supportsTopLevel, + bool supportsImplicitUsings, + bool supportsFileScopedNs) { + const string currentDefaultFramework = "net7.0"; + //string currentDefaultFramework = $"net{Environment.Version.Major}.{Environment.Version.Minor}"; + string workingDir = CreateTemporaryFolder(folderName: $"{name}-{langVersion ?? "null"}-{framework ?? "null"}"); - List args = new() { name, "-o", "MyProject" }; + List args = new() { "-o", "MyProject" }; if (!string.IsNullOrWhiteSpace(framework)) { args.Add("--framework"); @@ -605,115 +511,28 @@ public void NullableSupport(string name, bool buildPass, string? framework, stri args.Add(langVersion); } - new DotnetNewCommand(_log, args.ToArray()) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr(); - - CommandResult buildResult = new DotnetBuildCommand(_log, "MyProject") - .WithWorkingDirectory(workingDir) - .Execute(); - - if (buildPass) - { - buildResult.Should().ExitWith(0).And.NotHaveStdErr(); - } - else - { - buildResult.Should().Fail(); - return; - } - - XDocument projectXml = XDocument.Load(Path.Combine(workingDir, "MyProject", "MyProject.csproj")); - XNamespace ns = projectXml.Root?.Name.Namespace ?? throw new Exception("Unexpected project file format"); - if (supportsFeature) - { - Assert.Equal("enable", projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + "Nullable")?.Value); - } - else - { - Assert.Null(projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + "Nullable")); - } - } - - /// - /// Creates all possible combinations for supported templates, language versions and frameworks. - /// - public static IEnumerable ImplicitUsingsSupport_Data() - { - var templatesToTest = new[] - { - new { Template = "console", Frameworks = new[] { null, "net7.0" } }, - new { Template = "classlib", Frameworks = new[] { null, "net7.0", "netstandard2.0", "netstandard2.1" } } - }; - string[] unsupportedLanguageVersions = { "1", "ISO-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", "latest", "latestMajor", "default", "preview" }; - - string?[] supportedInFramework = { null, "net7.0" }; - string?[] supportedInLangVersion = { null, "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; - - foreach (var template in templatesToTest) - { - foreach (string langVersion in unsupportedLanguageVersions) - { - foreach (string? framework in template.Frameworks) - { - yield return new object?[] - { - template.Template, - false, //dotnet build should fail - framework, - langVersion, - supportedInLangVersion.Contains(langVersion) && supportedInFramework.Contains(framework) - }; - } - } - foreach (string? langVersion in supportedLanguageVersions) - { - foreach (string? framework in template.Frameworks) - { - yield return new object?[] - { - template.Template, - true, //dotnet build should pass - framework, - langVersion, - supportedInLangVersion.Contains(langVersion) && supportedInFramework.Contains(framework) - }; - } - } - } - } - - [Theory] - //creates all possible combinations for supported templates, language versions and frameworks - [MemberData(nameof(ImplicitUsingsSupport_Data))] - public void ImplicitUsingsSupport(string name, bool buildPass, string? framework, string? langVersion, bool supportsFeature) - { - string workingDir = CreateTemporaryFolder(folderName: $"{name}-{langVersion ?? "null"}-{framework ?? "null"}"); - - List args = new() { name, "-o", "MyProject" }; - if (!string.IsNullOrWhiteSpace(framework)) - { - args.Add("--framework"); - args.Add(framework); - } - if (!string.IsNullOrWhiteSpace(langVersion)) + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: name) { - args.Add("--langVersion"); - args.Add(langVersion); + TemplateSpecificArgs = args, + ExpectationsDirectory = "Approvals", + OutputDirectory = workingDir, + SettingsDirectory = _fixture.HomeDirectory, + DoNotPrependTemplateToScenarioName = false, + DoNotAppendParamsToScenarioName = true, + ScenarioDistinguisher = !buildPass ? + "OutOfSupport" : + $"Nullable-{supportsNullable}#TopLevel-{supportsTopLevel}#ImplicitUsings-{supportsImplicitUsings}#FileScopedNs-{supportsFileScopedNs}" + (langVersion == null ? "#NoLang" : null), + VerificationExcludePatterns = buildPass ? null : new[] { "*" }, } + .WithCustomScrubbers( + ScrubbersDefinition.Empty + //Todo: add extension here (once fixed in templating) + .AddScrubber(sb => sb.Replace($"{langVersion}", "%LANG%")) + .AddScrubber(sb => sb.Replace($"{framework ?? currentDefaultFramework}", "%FRAMEWORK%"), "csproj") + ); - new DotnetNewCommand(_log, args.ToArray()) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr(); + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); CommandResult buildResult = new DotnetBuildCommand(_log, "MyProject") .WithWorkingDirectory(workingDir) @@ -726,124 +545,10 @@ public void ImplicitUsingsSupport(string name, bool buildPass, string? framework else { buildResult.Should().Fail(); - return; - } - string codeFileName = name == "console" ? "Program.cs" : "Class1.cs"; - string programFileContent = File.ReadAllText(Path.Combine(workingDir, "MyProject", codeFileName)); - XDocument projectXml = XDocument.Load(Path.Combine(workingDir, "MyProject", "MyProject.csproj")); - XNamespace ns = projectXml.Root?.Name.Namespace ?? throw new Exception("Unexpected project file format"); - if (supportsFeature) - { - Assert.DoesNotContain("using System;", programFileContent); - Assert.Equal("enable", projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + "ImplicitUsings")?.Value); - } - else - { - Assert.Contains("using System;", programFileContent); - Assert.Null(projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + "ImplicitUsings")); - } - } - - public static IEnumerable FileScopedNamespacesSupport_Data() - { - var templatesToTest = new[] - { - new { Template = "classlib", Frameworks = new[] { null, "net7.0", "netstandard2.0", "netstandard2.1" } } - }; - string[] unsupportedLanguageVersions = { "1", "ISO-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", "latest", "latestMajor", "default", "preview" }; - - string?[] supportedFrameworks = { null, "net7.0" }; - string?[] fileScopedNamespacesSupportedLanguages = { "10.0", "11.0", "latest", "latestMajor", "default", "preview" }; - - foreach (var template in templatesToTest) - { - foreach (string? langVersion in unsupportedLanguageVersions) - { - foreach (string? framework in template.Frameworks) - { - yield return new object?[] { template.Template, false, framework, langVersion, fileScopedNamespacesSupportedLanguages.Contains(langVersion) || langVersion == null && supportedFrameworks.Contains(framework) }; - } - } - foreach (string? langVersion in supportedLanguageVersions) - { - foreach (string? framework in template.Frameworks) - { - yield return new object?[] { template.Template, true, framework, langVersion, fileScopedNamespacesSupportedLanguages.Contains(langVersion) || langVersion == null && supportedFrameworks.Contains(framework) }; - } - } } + Directory.Delete(workingDir, true); } - [Theory] - //creates all possible combinations for supported templates, language versions and frameworks - [MemberData(nameof(FileScopedNamespacesSupport_Data))] - public void FileScopedNamespacesSupport(string name, bool pass, string? framework, string? langVersion, bool supportsFeature) - { - string workingDir = CreateTemporaryFolder(folderName: $"{name}-{langVersion ?? "null"}-{framework ?? "null"}"); - - List args = new() { name, "-o", "MyProject" }; - if (!string.IsNullOrWhiteSpace(framework)) - { - args.Add("--framework"); - args.Add(framework); - } - if (!string.IsNullOrWhiteSpace(langVersion)) - { - args.Add("--langVersion"); - args.Add(langVersion); - } - - new DotnetNewCommand(_log, args.ToArray()) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr(); - - CommandResult buildResult = new DotnetBuildCommand(_log, "MyProject") - .WithWorkingDirectory(workingDir) - .Execute(); - - if (pass) - { - buildResult.Should().ExitWith(0).And.NotHaveStdErr(); - } - else - { - buildResult.Should().Fail(); - return; - } - string codeFileName = name == "console" ? "Program.cs" : "Class1.cs"; - string programFileContent = File.ReadAllText(Path.Combine(workingDir, "MyProject", codeFileName)); - - string supportedContent = -@"namespace MyProject; -public class Class1 -{ - -}"; - string unsupportedContent = -@"namespace MyProject -{ - public class Class1 - { - - } -}"; - - if (supportsFeature) - { - Assert.DoesNotContain(unsupportedContent, programFileContent); - Assert.Contains(supportedContent, programFileContent); - } - else - { - Assert.DoesNotContain(supportedContent, programFileContent); - Assert.Contains(unsupportedContent, programFileContent); - } - } #endregion [Theory] @@ -885,10 +590,9 @@ public class Class1 [InlineData("TargetFramework", "net7.0", "Class Library", "classlib", "VB", null)] [InlineData("Nullable", null, "Class Library", "classlib", "VB", "netstandard2.0")] - public void SetPropertiesByDefault(string propertyName, string? propertyValue, string expectedTemplateName, string templateShortName, string? language, string? framework) + public async void SetPropertiesByDefault(string propertyName, string? propertyValue, string expectedTemplateName, string templateShortName, string? language, string? framework) { - string workingDir = CreateTemporaryFolder(folderName: $"{propertyName}-{templateShortName}-{templateShortName.Replace("#", "Sharp") ?? "null"}-{framework ?? "null"}"); - List args = new() { templateShortName, "--no-restore" }; + List args = new() { "--no-restore" }; if (!string.IsNullOrWhiteSpace(language)) { args.Add("--language"); @@ -900,34 +604,44 @@ public void SetPropertiesByDefault(string propertyName, string? propertyValue, s args.Add(framework); } - new DotnetNewCommand(_log, args.ToArray()) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr() - .And.HaveStdOut($@"The template ""{expectedTemplateName}"" was created successfully."); - - string expectedExtension = language switch - { - "C#" => "*.csproj", - "F#" => "*.fsproj", - "VB" => "*.vbproj", - _ => "*.csproj" - }; - string projectFile = Directory.GetFiles(workingDir, expectedExtension).Single(); - XDocument projectXml = XDocument.Load(projectFile); - XNamespace ns = projectXml.Root?.Name.Namespace ?? throw new Exception("Unexpected project file format"); - if (propertyValue != null) + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName) { - Assert.Equal(propertyValue, projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + propertyName)?.Value); + TemplateSpecificArgs = args, + SettingsDirectory = _fixture.HomeDirectory, + VerifyCommandOutput = true, + VerificationIncludePatterns = new[] { "**/*.*proj", "std-streams/stdout.txt", "**\\*.*proj", "std-streams\\stdout.txt" } } - else + .WithCustomDirectoryVerifier(async (directory, fetcher) => { - Assert.Null(projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + propertyName)); - } - Directory.Delete(workingDir, true); + int filesNum = 0; + await foreach (var (filePath, scrubbedContent) in fetcher.Value) + { + filesNum++; + if (filePath.EndsWith("stdout.txt", StringComparison.Ordinal)) + { + scrubbedContent.Should().BeEquivalentTo($@"The template ""{expectedTemplateName}"" was created successfully."); + } + + if (filePath.EndsWith("proj", StringComparison.OrdinalIgnoreCase)) + { + XDocument projectXml = XDocument.Parse(scrubbedContent); + XNamespace ns = projectXml.Root?.Name.Namespace ?? throw new Exception("Unexpected project file format"); + if (propertyValue != null) + { + Assert.Equal(propertyValue, projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + propertyName)?.Value); + } + else + { + Assert.Null(projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + propertyName)); + } + } + } + + filesNum.Should().Be(2); + }); + + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); } [Theory] @@ -951,10 +665,9 @@ public void SetPropertiesByDefault(string propertyName, string? propertyValue, s [InlineData("TargetFramework", "net5.0", "-f", "net5.0", "Class library", "classlib", null, null)] [InlineData("TargetFramework", "net5.0", "-f", "net5.0", "Class library", "classlib", "VB", null)] [InlineData("TargetFramework", "net5.0", "-f", "net5.0", "Class library", "classlib", "F#", null)] - public void CanSetProperty(string propertyName, string? propertyValue, string argName, string argValue, string expectedTemplateName, string templateShortName, string? language, string? framework) + public async void CanSetProperty(string propertyName, string? propertyValue, string argName, string argValue, string expectedTemplateName, string templateShortName, string? language, string? framework) { - string workingDir = CreateTemporaryFolder(folderName: $"{propertyName}-{templateShortName}-{templateShortName.Replace("#", "Sharp") ?? "null"}-{framework ?? "null"}"); - List args = new() { templateShortName, "--no-restore" }; + List args = new() { "--no-restore" }; if (!string.IsNullOrWhiteSpace(language)) { args.Add("--language"); @@ -971,34 +684,44 @@ public void CanSetProperty(string propertyName, string? propertyValue, string ar args.Add(argValue); } - new DotnetNewCommand(_log, args.ToArray()) - .WithCustomHive(_fixture.HomeDirectory) - .WithWorkingDirectory(workingDir) - .Execute() - .Should() - .ExitWith(0) - .And.NotHaveStdErr() - .And.HaveStdOut($@"The template ""{expectedTemplateName}"" was created successfully."); - - string expectedExtension = language switch - { - "C#" => "*.csproj", - "F#" => "*.fsproj", - "VB" => "*.vbproj", - _ => "*.csproj" - }; - string projectFile = Directory.GetFiles(workingDir, expectedExtension).Single(); - XDocument projectXml = XDocument.Load(projectFile); - XNamespace ns = projectXml.Root?.Name.Namespace ?? throw new Exception("Unexpected project file format"); - if (propertyValue != null) + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName) { - Assert.Equal(propertyValue, projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + propertyName)?.Value); + TemplateSpecificArgs = args, + SettingsDirectory = _fixture.HomeDirectory, + VerifyCommandOutput = true, + VerificationIncludePatterns = new[] { "**/*.*proj", "std-streams/stdout.txt", "**\\*.*proj", "std-streams\\stdout.txt" } } - else + .WithCustomDirectoryVerifier(async (directory, fetcher) => { - Assert.Null(projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + propertyName)); - } - Directory.Delete(workingDir, true); + int filesNum = 0; + await foreach (var (filePath, scrubbedContent) in fetcher.Value) + { + filesNum++; + if (filePath.EndsWith("stdout.txt", StringComparison.Ordinal)) + { + scrubbedContent.Should().BeEquivalentTo($@"The template ""{expectedTemplateName}"" was created successfully."); + } + + if (filePath.EndsWith("proj", StringComparison.OrdinalIgnoreCase)) + { + XDocument projectXml = XDocument.Parse(scrubbedContent); + XNamespace ns = projectXml.Root?.Name.Namespace ?? throw new Exception("Unexpected project file format"); + if (propertyValue != null) + { + Assert.Equal(propertyValue, projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + propertyName)?.Value); + } + else + { + Assert.Null(projectXml.Root?.Element(ns + "PropertyGroup")?.Element(ns + propertyName)); + } + } + } + + filesNum.Should().Be(2); + }); + + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); } } } diff --git a/src/Tests/dotnet-new.Tests/DotnetNewInstantiateTests.Approval.cs b/src/Tests/dotnet-new.Tests/DotnetNewInstantiateTests.Approval.cs index 1f55354da757..34d40da21e88 100644 --- a/src/Tests/dotnet-new.Tests/DotnetNewInstantiateTests.Approval.cs +++ b/src/Tests/dotnet-new.Tests/DotnetNewInstantiateTests.Approval.cs @@ -362,11 +362,10 @@ public Task CanInstantiateTemplate_ConditionalProcessing() string[] actualFiles = Directory.GetFiles(workingDirectory); return Task.WhenAll( - actualFiles.Select( + actualFiles.Where(f => Path.GetExtension(f).Equals(".txt")).Select( async (file) => await VerifyFile(file) .UseMethodName($"CanInstantiateTemplate_ConditionalProcessing_{Path.GetFileName(file)}") - .UseExtension("txt") )); } From 77e5fde63f0f7f9e4b1d256b331d71f349b65907 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Fri, 21 Oct 2022 14:48:42 +0200 Subject: [PATCH 04/12] Udpate dotnet-new.IntegrationTests.csproj to use internal feed package --- .../dotnet-new.Tests/dotnet-new.IntegrationTests.csproj | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj b/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj index dca0aee2aee1..a75adff775e5 100644 --- a/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj +++ b/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj @@ -10,23 +10,16 @@ true - - - + - - From d3606772dc94942bc6ff402e3389cbccf2c0a592 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Fri, 21 Oct 2022 16:57:06 +0200 Subject: [PATCH 05/12] Fix version mismatches --- eng/Versions.props | 2 +- .../MyProject/Program.cs | 12 -------- .../MyProject/console.csproj | 9 ------ .../MyProject/Program.cs | 12 -------- .../MyProject/console.csproj | 10 ------- .../MyProject/Program.cs | 4 --- .../MyProject/console.csproj | 10 ------- .../MyProject/Program.cs | 2 -- .../MyProject/console.csproj | 10 ------- .../MyProject/Program.cs | 2 -- .../MyProject/console.csproj | 11 ------- .../dotnet-new.Tests/CommonTemplatesTests.cs | 30 +++++++++---------- 12 files changed, 16 insertions(+), 98 deletions(-) delete mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs delete mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj delete mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs delete mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj delete mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/Program.cs delete mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/console.csproj delete mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/Program.cs delete mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/console.csproj delete mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/Program.cs delete mode 100644 src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/console.csproj diff --git a/eng/Versions.props b/eng/Versions.props index 0b5ea2e9c763..b4c180b8c759 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -133,7 +133,7 @@ $(MicrosoftTemplateEngineAbstractionsPackageVersion) $(MicrosoftTemplateEngineAbstractionsPackageVersion) - $(MicrosoftTemplateEngineAbstractionsPackageVersion) + $(MicrosoftTemplateEngineAbstractionsPackageVersion) diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs deleted file mode 100644 index eb556c611f8f..000000000000 --- a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace console -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("Hello, World!"); - } - } -} diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj deleted file mode 100644 index e90b46d9acdb..000000000000 --- a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-False#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - Exe - net7.0 - %LANG% - - - diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs deleted file mode 100644 index eb556c611f8f..000000000000 --- a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace console -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("Hello, World!"); - } - } -} diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj deleted file mode 100644 index 7dfb8ec8ba15..000000000000 --- a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-False#ImplicitUsings-False.verified/MyProject/console.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - Exe - net7.0 - %LANG% - enable - - - diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/Program.cs deleted file mode 100644 index ea0a451f4903..000000000000 --- a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/Program.cs +++ /dev/null @@ -1,4 +0,0 @@ -// See https://aka.ms/new-console-template for more information -using System; - -Console.WriteLine("Hello, World!"); diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/console.csproj deleted file mode 100644 index 7dfb8ec8ba15..000000000000 --- a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-False.verified/MyProject/console.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - Exe - net7.0 - %LANG% - enable - - - diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/Program.cs deleted file mode 100644 index 3751555cbd32..000000000000 --- a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/Program.cs +++ /dev/null @@ -1,2 +0,0 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/console.csproj deleted file mode 100644 index 780397f26459..000000000000 --- a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True#NoLang.verified/MyProject/console.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - Exe - net7.0 - enable - enable - - - diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/Program.cs b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/Program.cs deleted file mode 100644 index 3751555cbd32..000000000000 --- a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/Program.cs +++ /dev/null @@ -1,2 +0,0 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); diff --git a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/console.csproj b/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/console.csproj deleted file mode 100644 index e8aab907fdf2..000000000000 --- a/src/Tests/dotnet-new.Tests/Approvals/TopLevelProgramSupport.Nullable-True#TopLevel-True#ImplicitUsings-True.verified/MyProject/console.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - Exe - net7.0 - %LANG% - enable - enable - - - diff --git a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs index 888911fb9252..ee6e9e044606 100644 --- a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs +++ b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs @@ -92,8 +92,8 @@ public async void AllCommonProjectsCreateRestoreAndBuild(string expectedTemplate VerifyCommandOutput = true, VerificationExcludePatterns = new[] { "*.cs", "*.fs", "*.vb", "*.*proj" }, DoNotPrependCallerMethodNameToScenarioName = false, - DoNotAppendParamsToScenarioName = true, - DoNotPrependTemplateToScenarioName = true, + DoNotAppendTemplateArgsToScenarioName = true, + DoNotPrependTemplateNameToScenarioName = true, } .WithCustomScrubbers( ScrubbersDefinition.Empty @@ -184,9 +184,9 @@ public async void AllCommonProjectsCreate_NoRestore(string expectedTemplateName, ExpectationsDirectory = "Approvals", VerifyCommandOutput = true, VerificationIncludePatterns = new[] { "*.txt" }, - DoNotAppendParamsToScenarioName = true, + DoNotAppendTemplateArgsToScenarioName = true, SettingsDirectory = _fixture.HomeDirectory, - DoNotPrependTemplateToScenarioName = true, + DoNotPrependTemplateNameToScenarioName = true, } .WithCustomScrubbers( ScrubbersDefinition.Empty @@ -212,9 +212,9 @@ public async void AllCommonItemsCreate(string expectedTemplateName, string templ ExpectationsDirectory = "Approvals", VerifyCommandOutput = true, VerificationIncludePatterns = new[] { "*.txt" }, - DoNotAppendParamsToScenarioName = true, + DoNotAppendTemplateArgsToScenarioName = true, SettingsDirectory = _fixture.HomeDirectory, - DoNotPrependTemplateToScenarioName = true, + DoNotPrependTemplateNameToScenarioName = true, } .WithCustomScrubbers( ScrubbersDefinition.Empty @@ -364,9 +364,9 @@ public async void TopLevelProgramSupport_WhenFlagIsEnabled(string? langVersion) ExpectationsDirectory = "Approvals", OutputDirectory = workingDir, SettingsDirectory = _fixture.HomeDirectory, - // DoNotPrependTemplateToScenarioName = true, - DoNotAppendParamsToScenarioName = true, - ScenarioDistinguisher = langVersion == null ? "#NoLang" : null, + // DoNotPrependTemplateNameToScenarioName = true, + DoNotAppendTemplateArgsToScenarioName = true, + ScenarioName = langVersion == null ? "#NoLang" : null, } .WithCustomScrubbers( ScrubbersDefinition.Empty @@ -400,9 +400,9 @@ public async void TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespace TemplateSpecificArgs = args, ExpectationsDirectory = "Approvals", SettingsDirectory = _fixture.HomeDirectory, - // DoNotPrependTemplateToScenarioName = true, - DoNotAppendParamsToScenarioName = true, - DoNotPrependTemplateToScenarioName = true, + // DoNotPrependTemplateNameToScenarioName = true, + DoNotAppendTemplateArgsToScenarioName = true, + DoNotPrependTemplateNameToScenarioName = true, } .WithCustomScrubbers( ScrubbersDefinition.Empty @@ -519,9 +519,9 @@ public async void FeaturesSupport( ExpectationsDirectory = "Approvals", OutputDirectory = workingDir, SettingsDirectory = _fixture.HomeDirectory, - DoNotPrependTemplateToScenarioName = false, - DoNotAppendParamsToScenarioName = true, - ScenarioDistinguisher = !buildPass ? + DoNotPrependTemplateNameToScenarioName = false, + DoNotAppendTemplateArgsToScenarioName = true, + ScenarioName = !buildPass ? "OutOfSupport" : $"Nullable-{supportsNullable}#TopLevel-{supportsTopLevel}#ImplicitUsings-{supportsImplicitUsings}#FileScopedNs-{supportsFileScopedNs}" + (langVersion == null ? "#NoLang" : null), VerificationExcludePatterns = buildPass ? null : new[] { "*" }, From b1ce169c4dc544347af84461b23f12ffc077a407 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Tue, 25 Oct 2022 08:19:25 +0200 Subject: [PATCH 06/12] Testing Changes --- .../dotnet-new.Tests/CommonTemplatesTests.cs | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs index ee6e9e044606..10e87f44c2f8 100644 --- a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs +++ b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs @@ -246,6 +246,71 @@ public async void EditorConfigTests_Empty() await engine.Execute(options).ConfigureAwait(false); } + [Fact] + public void EditorConfigTests_orig() + { + string workingDir = CreateTemporaryFolder(); + + new DotnetNewCommand(_log, "editorconfig") + .WithCustomHive(_fixture.HomeDirectory) + .WithWorkingDirectory(workingDir) + .Execute() + .Should() + .ExitWith(0) + .And.NotHaveStdErr() + .And.HaveStdOut($@"The template ""EditorConfig file"" was created successfully."); + + string path = Path.Combine(workingDir, ".editorconfig"); + string editorConfigContent = File.ReadAllText(path); + Assert.Contains("dotnet_naming_rule", editorConfigContent); + Assert.Contains("dotnet_style_", editorConfigContent); + Assert.Contains("dotnet_naming_symbols", editorConfigContent); + File.Delete(path); + + new DotnetNewCommand(_log, "editorconfig", "--empty") + .WithCustomHive(_fixture.HomeDirectory) + .WithWorkingDirectory(workingDir) + .Execute() + .Should() + .ExitWith(0) + .And.NotHaveStdErr() + .And.HaveStdOut($@"The template ""EditorConfig file"" was created successfully."); + + editorConfigContent = File.ReadAllText(path); + Assert.DoesNotContain("dotnet_naming_rule", editorConfigContent); + Assert.DoesNotContain("dotnet_style_", editorConfigContent); + Assert.DoesNotContain("dotnet_naming_symbols", editorConfigContent); + Assert.Contains("root = true", editorConfigContent); + Directory.Delete(workingDir, true); + + Assert.Fail("Fail to get logs"); + } + + [Fact] + public void EditorConfigTests() + { + string workingDir = CreateTemporaryFolder(); + string path = Path.Combine(workingDir, ".editorconfig"); + + new DotnetNewCommand(_log, "editorconfig", "--empty") + .WithCustomHive(_fixture.HomeDirectory) + .WithWorkingDirectory(workingDir) + .Execute() + .Should() + .ExitWith(0) + .And.NotHaveStdErr() + .And.HaveStdOut($@"The template ""EditorConfig file"" was created successfully."); + + string editorConfigContent = File.ReadAllText(path); + Assert.DoesNotContain("dotnet_naming_rule", editorConfigContent); + Assert.DoesNotContain("dotnet_style_", editorConfigContent); + Assert.DoesNotContain("dotnet_naming_symbols", editorConfigContent); + Assert.Contains("root = true", editorConfigContent); + Directory.Delete(workingDir, true); + + Assert.Fail("Fail to get logs"); + } + [Fact] public async void EditorConfigTests_Default() { @@ -413,6 +478,52 @@ public async void TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespace await engine.Execute(options).ConfigureAwait(false); } + [Theory] + [InlineData("9.0")] + [InlineData("9")] + public void TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespaces_orig(string? langVersion) + { + string workingDir = CreateTemporaryFolder(folderName: $"{langVersion ?? "null"}"); + + List args = new() { "console", "-o", "MyProject", "--use-program-main" }; + if (!string.IsNullOrEmpty(langVersion)) + { + args.Add("--langVersion"); + args.Add(langVersion); + } + + new DotnetNewCommand(_log, args.ToArray()) + .WithCustomHive(_fixture.HomeDirectory) + .WithWorkingDirectory(workingDir) + .Execute() + .Should() + .ExitWith(0) + .And.NotHaveStdErr(); + + new DotnetBuildCommand(_log, "MyProject") + .WithWorkingDirectory(workingDir) + .Execute() + .Should().ExitWith(0).And.NotHaveStdErr(); + + string programFileContent = File.ReadAllText(Path.Combine(workingDir, "MyProject", "Program.cs")); + string expectedTopLevelContent = + @"namespace MyProject +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine(""Hello, World!""); + } + } +} +"; + Assert.DoesNotContain("// See https://aka.ms/new-console-template for more information", programFileContent); + Assert.Contains(expectedTopLevelContent, programFileContent); + + Assert.Fail("Fail to get logs"); + } + /// /// Creates all possible combinations for supported templates, language versions and frameworks. /// From cd7b6bb6cf1cd4dc8565eb5baa6137e862e31451 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Tue, 25 Oct 2022 13:04:53 +0200 Subject: [PATCH 07/12] Adjust the build inclusion of Approval files --- src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj b/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj index a75adff775e5..2e6075e99c70 100644 --- a/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj +++ b/src/Tests/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj @@ -70,7 +70,6 @@ namespace Microsoft.DotNet.Cli.New.IntegrationTests - From 6d647375d3e30dec5e9f6eb2ee544e675fe708e2 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Tue, 25 Oct 2022 21:12:25 +0200 Subject: [PATCH 08/12] Another test - run dotnet without full path and env vars --- .../dotnet-new.Tests/CommonTemplatesTests.cs | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs index 10e87f44c2f8..010b599e679c 100644 --- a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs +++ b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs @@ -311,6 +311,51 @@ public void EditorConfigTests() Assert.Fail("Fail to get logs"); } + [Fact] + public void EditorConfigTests__2() + { + string workingDir = CreateTemporaryFolder(); + string path = Path.Combine(workingDir, ".editorconfig"); + + //Theory - the missing env vars or dotnet full path is the culprit + SdkCommandSpec spec = new SdkCommandSpec() + { + FileName = "dotnet", + Arguments = new[] { "new", "editorconfig", "--empty" }.ToList(), + WorkingDirectory = workingDir + }; + + var command = spec.ToCommand() + .CaptureStdOut() + .CaptureStdErr(); + + var result = ((Microsoft.DotNet.Cli.Utils.Command)command).Execute(); + + Log.WriteLine($"> {result.StartInfo.FileName} {result.StartInfo.Arguments}"); + Log.WriteLine(result.StdOut); + + if (!string.IsNullOrEmpty(result.StdErr)) + { + Log.WriteLine(""); + Log.WriteLine("StdErr:"); + Log.WriteLine(result.StdErr); + } + + if (result.ExitCode != 0) + { + Log.WriteLine($"Exit Code: {result.ExitCode}"); + } + + string editorConfigContent = File.ReadAllText(path); + Assert.DoesNotContain("dotnet_naming_rule", editorConfigContent); + Assert.DoesNotContain("dotnet_style_", editorConfigContent); + Assert.DoesNotContain("dotnet_naming_symbols", editorConfigContent); + Assert.Contains("root = true", editorConfigContent); + Directory.Delete(workingDir, true); + + Assert.Fail("Fail to get logs"); + } + [Fact] public async void EditorConfigTests_Default() { @@ -524,6 +569,76 @@ static void Main(string[] args) Assert.Fail("Fail to get logs"); } + [Theory] + [InlineData("9.0")] + [InlineData("9")] + public void TopLevelProgramSupport_WhenFlagIsEnabled_2_NoFileScopedNamespaces_orig__2(string? langVersion) + { + string workingDir = CreateTemporaryFolder(folderName: $"{langVersion ?? "null"}"); + + List args = new() { "new", "console", "-o", "MyProject", "--use-program-main" }; + if (!string.IsNullOrEmpty(langVersion)) + { + args.Add("--langVersion"); + args.Add(langVersion); + } + + //Theory - the missing env vars or dotnet full path is the culprit + SdkCommandSpec spec = new SdkCommandSpec() + { + FileName = "dotnet", + Arguments = args, + WorkingDirectory = workingDir + }; + + var command = spec.ToCommand() + .CaptureStdOut() + .CaptureStdErr(); + + var result = ((Microsoft.DotNet.Cli.Utils.Command)command).Execute(); + + Log.WriteLine($"> {result.StartInfo.FileName} {result.StartInfo.Arguments}"); + Log.WriteLine(result.StdOut); + + if (!string.IsNullOrEmpty(result.StdErr)) + { + Log.WriteLine(""); + Log.WriteLine("StdErr:"); + Log.WriteLine(result.StdErr); + } + + if (result.ExitCode != 0) + { + Log.WriteLine($"Exit Code: {result.ExitCode}"); + } + + result.ExitCode.Should().Be(0, "Expected zero exit code"); + result.StdErr.Should().BeNullOrEmpty("Expected no stderr"); + + new DotnetBuildCommand(_log, "MyProject") + .WithWorkingDirectory(workingDir) + .Execute() + .Should().ExitWith(0).And.NotHaveStdErr(); + + string programFileContent = File.ReadAllText(Path.Combine(workingDir, "MyProject", "Program.cs")); + string expectedTopLevelContent = + @"namespace MyProject +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine(""Hello, World!""); + } + } +} +"; + Assert.DoesNotContain("// See https://aka.ms/new-console-template for more information", programFileContent); + Assert.Contains(expectedTopLevelContent, programFileContent); + + Assert.Fail("Fail to get logs"); + } + /// /// Creates all possible combinations for supported templates, language versions and frameworks. /// From d8f6ddcdd200192806fc5979dc717e7250257c4c Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Wed, 26 Oct 2022 00:01:23 +0200 Subject: [PATCH 09/12] Reflect API renames --- .../dotnet-new.Tests/CommonTemplatesTests.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs index 010b599e679c..706039630d94 100644 --- a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs +++ b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs @@ -87,7 +87,7 @@ public async void AllCommonProjectsCreateRestoreAndBuild(string expectedTemplate TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName) { TemplateSpecificArgs = args, - ExpectationsDirectory = "Approvals", + SnapshotsDirectory = "Approvals", OutputDirectory = workingDir, VerifyCommandOutput = true, VerificationExcludePatterns = new[] { "*.cs", "*.fs", "*.vb", "*.*proj" }, @@ -181,7 +181,7 @@ public async void AllCommonProjectsCreate_NoRestore(string expectedTemplateName, TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName) { TemplateSpecificArgs = args, - ExpectationsDirectory = "Approvals", + SnapshotsDirectory = "Approvals", VerifyCommandOutput = true, VerificationIncludePatterns = new[] { "*.txt" }, DoNotAppendTemplateArgsToScenarioName = true, @@ -209,7 +209,7 @@ public async void AllCommonItemsCreate(string expectedTemplateName, string templ { TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName) { - ExpectationsDirectory = "Approvals", + SnapshotsDirectory = "Approvals", VerifyCommandOutput = true, VerificationIncludePatterns = new[] { "*.txt" }, DoNotAppendTemplateArgsToScenarioName = true, @@ -237,7 +237,7 @@ public async void EditorConfigTests_Empty() TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: "editorconfig") { TemplateSpecificArgs = new[] { "--empty" }, - ExpectationsDirectory = "Approvals", + SnapshotsDirectory = "Approvals", SettingsDirectory = _fixture.HomeDirectory, VerifyCommandOutput = true, }; @@ -361,7 +361,7 @@ public async void EditorConfigTests_Default() { TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: "editorconfig") { - ExpectationsDirectory = "Approvals", + SnapshotsDirectory = "Approvals", SettingsDirectory = _fixture.HomeDirectory, } .WithCustomDirectoryVerifier(async (content, contentFetcher) => @@ -395,7 +395,7 @@ public async void GlobalJsonTests(params string[] parameters) TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: parameters[0]) { TemplateSpecificArgs = parameters[1..], - ExpectationsDirectory = "Approvals", + SnapshotsDirectory = "Approvals", SettingsDirectory = _fixture.HomeDirectory, VerifyCommandOutput = true, }; @@ -471,7 +471,7 @@ public async void TopLevelProgramSupport_WhenFlagIsEnabled(string? langVersion) TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: "console") { TemplateSpecificArgs = args, - ExpectationsDirectory = "Approvals", + SnapshotsDirectory = "Approvals", OutputDirectory = workingDir, SettingsDirectory = _fixture.HomeDirectory, // DoNotPrependTemplateNameToScenarioName = true, @@ -508,7 +508,7 @@ public async void TopLevelProgramSupport_WhenFlagIsEnabled_NoFileScopedNamespace TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: "console") { TemplateSpecificArgs = args, - ExpectationsDirectory = "Approvals", + SnapshotsDirectory = "Approvals", SettingsDirectory = _fixture.HomeDirectory, // DoNotPrependTemplateNameToScenarioName = true, DoNotAppendTemplateArgsToScenarioName = true, @@ -742,7 +742,7 @@ public async void FeaturesSupport( TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: name) { TemplateSpecificArgs = args, - ExpectationsDirectory = "Approvals", + SnapshotsDirectory = "Approvals", OutputDirectory = workingDir, SettingsDirectory = _fixture.HomeDirectory, DoNotPrependTemplateNameToScenarioName = false, From 0c399ad724f6c89dc9f0d38655e0001ea00ddb78 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Wed, 26 Oct 2022 09:36:47 +0200 Subject: [PATCH 10/12] Tests #3 --- .../dotnet-new.Tests/CommonTemplatesTests.cs | 189 ++++++++++++++++++ 1 file changed, 189 insertions(+) diff --git a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs index 706039630d94..b7dd9a4e1284 100644 --- a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs +++ b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs @@ -9,11 +9,13 @@ using FluentAssertions; using Microsoft.DotNet.Cli.Utils; using Microsoft.Extensions.Logging; +using Microsoft.NET.TestFramework; using Microsoft.NET.TestFramework.Assertions; using Microsoft.NET.TestFramework.Commands; using Microsoft.TemplateEngine.Authoring.TemplateVerifier; using Microsoft.TemplateEngine.TestHelper; using Xunit.Abstractions; +using SdkCommandSpec = Microsoft.NET.TestFramework.Commands.SdkCommandSpec; namespace Microsoft.DotNet.Cli.New.IntegrationTests { @@ -356,6 +358,51 @@ public void EditorConfigTests__2() Assert.Fail("Fail to get logs"); } + [Fact] + public void EditorConfigTests__3() + { + string workingDir = CreateTemporaryFolder(); + string path = Path.Combine(workingDir, "editorconfig", ".editorconfig"); + + //Theory - the missing env vars or dotnet full path is the culprit + SdkCommandSpec spec = new SdkCommandSpec() + { + FileName = "dotnet", + Arguments = new[] { "new", "editorconfig", "--empty", "-o", "editorconfig", "-n", "editorconfig" }.ToList(), + WorkingDirectory = workingDir + }; + + var command = spec.ToCommand() + .CaptureStdOut() + .CaptureStdErr(); + + var result = ((Microsoft.DotNet.Cli.Utils.Command)command).Execute(); + + Log.WriteLine($"> {result.StartInfo.FileName} {result.StartInfo.Arguments}"); + Log.WriteLine(result.StdOut); + + if (!string.IsNullOrEmpty(result.StdErr)) + { + Log.WriteLine(""); + Log.WriteLine("StdErr:"); + Log.WriteLine(result.StdErr); + } + + if (result.ExitCode != 0) + { + Log.WriteLine($"Exit Code: {result.ExitCode}"); + } + + string editorConfigContent = File.ReadAllText(path); + Assert.DoesNotContain("dotnet_naming_rule", editorConfigContent); + Assert.DoesNotContain("dotnet_style_", editorConfigContent); + Assert.DoesNotContain("dotnet_naming_symbols", editorConfigContent); + Assert.Contains("root = true", editorConfigContent); + Directory.Delete(workingDir, true); + + Assert.Fail("Fail to get logs"); + } + [Fact] public async void EditorConfigTests_Default() { @@ -639,6 +686,148 @@ static void Main(string[] args) Assert.Fail("Fail to get logs"); } + [Theory] + [InlineData("9.0")] + [InlineData("9")] + public void TopLevelProgramSupport_WhenFlagIsEnabled_3_NoFileScopedNamespaces_orig__3(string? langVersion) + { + string workingDir = CreateTemporaryFolder(folderName: $"{langVersion ?? "null"}"); + + List args = new() { "new", "console", "-o", "MyProject", "--use-program-main" }; + if (!string.IsNullOrEmpty(langVersion)) + { + args.Add("--langVersion"); + args.Add(langVersion); + } + + //Theory - the missing env vars or dotnet full path is the culprit + SdkCommandSpec spec = new SdkCommandSpec() + { + FileName = TestContext.Current.ToolsetUnderTest.DotNetHostPath, + Arguments = args, + WorkingDirectory = workingDir + }; + + var command = spec.ToCommand() + .CaptureStdOut() + .CaptureStdErr(); + + var result = ((Microsoft.DotNet.Cli.Utils.Command)command).Execute(); + + Log.WriteLine($"> {result.StartInfo.FileName} {result.StartInfo.Arguments}"); + Log.WriteLine(result.StdOut); + + if (!string.IsNullOrEmpty(result.StdErr)) + { + Log.WriteLine(""); + Log.WriteLine("StdErr:"); + Log.WriteLine(result.StdErr); + } + + if (result.ExitCode != 0) + { + Log.WriteLine($"Exit Code: {result.ExitCode}"); + } + + result.ExitCode.Should().Be(0, "Expected zero exit code"); + result.StdErr.Should().BeNullOrEmpty("Expected no stderr"); + + new DotnetBuildCommand(_log, "MyProject") + .WithWorkingDirectory(workingDir) + .Execute() + .Should().ExitWith(0).And.NotHaveStdErr(); + + string programFileContent = File.ReadAllText(Path.Combine(workingDir, "MyProject", "Program.cs")); + string expectedTopLevelContent = + @"namespace MyProject +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine(""Hello, World!""); + } + } +} +"; + Assert.DoesNotContain("// See https://aka.ms/new-console-template for more information", programFileContent); + Assert.Contains(expectedTopLevelContent, programFileContent); + + Assert.Fail("Fail to get logs"); + } + + [Theory] + [InlineData("9.0")] + [InlineData("9")] + public void TopLevelProgramSupport_WhenFlagIsEnabled_4_NoFileScopedNamespaces_orig__4(string? langVersion) + { + string workingDir = CreateTemporaryFolder(folderName: $"{langVersion ?? "null"}"); + + List args = new() { "new", "console", "-o", "MyProject", "--use-program-main" }; + if (!string.IsNullOrEmpty(langVersion)) + { + args.Add("--langVersion"); + args.Add(langVersion); + } + + //Theory - the missing env vars or dotnet full path is the culprit + SdkCommandSpec spec = new SdkCommandSpec() + { + FileName = TestContext.Current.ToolsetUnderTest.DotNetHostPath, + Arguments = args, + WorkingDirectory = workingDir + }; + + TestContext.Current.AddTestEnvironmentVariables(spec); + + var command = spec.ToCommand() + .CaptureStdOut() + .CaptureStdErr(); + + var result = ((Microsoft.DotNet.Cli.Utils.Command)command).Execute(); + + Log.WriteLine($"> {result.StartInfo.FileName} {result.StartInfo.Arguments}"); + Log.WriteLine(result.StdOut); + + if (!string.IsNullOrEmpty(result.StdErr)) + { + Log.WriteLine(""); + Log.WriteLine("StdErr:"); + Log.WriteLine(result.StdErr); + } + + if (result.ExitCode != 0) + { + Log.WriteLine($"Exit Code: {result.ExitCode}"); + } + + result.ExitCode.Should().Be(0, "Expected zero exit code"); + result.StdErr.Should().BeNullOrEmpty("Expected no stderr"); + + new DotnetBuildCommand(_log, "MyProject") + .WithWorkingDirectory(workingDir) + .Execute() + .Should().ExitWith(0).And.NotHaveStdErr(); + + string programFileContent = File.ReadAllText(Path.Combine(workingDir, "MyProject", "Program.cs")); + string expectedTopLevelContent = + @"namespace MyProject +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine(""Hello, World!""); + } + } +} +"; + Assert.DoesNotContain("// See https://aka.ms/new-console-template for more information", programFileContent); + Assert.Contains(expectedTopLevelContent, programFileContent); + + Assert.Fail("Fail to get logs"); + } + /// /// Creates all possible combinations for supported templates, language versions and frameworks. /// From 576a4e0e3a39fdac14f5258b17b63b4b9bcf4297 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Wed, 26 Oct 2022 18:07:21 +0200 Subject: [PATCH 11/12] Test #3 --- .../dotnet-new.Tests/CommonTemplatesTests.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs index b7dd9a4e1284..b67d8d247e83 100644 --- a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs +++ b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs @@ -248,6 +248,30 @@ public async void EditorConfigTests_Empty() await engine.Execute(options).ConfigureAwait(false); } + [Fact] + public async void EditorConfigTests_Empty_custom() + { + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: "editorconfig") + { + TemplateSpecificArgs = new[] { "--empty" }, + SnapshotsDirectory = "Approvals", + SettingsDirectory = _fixture.HomeDirectory, + } + .WithCustomDirectoryVerifier(async (content, contentFetcher) => + { + await foreach (var (filePath, scrubbedContent) in contentFetcher.Value) + { + filePath.Replace(Path.DirectorySeparatorChar, '/').Should().BeEquivalentTo(@"editorconfig/.editorconfig"); + scrubbedContent.Trim().Should().BeEquivalentTo("root = true"); + } + }); + + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); + + Assert.Fail("Fail to get logs - as file is obviously created"); + } + [Fact] public void EditorConfigTests_orig() { From 89c4870085d0352ff787042f0dbf5b9062204084 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Wed, 26 Oct 2022 23:58:56 +0200 Subject: [PATCH 12/12] Tests #4 --- .../editorconfig/.editorconfig | 2 + .../std-streams/stderr.txt | 1 + .../std-streams/stdout.txt | 1 + .../editorconfig/.editorconfig | 2 + .../std-streams/stderr.txt | 1 + .../std-streams/stdout.txt | 1 + .../editorconfig/.editorconfig | 2 + .../std-streams/stderr.txt | 1 + .../std-streams/stdout.txt | 1 + .../dotnet-new.Tests/CommonTemplatesTests.cs | 104 ++++++++++++++++++ 10 files changed, 116 insertions(+) create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/editorconfig/.editorconfig create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/std-streams/stderr.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/std-streams/stdout.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/editorconfig/.editorconfig create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/std-streams/stderr.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/std-streams/stdout.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/editorconfig/.editorconfig create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/std-streams/stderr.txt create mode 100644 src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/std-streams/stdout.txt diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/editorconfig/.editorconfig b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/editorconfig/.editorconfig new file mode 100644 index 000000000000..6a5db887fd68 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/editorconfig/.editorconfig @@ -0,0 +1,2 @@ +root = true + diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/std-streams/stderr.txt b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/std-streams/stderr.txt new file mode 100644 index 000000000000..5f282702bb03 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/std-streams/stderr.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/std-streams/stdout.txt b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/std-streams/stdout.txt new file mode 100644 index 000000000000..7d111cb75350 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.received/std-streams/stdout.txt @@ -0,0 +1 @@ +The template "EditorConfig file" was created successfully. \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/editorconfig/.editorconfig b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/editorconfig/.editorconfig new file mode 100644 index 000000000000..6a5db887fd68 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/editorconfig/.editorconfig @@ -0,0 +1,2 @@ +root = true + diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/std-streams/stderr.txt b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/std-streams/stderr.txt new file mode 100644 index 000000000000..5f282702bb03 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/std-streams/stderr.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/std-streams/stdout.txt b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/std-streams/stdout.txt new file mode 100644 index 000000000000..7d111cb75350 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty2.editorconfig.--empty.verified/std-streams/stdout.txt @@ -0,0 +1 @@ +The template "EditorConfig file" was created successfully. \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/editorconfig/.editorconfig b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/editorconfig/.editorconfig new file mode 100644 index 000000000000..6a5db887fd68 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/editorconfig/.editorconfig @@ -0,0 +1,2 @@ +root = true + diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/std-streams/stderr.txt b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/std-streams/stderr.txt new file mode 100644 index 000000000000..5f282702bb03 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/std-streams/stderr.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/std-streams/stdout.txt b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/std-streams/stdout.txt new file mode 100644 index 000000000000..7d111cb75350 --- /dev/null +++ b/src/Tests/dotnet-new.Tests/Approvals/EditorConfigTests_Empty_withWorkDir.editorconfig.--empty.verified/std-streams/stdout.txt @@ -0,0 +1 @@ +The template "EditorConfig file" was created successfully. \ No newline at end of file diff --git a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs index b67d8d247e83..ad24b046c05d 100644 --- a/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs +++ b/src/Tests/dotnet-new.Tests/CommonTemplatesTests.cs @@ -248,6 +248,40 @@ public async void EditorConfigTests_Empty() await engine.Execute(options).ConfigureAwait(false); } + [Fact] + public async void EditorConfigTests_Empty2() + { + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: "editorconfig") + { + TemplateSpecificArgs = new[] { "--empty" }, + SnapshotsDirectory = "Approvals", + SettingsDirectory = _fixture.HomeDirectory, + DisableDefaultVerificationExcludePatterns = true, + VerifyCommandOutput = true, + }; + + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); + } + + [Fact] + public async void EditorConfigTests_Empty_withWorkDir() + { + string workingDir = CreateTemporaryFolder(); + + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: "editorconfig") + { + TemplateSpecificArgs = new[] { "--empty" }, + SnapshotsDirectory = "Approvals", + SettingsDirectory = _fixture.HomeDirectory, + OutputDirectory = workingDir, + VerifyCommandOutput = true, + }; + + VerificationEngine engine = new VerificationEngine(_logger); + await engine.Execute(options).ConfigureAwait(false); + } + [Fact] public async void EditorConfigTests_Empty_custom() { @@ -710,6 +744,76 @@ static void Main(string[] args) Assert.Fail("Fail to get logs"); } + [Theory] + [InlineData("9.0")] + [InlineData("9")] + public void TopLevelProgramSupport_WhenFlagIsEnabled_X_NoFileScopedNamespaces_orig__X_DotnetDotnet(string? langVersion) + { + string workingDir = CreateTemporaryFolder(folderName: $"{langVersion ?? "null"}"); + + List args = new() { TestContext.Current.ToolsetUnderTest.DotNetHostPath, "new", "console", "-o", "MyProject", "--use-program-main" }; + if (!string.IsNullOrEmpty(langVersion)) + { + args.Add("--langVersion"); + args.Add(langVersion); + } + + //Theory - the missing env vars or dotnet full path is the culprit + SdkCommandSpec spec = new SdkCommandSpec() + { + FileName = "dotnet", + Arguments = args, + WorkingDirectory = workingDir + }; + + var command = spec.ToCommand() + .CaptureStdOut() + .CaptureStdErr(); + + var result = ((Microsoft.DotNet.Cli.Utils.Command)command).Execute(); + + Log.WriteLine($"> {result.StartInfo.FileName} {result.StartInfo.Arguments}"); + Log.WriteLine(result.StdOut); + + if (!string.IsNullOrEmpty(result.StdErr)) + { + Log.WriteLine(""); + Log.WriteLine("StdErr:"); + Log.WriteLine(result.StdErr); + } + + if (result.ExitCode != 0) + { + Log.WriteLine($"Exit Code: {result.ExitCode}"); + } + + result.ExitCode.Should().Be(0, "Expected zero exit code"); + result.StdErr.Should().BeNullOrEmpty("Expected no stderr"); + + new DotnetBuildCommand(_log, "MyProject") + .WithWorkingDirectory(workingDir) + .Execute() + .Should().ExitWith(0).And.NotHaveStdErr(); + + string programFileContent = File.ReadAllText(Path.Combine(workingDir, "MyProject", "Program.cs")); + string expectedTopLevelContent = + @"namespace MyProject +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine(""Hello, World!""); + } + } +} +"; + Assert.DoesNotContain("// See https://aka.ms/new-console-template for more information", programFileContent); + Assert.Contains(expectedTopLevelContent, programFileContent); + + Assert.Fail("Fail to get logs"); + } + [Theory] [InlineData("9.0")] [InlineData("9")]