mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-16 20:23:20 +08:00
Add tests for generic exception formatting
This commit is contained in:
parent
a6b96e9297
commit
7e1142df58
@ -6,6 +6,8 @@ public static class TestExceptions
|
|||||||
|
|
||||||
public static bool GenericMethodThatThrows<T0, T1, TRet>(int? number) => throw new InvalidOperationException("Throwing!");
|
public static bool GenericMethodThatThrows<T0, T1, TRet>(int? number) => throw new InvalidOperationException("Throwing!");
|
||||||
|
|
||||||
|
public static bool MethodThatThrowsGenericException<T>() => throw new GenericException<T>("Throwing!", default);
|
||||||
|
|
||||||
public static void ThrowWithInnerException()
|
public static void ThrowWithInnerException()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -42,3 +44,6 @@ public static class TestExceptions
|
|||||||
return ("key", new List<T>());
|
return ("key", new List<T>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma warning disable CS9113 // Parameter is unread.
|
||||||
|
public class GenericException<T>(string message, T value) : Exception(message);
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
[38;5;7mSpectre.Console.Tests.Data.[0m[38;5;15mGenericException<Spectre.Console.IAnsiConsole>[0m: [1;38;5;9mThrowing![0m
|
||||||
|
[38;5;8mat[0m [38;5;12mbool[0m [38;5;7mSpectre.Console.Tests.Data.TestExceptions.[0m[38;5;11mMethodThatThrowsGenericException<T>[0m[38;5;7m()[0m [38;5;8min[0m [38;5;7m{ProjectDirectory}Data/[0m[1;38;5;11mExceptions.cs[0m[38;5;8m:[0m[38;5;12m9[0m
|
||||||
|
[38;5;8mat[0m [38;5;12mvoid[0m [38;5;7mSpectre.Console.Tests.Unit.ExceptionTests.<>c.[0m[38;5;11m<Should_Write_GenericException>b__8_0[0m[38;5;7m()[0m [38;5;8min[0m [38;5;7m{ProjectDirectory}Unit/[0m[1;38;5;11mExceptionTests.cs[0m[38;5;8m:[0m[38;5;12m134[0m
|
||||||
|
[38;5;8mat[0m [38;5;12mException[0m [38;5;7mSpectre.Console.Tests.Unit.ExceptionTests.[0m[38;5;11mGetException[0m[38;5;7m([0m[38;5;12mAction[0m [38;5;7maction)[0m [38;5;8min[0m [38;5;7m{ProjectDirectory}Unit/[0m[1;38;5;11mExceptionTests.cs[0m[38;5;8m:[0m[38;5;12m147[0m
|
@ -0,0 +1,4 @@
|
|||||||
|
[38;5;15mGenericException<IAnsiConsole>[0m: [1;38;5;9mThrowing![0m
|
||||||
|
[38;5;8mat[0m [38;5;12mbool[0m [38;5;7mSpectre.Console.Tests.Data.TestExceptions.[0m[38;5;11mMethodThatThrowsGenericException<T>[0m[38;5;7m()[0m [38;5;8min[0m [38;5;7m{ProjectDirectory}Data/[0m[1;38;5;11mExceptions.cs[0m[38;5;8m:[0m[38;5;12m9[0m
|
||||||
|
[38;5;8mat[0m [38;5;12mvoid[0m [38;5;7mSpectre.Console.Tests.Unit.ExceptionTests.<>c.[0m[38;5;11m<Should_Write_GenericException>b__8_0[0m[38;5;7m()[0m [38;5;8min[0m [38;5;7m{ProjectDirectory}Unit/[0m[1;38;5;11mExceptionTests.cs[0m[38;5;8m:[0m[38;5;12m134[0m
|
||||||
|
[38;5;8mat[0m [38;5;12mException[0m [38;5;7mSpectre.Console.Tests.Unit.ExceptionTests.[0m[38;5;11mGetException[0m[38;5;7m([0m[38;5;12mAction[0m [38;5;7maction)[0m [38;5;8min[0m [38;5;7m{ProjectDirectory}Unit/[0m[1;38;5;11mExceptionTests.cs[0m[38;5;8m:[0m[38;5;12m147[0m
|
@ -123,6 +123,23 @@ public sealed class ExceptionTests
|
|||||||
return Verifier.Verify(result);
|
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<IAnsiConsole>());
|
||||||
|
|
||||||
|
// When
|
||||||
|
var result = console.WriteNormalizedException(dex, exceptionFormats);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
return Verifier.Verify(result).UseParameters(exceptionFormats);
|
||||||
|
}
|
||||||
|
|
||||||
public static Exception GetException(Action action)
|
public static Exception GetException(Action action)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
Loading…
x
Reference in New Issue
Block a user