Skip to content

Commit

Permalink
Stop ExceptionTests.cs from spamming console output (dotnet#29237)
Browse files Browse the repository at this point in the history
The VerifyCallStack test helper method is doing a Console.WriteLine regardless of whether anything failed.  I'm moving it to only happen if something actually goes wrong.
  • Loading branch information
stephentoub authored Apr 20, 2018
1 parent e3f4a92 commit 23096f8
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/System.Runtime/tests/System/ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,27 @@ private static void VerifyCallStack(
(string CallerMemberName, string SourceFilePath, int SourceLineNumber) expectedStackFrame,
string reportedCallStack, int skipFrames)
{
Console.WriteLine("* ExceptionTests - reported call stack:\n{0}", reportedCallStack);
const string frameParserRegex = @"\s+at\s.+\.(?<memberName>[^(.]+)\([^)]*\)\sin\s(?<filePath>.*)\:line\s(?<lineNumber>[\d]+)";

using (var sr = new StringReader(reportedCallStack))
try
{
const string frameParserRegex = @"\s+at\s.+\.(?<memberName>[^(.]+)\([^)]*\)\sin\s(?<filePath>.*)\:line\s(?<lineNumber>[\d]+)";

using (var sr = new StringReader(reportedCallStack))
{
for (int i = 0; i < skipFrames; i++)
sr.ReadLine();
string frame = sr.ReadLine();
Assert.NotNull(frame);
var match = Regex.Match(frame, frameParserRegex);
Assert.True(match.Success);
Assert.Equal(expectedStackFrame.CallerMemberName, match.Groups["memberName"].Value);
Assert.Equal(expectedStackFrame.SourceFilePath, match.Groups["filePath"].Value);
Assert.Equal(expectedStackFrame.SourceLineNumber, Convert.ToInt32(match.Groups["lineNumber"].Value));
}
}
catch
{
for (int i = 0; i < skipFrames; i++)
sr.ReadLine();
string frame = sr.ReadLine();
Assert.NotNull(frame);
var match = Regex.Match(frame, frameParserRegex);
Assert.True(match.Success);
Assert.Equal(expectedStackFrame.CallerMemberName, match.Groups["memberName"].Value);
Assert.Equal(expectedStackFrame.SourceFilePath, match.Groups["filePath"].Value);
Assert.Equal(expectedStackFrame.SourceLineNumber, Convert.ToInt32(match.Groups["lineNumber"].Value));
Console.WriteLine("* ExceptionTests - reported call stack:\n{0}", reportedCallStack);
throw;
}
}

Expand Down

0 comments on commit 23096f8

Please sign in to comment.