From 264e34629e297b65ad4308fd001fd9c2a32e9e18 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 25 Oct 2024 14:45:32 +1100 Subject: [PATCH] . --- docs/combinations.md | 43 ++++++++++ docs/mdsource/combinations.source.md | 19 ++++- ...AddressExceptionsDisabledTest.verified.txt | 10 +++ ...ifyCombinationsTests.Defaults.verified.txt | 5 ++ ...nsTests.WithCaptureExceptions.verified.txt | 5 ++ .../VerifyCombinationsTests.cs | 85 +++++++++++++++++++ src/Verify.Expecto/Verifier_Combination.cs | 18 ++-- src/Verify.Fixie/Verifier_Combination.cs | 18 ++-- src/Verify.MSTest/Verifier_Combination.cs | 18 ++-- src/Verify.MSTest/VerifyBase_Combination.cs | 18 ++-- src/Verify.NUnit/Verifier_Combination.cs | 18 ++-- src/Verify.NUnit/VerifyBase_Combination.cs | 18 ++-- src/Verify.TUnit/Verifier_Combination.cs | 18 ++-- ...rifyCombinationsTests.UnBound.verified.txt | 72 ++++++++++++---- .../VerifyCombinationsTests.cs | 7 +- src/Verify.Xunit/Verifier.cs | 10 ++- src/Verify.Xunit/Verifier_Combination.cs | 18 ++-- src/Verify.Xunit/VerifyBase_Combination.cs | 18 ++-- src/Verify.XunitV3/Verifier_Combination.cs | 18 ++-- src/Verify.XunitV3/VerifyBase_Combination.cs | 18 ++-- src/Verify/Combinations/CombinationResults.cs | 4 +- .../InnerVerifier_Combinations.cs | 69 ++++++++++++--- .../Combinations/VerifyCombinationSettings.cs | 9 ++ 23 files changed, 401 insertions(+), 135 deletions(-) create mode 100644 src/StaticSettingsTests/VerifyCombinationsTests.BuildAddressExceptionsDisabledTest.verified.txt create mode 100644 src/StaticSettingsTests/VerifyCombinationsTests.Defaults.verified.txt create mode 100644 src/StaticSettingsTests/VerifyCombinationsTests.WithCaptureExceptions.verified.txt create mode 100644 src/StaticSettingsTests/VerifyCombinationsTests.cs create mode 100644 src/Verify/Combinations/VerifyCombinationSettings.cs diff --git a/docs/combinations.md b/docs/combinations.md index 2f5607e3d0..a9716cf2f4 100644 --- a/docs/combinations.md +++ b/docs/combinations.md @@ -7,6 +7,8 @@ To change this file edit the source file and then run MarkdownSnippets. # VerifyCombinations +VerifyCombinations allows all combinations of the given input lists to be executed, and the results all written to one file. + ## Method being tested @@ -70,6 +72,10 @@ public Task BuildAddressTest() ## CaptureExceptions +By default exceptions are not captured. + +To enable exception capture use `captureExceptions = true` + ```cs @@ -153,3 +159,40 @@ Actual value was 0., ``` snippet source | anchor + + +### Global CaptureExceptions + +Exception capture can be enable globally: + + + +```cs +[ModuleInitializer] +public static void Initialize() => + VerifyCombinationSettings.CaptureExceptions(); +``` +snippet source | anchor + + +If exception capture has been enabled globally, it can be disable at the method test level using `captureExceptions: false`. + + + +```cs +[Fact] +public Task BuildAddressExceptionsDisabledTest() +{ + int[] streetNumbers = [1, 10]; + string[] streets = ["Smith St", "Wallace St"]; + string[] cities = ["Sydney", "Chicago"]; + return VerifyCombinations( + BuildAddress, + streetNumbers, + streets, + cities, + captureExceptions: false); +} +``` +snippet source | anchor + diff --git a/docs/mdsource/combinations.source.md b/docs/mdsource/combinations.source.md index 01150287b5..fcc27143a4 100644 --- a/docs/mdsource/combinations.source.md +++ b/docs/mdsource/combinations.source.md @@ -1,5 +1,7 @@ # VerifyCombinations +VerifyCombinations allows all combinations of the given input lists to be executed, and the results all written to one file. + ## Method being tested @@ -18,9 +20,24 @@ snippet: VerifyCombinationsSample.BuildAddressTest.verified.txt ## CaptureExceptions +By default exceptions are not captured. + +To enable exception capture use `captureExceptions = true` + snippet: CombinationSample_CaptureExceptions ### Result -snippet: VerifyCombinationsSample.BuildAddressExceptionsTest.verified.txt \ No newline at end of file +snippet: VerifyCombinationsSample.BuildAddressExceptionsTest.verified.txt + + +### Global CaptureExceptions + +Exception capture can be enable globally: + +snippet: GlobalCaptureExceptions + +If exception capture has been enabled globally, it can be disable at the method test level using `captureExceptions: false`. + +snippet: CombinationSample_CaptureExceptionsFalse \ No newline at end of file diff --git a/src/StaticSettingsTests/VerifyCombinationsTests.BuildAddressExceptionsDisabledTest.verified.txt b/src/StaticSettingsTests/VerifyCombinationsTests.BuildAddressExceptionsDisabledTest.verified.txt new file mode 100644 index 0000000000..3125800fa2 --- /dev/null +++ b/src/StaticSettingsTests/VerifyCombinationsTests.BuildAddressExceptionsDisabledTest.verified.txt @@ -0,0 +1,10 @@ +{ + 1, Smith St , Sydney : 1 Smith St, Sydney, + 1, Smith St , Chicago: 1 Smith St, Chicago, + 1, Wallace St, Sydney : 1 Wallace St, Sydney, + 1, Wallace St, Chicago: 1 Wallace St, Chicago, + 10, Smith St , Sydney : 10 Smith St, Sydney, + 10, Smith St , Chicago: 10 Smith St, Chicago, + 10, Wallace St, Sydney : 10 Wallace St, Sydney, + 10, Wallace St, Chicago: 10 Wallace St, Chicago +} \ No newline at end of file diff --git a/src/StaticSettingsTests/VerifyCombinationsTests.Defaults.verified.txt b/src/StaticSettingsTests/VerifyCombinationsTests.Defaults.verified.txt new file mode 100644 index 0000000000..cf2f9e5b1e --- /dev/null +++ b/src/StaticSettingsTests/VerifyCombinationsTests.Defaults.verified.txt @@ -0,0 +1,5 @@ +{ + A: a, + b: b, + C: c +} \ No newline at end of file diff --git a/src/StaticSettingsTests/VerifyCombinationsTests.WithCaptureExceptions.verified.txt b/src/StaticSettingsTests/VerifyCombinationsTests.WithCaptureExceptions.verified.txt new file mode 100644 index 0000000000..ff17ad0705 --- /dev/null +++ b/src/StaticSettingsTests/VerifyCombinationsTests.WithCaptureExceptions.verified.txt @@ -0,0 +1,5 @@ +{ + A: a, + b: ArgumentException: B is not allowed, + C: c +} \ No newline at end of file diff --git a/src/StaticSettingsTests/VerifyCombinationsTests.cs b/src/StaticSettingsTests/VerifyCombinationsTests.cs new file mode 100644 index 0000000000..71e799f0a9 --- /dev/null +++ b/src/StaticSettingsTests/VerifyCombinationsTests.cs @@ -0,0 +1,85 @@ +#pragma warning disable VerifyCombinations +public class VerifyCombinationsTests +{ + #region GlobalCaptureExceptions + + [ModuleInitializer] + public static void Initialize() => + VerifyCombinationSettings.CaptureExceptions(); + + #endregion + + [Fact] + public Task Defaults() + { + string[] list = ["A", "b", "C"]; + return VerifyCombinations( + _ => _.ToLower(), + list); + } + + [Fact] + public Task WithCaptureExceptions() + { + string[] a = ["A", "b", "C"]; + return VerifyCombinations( + a => + { + if (a == "b") + { + throw new ArgumentException("B is not allowed"); + } + + return a.ToLower(); + }, + a, + captureExceptions: true); + } + + [Fact] + public Task WithNoCaptureExceptions() + { + string[] a = ["A", "b", "C"]; + return Assert.ThrowsAsync(() => + { + return VerifyCombinations( + a => + { + if (a == "b") + { + throw new ArgumentException("B is not allowed"); + } + + return a.ToLower(); + }, + a, + captureExceptions: false); + }); + } + public static string BuildAddress(int streetNumber, string street, string city) + { + ArgumentException.ThrowIfNullOrWhiteSpace(street); + ArgumentException.ThrowIfNullOrWhiteSpace(city); + ArgumentOutOfRangeException.ThrowIfLessThan(streetNumber, 1); + + return $"{streetNumber} {street}, {city}"; + } + + #region CombinationSample_CaptureExceptionsFalse + + [Fact] + public Task BuildAddressExceptionsDisabledTest() + { + int[] streetNumbers = [1, 10]; + string[] streets = ["Smith St", "Wallace St"]; + string[] cities = ["Sydney", "Chicago"]; + return VerifyCombinations( + BuildAddress, + streetNumbers, + streets, + cities, + captureExceptions: false); + } + + #endregion +} \ No newline at end of file diff --git a/src/Verify.Expecto/Verifier_Combination.cs b/src/Verify.Expecto/Verifier_Combination.cs index 7c3a2f0983..48d9daa6e0 100644 --- a/src/Verify.Expecto/Verifier_Combination.cs +++ b/src/Verify.Expecto/Verifier_Combination.cs @@ -9,7 +9,7 @@ public static Task VerifyCombinations( string name, Func method, IEnumerable a, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -25,7 +25,7 @@ public static Task VerifyCombinations( Func method, IEnumerable a, IEnumerable b, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -42,7 +42,7 @@ public static Task VerifyCombinations( IEnumerable a, IEnumerable b, IEnumerable c, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -60,7 +60,7 @@ public static Task VerifyCombinations( IEnumerable b, IEnumerable c, IEnumerable d, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -79,7 +79,7 @@ public static Task VerifyCombinations( IEnumerable c, IEnumerable d, IEnumerable e, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -99,7 +99,7 @@ public static Task VerifyCombinations( IEnumerable d, IEnumerable e, IEnumerable f, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -120,7 +120,7 @@ public static Task VerifyCombinations( IEnumerable e, IEnumerable f, IEnumerable g, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -142,7 +142,7 @@ public static Task VerifyCombinations( IEnumerable f, IEnumerable g, IEnumerable h, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -157,7 +157,7 @@ public static Task VerifyCombinations( string name, Func method, List> lists, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( diff --git a/src/Verify.Fixie/Verifier_Combination.cs b/src/Verify.Fixie/Verifier_Combination.cs index 27d562c758..43d47ad8e7 100644 --- a/src/Verify.Fixie/Verifier_Combination.cs +++ b/src/Verify.Fixie/Verifier_Combination.cs @@ -8,7 +8,7 @@ public static partial class Verifier public static SettingsTask VerifyCombinations( Func method, IEnumerable a, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -22,7 +22,7 @@ public static SettingsTask VerifyCombinations( Func method, IEnumerable a, IEnumerable b, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -37,7 +37,7 @@ public static SettingsTask VerifyCombinations( IEnumerable a, IEnumerable b, IEnumerable c, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -53,7 +53,7 @@ public static SettingsTask VerifyCombinations( IEnumerable b, IEnumerable c, IEnumerable d, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -70,7 +70,7 @@ public static SettingsTask VerifyCombinations( IEnumerable c, IEnumerable d, IEnumerable e, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -88,7 +88,7 @@ public static SettingsTask VerifyCombinations( IEnumerable d, IEnumerable e, IEnumerable f, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -107,7 +107,7 @@ public static SettingsTask VerifyCombinations( IEnumerable e, IEnumerable f, IEnumerable g, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -127,7 +127,7 @@ public static SettingsTask VerifyCombinations( IEnumerable f, IEnumerable g, IEnumerable h, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -140,7 +140,7 @@ public static SettingsTask VerifyCombinations( public static SettingsTask VerifyCombinations( Func method, List> lists, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( diff --git a/src/Verify.MSTest/Verifier_Combination.cs b/src/Verify.MSTest/Verifier_Combination.cs index cb87dfe1ed..b7447cc5cc 100644 --- a/src/Verify.MSTest/Verifier_Combination.cs +++ b/src/Verify.MSTest/Verifier_Combination.cs @@ -8,7 +8,7 @@ public static partial class Verifier public static SettingsTask VerifyCombinations( Func method, IEnumerable a, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -22,7 +22,7 @@ public static SettingsTask VerifyCombinations( Func method, IEnumerable a, IEnumerable b, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -37,7 +37,7 @@ public static SettingsTask VerifyCombinations( IEnumerable a, IEnumerable b, IEnumerable c, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -53,7 +53,7 @@ public static SettingsTask VerifyCombinations( IEnumerable b, IEnumerable c, IEnumerable d, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -70,7 +70,7 @@ public static SettingsTask VerifyCombinations( IEnumerable c, IEnumerable d, IEnumerable e, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -88,7 +88,7 @@ public static SettingsTask VerifyCombinations( IEnumerable d, IEnumerable e, IEnumerable f, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -107,7 +107,7 @@ public static SettingsTask VerifyCombinations( IEnumerable e, IEnumerable f, IEnumerable g, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -127,7 +127,7 @@ public static SettingsTask VerifyCombinations( IEnumerable f, IEnumerable g, IEnumerable h, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -140,7 +140,7 @@ public static SettingsTask VerifyCombinations( public static SettingsTask VerifyCombinations( Func method, List> lists, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( diff --git a/src/Verify.MSTest/VerifyBase_Combination.cs b/src/Verify.MSTest/VerifyBase_Combination.cs index f79e58c542..03aba286a2 100644 --- a/src/Verify.MSTest/VerifyBase_Combination.cs +++ b/src/Verify.MSTest/VerifyBase_Combination.cs @@ -10,7 +10,7 @@ public partial class VerifyBase public SettingsTask VerifyCombinations( Func method, IEnumerable a, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verifier.VerifyCombinations(method, a, captureExceptions, settings, sourceFile); @@ -21,7 +21,7 @@ public SettingsTask VerifyCombinations( Func method, IEnumerable a, IEnumerable b, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verifier.VerifyCombinations(method, a, b, captureExceptions, settings, sourceFile); @@ -33,7 +33,7 @@ public SettingsTask VerifyCombinations( IEnumerable a, IEnumerable b, IEnumerable c, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verifier.VerifyCombinations(method, a, b, c, captureExceptions, settings, sourceFile); @@ -46,7 +46,7 @@ public SettingsTask VerifyCombinations( IEnumerable b, IEnumerable c, IEnumerable d, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verifier.VerifyCombinations(method, a, b, c, d, captureExceptions, settings, sourceFile); @@ -60,7 +60,7 @@ public SettingsTask VerifyCombinations( IEnumerable c, IEnumerable d, IEnumerable e, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verifier.VerifyCombinations(method, a, b, c, d, e, captureExceptions, settings, sourceFile); @@ -75,7 +75,7 @@ public SettingsTask VerifyCombinations( IEnumerable d, IEnumerable e, IEnumerable f, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verifier.VerifyCombinations(method, a, b, c, d, e, f, captureExceptions, settings, sourceFile); @@ -91,7 +91,7 @@ public SettingsTask VerifyCombinations( IEnumerable e, IEnumerable f, IEnumerable g, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verifier.VerifyCombinations(method, a, b, c, d, e, f, g, captureExceptions, settings, sourceFile); @@ -108,7 +108,7 @@ public SettingsTask VerifyCombinations( IEnumerable f, IEnumerable g, IEnumerable h, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verifier.VerifyCombinations(method, a, b, c, d, e, f, g, h, captureExceptions, settings, sourceFile); @@ -118,7 +118,7 @@ public SettingsTask VerifyCombinations( public SettingsTask VerifyCombinations( Func method, List> lists, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verifier.VerifyCombinations(method, lists, captureExceptions, settings, sourceFile); diff --git a/src/Verify.NUnit/Verifier_Combination.cs b/src/Verify.NUnit/Verifier_Combination.cs index c145ed9169..cde1a3d09a 100644 --- a/src/Verify.NUnit/Verifier_Combination.cs +++ b/src/Verify.NUnit/Verifier_Combination.cs @@ -8,7 +8,7 @@ public static partial class Verifier public static SettingsTask VerifyCombinations( Func method, IEnumerable a, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -22,7 +22,7 @@ public static SettingsTask VerifyCombinations( Func method, IEnumerable a, IEnumerable b, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -37,7 +37,7 @@ public static SettingsTask VerifyCombinations( IEnumerable a, IEnumerable b, IEnumerable c, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -53,7 +53,7 @@ public static SettingsTask VerifyCombinations( IEnumerable b, IEnumerable c, IEnumerable d, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -70,7 +70,7 @@ public static SettingsTask VerifyCombinations( IEnumerable c, IEnumerable d, IEnumerable e, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -88,7 +88,7 @@ public static SettingsTask VerifyCombinations( IEnumerable d, IEnumerable e, IEnumerable f, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -107,7 +107,7 @@ public static SettingsTask VerifyCombinations( IEnumerable e, IEnumerable f, IEnumerable g, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -127,7 +127,7 @@ public static SettingsTask VerifyCombinations( IEnumerable f, IEnumerable g, IEnumerable h, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -140,7 +140,7 @@ public static SettingsTask VerifyCombinations( public static SettingsTask VerifyCombinations( Func method, List> lists, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( diff --git a/src/Verify.NUnit/VerifyBase_Combination.cs b/src/Verify.NUnit/VerifyBase_Combination.cs index ef71f3536c..2a5be6ae6b 100644 --- a/src/Verify.NUnit/VerifyBase_Combination.cs +++ b/src/Verify.NUnit/VerifyBase_Combination.cs @@ -8,7 +8,7 @@ public partial class VerifyBase public SettingsTask VerifyCombinations( Func method, IEnumerable a, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, captureExceptions, settings ?? this.settings, sourceFile); @@ -18,7 +18,7 @@ public SettingsTask VerifyCombinations( Func method, IEnumerable a, IEnumerable b, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, captureExceptions, settings ?? this.settings, sourceFile); @@ -29,7 +29,7 @@ public SettingsTask VerifyCombinations( IEnumerable a, IEnumerable b, IEnumerable c, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, captureExceptions, settings ?? this.settings, sourceFile); @@ -41,7 +41,7 @@ public SettingsTask VerifyCombinations( IEnumerable b, IEnumerable c, IEnumerable d, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, captureExceptions, settings ?? this.settings, sourceFile); @@ -54,7 +54,7 @@ public SettingsTask VerifyCombinations( IEnumerable c, IEnumerable d, IEnumerable e, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, captureExceptions, settings ?? this.settings, sourceFile); @@ -68,7 +68,7 @@ public SettingsTask VerifyCombinations( IEnumerable d, IEnumerable e, IEnumerable f, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, f, captureExceptions, settings ?? this.settings, sourceFile); @@ -83,7 +83,7 @@ public SettingsTask VerifyCombinations( IEnumerable e, IEnumerable f, IEnumerable g, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, f, g, captureExceptions, settings ?? this.settings, sourceFile); @@ -99,7 +99,7 @@ public SettingsTask VerifyCombinations( IEnumerable f, IEnumerable g, IEnumerable h, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, f, g, h, captureExceptions, settings ?? this.settings, sourceFile); @@ -108,7 +108,7 @@ public SettingsTask VerifyCombinations( public SettingsTask VerifyCombinations( Func method, List> lists, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, lists, captureExceptions, settings ?? this.settings, sourceFile); } \ No newline at end of file diff --git a/src/Verify.TUnit/Verifier_Combination.cs b/src/Verify.TUnit/Verifier_Combination.cs index 1fd9044ba5..5a935daf65 100644 --- a/src/Verify.TUnit/Verifier_Combination.cs +++ b/src/Verify.TUnit/Verifier_Combination.cs @@ -8,7 +8,7 @@ public static partial class Verifier public static SettingsTask VerifyCombinations( Func method, IEnumerable a, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -22,7 +22,7 @@ public static SettingsTask VerifyCombinations( Func method, IEnumerable a, IEnumerable b, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -37,7 +37,7 @@ public static SettingsTask VerifyCombinations( IEnumerable a, IEnumerable b, IEnumerable c, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -53,7 +53,7 @@ public static SettingsTask VerifyCombinations( IEnumerable b, IEnumerable c, IEnumerable d, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -70,7 +70,7 @@ public static SettingsTask VerifyCombinations( IEnumerable c, IEnumerable d, IEnumerable e, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -88,7 +88,7 @@ public static SettingsTask VerifyCombinations( IEnumerable d, IEnumerable e, IEnumerable f, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -107,7 +107,7 @@ public static SettingsTask VerifyCombinations( IEnumerable e, IEnumerable f, IEnumerable g, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -127,7 +127,7 @@ public static SettingsTask VerifyCombinations( IEnumerable f, IEnumerable g, IEnumerable h, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -140,7 +140,7 @@ public static SettingsTask VerifyCombinations( public static SettingsTask VerifyCombinations( Func method, List> lists, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( diff --git a/src/Verify.Xunit.Tests/VerifyCombinationsTests.UnBound.verified.txt b/src/Verify.Xunit.Tests/VerifyCombinationsTests.UnBound.verified.txt index a0db286f38..7f9a9b50c3 100644 --- a/src/Verify.Xunit.Tests/VerifyCombinationsTests.UnBound.verified.txt +++ b/src/Verify.Xunit.Tests/VerifyCombinationsTests.UnBound.verified.txt @@ -1,20 +1,56 @@ { - A, 1, True : a1True, - A, 1, False: a1False, - A, 2, True : a2True, - A, 2, False: a2False, - A, 3, True : a3True, - A, 3, False: a3False, - b, 1, True : b1True, - b, 1, False: b1False, - b, 2, True : b2True, - b, 2, False: b2False, - b, 3, True : b3True, - b, 3, False: b3False, - C, 1, True : c1True, - C, 1, False: c1False, - C, 2, True : c2True, - C, 2, False: c2False, - C, 3, True : c3True, - C, 3, False: c3False + A, 1, True , True : a1TrueTrue, + A, 1, True , 4 : a1TrueTrue, + A, 1, True , False: a1TrueTrue, + A, 1, False, True : a1FalseFalse, + A, 1, False, 4 : a1FalseFalse, + A, 1, False, False: a1FalseFalse, + A, 2, True , True : a2TrueTrue, + A, 2, True , 4 : a2TrueTrue, + A, 2, True , False: a2TrueTrue, + A, 2, False, True : a2FalseFalse, + A, 2, False, 4 : a2FalseFalse, + A, 2, False, False: a2FalseFalse, + A, 3, True , True : a3TrueTrue, + A, 3, True , 4 : a3TrueTrue, + A, 3, True , False: a3TrueTrue, + A, 3, False, True : a3FalseFalse, + A, 3, False, 4 : a3FalseFalse, + A, 3, False, False: a3FalseFalse, + b, 1, True , True : b1TrueTrue, + b, 1, True , 4 : b1TrueTrue, + b, 1, True , False: b1TrueTrue, + b, 1, False, True : b1FalseFalse, + b, 1, False, 4 : b1FalseFalse, + b, 1, False, False: b1FalseFalse, + b, 2, True , True : b2TrueTrue, + b, 2, True , 4 : b2TrueTrue, + b, 2, True , False: b2TrueTrue, + b, 2, False, True : b2FalseFalse, + b, 2, False, 4 : b2FalseFalse, + b, 2, False, False: b2FalseFalse, + b, 3, True , True : b3TrueTrue, + b, 3, True , 4 : b3TrueTrue, + b, 3, True , False: b3TrueTrue, + b, 3, False, True : b3FalseFalse, + b, 3, False, 4 : b3FalseFalse, + b, 3, False, False: b3FalseFalse, + C, 1, True , True : c1TrueTrue, + C, 1, True , 4 : c1TrueTrue, + C, 1, True , False: c1TrueTrue, + C, 1, False, True : c1FalseFalse, + C, 1, False, 4 : c1FalseFalse, + C, 1, False, False: c1FalseFalse, + C, 2, True , True : c2TrueTrue, + C, 2, True , 4 : c2TrueTrue, + C, 2, True , False: c2TrueTrue, + C, 2, False, True : c2FalseFalse, + C, 2, False, 4 : c2FalseFalse, + C, 2, False, False: c2FalseFalse, + C, 3, True , True : c3TrueTrue, + C, 3, True , 4 : c3TrueTrue, + C, 3, True , False: c3TrueTrue, + C, 3, False, True : c3FalseFalse, + C, 3, False, 4 : c3FalseFalse, + C, 3, False, False: c3FalseFalse } \ No newline at end of file diff --git a/src/Verify.Xunit.Tests/VerifyCombinationsTests.cs b/src/Verify.Xunit.Tests/VerifyCombinationsTests.cs index 6ec2f2d7a3..c138c5a562 100644 --- a/src/Verify.Xunit.Tests/VerifyCombinationsTests.cs +++ b/src/Verify.Xunit.Tests/VerifyCombinationsTests.cs @@ -100,11 +100,13 @@ public Task UnBound() string[] a = ["A", "b", "C"]; int[] b = [1, 2, 3]; bool[] c = [true, false]; + object[] d = [true, 4, false]; var list = new List> { a.Cast(), b.Cast(), - c.Cast() + c.Cast(), + d.Cast() }; return VerifyCombinations( _ => @@ -112,7 +114,8 @@ public Task UnBound() var a = (string)_[0]!; var b = (int)_[1]!; var c = (bool)_[2]!; - return a.ToLower() + b + c; + var d = (bool)_[2]!; + return a.ToLower() + b + c + d; }, list); } diff --git a/src/Verify.Xunit/Verifier.cs b/src/Verify.Xunit/Verifier.cs index c7896cf7c2..ffbd964dbe 100644 --- a/src/Verify.Xunit/Verifier.cs +++ b/src/Verify.Xunit/Verifier.cs @@ -67,7 +67,15 @@ static SettingsTask Verify( async settings => { using var verifier = BuildVerifier(settings, sourceFile, useUniqueDirectory); - return await verify(verifier); + try + { + return await verify(verifier); + } + catch (TargetInvocationException exception) + when (exception.InnerException != null) + { + throw exception.InnerException!; + } }); } } \ No newline at end of file diff --git a/src/Verify.Xunit/Verifier_Combination.cs b/src/Verify.Xunit/Verifier_Combination.cs index a84ace4cf7..3104718f9f 100644 --- a/src/Verify.Xunit/Verifier_Combination.cs +++ b/src/Verify.Xunit/Verifier_Combination.cs @@ -8,7 +8,7 @@ public static partial class Verifier public static SettingsTask VerifyCombinations( Func method, IEnumerable a, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -22,7 +22,7 @@ public static SettingsTask VerifyCombinations( Func method, IEnumerable a, IEnumerable b, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -37,7 +37,7 @@ public static SettingsTask VerifyCombinations( IEnumerable a, IEnumerable b, IEnumerable c, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -53,7 +53,7 @@ public static SettingsTask VerifyCombinations( IEnumerable b, IEnumerable c, IEnumerable d, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -70,7 +70,7 @@ public static SettingsTask VerifyCombinations( IEnumerable c, IEnumerable d, IEnumerable e, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -88,7 +88,7 @@ public static SettingsTask VerifyCombinations( IEnumerable d, IEnumerable e, IEnumerable f, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -107,7 +107,7 @@ public static SettingsTask VerifyCombinations( IEnumerable e, IEnumerable f, IEnumerable g, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -127,7 +127,7 @@ public static SettingsTask VerifyCombinations( IEnumerable f, IEnumerable g, IEnumerable h, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -140,7 +140,7 @@ public static SettingsTask VerifyCombinations( public static SettingsTask VerifyCombinations( Func method, List> lists, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( diff --git a/src/Verify.Xunit/VerifyBase_Combination.cs b/src/Verify.Xunit/VerifyBase_Combination.cs index a1ec86d5f2..04f5d6cf7b 100644 --- a/src/Verify.Xunit/VerifyBase_Combination.cs +++ b/src/Verify.Xunit/VerifyBase_Combination.cs @@ -8,7 +8,7 @@ public partial class VerifyBase public SettingsTask VerifyCombinations( Func method, IEnumerable a, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, captureExceptions, settings ?? this.settings, sourceFile); @@ -18,7 +18,7 @@ public SettingsTask VerifyCombinations( Func method, IEnumerable a, IEnumerable b, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, captureExceptions, settings ?? this.settings, sourceFile); @@ -29,7 +29,7 @@ public SettingsTask VerifyCombinations( IEnumerable a, IEnumerable b, IEnumerable c, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, captureExceptions, settings ?? this.settings, sourceFile); @@ -41,7 +41,7 @@ public SettingsTask VerifyCombinations( IEnumerable b, IEnumerable c, IEnumerable d, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, captureExceptions, settings ?? this.settings, sourceFile); @@ -54,7 +54,7 @@ public SettingsTask VerifyCombinations( IEnumerable c, IEnumerable d, IEnumerable e, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, captureExceptions, settings ?? this.settings, sourceFile); @@ -68,7 +68,7 @@ public SettingsTask VerifyCombinations( IEnumerable d, IEnumerable e, IEnumerable f, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, f, captureExceptions, settings ?? this.settings, sourceFile); @@ -83,7 +83,7 @@ public SettingsTask VerifyCombinations( IEnumerable e, IEnumerable f, IEnumerable g, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, f, g, captureExceptions, settings ?? this.settings, sourceFile); @@ -99,7 +99,7 @@ public SettingsTask VerifyCombinations( IEnumerable f, IEnumerable g, IEnumerable h, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, f, g, h, captureExceptions, settings ?? this.settings, sourceFile); @@ -108,7 +108,7 @@ public SettingsTask VerifyCombinations( public SettingsTask VerifyCombinations( Func method, List> lists, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, lists, captureExceptions, settings ?? this.settings, sourceFile); } \ No newline at end of file diff --git a/src/Verify.XunitV3/Verifier_Combination.cs b/src/Verify.XunitV3/Verifier_Combination.cs index a84ace4cf7..3104718f9f 100644 --- a/src/Verify.XunitV3/Verifier_Combination.cs +++ b/src/Verify.XunitV3/Verifier_Combination.cs @@ -8,7 +8,7 @@ public static partial class Verifier public static SettingsTask VerifyCombinations( Func method, IEnumerable a, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -22,7 +22,7 @@ public static SettingsTask VerifyCombinations( Func method, IEnumerable a, IEnumerable b, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -37,7 +37,7 @@ public static SettingsTask VerifyCombinations( IEnumerable a, IEnumerable b, IEnumerable c, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -53,7 +53,7 @@ public static SettingsTask VerifyCombinations( IEnumerable b, IEnumerable c, IEnumerable d, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -70,7 +70,7 @@ public static SettingsTask VerifyCombinations( IEnumerable c, IEnumerable d, IEnumerable e, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -88,7 +88,7 @@ public static SettingsTask VerifyCombinations( IEnumerable d, IEnumerable e, IEnumerable f, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -107,7 +107,7 @@ public static SettingsTask VerifyCombinations( IEnumerable e, IEnumerable f, IEnumerable g, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -127,7 +127,7 @@ public static SettingsTask VerifyCombinations( IEnumerable f, IEnumerable g, IEnumerable h, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( @@ -140,7 +140,7 @@ public static SettingsTask VerifyCombinations( public static SettingsTask VerifyCombinations( Func method, List> lists, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null, [CallerFilePath] string sourceFile = "") => Verify( diff --git a/src/Verify.XunitV3/VerifyBase_Combination.cs b/src/Verify.XunitV3/VerifyBase_Combination.cs index a1ec86d5f2..04f5d6cf7b 100644 --- a/src/Verify.XunitV3/VerifyBase_Combination.cs +++ b/src/Verify.XunitV3/VerifyBase_Combination.cs @@ -8,7 +8,7 @@ public partial class VerifyBase public SettingsTask VerifyCombinations( Func method, IEnumerable a, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, captureExceptions, settings ?? this.settings, sourceFile); @@ -18,7 +18,7 @@ public SettingsTask VerifyCombinations( Func method, IEnumerable a, IEnumerable b, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, captureExceptions, settings ?? this.settings, sourceFile); @@ -29,7 +29,7 @@ public SettingsTask VerifyCombinations( IEnumerable a, IEnumerable b, IEnumerable c, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, captureExceptions, settings ?? this.settings, sourceFile); @@ -41,7 +41,7 @@ public SettingsTask VerifyCombinations( IEnumerable b, IEnumerable c, IEnumerable d, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, captureExceptions, settings ?? this.settings, sourceFile); @@ -54,7 +54,7 @@ public SettingsTask VerifyCombinations( IEnumerable c, IEnumerable d, IEnumerable e, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, captureExceptions, settings ?? this.settings, sourceFile); @@ -68,7 +68,7 @@ public SettingsTask VerifyCombinations( IEnumerable d, IEnumerable e, IEnumerable f, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, f, captureExceptions, settings ?? this.settings, sourceFile); @@ -83,7 +83,7 @@ public SettingsTask VerifyCombinations( IEnumerable e, IEnumerable f, IEnumerable g, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, f, g, captureExceptions, settings ?? this.settings, sourceFile); @@ -99,7 +99,7 @@ public SettingsTask VerifyCombinations( IEnumerable f, IEnumerable g, IEnumerable h, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, a, b, c, d, e, f, g, h, captureExceptions, settings ?? this.settings, sourceFile); @@ -108,7 +108,7 @@ public SettingsTask VerifyCombinations( public SettingsTask VerifyCombinations( Func method, List> lists, - bool captureExceptions = false, + bool? captureExceptions = null, VerifySettings? settings = null) => Verifier.VerifyCombinations(method, lists, captureExceptions, settings ?? this.settings, sourceFile); } \ No newline at end of file diff --git a/src/Verify/Combinations/CombinationResults.cs b/src/Verify/Combinations/CombinationResults.cs index 30369a1c8f..aa21a7e69b 100644 --- a/src/Verify/Combinations/CombinationResults.cs +++ b/src/Verify/Combinations/CombinationResults.cs @@ -1,7 +1,7 @@ namespace VerifyTests; -public class CombinationResults(IReadOnlyList items, IReadOnlyList? keyTypes) +public class CombinationResults(IReadOnlyList items, IReadOnlyList keyTypes) { public IReadOnlyList Items { get; } = items; - public IReadOnlyList? KeyTypes { get; } = keyTypes; + public IReadOnlyList KeyTypes { get; } = keyTypes; } \ No newline at end of file diff --git a/src/Verify/Combinations/InnerVerifier_Combinations.cs b/src/Verify/Combinations/InnerVerifier_Combinations.cs index 1a19014cc7..1e506e6b0c 100644 --- a/src/Verify/Combinations/InnerVerifier_Combinations.cs +++ b/src/Verify/Combinations/InnerVerifier_Combinations.cs @@ -5,7 +5,7 @@ partial class InnerVerifier { public Task VerifyCombinations( Func method, - bool captureExceptions, + bool? captureExceptions, IEnumerable a) { var target = GetCombinations( @@ -20,7 +20,7 @@ public Task VerifyCombinations( public Task VerifyCombinations( Func method, - bool captureExceptions, + bool? captureExceptions, IEnumerable a, IEnumerable b) { @@ -40,7 +40,7 @@ public Task VerifyCombinations( public Task VerifyCombinations( Func method, - bool captureExceptions, + bool? captureExceptions, IEnumerable a, IEnumerable b, IEnumerable c) @@ -63,7 +63,7 @@ public Task VerifyCombinations( public Task VerifyCombinations( Func method, - bool captureExceptions, + bool? captureExceptions, IEnumerable a, IEnumerable b, IEnumerable c, @@ -89,7 +89,7 @@ public Task VerifyCombinations( public Task VerifyCombinations( Func method, - bool captureExceptions, + bool? captureExceptions, IEnumerable a, IEnumerable b, IEnumerable c, @@ -118,7 +118,7 @@ public Task VerifyCombinations( public Task VerifyCombinations( Func method, - bool captureExceptions, + bool? captureExceptions, IEnumerable a, IEnumerable b, IEnumerable c, @@ -150,7 +150,7 @@ public Task VerifyCombinations( public Task VerifyCombinations( Func method, - bool captureExceptions, + bool? captureExceptions, IEnumerable a, IEnumerable b, IEnumerable c, @@ -185,7 +185,7 @@ public Task VerifyCombinations( public Task VerifyCombinations( Func method, - bool captureExceptions, + bool? captureExceptions, IEnumerable a, IEnumerable b, IEnumerable c, @@ -223,7 +223,7 @@ public Task VerifyCombinations( public Task VerifyCombinations( Func method, - bool captureExceptions, + bool? captureExceptions, List> lists) { var target = GetCombinations(method, captureExceptions, lists, null); @@ -232,12 +232,16 @@ public Task VerifyCombinations( static CombinationResults GetCombinations( Func method, - bool captureExceptions, + bool? captureExceptions, List> lists, Type[]? keyTypes) { var items = new List(); var listCopy = lists.Select(_ => _.ToList()).ToList(); + keyTypes = BuildKeyTypes(lists, keyTypes); + + var resolvedCaptureException = captureExceptions ?? VerifyCombinationSettings.captureExceptions; + var combinationGenerator = new CombinationGenerator( listCopy, combo => @@ -249,13 +253,13 @@ static CombinationResults GetCombinations( value = method(combo); } catch (TargetInvocationException exception) - when (captureExceptions) + when (resolvedCaptureException) { items.Add(new(keys, exception.InnerException!)); return; } catch (Exception exception) - when (captureExceptions) + when (resolvedCaptureException) { items.Add(new(keys, exception)); return; @@ -266,4 +270,45 @@ static CombinationResults GetCombinations( combinationGenerator.Run(); return new(items, keyTypes); } + + static Type[] BuildKeyTypes(List> lists, Type[]? types) + { + if (types != null) + { + return types; + } + + types = new Type[lists.Count]; + for (var index = 0; index < lists.Count; index++) + { + var keys = lists[index]; + Type? type = null; + foreach (var key in keys) + { + if (key == null) + { + continue; + } + + var current = key.GetType(); + if (type == null) + { + type = current; + continue; + } + + if (type != current) + { + type = null; + break; + } + + type = current; + } + + types[index] = type ?? typeof(object); + } + + return types; + } } \ No newline at end of file diff --git a/src/Verify/Combinations/VerifyCombinationSettings.cs b/src/Verify/Combinations/VerifyCombinationSettings.cs new file mode 100644 index 0000000000..7c89f39aa3 --- /dev/null +++ b/src/Verify/Combinations/VerifyCombinationSettings.cs @@ -0,0 +1,9 @@ +namespace VerifyTests; + +public static class VerifyCombinationSettings +{ + internal static bool captureExceptions; + + public static void CaptureExceptions() => + captureExceptions = true; +} \ No newline at end of file