Skip to content

Commit

Permalink
Change Version switch output to finish with a newline (#9485)
Browse files Browse the repository at this point in the history
* Add to change wave 17.10
* VersionSwitch test changed from Theory to Fact to remove overlap with other test
  • Loading branch information
jrdodds authored Dec 13, 2023
1 parent b2016b8 commit 1ac1bff
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
1 change: 1 addition & 0 deletions documentation/wiki/ChangeWaves.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
85 changes: 85 additions & 0 deletions src/MSBuild.UnitTests/XMake_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,91 @@ public void Help(string indicator)
.ShouldBe(MSBuildApp.ExitType.Success);
}

[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<string> 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,
},
};

process.Start();
process.WaitForExit();
process.ExitCode.ShouldBe(0);

string output = process.StandardOutput.ReadToEnd();
output.EndsWith(Environment.NewLine).ShouldBeTrue();

process.Close();
}

/// <summary>
/// PR: Change Version switch output to finish with a newline https://github.com/dotnet/msbuild/pull/9485
/// </summary>
[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<string> 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,
},
};

process.Start();
process.WaitForExit();
process.ExitCode.ShouldBe(0);

string output = process.StandardOutput.ReadToEnd();
output.EndsWith(Environment.NewLine).ShouldBeFalse();

process.Close();
}

[Fact]
public void ErrorCommandLine()
{
Expand Down
10 changes: 9 additions & 1 deletion src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4487,7 +4487,15 @@ private static void ShowHelpPrompt()
/// </summary>
private static void ShowVersion()
{
Console.Write(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());
}
}
}
}

0 comments on commit 1ac1bff

Please sign in to comment.