Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public static class TestConsoleExtensions
{
private static readonly Regex _lineNumberRegex = new Regex(":\\d+", RegexOptions.Singleline);
private static readonly Regex _filenameRegex = new Regex("\\sin\\s.*cs:nn", RegexOptions.Multiline);
private static readonly Regex _pathSeparatorRegex = new Regex(@"[/\\]+");

public static string WriteNormalizedException(this TestConsole console, Exception ex, ExceptionFormats formats = ExceptionFormats.Default)
{
Expand All @@ -21,18 +22,20 @@ public static string WriteNormalizedException(this TestConsole console, Exceptio

public static string NormalizeStackTrace(string text)
{
text = _lineNumberRegex.Replace(text, match =>
{
return ":nn";
});
// First normalize line numbers
text = _lineNumberRegex.Replace(text, ":nn");

return _filenameRegex.Replace(text, match =>
// Then normalize paths and filenames
text = _filenameRegex.Replace(text, match =>
{
var value = match.Value;
var index = value.LastIndexOfAny(new[] { '\\', '/' });
var filename = value.Substring(index + 1, value.Length - index - 1);

return $" in /xyz/{filename}";
});

// Finally normalize any remaining path separators
return _pathSeparatorRegex.Replace(text, "/");
}
}