Skip to content

Commit

Permalink
Delete TestProjectFixture and associated helpers (#99847)
Browse files Browse the repository at this point in the history
As part of #77800, we have gotten rid of building/publishing projects using the SDK during hosting test runs.

This change removes test utilities like `TestProjectFixture` and `TestProject` which revolved around that building / publishing functionality. It also removes the `BuildReporter`/`AnsIConsole` logging from the test utils. It was a lot of infrastructure to set font colour and weight for output that would not normally be seen (redirected to a log file usually - only seen on non-Windows when running directly via dotnet test, not arcade infrastructure).
  • Loading branch information
elinor-fung authored Mar 21, 2024
1 parent 12d96cc commit 7b81118
Show file tree
Hide file tree
Showing 20 changed files with 29 additions and 927 deletions.
6 changes: 2 additions & 4 deletions src/installer/tests/HostActivation.Tests/NativeUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
using Microsoft.DotNet.CoreSetup.Test;
using Microsoft.DotNet.Cli.Build.Framework;

namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeUnitTests
namespace HostActivation.Tests
{
public class NativeUnitTests
{
[Fact]
public void Native_Test_Fx_Ver()
{
RepoDirectoriesProvider repoDirectoriesProvider = new RepoDirectoriesProvider();

string testPath = Path.Combine(repoDirectoriesProvider.HostTestArtifacts, Binaries.GetExeFileNameForCurrentPlatform("test_fx_ver"));
string testPath = Path.Combine(RepoDirectoriesProvider.Default.HostTestArtifacts, Binaries.GetExeFileNameForCurrentPlatform("test_fx_ver"));

Command testCommand = Command.Create(testPath);
testCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public RegisteredInstallLocationOverride(string productBinaryPath)
// On Linux/macOS the install location is registered in a file which is normally
// located in /etc/dotnet/install_location
// So we need to redirect it to a different place here.
string directory = Path.Combine(TestArtifact.TestArtifactsPath, "installLocationOverride" + Process.GetCurrentProcess().Id.ToString());
string directory = Path.Combine(TestContext.TestArtifactsPath, "installLocationOverride" + Process.GetCurrentProcess().Id.ToString());
if (Directory.Exists(directory))
Directory.Delete(directory, true);
Directory.CreateDirectory(directory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.DotNet.CoreSetup.Packaging.Tests
{
public class NETCoreTests
{
private readonly RepoDirectoriesProvider dirs = new RepoDirectoriesProvider();
private readonly RepoDirectoriesProvider dirs = RepoDirectoriesProvider.Default;

[Fact]
public void NETCoreTargetingPackIsValid()
Expand Down
52 changes: 0 additions & 52 deletions src/installer/tests/TestUtils/AnsiColorExtensions.cs

This file was deleted.

145 changes: 0 additions & 145 deletions src/installer/tests/TestUtils/AnsiConsole.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,5 @@ public string GetDiagnosticsInfo()
$"StdOut:{Environment.NewLine}{Result.StdOut}{Environment.NewLine}" +
$"StdErr:{Environment.NewLine}{Result.StdErr}{Environment.NewLine}";
}

public AndConstraint<CommandResultAssertions> HaveSkippedProjectCompilation(string skippedProject, string frameworkFullName)
{
Result.StdOut.Should().Contain("Project {0} ({1}) was previously compiled. Skipping compilation.", skippedProject, frameworkFullName);

return new AndConstraint<CommandResultAssertions>(this);
}

public AndConstraint<CommandResultAssertions> HaveCompiledProject(string compiledProject, string frameworkFullName)
{
Result.StdOut.Should().Contain($"Project {0} ({1}) will be compiled", compiledProject, frameworkFullName);

return new AndConstraint<CommandResultAssertions>(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,5 @@ public static DirectoryInfoAssertions Should(this DirectoryInfo dir)
{
return new DirectoryInfoAssertions(dir);
}

public static DirectoryInfo Sub(this DirectoryInfo dir, string name)
{
return new DirectoryInfo(Path.Combine(dir.FullName, name));
}
}
}
22 changes: 0 additions & 22 deletions src/installer/tests/TestUtils/BuildFailureException.cs

This file was deleted.

38 changes: 0 additions & 38 deletions src/installer/tests/TestUtils/BuildReporter.cs

This file was deleted.

35 changes: 16 additions & 19 deletions src/installer/tests/TestUtils/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;

namespace Microsoft.DotNet.Cli.Build.Framework
Expand Down Expand Up @@ -315,33 +313,32 @@ private string FormatProcessInfo(ProcessStartInfo info, bool includeWorkingDirec
return prefix + " " + info.Arguments;
}

private static DateTime _initialTime = DateTime.Now;

private string GetFormattedTime()
{
const string TimeSpanFormat = @"hh\:mm\:ss\.fff";
return (DateTime.Now - _initialTime).ToString(TimeSpanFormat);
}

private void ReportExecBegin()
{
BuildReporter.BeginSection("EXEC", FormatProcessInfo(Process.StartInfo, includeWorkingDirectory: false));
string message = FormatProcessInfo(Process.StartInfo, includeWorkingDirectory: false);
Console.WriteLine($"[EXEC >] [....] [{GetFormattedTime()}] {message}");
}

private void ReportExecWaitOnExit()
{
BuildReporter.SectionComment("EXEC", $"Waiting for process {Process.Id} to exit...");
string message = $"Waiting for process {Process.Id} to exit...";
Console.WriteLine($"[EXEC -] [....] [{GetFormattedTime()}] {message}");
}

private void ReportExecEnd(int exitCode, bool fExpectedToFail)
{
bool success = exitCode == 0;
string msgExpectedToFail = "";

if (fExpectedToFail)
{
success = !success;
msgExpectedToFail = "failed as expected and ";
}

var message = $"{FormatProcessInfo(Process.StartInfo, includeWorkingDirectory: !success)} {msgExpectedToFail}exited with {exitCode}";

BuildReporter.EndSection(
"EXEC",
success ? message.Green() : message.Red().Bold(),
success);
bool success = fExpectedToFail ? exitCode != 0 : exitCode == 0;
var status = success ? " OK " : "FAIL";
var message = $"{FormatProcessInfo(Process.StartInfo, includeWorkingDirectory: !success)} exited with {exitCode}. Expected: {(fExpectedToFail ? "non-zero" : "0")}";
Console.WriteLine($"[EXEC <] [{status}] [{GetFormattedTime()}] {message}");
}

private void ThrowIfRunning([CallerMemberName] string memberName = null)
Expand Down
2 changes: 1 addition & 1 deletion src/installer/tests/TestUtils/CommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static Command EnableHostTracing(this Command command)

public static Command EnableHostTracingToFile(this Command command, out string filePath)
{
filePath = Path.Combine(TestArtifact.TestArtifactsPath, "trace" + Guid.NewGuid().ToString() + ".log");
filePath = Path.Combine(TestContext.TestArtifactsPath, "trace" + Guid.NewGuid().ToString() + ".log");
if (File.Exists(filePath))
{
File.Delete(filePath);
Expand Down
Loading

0 comments on commit 7b81118

Please sign in to comment.