summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose <pepone@users.noreply.github.com>2020-12-17 10:20:20 +0100
committerGitHub <noreply@github.com>2020-12-17 10:20:20 +0100
commit2a7b7db5676ce313451d257ef1a36290924dd936 (patch)
treedc9c1fd83c32f99068a5e19184d149d921829a21
parentReplace bogus version 3.7.5.2 with 3.7.5.0 in CSharp test projects (diff)
downloadice-2a7b7db5676ce313451d257ef1a36290924dd936.tar.bz2
ice-2a7b7db5676ce313451d257ef1a36290924dd936.tar.xz
ice-2a7b7db5676ce313451d257ef1a36290924dd936.zip
Use custom trace listener with tests to abort upon failure (#1202)
-rw-r--r--csharp/test/TestCommon/TestHelper.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/csharp/test/TestCommon/TestHelper.cs b/csharp/test/TestCommon/TestHelper.cs
index b2c0d723c88..aaffddc1554 100644
--- a/csharp/test/TestCommon/TestHelper.cs
+++ b/csharp/test/TestCommon/TestHelper.cs
@@ -26,6 +26,48 @@ namespace Test
public abstract class TestHelper
{
+ // A custom trace listener that always aborts the application upon failure.
+ internal class TestTraceListener : DefaultTraceListener
+ {
+ public override void Fail(string message)
+ {
+ Fail(message, null);
+ }
+
+ public override void Fail(string message, string detailMessage)
+ {
+ var sb = new StringBuilder();
+ sb.Append("failed:\n");
+ if (message != null && message.Length > 0)
+ {
+ sb.Append("message: ").Append(message).Append('\n');
+ }
+ if (detailMessage != null && detailMessage.Length > 0)
+ {
+ sb.Append("details: ").Append(detailMessage).Append('\n');
+ }
+ try
+ {
+ sb.Append(new StackTrace(fNeedFileInfo: true).ToString()).Append('\n');
+ }
+ catch
+ {
+ }
+
+ Console.WriteLine(sb.ToString());
+ Environment.Exit(1);
+ }
+ }
+
+ static TestHelper()
+ {
+ // Replace the default trace listener that is responsible of displaying the retry/abort dialog
+ // with our custom trace listener that always aborts upon failure.
+ // see: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.defaulttracelistener?view=net-5.0#remarks
+ Trace.Listeners.Clear();
+ Trace.Listeners.Add(new TestTraceListener());
+ }
+
public abstract void run(string[] args);
public string getTestEndpoint(int num = 0, string protocol = "")