From 8dab7ebcb7bacb46a24892ec7a587ffae4b823e4 Mon Sep 17 00:00:00 2001 From: Jonathan Dodds Date: Fri, 1 Dec 2023 13:11:25 -0500 Subject: [PATCH 1/4] change Version output and add unit test --- src/MSBuild.UnitTests/XMake_Tests.cs | 39 ++++++++++++++++++++++++++++ src/MSBuild/XMake.cs | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index 1fafe1f5bef..dfd2d9bc7e3 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -523,6 +523,45 @@ public void Help(string indicator) .ShouldBe(MSBuildApp.ExitType.Success); } + [Theory] + [InlineData("--version")] + [InlineData("-version")] + [InlineData(@"/version")] + [InlineData("-ver")] + [InlineData(@"/ver")] + public void VersionSwitch(string cmdSwitch) + { + List cmdLine = new() + { +#if !FEATURE_RUN_EXE_IN_TESTS + EnvironmentProvider.GetDotnetExePath(), +#endif + FileUtilities.EnsureDoubleQuotes(RunnerUtilities.PathToCurrentlyRunningMsBuildExe), + "-nologo", + cmdSwitch + }; + + using Process process = new() + { + StartInfo = + { + FileName = cmdLine[0], + Arguments = string.Join(" ", cmdLine.Skip(1)), + UseShellExecute = false, + RedirectStandardOutput = true, + }, + }; + + process.Start(); + process.WaitForExit(); + process.ExitCode.ShouldBe(0); + + string output = process.StandardOutput.ReadToEnd(); + output.EndsWith(Environment.NewLine).ShouldBeTrue(); + + process.Close(); + } + [Fact] public void ErrorCommandLine() { diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index d5b98d4906b..22dde775971 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -4487,7 +4487,7 @@ private static void ShowHelpPrompt() /// private static void ShowVersion() { - Console.Write(ProjectCollection.Version.ToString()); + Console.WriteLine(ProjectCollection.Version.ToString()); } } } From ed3ac214fee7494c6519bd8f70fe76082ac49043 Mon Sep 17 00:00:00 2001 From: Jonathan Dodds Date: Fri, 1 Dec 2023 20:01:34 -0500 Subject: [PATCH 2/4] VersionSwitch test changed from Theory to Fact to remove overlap with other test --- src/MSBuild.UnitTests/XMake_Tests.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index dfd2d9bc7e3..03eda408813 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -523,13 +523,8 @@ public void Help(string indicator) .ShouldBe(MSBuildApp.ExitType.Success); } - [Theory] - [InlineData("--version")] - [InlineData("-version")] - [InlineData(@"/version")] - [InlineData("-ver")] - [InlineData(@"/ver")] - public void VersionSwitch(string cmdSwitch) + [Fact] + public void VersionSwitch() { List cmdLine = new() { @@ -538,7 +533,7 @@ public void VersionSwitch(string cmdSwitch) #endif FileUtilities.EnsureDoubleQuotes(RunnerUtilities.PathToCurrentlyRunningMsBuildExe), "-nologo", - cmdSwitch + "-version" }; using Process process = new() From 1845510a870069d8b8234352b6c21626019b4b7d Mon Sep 17 00:00:00 2001 From: Jonathan Dodds Date: Mon, 4 Dec 2023 12:57:51 -0500 Subject: [PATCH 3/4] Add to change wave 17.10 --- documentation/wiki/ChangeWaves.md | 1 + src/MSBuild.UnitTests/XMake_Tests.cs | 49 +++++++++++++++++++++++++++- src/MSBuild/XMake.cs | 10 +++++- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/documentation/wiki/ChangeWaves.md b/documentation/wiki/ChangeWaves.md index a2a867cec05..6282a09e7b1 100644 --- a/documentation/wiki/ChangeWaves.md +++ b/documentation/wiki/ChangeWaves.md @@ -28,6 +28,7 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t - [Warning on serialization custom events by default in .NET framework](https://github.com/dotnet/msbuild/pull/9318) - [Cache SDK resolver data process-wide](https://github.com/dotnet/msbuild/pull/9335) - [Target parameters will be unquoted](https://github.com/dotnet/msbuild/pull/9452), meaning the ';' symbol in the parameter target name will always be treated as separator +- [Change Version switch output to finish with a newline](https://github.com/dotnet/msbuild/pull/9485) ### 17.8 - [[RAR] Don't do I/O on SDK-provided references](https://github.com/dotnet/msbuild/pull/8688) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index 03eda408813..4bfa172a2dd 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -552,7 +552,54 @@ public void VersionSwitch() process.ExitCode.ShouldBe(0); string output = process.StandardOutput.ReadToEnd(); - output.EndsWith(Environment.NewLine).ShouldBeTrue(); + // Change Version switch output to finish with a newline https://github.com/dotnet/msbuild/pull/9485 + if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10)) + { + output.EndsWith(Environment.NewLine).ShouldBeTrue(); + } + else + { + output.EndsWith(Environment.NewLine).ShouldBeFalse(); + } + + process.Close(); + } + + /// + /// PR: Change Version switch output to finish with a newline https://github.com/dotnet/msbuild/pull/9485 + /// + [Fact] + public void VersionSwitchDisableChangeWave() + { + List cmdLine = new() + { +#if !FEATURE_RUN_EXE_IN_TESTS + EnvironmentProvider.GetDotnetExePath(), +#endif + FileUtilities.EnsureDoubleQuotes(RunnerUtilities.PathToCurrentlyRunningMsBuildExe), + "-nologo", + "-version" + }; + + using Process process = new() + { + StartInfo = + { + FileName = cmdLine[0], + Arguments = string.Join(" ", cmdLine.Skip(1)), + UseShellExecute = false, + RedirectStandardOutput = true, + }, + }; + // Disable Change Wave 17.10 + process.StartInfo.Environment.Add("MSBUILDDISABLEFEATURESFROMVERSION", ChangeWaves.Wave17_10.ToString()); + + process.Start(); + process.WaitForExit(); + process.ExitCode.ShouldBe(0); + + string output = process.StandardOutput.ReadToEnd(); + output.EndsWith(Environment.NewLine).ShouldBeFalse(); process.Close(); } diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 22dde775971..8f2970dddd1 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -4487,7 +4487,15 @@ private static void ShowHelpPrompt() /// private static void ShowVersion() { - Console.WriteLine(ProjectCollection.Version.ToString()); + // Change Version switch output to finish with a newline https://github.com/dotnet/msbuild/pull/9485 + if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10)) + { + Console.WriteLine(ProjectCollection.Version.ToString()); + } + else + { + Console.Write(ProjectCollection.Version.ToString()); + } } } } From 2a8e760f3cd7976ae92bb0712b002719c8fde954 Mon Sep 17 00:00:00 2001 From: Jonathan Dodds Date: Fri, 8 Dec 2023 07:48:38 -0500 Subject: [PATCH 4/4] change unit tests to use TestEnvironment --- src/MSBuild.UnitTests/XMake_Tests.cs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index 4bfa172a2dd..ddc95774837 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -526,6 +526,13 @@ public void Help(string indicator) [Fact] public void VersionSwitch() { + using TestEnvironment env = UnitTests.TestEnvironment.Create(); + + // Ensure Change Wave 17.10 is enabled. + ChangeWaves.ResetStateForTests(); + env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", ""); + BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); + List cmdLine = new() { #if !FEATURE_RUN_EXE_IN_TESTS @@ -552,15 +559,7 @@ public void VersionSwitch() process.ExitCode.ShouldBe(0); string output = process.StandardOutput.ReadToEnd(); - // Change Version switch output to finish with a newline https://github.com/dotnet/msbuild/pull/9485 - if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10)) - { - output.EndsWith(Environment.NewLine).ShouldBeTrue(); - } - else - { - output.EndsWith(Environment.NewLine).ShouldBeFalse(); - } + output.EndsWith(Environment.NewLine).ShouldBeTrue(); process.Close(); } @@ -571,6 +570,13 @@ public void VersionSwitch() [Fact] public void VersionSwitchDisableChangeWave() { + using TestEnvironment env = UnitTests.TestEnvironment.Create(); + + // Disable Change Wave 17.10 + ChangeWaves.ResetStateForTests(); + env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", ChangeWaves.Wave17_10.ToString()); + BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); + List cmdLine = new() { #if !FEATURE_RUN_EXE_IN_TESTS @@ -591,8 +597,6 @@ public void VersionSwitchDisableChangeWave() RedirectStandardOutput = true, }, }; - // Disable Change Wave 17.10 - process.StartInfo.Environment.Add("MSBUILDDISABLEFEATURESFROMVERSION", ChangeWaves.Wave17_10.ToString()); process.Start(); process.WaitForExit();