Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Align the tests usage of test environment #9682

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
f-alizada marked this conversation as resolved.
Show resolved Hide resolved
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
Loading