Skip to content

Commit

Permalink
Use CSharpier
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Aug 22, 2023
1 parent 0a439cc commit bcf52ac
Show file tree
Hide file tree
Showing 25 changed files with 236 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.25.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0" PrivateAssets="all" />
Expand Down
2 changes: 1 addition & 1 deletion GitHubActionsTestLogger.Demo/SampleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public class SampleTests

[Fact]
public void Test3() => Assert.True(false);
}
}
75 changes: 16 additions & 59 deletions GitHubActionsTestLogger.Tests/AnnotationSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class AnnotationSpecs
{
private readonly ITestOutputHelper _testOutput;

public AnnotationSpecs(ITestOutputHelper testOutput) =>
_testOutput = testOutput;
public AnnotationSpecs(ITestOutputHelper testOutput) => _testOutput = testOutput;

[Fact]
public void I_can_use_the_logger_to_produce_annotations_for_failed_tests()
Expand All @@ -22,10 +21,7 @@ public void I_can_use_the_logger_to_produce_annotations_for_failed_tests()
using var commandWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
commandWriter,
TextWriter.Null
),
new GitHubWorkflow(commandWriter, TextWriter.Null),
TestLoggerOptions.Default
);

Expand All @@ -36,14 +32,8 @@ public void I_can_use_the_logger_to_produce_annotations_for_failed_tests()
.SetOutcome(TestOutcome.Failed)
.SetErrorMessage("ErrorMessage")
.Build(),
new TestResultBuilder()
.SetDisplayName("Test2")
.SetOutcome(TestOutcome.Passed)
.Build(),
new TestResultBuilder()
.SetDisplayName("Test3")
.SetOutcome(TestOutcome.Skipped)
.Build()
new TestResultBuilder().SetDisplayName("Test2").SetOutcome(TestOutcome.Passed).Build(),
new TestResultBuilder().SetDisplayName("Test3").SetOutcome(TestOutcome.Skipped).Build()
);

// Assert
Expand All @@ -69,10 +59,7 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_source_info
using var commandWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
commandWriter,
TextWriter.Null
),
new GitHubWorkflow(commandWriter, TextWriter.Null),
TestLoggerOptions.Default
);

Expand Down Expand Up @@ -122,10 +109,7 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_source_info
using var commandWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
commandWriter,
TextWriter.Null
),
new GitHubWorkflow(commandWriter, TextWriter.Null),
TestLoggerOptions.Default
);

Expand Down Expand Up @@ -176,10 +160,7 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_the_test_na
using var commandWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
commandWriter,
TextWriter.Null
),
new GitHubWorkflow(commandWriter, TextWriter.Null),
new TestLoggerOptions
{
AnnotationTitleFormat = "<@test>",
Expand All @@ -189,10 +170,7 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_the_test_na

// Act
context.SimulateTestRun(
new TestResultBuilder()
.SetDisplayName("Test1")
.SetOutcome(TestOutcome.Failed)
.Build()
new TestResultBuilder().SetDisplayName("Test1").SetOutcome(TestOutcome.Failed).Build()
);

// Assert
Expand All @@ -211,10 +189,7 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_test_traits
using var commandWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
commandWriter,
TextWriter.Null
),
new GitHubWorkflow(commandWriter, TextWriter.Null),
new TestLoggerOptions
{
AnnotationTitleFormat = "<@traits.Category -> @test>",
Expand Down Expand Up @@ -248,10 +223,7 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_the_error_m
using var commandWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
commandWriter,
TextWriter.Null
),
new GitHubWorkflow(commandWriter, TextWriter.Null),
new TestLoggerOptions
{
AnnotationTitleFormat = "<@test: @error>",
Expand Down Expand Up @@ -284,10 +256,7 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_the_error_s
using var commandWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
commandWriter,
TextWriter.Null
),
new GitHubWorkflow(commandWriter, TextWriter.Null),
new TestLoggerOptions
{
AnnotationTitleFormat = "<@test: @trace>",
Expand Down Expand Up @@ -320,10 +289,7 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_the_target_
using var commandWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
commandWriter,
TextWriter.Null
),
new GitHubWorkflow(commandWriter, TextWriter.Null),
new TestLoggerOptions
{
AnnotationTitleFormat = "<@test (@framework)>",
Expand Down Expand Up @@ -358,22 +324,13 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_line_breaks
using var commandWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
commandWriter,
TextWriter.Null
),
new TestLoggerOptions
{
AnnotationMessageFormat = "foo\\nbar"
}
new GitHubWorkflow(commandWriter, TextWriter.Null),
new TestLoggerOptions { AnnotationMessageFormat = "foo\\nbar" }
);

// Act
context.SimulateTestRun(
new TestResultBuilder()
.SetDisplayName("Test1")
.SetOutcome(TestOutcome.Failed)
.Build()
new TestResultBuilder().SetDisplayName("Test1").SetOutcome(TestOutcome.Failed).Build()
);

// Assert
Expand All @@ -383,4 +340,4 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_line_breaks

_testOutput.WriteLine(output);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ internal class FakeTestLoggerEvents : TestLoggerEvents
public override event EventHandler<TestRunMessageEventArgs>? DiscoveryMessage;
public override event EventHandler<DiscoveredTestsEventArgs>? DiscoveredTests;
public override event EventHandler<DiscoveryCompleteEventArgs>? DiscoveryComplete;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.25.0" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
Expand Down
2 changes: 1 addition & 1 deletion GitHubActionsTestLogger.Tests/InitializationSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ public void I_can_use_the_logger_with_a_custom_configuration()
logger.Context?.Options.SummaryIncludePassedTests.Should().BeTrue();
logger.Context?.Options.SummaryIncludeSkippedTests.Should().BeTrue();
}
}
}
35 changes: 8 additions & 27 deletions GitHubActionsTestLogger.Tests/SummarySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class SummarySpecs
{
private readonly ITestOutputHelper _testOutput;

public SummarySpecs(ITestOutputHelper testOutput) =>
_testOutput = testOutput;
public SummarySpecs(ITestOutputHelper testOutput) => _testOutput = testOutput;

[Fact]
public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_test_suite_name()
Expand All @@ -22,10 +21,7 @@ public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_test_sui
using var summaryWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
TextWriter.Null,
summaryWriter
),
new GitHubWorkflow(TextWriter.Null, summaryWriter),
TestLoggerOptions.Default
);

Expand All @@ -47,14 +43,8 @@ public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_
using var summaryWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
TextWriter.Null,
summaryWriter
),
new TestLoggerOptions
{
SummaryIncludePassedTests = true
}
new GitHubWorkflow(TextWriter.Null, summaryWriter),
new TestLoggerOptions { SummaryIncludePassedTests = true }
);

// Act
Expand Down Expand Up @@ -100,14 +90,8 @@ public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_
using var summaryWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
TextWriter.Null,
summaryWriter
),
new TestLoggerOptions
{
SummaryIncludeSkippedTests = true
}
new GitHubWorkflow(TextWriter.Null, summaryWriter),
new TestLoggerOptions { SummaryIncludeSkippedTests = true }
);

// Act
Expand Down Expand Up @@ -153,10 +137,7 @@ public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_
using var summaryWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(
TextWriter.Null,
summaryWriter
),
new GitHubWorkflow(TextWriter.Null, summaryWriter),
TestLoggerOptions.Default
);

Expand Down Expand Up @@ -207,4 +188,4 @@ public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_

_testOutput.WriteLine(output);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,64 @@ public static void SimulateTestRun(
this TestLoggerContext context,
string testSuiteFilePath,
string targetFrameworkName,
params TestResult[] testResults)
params TestResult[] testResults
)
{
context.HandleTestRunStart(new TestRunStartEventArgs(new TestRunCriteria(
new[] { testSuiteFilePath },
1,
true,
// lang=xml
$"""
context.HandleTestRunStart(
new TestRunStartEventArgs(
new TestRunCriteria(
new[] { testSuiteFilePath },
1,
true,
// lang=xml
$"""
<RunSettings>
<RunConfiguration>
<TargetFrameworkVersion>{targetFrameworkName}</TargetFrameworkVersion>
</RunConfiguration>
</RunSettings>
"""
)));
)
)
);

foreach (var testResult in testResults)
context.HandleTestResult(new TestResultEventArgs(testResult));

context.HandleTestRunComplete(new TestRunCompleteEventArgs(
new TestRunStatistics(new Dictionary<TestOutcome, long>
{
[TestOutcome.Passed] = testResults.Count(r => r.Outcome == TestOutcome.Passed),
[TestOutcome.Failed] = testResults.Count(r => r.Outcome == TestOutcome.Failed),
[TestOutcome.Skipped] = testResults.Count(r => r.Outcome == TestOutcome.Skipped),
[TestOutcome.None] = testResults.Count(r => r.Outcome == TestOutcome.None)
}),
false,
false,
null,
new Collection<AttachmentSet>(),
TimeSpan.FromSeconds(1.234)
));
context.HandleTestRunComplete(
new TestRunCompleteEventArgs(
new TestRunStatistics(
new Dictionary<TestOutcome, long>
{
[TestOutcome.Passed] = testResults.Count(
r => r.Outcome == TestOutcome.Passed
),
[TestOutcome.Failed] = testResults.Count(
r => r.Outcome == TestOutcome.Failed
),
[TestOutcome.Skipped] = testResults.Count(
r => r.Outcome == TestOutcome.Skipped
),
[TestOutcome.None] = testResults.Count(r => r.Outcome == TestOutcome.None)
}
),
false,
false,
null,
new Collection<AttachmentSet>(),
TimeSpan.FromSeconds(1.234)
)
);
}

public static void SimulateTestRun(
this TestLoggerContext context,
string testSuiteName,
params TestResult[] testResults) =>
context.SimulateTestRun(testSuiteName, "FakeTargetFramework", testResults);
params TestResult[] testResults
) => context.SimulateTestRun(testSuiteName, "FakeTargetFramework", testResults);

public static void SimulateTestRun(
this TestLoggerContext context,
params TestResult[] testResults) =>
context.SimulateTestRun("FakeTests.dll", testResults);
}
params TestResult[] testResults
) => context.SimulateTestRun("FakeTests.dll", testResults);
}
Loading

0 comments on commit bcf52ac

Please sign in to comment.