Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 311
Simplify GitHubActionsAnnotationReporter#9677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
23 changes: 13 additions & 10 deletions
23 ...tform/Microsoft.Testing.Extensions.GitHubActionsReport/GitHubActionsAnnotationReporter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 15 additions & 16 deletions
31 .../UnitTests/Microsoft.Testing.Extensions.UnitTests/GitHubActionsAnnotationReporterTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -103,24 +103,21 @@ public void GetSkippedAnnotation_FallsBackToDefaultReason_WhenNoExplanation() | ||
| Assert.AreEqual("::warning title=Test skipped%3A MyNamespace.MyTest::The test was skipped without providing a reason.", text); | ||
| } | ||
| // Throws (and catches) an exception, reporting the exact line of the throw statement so tests can assert the | ||
| // resolved line without hard-coding a physical number that shifts whenever code above changes. | ||
| private static Exception CaptureException(string message, out int throwLine) | ||
| // Produces an exception whose stack trace deterministically points at this test file at a fixed line, so | ||
| // tests can assert the resolved file and line. A real 'throw' was previously used, but the runtime-reported | ||
| // line of a thrown exception shifts under Release JIT optimization (observed differing between .NET | ||
| // Framework net462 and net472), which made the exact-line assertion flaky in CI (see #9658). A synthetic | ||
| // frame keeps both the resolved file and line stable while still exercising the resolver's real | ||
| // repo-root/'/_/' path relativization: [CallerFilePath] yields this file's path (mapped to '/_/test/...' | ||
| // in deterministic CI builds, or an absolute path locally), exactly as a genuine frame would. | ||
| private static Exception CaptureException(string message, out int throwLine, [CallerFilePath] string filePath = "") | ||
| { | ||
| throwLine = 0; | ||
| try | ||
| { | ||
| throwLine = CurrentLine() + 1; | ||
| throw new Exception(message); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| return ex; | ||
| } | ||
| throwLine = 12345; | ||
| return new StackTraceException( | ||
| $" at Microsoft.Testing.Extensions.UnitTests.GitHubActionsAnnotationReporterTests.CaptureException() in {filePath}:line {throwLine}", | ||
Evangelink marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| message); | ||
| } | ||
| private static int CurrentLine([CallerLineNumber] int line = 0) => line; | ||
| private static IFileSystem CreateFileSystemWhereEveryFileExists() | ||
| { | ||
| var fileSystem = new Mock<IFileSystem>(); | ||
| @@ -134,7 +131,9 @@ private sealed class StackTraceException : Exception | ||
| { | ||
| private readonly string _stackTrace; | ||
| public StackTraceException(string stackTrace) => _stackTrace = stackTrace; | ||
| public StackTraceException(string stackTrace, string? message = null) | ||
| : base(message) | ||
| => _stackTrace = stackTrace; | ||
| public override string? StackTrace => _stackTrace; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.