From 5b83429a56125c0d4c12ac2c614506aa16c96a2e Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Mon, 11 Jan 2016 17:35:42 -0800 Subject: [PATCH] Clean up trace listeners to make them usable for unit tests We had two trace listeners: one that conditionally threw and one which always threw. Neither were used anywhere. This deletes the former and updates the latter to not write out log entries to the console. Writing to the Console isn't really portable or unit-test friendly. --- .../Desktop/TestUtilities.Desktop.csproj | 2 +- .../Desktop/ThrowingTraceListener.cs | 48 +++++++++++ src/Test/Utilities/Desktop/TraceListener.cs | 81 ------------------- 3 files changed, 49 insertions(+), 82 deletions(-) create mode 100644 src/Test/Utilities/Desktop/ThrowingTraceListener.cs delete mode 100644 src/Test/Utilities/Desktop/TraceListener.cs diff --git a/src/Test/Utilities/Desktop/TestUtilities.Desktop.csproj b/src/Test/Utilities/Desktop/TestUtilities.Desktop.csproj index 51356bacd24..598b6a17f84 100644 --- a/src/Test/Utilities/Desktop/TestUtilities.Desktop.csproj +++ b/src/Test/Utilities/Desktop/TestUtilities.Desktop.csproj @@ -124,7 +124,7 @@ True TestResource.resx - + diff --git a/src/Test/Utilities/Desktop/ThrowingTraceListener.cs b/src/Test/Utilities/Desktop/ThrowingTraceListener.cs new file mode 100644 index 00000000000..89b10efd94d --- /dev/null +++ b/src/Test/Utilities/Desktop/ThrowingTraceListener.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Xunit; + +namespace Microsoft.CodeAnalysis +{ + // To enable this for a process, add the following to the app.config for the project: + // + // + // + // + // + // + // + // + // + // + // + public sealed class ThrowingTraceListener : TraceListener + { + public override void Fail(string message, string detailMessage) + { + throw new DebugAssertFailureException(message + Environment.NewLine + detailMessage); + } + + public override void Write(string message) + { + } + + public override void WriteLine(string message) + { + } + + [Serializable] + public class DebugAssertFailureException : Exception + { + public DebugAssertFailureException() { } + public DebugAssertFailureException(string message) : base(message) { } + public DebugAssertFailureException(string message, Exception inner) : base(message, inner) { } + protected DebugAssertFailureException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) : base(info, context) + { } + } + } +} diff --git a/src/Test/Utilities/Desktop/TraceListener.cs b/src/Test/Utilities/Desktop/TraceListener.cs deleted file mode 100644 index 8935f64af26..00000000000 --- a/src/Test/Utilities/Desktop/TraceListener.cs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Diagnostics; - -namespace Microsoft.CodeAnalysis -{ -#if DEBUG - // To enable, add to in *.exe.config, specifying the assembly-qualified - // type name with optional initializeData="..." for .ctor args. For instance: - // - // - // - // - // - // - // - // - // - // - public sealed class TraceListener : System.Diagnostics.TraceListener - { - private readonly bool _continueOnFailure; - - public TraceListener() - { - } - - public TraceListener(bool continueOnFailure) - { - _continueOnFailure = continueOnFailure; - } - - public override void Fail(string message, string detailMessage) - { - // Tools currently depend on the prefix appearing as an exception. - WriteLine(new AssertFailureException(string.Format("{0}\r\n{1}", message, detailMessage))); - WriteLine(new StackTrace(fNeedFileInfo: true)); - if (!_continueOnFailure) - { - Environment.Exit(-1); - } - } - - public override void Write(string message) - { - Console.Write(message); - } - - public override void WriteLine(string message) - { - Console.WriteLine(message); - } - } - - public sealed class ThrowingTraceListener : System.Diagnostics.TraceListener - { - public override void Fail(string message, string detailMessage) - { - throw new AssertFailureException(string.Format("{0}\r\n{1}", message, detailMessage)); - } - - public override void Write(string message) - { - Console.Write(message); - } - - public override void WriteLine(string message) - { - Console.WriteLine(message); - } - } - - public sealed class AssertFailureException : Exception - { - public AssertFailureException(string message) : base(message) { } - } -#endif -} -- GitLab