Skip to content

Commit f86faac

Browse files
committed
Updated call stack collection mechanism to collect complete call stacks
1 parent 497862c commit f86faac

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

test/Microsoft.ML.TestFramework/BaseTestBaseline.cs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Diagnostics;
78
using System.IO;
8-
using System.Runtime.ExceptionServices;
99
using System.Text;
1010
using System.Text.RegularExpressions;
1111
using System.Threading;
@@ -81,7 +81,7 @@ protected BaseTestBaseline(ITestOutputHelper output) : base(output)
8181
protected IHostEnvironment Env => _env;
8282
protected MLContext ML;
8383
private bool _normal;
84-
private readonly List<Exception> _failures = new List<Exception>();
84+
private int _failures = 0;
8585

8686
protected override void Initialize()
8787
{
@@ -127,7 +127,7 @@ protected override void Cleanup()
127127
IsPassing ? "passed" : "failed");
128128

129129
if (!_normal)
130-
Done();
130+
Assert.Equal(0, _failures);
131131

132132
Contracts.AssertValue(LogWriter);
133133
LogWriter.Dispose();
@@ -138,7 +138,7 @@ protected override void Cleanup()
138138

139139
protected bool IsActive { get { return LogWriter != null; } }
140140

141-
protected bool IsPassing { get { return _failures.Count == 0; } }
141+
protected bool IsPassing { get { return _failures == 0; } }
142142

143143
// Called by a test to signal normal completion. If this is not called before the
144144
// TestScope is disposed, we assume the test was aborted.
@@ -148,18 +148,7 @@ protected void Done()
148148
Contracts.Assert(!_normal, "Done() should only be called once!");
149149
_normal = true;
150150

151-
switch (_failures.Count)
152-
{
153-
case 0:
154-
break;
155-
156-
case 1:
157-
ExceptionDispatchInfo.Capture(_failures[0]).Throw();
158-
break;
159-
160-
default:
161-
throw new AggregateException(_failures.ToArray());
162-
}
151+
Assert.Equal(0, _failures);
163152
}
164153

165154
protected bool Check(bool f, string msg)
@@ -179,16 +168,16 @@ protected bool Check(bool f, string msg, params object[] args)
179168
protected void Fail(string fmt, params object[] args)
180169
{
181170
Contracts.Assert(IsActive);
182-
try
183-
{
184-
throw new InvalidOperationException(string.Format(fmt, args));
185-
}
186-
catch (Exception ex)
171+
_failures++;
172+
Log($"*** Failure #{_failures}: " + fmt, args);
173+
174+
var stackTrace = new StackTrace(true);
175+
for (int i = 0; i < stackTrace.FrameCount; i++)
187176
{
188-
_failures.Add(ex);
177+
var frame = stackTrace.GetFrame(i);
178+
Log($"\t\t{frame.GetMethod()} {frame.GetFileName()} {frame.GetFileLineNumber()}");
189179
}
190180

191-
Log("*** Failure: " + fmt, args);
192181
}
193182

194183
protected void Log(string msg)

0 commit comments

Comments
 (0)