Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: dotnet build --configuration Release --no-restore -bl:logs/build.binlog

- name: Test
run: dotnet test --configuration Release --no-build --logger trx --results-directory TestResults --collect:"Code Coverage;Format=Cobertura"
run: dotnet test --configuration Release --no-build --report-trx --results-directory TestResults --coverage

# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: dotnet build --configuration Release --no-restore -bl:logs/build.binlog

- name: Test
run: dotnet test --configuration Release --no-build --logger trx --results-directory TestResults --collect:"Code Coverage;Format=Cobertura"
run: dotnet test --configuration Release --no-build --report-trx --results-directory TestResults --coverage

# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v4
Expand Down
7 changes: 5 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"msbuild-sdks": {
"Microsoft.Build.NoTargets": "3.7.56",
"MSTest.Sdk": "3.6.0"
"MSTest.Sdk": "3.11.1"
},
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
}
46 changes: 9 additions & 37 deletions src/Tests/E2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Text.RegularExpressions;
using ReferenceTrimmer.Loggers.MSVC;

[assembly: Parallelize(Workers = 1, Scope = ExecutionScope.MethodLevel)]

namespace ReferenceTrimmer.Tests;

[TestClass]
Expand Down Expand Up @@ -257,14 +259,9 @@ await RunMSBuildAsync(
}

[TestMethod]
[OSCondition(OperatingSystems.Windows, IgnoreMessage = "The GAC is Windows-specific")]
public async Task UnusedReferenceFromGac()
{
// The GAC is Windows-specific
if (!OperatingSystem.IsWindows())
{
Assert.Inconclusive();
}

await RunMSBuildAsync(
projectFile: "Library.csproj",
expectedWarnings: new[]
Expand All @@ -274,14 +271,9 @@ await RunMSBuildAsync(
}

[TestMethod]
[OSCondition(OperatingSystems.Windows, IgnoreMessage = "The GAC is Windows-specific")]
public async Task UsedReferenceFromGac()
{
// The GAC is Windows-specific
if (!OperatingSystem.IsWindows())
{
Assert.Inconclusive();
}

await RunMSBuildAsync(
projectFile: "Library.csproj",
expectedWarnings: []);
Expand Down Expand Up @@ -418,28 +410,18 @@ public Task ReferenceTrimmerDisabled()
}

[TestMethod]
[OSCondition(OperatingSystems.Windows, IgnoreMessage = "This test only applies to Windows")]
public async Task LegacyStyleProject()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.Inconclusive("This test only applies to Windows");
return;
}

await RunMSBuildAsync(
projectFile: "Library/Library.csproj",
expectedWarnings: []);
}

[TestMethod]
[OSCondition(OperatingSystems.Windows, IgnoreMessage = "This test only applies to Windows")]
public async Task UnusedWinSdkImportLibrary()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.Inconclusive("This test only applies to Windows");
return;
}

await RunMSBuildAsync(
projectFile: "App/App.vcxproj",
expectedWarnings: [],
Expand All @@ -456,14 +438,9 @@ await RunMSBuildAsync(
}

[TestMethod]
[OSCondition(OperatingSystems.Windows, IgnoreMessage = "This test only applies to Windows")]
public async Task UnusedCppLibrary()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.Inconclusive("This test only applies to Windows");
return;
}

await RunMSBuildAsync(
projectFile: "App/App.vcxproj",
expectedWarnings: [],
Expand All @@ -478,14 +455,9 @@ await RunMSBuildAsync(
}

[TestMethod]
[OSCondition(OperatingSystems.Windows, IgnoreMessage = "This test only applies to Windows")]
public async Task UnusedCppDelayLoadLibrary()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.Inconclusive("This test only applies to Windows");
return;
}

await RunMSBuildAsync(
projectFile: "App/App.vcxproj",
expectedWarnings: [],
Expand Down Expand Up @@ -600,7 +572,7 @@ private async Task RunMSBuildAsync(string projectFile, Warning[] expectedWarning
Assert.AreEqual(File.Exists(unusedLibraryLogPath), expectUnusedMsvcLibrariesLog);

string errors = await File.ReadAllTextAsync(errorsFilePath);
Assert.IsTrue(errors.Length == 0, $"Build of {projectFile} was not successful.{Environment.NewLine}Error log: {errors}");
Assert.AreEqual(0, errors.Length, $"Build of {projectFile} was not successful.{Environment.NewLine}Error log: {errors}");

List<Warning> actualWarnings = new();
foreach (string line in await File.ReadAllLinesAsync(warningsFilePath))
Expand Down
44 changes: 22 additions & 22 deletions src/Tests/MsvcLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public void ForwardingLogger_ForwardsNothingIfLinkTaskNotStarted()
{
eventSource.AssertExpectedForwardingEventSubscriptions();
eventSource.SendTaskStarted(new TaskStartedEventArgs(message: "Not Link!", helpKeyword: "NotLink", projectFile: "a.proj", taskFile: "a.proj", taskName: "NotLink"));
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendMessageRaised(new BuildMessageEventArgs(message: "a non-link message", helpKeyword: "NotLink", senderName: "NotLink", MessageImportance.High, DateTime.Now) { ProjectFile = "a.proj" });
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendTaskFinished(new TaskFinishedEventArgs(message: "Not Link!", helpKeyword: "NotLink", projectFile: "a.proj", taskFile: "a.proj", taskName: "NotLink", succeeded: true));
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
}
finally
{
Expand All @@ -123,11 +123,11 @@ public void ForwardingLogger_ForwardsNothingIfLinkTaskGetsNoUnusedLibMessages()
{
eventSource.AssertExpectedForwardingEventSubscriptions();
eventSource.SendTaskStarted(new TaskStartedEventArgs(message: "Link starting", helpKeyword: "Link", projectFile: "a.proj", taskFile: "a.proj", taskName: "Link"));
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendMessageRaised(new BuildMessageEventArgs(message: "Generic link message", helpKeyword: "Link", senderName: "Link", MessageImportance.High, DateTime.Now) { ProjectFile = "a.proj" });
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendTaskFinished(new TaskFinishedEventArgs(message: "Link finished", helpKeyword: "Link", projectFile: "a.proj", taskFile: "a.proj", taskName: "Link", succeeded: true));
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
}
finally
{
Expand All @@ -146,11 +146,11 @@ public void ForwardingLogger_ForwardsNothingIfLinkTaskGetsUnusedLibHeaderOnly()
{
eventSource.AssertExpectedForwardingEventSubscriptions();
eventSource.SendTaskStarted(new TaskStartedEventArgs(message: "Link starting", helpKeyword: "Link", projectFile: "a.proj", taskFile: "a.proj", taskName: "Link"));
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendMessageRaised(new BuildMessageEventArgs(message: "Unused libraries:", helpKeyword: "Link", senderName: "Link", MessageImportance.High, DateTime.Now) { ProjectFile = "a.proj" });
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendTaskFinished(new TaskFinishedEventArgs(message: "Link finished", helpKeyword: "Link", projectFile: "a.proj", taskFile: "a.proj", taskName: "Link", succeeded: true));
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
}
finally
{
Expand All @@ -169,23 +169,23 @@ public void ForwardingLogger_ForwardsUnusedLibs()
{
eventSource.AssertExpectedForwardingEventSubscriptions();
eventSource.SendTaskStarted(new TaskStartedEventArgs(message: "Link starting", helpKeyword: "Link", projectFile: "a.proj", taskFile: "a.proj", taskName: "Link"));
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendMessageRaised(new BuildMessageEventArgs(message: "Unused libraries:", helpKeyword: "Link", senderName: "Link", MessageImportance.High, DateTime.Now) { ProjectFile = "a.proj" });
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendMessageRaised(new BuildMessageEventArgs(message: " user32.lib", helpKeyword: "Link", senderName: "Link", MessageImportance.High, DateTime.Now) { ProjectFile = "a.proj" });
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendMessageRaised(new BuildMessageEventArgs(message: " bar.lib", helpKeyword: "Link", senderName: "Link", MessageImportance.High, DateTime.Now) { ProjectFile = "a.proj" });
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendMessageRaised(new BuildMessageEventArgs(message: string.Empty, helpKeyword: "Link", senderName: "Link", MessageImportance.High, DateTime.Now) { ProjectFile = "a.proj" });
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendTaskFinished(new TaskFinishedEventArgs(message: "Link finished", helpKeyword: "Link", projectFile: "a.proj", taskFile: "a.proj", taskName: "Link", succeeded: true));
Assert.AreEqual(1, eventRedirector.Events.Count);
Assert.HasCount(1, eventRedirector.Events);
var unusedLibArgs = eventRedirector.Events[0] as UnusedLibsCustomBuildEventArgs;
Assert.IsNotNull(unusedLibArgs);
Assert.AreEqual("a.proj", unusedLibArgs.ProjectPath);
Assert.IsTrue(unusedLibArgs.Message!.Contains("user32.lib", StringComparison.Ordinal), unusedLibArgs.Message);
Assert.IsTrue(unusedLibArgs.Message.Contains("bar.lib", StringComparison.Ordinal), unusedLibArgs.Message);
Assert.IsTrue(unusedLibArgs.UnusedLibraryPathsJson.Length > 0);
Assert.IsGreaterThan(0, unusedLibArgs.UnusedLibraryPathsJson.Length);
}
finally
{
Expand All @@ -204,17 +204,17 @@ public void ForwardingLogger_ForwardsNothingIfLinkTaskFails()
{
eventSource.AssertExpectedForwardingEventSubscriptions();
eventSource.SendTaskStarted(new TaskStartedEventArgs(message: "Link starting", helpKeyword: "Link", projectFile: "a.proj", taskFile: "a.proj", taskName: "Link"));
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendMessageRaised(new BuildMessageEventArgs(message: "Unused libraries:", helpKeyword: "Link", senderName: "Link", MessageImportance.High, DateTime.Now) { ProjectFile = "a.proj" });
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendMessageRaised(new BuildMessageEventArgs(message: " kernel32.lib", helpKeyword: "Link", senderName: "Link", MessageImportance.High, DateTime.Now) { ProjectFile = "a.proj" });
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendMessageRaised(new BuildMessageEventArgs(message: " foo.lib", helpKeyword: "Link", senderName: "Link", MessageImportance.High, DateTime.Now) { ProjectFile = "a.proj" });
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendMessageRaised(new BuildMessageEventArgs(message: string.Empty, helpKeyword: "Link", senderName: "Link", MessageImportance.High, DateTime.Now) { ProjectFile = "a.proj" });
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
eventSource.SendTaskFinished(new TaskFinishedEventArgs(message: "Link finished", helpKeyword: "Link", projectFile: "a.proj", taskFile: "a.proj", taskName: "Link", succeeded: false));
Assert.AreEqual(0, eventRedirector.Events.Count);
Assert.IsEmpty(eventRedirector.Events);
}
finally
{
Expand Down