Skip to content

Commit

Permalink
Use @ instead of $ for replacement tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Jun 1, 2023
1 parent b60fbcd commit 5c40018
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
20 changes: 10 additions & 10 deletions GitHubActionsTestLogger.Tests/AnnotationSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_the_test_na
),
new TestLoggerOptions
{
AnnotationTitleFormat = "<$test>",
AnnotationMessageFormat = "[$test]"
AnnotationTitleFormat = "<@test>",
AnnotationMessageFormat = "[@test]"
}
);

Expand Down Expand Up @@ -217,8 +217,8 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_test_traits
),
new TestLoggerOptions
{
AnnotationTitleFormat = "<$traits.Category -> $test>",
AnnotationMessageFormat = "[$traits.Category -> $test]"
AnnotationTitleFormat = "<@traits.Category -> @test>",
AnnotationMessageFormat = "[@traits.Category -> @test]"
}
);

Expand Down Expand Up @@ -254,8 +254,8 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_the_error_m
),
new TestLoggerOptions
{
AnnotationTitleFormat = "<$test: $error>",
AnnotationMessageFormat = "[$test: $error]"
AnnotationTitleFormat = "<@test: @error>",
AnnotationMessageFormat = "[@test: @error]"
}
);

Expand Down Expand Up @@ -290,8 +290,8 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_the_error_s
),
new TestLoggerOptions
{
AnnotationTitleFormat = "<$test: $trace>",
AnnotationMessageFormat = "[$test: $trace]"
AnnotationTitleFormat = "<@test: @trace>",
AnnotationMessageFormat = "[@test: @trace]"
}
);

Expand Down Expand Up @@ -326,8 +326,8 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_the_target_
),
new TestLoggerOptions
{
AnnotationTitleFormat = "<$test ($framework)>",
AnnotationMessageFormat = "[$test ($framework)]"
AnnotationTitleFormat = "<@test (@framework)>",
AnnotationMessageFormat = "[@test (@framework)]"
}
);

Expand Down
29 changes: 23 additions & 6 deletions GitHubActionsTestLogger/TestLoggerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,41 @@ private string FormatAnnotation(string format, TestResult testResult)
{
var buffer = new StringBuilder(format);

// New line token (don't include caret return for consistency across platforms)
// Escaped new line token (backwards compat)
buffer.Replace("\\n", "\n");

// Name token
buffer.Replace("$test", testResult.TestCase.DisplayName ?? "");
buffer
.Replace("@test", testResult.TestCase.DisplayName)
// Backwards compat
.Replace("$test", testResult.TestCase.DisplayName);

// Trait tokens
foreach (var trait in testResult.Traits.Union(testResult.TestCase.Traits))
buffer.Replace($"$traits.{trait.Name}", trait.Value);
{
buffer
.Replace($"@traits.{trait.Name}", trait.Value)
// Backwards compat
.Replace($"$traits.{trait.Name}", trait.Value);
}

// Error message
buffer.Replace("$error", testResult.ErrorMessage ?? "");
buffer
.Replace("@error", testResult.ErrorMessage ?? "")
// Backwards compat
.Replace("$error", testResult.ErrorMessage ?? "");

// Error trace
buffer.Replace("$trace", testResult.ErrorStackTrace ?? "");
buffer
.Replace("@trace", testResult.ErrorStackTrace ?? "")
// Backwards compat
.Replace("$trace", testResult.ErrorStackTrace ?? "");

// Target framework
buffer.Replace("$framework", _testRunCriteria?.TryGetTargetFramework() ?? "");
buffer
.Replace("@framework", _testRunCriteria?.TryGetTargetFramework() ?? "")
// Backwards compat
.Replace("$framework", _testRunCriteria?.TryGetTargetFramework() ?? "");

return buffer.Trim().ToString();
}
Expand Down
4 changes: 2 additions & 2 deletions GitHubActionsTestLogger/TestLoggerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace GitHubActionsTestLogger;

public partial class TestLoggerOptions
{
public string AnnotationTitleFormat { get; init; } = "$test";
public string AnnotationTitleFormat { get; init; } = "@test";

public string AnnotationMessageFormat { get; init; } = "$error";
public string AnnotationMessageFormat { get; init; } = "@error";

public bool SummaryIncludePassedTests { get; init; }

Expand Down

0 comments on commit 5c40018

Please sign in to comment.