提交 5b83429a 编写于 作者: J Jason Malinowski

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.
上级 5e0e499c
......@@ -124,7 +124,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>TestResource.resx</DependentUpon>
</Compile>
<Compile Include="TraceListener.cs" />
<Compile Include="ThrowingTraceListener.cs" />
<Compile Include="Traits.cs" />
<Compile Include="Win32Res.cs" />
</ItemGroup>
......
// 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:
//
// <configuration>
// <system.diagnostics>
// <trace>
// <listeners>
// <remove name="Default" />
// <add name="ThrowingTraceListener" type="Microsoft.CodeAnalysis.ThrowingTraceListener, Roslyn.Test.Utilities.Desktop" />
// </listeners>
// </trace>
// </system.diagnostics>
//</configuration>
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)
{ }
}
}
}
// 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 <listeners> in *.exe.config, specifying the assembly-qualified
// type name with optional initializeData="..." for .ctor args. For instance:
// <configuration>
// <system.diagnostics>
// <trace>
// <listeners>
// <add name=""
// type="Microsoft.CodeAnalysis.TraceListener, Microsoft.CodeAnalysis, Version=..."
// initializeData="true"/>
// <remove name="Default"/>
// </listeners>
// </trace>
// </system.diagnostics>
// </configuration>
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
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册