Skip to content

Commit 7b81118

Browse files
authored
Delete TestProjectFixture and associated helpers (#99847)
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).
1 parent 12d96cc commit 7b81118

20 files changed

+29
-927
lines changed

src/installer/tests/HostActivation.Tests/NativeUnitTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
using Microsoft.DotNet.CoreSetup.Test;
99
using Microsoft.DotNet.Cli.Build.Framework;
1010

11-
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeUnitTests
11+
namespace HostActivation.Tests
1212
{
1313
public class NativeUnitTests
1414
{
1515
[Fact]
1616
public void Native_Test_Fx_Ver()
1717
{
18-
RepoDirectoriesProvider repoDirectoriesProvider = new RepoDirectoriesProvider();
19-
20-
string testPath = Path.Combine(repoDirectoriesProvider.HostTestArtifacts, Binaries.GetExeFileNameForCurrentPlatform("test_fx_ver"));
18+
string testPath = Path.Combine(RepoDirectoriesProvider.Default.HostTestArtifacts, Binaries.GetExeFileNameForCurrentPlatform("test_fx_ver"));
2119

2220
Command testCommand = Command.Create(testPath);
2321
testCommand

src/installer/tests/HostActivation.Tests/RegisteredInstallLocationOverride.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public RegisteredInstallLocationOverride(string productBinaryPath)
5656
// On Linux/macOS the install location is registered in a file which is normally
5757
// located in /etc/dotnet/install_location
5858
// So we need to redirect it to a different place here.
59-
string directory = Path.Combine(TestArtifact.TestArtifactsPath, "installLocationOverride" + Process.GetCurrentProcess().Id.ToString());
59+
string directory = Path.Combine(TestContext.TestArtifactsPath, "installLocationOverride" + Process.GetCurrentProcess().Id.ToString());
6060
if (Directory.Exists(directory))
6161
Directory.Delete(directory, true);
6262
Directory.CreateDirectory(directory);

src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/NETCoreTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.DotNet.CoreSetup.Packaging.Tests
88
{
99
public class NETCoreTests
1010
{
11-
private readonly RepoDirectoriesProvider dirs = new RepoDirectoriesProvider();
11+
private readonly RepoDirectoriesProvider dirs = RepoDirectoriesProvider.Default;
1212

1313
[Fact]
1414
public void NETCoreTargetingPackIsValid()

src/installer/tests/TestUtils/AnsiColorExtensions.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/installer/tests/TestUtils/AnsiConsole.cs

Lines changed: 0 additions & 145 deletions
This file was deleted.

src/installer/tests/TestUtils/Assertions/CommandResultAssertions.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,5 @@ public string GetDiagnosticsInfo()
155155
$"StdOut:{Environment.NewLine}{Result.StdOut}{Environment.NewLine}" +
156156
$"StdErr:{Environment.NewLine}{Result.StdErr}{Environment.NewLine}";
157157
}
158-
159-
public AndConstraint<CommandResultAssertions> HaveSkippedProjectCompilation(string skippedProject, string frameworkFullName)
160-
{
161-
Result.StdOut.Should().Contain("Project {0} ({1}) was previously compiled. Skipping compilation.", skippedProject, frameworkFullName);
162-
163-
return new AndConstraint<CommandResultAssertions>(this);
164-
}
165-
166-
public AndConstraint<CommandResultAssertions> HaveCompiledProject(string compiledProject, string frameworkFullName)
167-
{
168-
Result.StdOut.Should().Contain($"Project {0} ({1}) will be compiled", compiledProject, frameworkFullName);
169-
170-
return new AndConstraint<CommandResultAssertions>(this);
171-
}
172158
}
173159
}

src/installer/tests/TestUtils/Assertions/DirectoryInfoExtensions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,5 @@ public static DirectoryInfoAssertions Should(this DirectoryInfo dir)
1111
{
1212
return new DirectoryInfoAssertions(dir);
1313
}
14-
15-
public static DirectoryInfo Sub(this DirectoryInfo dir, string name)
16-
{
17-
return new DirectoryInfo(Path.Combine(dir.FullName, name));
18-
}
1914
}
2015
}

src/installer/tests/TestUtils/BuildFailureException.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/installer/tests/TestUtils/BuildReporter.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/installer/tests/TestUtils/Command.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
using System.ComponentModel;
77
using System.Diagnostics;
88
using System.IO;
9-
using System.Linq;
109
using System.Runtime.CompilerServices;
11-
using System.Runtime.InteropServices;
1210
using System.Threading;
1311

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

316+
private static DateTime _initialTime = DateTime.Now;
317+
318+
private string GetFormattedTime()
319+
{
320+
const string TimeSpanFormat = @"hh\:mm\:ss\.fff";
321+
return (DateTime.Now - _initialTime).ToString(TimeSpanFormat);
322+
}
323+
318324
private void ReportExecBegin()
319325
{
320-
BuildReporter.BeginSection("EXEC", FormatProcessInfo(Process.StartInfo, includeWorkingDirectory: false));
326+
string message = FormatProcessInfo(Process.StartInfo, includeWorkingDirectory: false);
327+
Console.WriteLine($"[EXEC >] [....] [{GetFormattedTime()}] {message}");
321328
}
322329

323330
private void ReportExecWaitOnExit()
324331
{
325-
BuildReporter.SectionComment("EXEC", $"Waiting for process {Process.Id} to exit...");
332+
string message = $"Waiting for process {Process.Id} to exit...";
333+
Console.WriteLine($"[EXEC -] [....] [{GetFormattedTime()}] {message}");
326334
}
327335

328336
private void ReportExecEnd(int exitCode, bool fExpectedToFail)
329337
{
330-
bool success = exitCode == 0;
331-
string msgExpectedToFail = "";
332-
333-
if (fExpectedToFail)
334-
{
335-
success = !success;
336-
msgExpectedToFail = "failed as expected and ";
337-
}
338-
339-
var message = $"{FormatProcessInfo(Process.StartInfo, includeWorkingDirectory: !success)} {msgExpectedToFail}exited with {exitCode}";
340-
341-
BuildReporter.EndSection(
342-
"EXEC",
343-
success ? message.Green() : message.Red().Bold(),
344-
success);
338+
bool success = fExpectedToFail ? exitCode != 0 : exitCode == 0;
339+
var status = success ? " OK " : "FAIL";
340+
var message = $"{FormatProcessInfo(Process.StartInfo, includeWorkingDirectory: !success)} exited with {exitCode}. Expected: {(fExpectedToFail ? "non-zero" : "0")}";
341+
Console.WriteLine($"[EXEC <] [{status}] [{GetFormattedTime()}] {message}");
345342
}
346343

347344
private void ThrowIfRunning([CallerMemberName] string memberName = null)

0 commit comments

Comments
 (0)