Skip to content

Commit

Permalink
Align the tests usage of test environment (#9682)
Browse files Browse the repository at this point in the history
* Align the tests usage of test environment (XMake_Tests)
  • Loading branch information
f-alizada committed Jan 26, 2024
1 parent 44bcbf3 commit 0d8d09e
Showing 1 changed file with 50 additions and 143 deletions.
193 changes: 50 additions & 143 deletions src/MSBuild.UnitTests/XMake_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public void Help(string indicator)
[Fact]
public void VersionSwitch()
{
using TestEnvironment env = UnitTests.TestEnvironment.Create();
using TestEnvironment env = TestEnvironment.Create();

// Ensure Change Wave 17.10 is enabled.
ChangeWaves.ResetStateForTests();
Expand Down Expand Up @@ -570,7 +570,7 @@ public void VersionSwitch()
[Fact]
public void VersionSwitchDisableChangeWave()
{
using TestEnvironment env = UnitTests.TestEnvironment.Create();
using TestEnvironment env = TestEnvironment.Create();

// Disable Change Wave 17.10
ChangeWaves.ResetStateForTests();
Expand Down Expand Up @@ -1276,33 +1276,15 @@ public void ResponseFileSwitchesAppearInCommandLine()
[Fact]
public void ResponseFileInProjectDirectoryExplicit()
{
string directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
string projectPath = Path.Combine(directory, "my.proj");
string rspPath = Path.Combine(directory, AutoResponseFileName);

try
{
Directory.CreateDirectory(directory);

string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
File.WriteAllText(projectPath, content);

string rspContent = "/p:A=1";
File.WriteAllText(rspPath, rspContent);

var msbuildParameters = "\"" + projectPath + "\"";

string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeTrue();
var directory = _env.CreateFolder();
string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
var projectPath = directory.CreateFile("my.proj", content).Path;
directory.CreateFile(AutoResponseFileName, "/p:A=1");
var msbuildParameters = "\"" + projectPath + "\"";
string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeTrue();

output.ShouldContain("[A=1]");
}
finally
{
File.Delete(projectPath);
File.Delete(rspPath);
FileUtilities.DeleteWithoutTrailingBackslash(directory);
}
output.ShouldContain("[A=1]");
}

/// <summary>
Expand All @@ -1311,33 +1293,17 @@ public void ResponseFileInProjectDirectoryExplicit()
[Fact]
public void ResponseFileInProjectDirectoryRandomName()
{
string directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
string projectPath = Path.Combine(directory, "my.proj");
string rspPath = Path.Combine(directory, "foo.rsp");

try
{
Directory.CreateDirectory(directory);

string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
File.WriteAllText(projectPath, content);

string rspContent = "/p:A=1";
File.WriteAllText(rspPath, rspContent);
var directory = _env.CreateFolder();
string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
var projectPath = directory.CreateFile("my.proj", content).Path;
directory.CreateFile("foo.rsp", "/p:A=1");

var msbuildParameters = "\"" + projectPath + "\"";
var msbuildParameters = "\"" + projectPath + "\"";

string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeTrue();
string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeTrue();

output.ShouldContain("[A=]");
}
finally
{
File.Delete(projectPath);
File.Delete(rspPath);
FileUtilities.DeleteWithoutTrailingBackslash(directory);
}
output.ShouldContain("[A=]");
}

/// <summary>
Expand All @@ -1347,33 +1313,18 @@ public void ResponseFileInProjectDirectoryRandomName()
[Fact]
public void ResponseFileInProjectDirectoryCommandLineWins()
{
string directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
string projectPath = Path.Combine(directory, "my.proj");
string rspPath = Path.Combine(directory, AutoResponseFileName);

try
{
Directory.CreateDirectory(directory);

string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
File.WriteAllText(projectPath, content);
var directory = _env.CreateFolder();

string rspContent = "/p:A=1";
File.WriteAllText(rspPath, rspContent);
string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
var projectPath = directory.CreateFile("my.proj", content).Path;
directory.CreateFile(AutoResponseFileName, "/p:A=1");

var msbuildParameters = "\"" + projectPath + "\"" + " /p:A=2";
var msbuildParameters = "\"" + projectPath + "\"" + " /p:A=2";

string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeTrue();
string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeTrue();

output.ShouldContain("[A=2]");
}
finally
{
File.Delete(projectPath);
File.Delete(rspPath);
FileUtilities.DeleteWithoutTrailingBackslash(directory);
}
output.ShouldContain("[A=2]");
}

/// <summary>
Expand Down Expand Up @@ -1460,33 +1411,17 @@ public void ProjectDirectoryIsMSBuildExeDirectory()
[Fact]
public void ResponseFileInProjectDirectoryItselfWithNoAutoResponseSwitch()
{
string directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
string projectPath = Path.Combine(directory, "my.proj");
string rspPath = Path.Combine(directory, AutoResponseFileName);

try
{
Directory.CreateDirectory(directory);

string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
File.WriteAllText(projectPath, content);

string rspContent = "/p:A=1 /noautoresponse";
File.WriteAllText(rspPath, rspContent);
var directory = _env.CreateFolder();
string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
var projectPath = directory.CreateFile("my.proj", content).Path;
directory.CreateFile(AutoResponseFileName, "/p:A=1 /noautoresponse");

var msbuildParameters = "\"" + projectPath + "\"";
var msbuildParameters = "\"" + projectPath + "\"";

string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeFalse();
string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeFalse();

output.ShouldContain("MSB1027"); // msbuild.rsp cannot have /noautoresponse in it
}
finally
{
File.Delete(projectPath);
File.Delete(rspPath);
FileUtilities.DeleteWithoutTrailingBackslash(directory);
}
output.ShouldContain("MSB1027"); // msbuild.rsp cannot have /noautoresponse in it
}

/// <summary>
Expand All @@ -1495,33 +1430,16 @@ public void ResponseFileInProjectDirectoryItselfWithNoAutoResponseSwitch()
[Fact]
public void ResponseFileInProjectDirectoryButCommandLineNoAutoResponseSwitch()
{
string directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
string projectPath = Path.Combine(directory, "my.proj");
string rspPath = Path.Combine(directory, AutoResponseFileName);

try
{
Directory.CreateDirectory(directory);

string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
File.WriteAllText(projectPath, content);

string rspContent = "/p:A=1 /noautoresponse";
File.WriteAllText(rspPath, rspContent);

var msbuildParameters = "\"" + projectPath + "\" /noautoresponse";
var directory = _env.CreateFolder();
string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
var projectPath = directory.CreateFile("my.proj", content).Path;
directory.CreateFile(AutoResponseFileName, "/p:A=1 /noautoresponse");

string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeTrue();
var msbuildParameters = "\"" + projectPath + "\" /noautoresponse";

output.ShouldContain("[A=]");
}
finally
{
File.Delete(projectPath);
File.Delete(rspPath);
FileUtilities.DeleteWithoutTrailingBackslash(directory);
}
string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeTrue();
output.ShouldContain("[A=]");
}

/// <summary>
Expand All @@ -1531,28 +1449,17 @@ public void ResponseFileInProjectDirectoryButCommandLineNoAutoResponseSwitch()
[Fact]
public void ResponseFileInProjectDirectoryNullCase()
{
string directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
string projectPath = Path.Combine(directory, "my.proj");

try
{
Directory.CreateDirectory(directory);
var directory = _env.CreateFolder();
string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");

string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
File.WriteAllText(projectPath, content);
var projectPath = directory.CreateFile("my.proj", content).Path;

var msbuildParameters = "\"" + projectPath + "\"";
var msbuildParameters = "\"" + projectPath + "\"";

string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeTrue();
string output = RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
successfulExit.ShouldBeTrue();

output.ShouldContain("[A=]");
}
finally
{
File.Delete(projectPath);
FileUtilities.DeleteWithoutTrailingBackslash(directory);
}
output.ShouldContain("[A=]");
}

/// <summary>
Expand Down Expand Up @@ -1931,7 +1838,7 @@ internal sealed class IgnoreProjectExtensionsHelper
internal IgnoreProjectExtensionsHelper(string[] filesInDirectory)
{
_directoryFileNameList = new List<string>();
foreach (string file in filesInDirectory)
foreach (var file in filesInDirectory)
{
_directoryFileNameList.Add(file);
}
Expand Down

0 comments on commit 0d8d09e

Please sign in to comment.