diff --git a/src/Tests/Spectre.Console.Tests/Data/Exceptions.cs b/src/Tests/Spectre.Console.Tests/Data/Exceptions.cs index b011a90..a7e066e 100644 --- a/src/Tests/Spectre.Console.Tests/Data/Exceptions.cs +++ b/src/Tests/Spectre.Console.Tests/Data/Exceptions.cs @@ -6,6 +6,8 @@ public static class TestExceptions public static bool GenericMethodThatThrows(int? number) => throw new InvalidOperationException("Throwing!"); + public static bool MethodThatThrowsGenericException() => throw new GenericException("Throwing!", default); + public static void ThrowWithInnerException() { try @@ -42,3 +44,6 @@ public static class TestExceptions return ("key", new List()); } } + +#pragma warning disable CS9113 // Parameter is unread. +public class GenericException(string message, T value) : Exception(message); diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Exception/GenericException.Output_exceptionFormats=Default.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Exception/GenericException.Output_exceptionFormats=Default.verified.txt new file mode 100644 index 0000000..08cbf07 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Exception/GenericException.Output_exceptionFormats=Default.verified.txt @@ -0,0 +1,4 @@ +Spectre.Console.Tests.Data.GenericException: Throwing! + at bool Spectre.Console.Tests.Data.TestExceptions.MethodThatThrowsGenericException() in {ProjectDirectory}Data/Exceptions.cs:9 + at void Spectre.Console.Tests.Unit.ExceptionTests.<>c.b__8_0() in {ProjectDirectory}Unit/ExceptionTests.cs:134 + at Exception Spectre.Console.Tests.Unit.ExceptionTests.GetException(Action action) in {ProjectDirectory}Unit/ExceptionTests.cs:147 diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Exception/GenericException.Output_exceptionFormats=ShortenTypes.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Exception/GenericException.Output_exceptionFormats=ShortenTypes.verified.txt new file mode 100644 index 0000000..8da66ac --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Exception/GenericException.Output_exceptionFormats=ShortenTypes.verified.txt @@ -0,0 +1,4 @@ +GenericException: Throwing! + at bool Spectre.Console.Tests.Data.TestExceptions.MethodThatThrowsGenericException() in {ProjectDirectory}Data/Exceptions.cs:9 + at void Spectre.Console.Tests.Unit.ExceptionTests.<>c.b__8_0() in {ProjectDirectory}Unit/ExceptionTests.cs:134 + at Exception Spectre.Console.Tests.Unit.ExceptionTests.GetException(Action action) in {ProjectDirectory}Unit/ExceptionTests.cs:147 diff --git a/src/Tests/Spectre.Console.Tests/Unit/ExceptionTests.cs b/src/Tests/Spectre.Console.Tests/Unit/ExceptionTests.cs index a8eb258..2bc90de 100644 --- a/src/Tests/Spectre.Console.Tests/Unit/ExceptionTests.cs +++ b/src/Tests/Spectre.Console.Tests/Unit/ExceptionTests.cs @@ -123,6 +123,23 @@ public sealed class ExceptionTests return Verifier.Verify(result); } + [Theory] + [InlineData(ExceptionFormats.Default)] + [InlineData(ExceptionFormats.ShortenTypes)] + [Expectation("GenericException")] + public Task Should_Write_GenericException(ExceptionFormats exceptionFormats) + { + // Given + var console = new TestConsole { EmitAnsiSequences = true }.Width(1024); + var dex = GetException(() => TestExceptions.MethodThatThrowsGenericException()); + + // When + var result = console.WriteNormalizedException(dex, exceptionFormats); + + // Then + return Verifier.Verify(result).UseParameters(exceptionFormats); + } + public static Exception GetException(Action action) { try