From 68e54edc630099137b30ab946a80a8231a0d3d44 Mon Sep 17 00:00:00 2001 From: Ron Martin Date: Fri, 8 Apr 2022 20:05:40 -0400 Subject: Fix "flaky" DUtil test. --- .../WixBuildTools.TestSupport/WixAssert.cs | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/internal/WixBuildTools.TestSupport/WixAssert.cs') diff --git a/src/internal/WixBuildTools.TestSupport/WixAssert.cs b/src/internal/WixBuildTools.TestSupport/WixAssert.cs index 6d14bc89..1db842c3 100644 --- a/src/internal/WixBuildTools.TestSupport/WixAssert.cs +++ b/src/internal/WixBuildTools.TestSupport/WixAssert.cs @@ -91,5 +91,52 @@ namespace WixBuildTools.TestSupport return this.stringComparer.GetHashCode((string)obj); } } + + // There appears to have been a bug in VC++, which might or might not have been partially + // or completely corrected. It was unable to disambiguate a call to: + // Xunit::Assert::Throws(System::Type^, System::Action^) + // from a call to: + // Xunit::Assert::Throws(System::Type^, System::Func^) + // that implicitly ignores its return value. + // + // The ambiguity may have been reported by some versions of the compiler and not by others. + // Some versions of the compiler may not have emitted any code in this situation, making it + // appear that the test has passed when, in fact, it hasn't been run. + // + // This situation is not an issue for C#. + // + // The following method is used to isolate DUtilTests in order to overcome the above problem. + + /// + /// This shim allows C++/CLR code to call the Xunit method with the same signature + /// without getting an ambiguous overload error. If the specified test code + /// fails to generate an exception of the exact specified type, an assertion + /// exception is thrown. Otherwise, execution flow proceeds as normal. + /// + /// The type name of the expected exception. + /// An Action delegate to run the test code. + public static new void Throws(System.Action testCode) + where T : System.Exception + { + Xunit.Assert.Throws(testCode); + } + + // This shim has been tested, but is not currently used anywhere. It was provided + // at the same time as the preceding shim because it involved the same overload + // resolution conflict. + + /// + /// This shim allows C++/CLR code to call the Xunit method with the same signature + /// without getting an ambiguous overload error. If the specified test code + /// fails to generate an exception of the exact specified type, an assertion + /// exception is thrown. Otherwise, execution flow proceeds as normal. + /// + /// The type object associated with exceptions of the expected type. + /// An Action delegate to run the test code. + /// An exception of a type other than the type specified, is such an exception is thrown. + public static new System.Exception Throws(System.Type exceptionType, System.Action testCode) + { + return Xunit.Assert.Throws(exceptionType, testCode); + } } } -- cgit v1.2.3-55-g6feb