diff options
author | Ron Martin <cpuwzd@comcast.net> | 2022-04-08 20:05:40 -0400 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-04-13 10:21:23 -0500 |
commit | 68e54edc630099137b30ab946a80a8231a0d3d44 (patch) | |
tree | fa5db883fbb62c1335fd0f1a462e66814aa4cec0 | |
parent | 75f4dce4ea53b82f99932573f27ccfc799d0c5c1 (diff) | |
download | wix-68e54edc630099137b30ab946a80a8231a0d3d44.tar.gz wix-68e54edc630099137b30ab946a80a8231a0d3d44.tar.bz2 wix-68e54edc630099137b30ab946a80a8231a0d3d44.zip |
Fix "flaky" DUtil test.
-rw-r--r-- | src/internal/WixBuildTools.TestSupport/WixAssert.cs | 47 | ||||
-rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/DUtilTests.cpp | 5 |
2 files changed, 50 insertions, 2 deletions
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 | |||
91 | return this.stringComparer.GetHashCode((string)obj); | 91 | return this.stringComparer.GetHashCode((string)obj); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | |||
95 | // There appears to have been a bug in VC++, which might or might not have been partially | ||
96 | // or completely corrected. It was unable to disambiguate a call to: | ||
97 | // Xunit::Assert::Throws(System::Type^, System::Action^) | ||
98 | // from a call to: | ||
99 | // Xunit::Assert::Throws(System::Type^, System::Func<System::Object^>^) | ||
100 | // that implicitly ignores its return value. | ||
101 | // | ||
102 | // The ambiguity may have been reported by some versions of the compiler and not by others. | ||
103 | // Some versions of the compiler may not have emitted any code in this situation, making it | ||
104 | // appear that the test has passed when, in fact, it hasn't been run. | ||
105 | // | ||
106 | // This situation is not an issue for C#. | ||
107 | // | ||
108 | // The following method is used to isolate DUtilTests in order to overcome the above problem. | ||
109 | |||
110 | /// <summary> | ||
111 | /// This shim allows C++/CLR code to call the Xunit method with the same signature | ||
112 | /// without getting an ambiguous overload error. If the specified test code | ||
113 | /// fails to generate an exception of the exact specified type, an assertion | ||
114 | /// exception is thrown. Otherwise, execution flow proceeds as normal. | ||
115 | /// </summary> | ||
116 | /// <typeparam name="T">The type name of the expected exception.</typeparam> | ||
117 | /// <param name="testCode">An Action delegate to run the test code.</param> | ||
118 | public static new void Throws<T>(System.Action testCode) | ||
119 | where T : System.Exception | ||
120 | { | ||
121 | Xunit.Assert.Throws<T>(testCode); | ||
122 | } | ||
123 | |||
124 | // This shim has been tested, but is not currently used anywhere. It was provided | ||
125 | // at the same time as the preceding shim because it involved the same overload | ||
126 | // resolution conflict. | ||
127 | |||
128 | /// <summary> | ||
129 | /// This shim allows C++/CLR code to call the Xunit method with the same signature | ||
130 | /// without getting an ambiguous overload error. If the specified test code | ||
131 | /// fails to generate an exception of the exact specified type, an assertion | ||
132 | /// exception is thrown. Otherwise, execution flow proceeds as normal. | ||
133 | /// </summary> | ||
134 | /// <param name="exceptionType">The type object associated with exceptions of the expected type.</param> | ||
135 | /// <param name="testCode">An Action delegate to run the test code.</param> | ||
136 | /// <returns>An exception of a type other than the type specified, is such an exception is thrown.</returns> | ||
137 | public static new System.Exception Throws(System.Type exceptionType, System.Action testCode) | ||
138 | { | ||
139 | return Xunit.Assert.Throws(exceptionType, testCode); | ||
140 | } | ||
94 | } | 141 | } |
95 | } | 142 | } |
diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilTests.cpp b/src/libs/dutil/test/DUtilUnitTest/DUtilTests.cpp index c3ac6a79..d92a9272 100644 --- a/src/libs/dutil/test/DUtilUnitTest/DUtilTests.cpp +++ b/src/libs/dutil/test/DUtilUnitTest/DUtilTests.cpp | |||
@@ -11,7 +11,7 @@ namespace DutilTests | |||
11 | public ref class DUtil | 11 | public ref class DUtil |
12 | { | 12 | { |
13 | public: | 13 | public: |
14 | [Fact(Skip = "Flaky")] | 14 | [Fact] |
15 | void DUtilTraceErrorSourceFiltersOnTraceLevel() | 15 | void DUtilTraceErrorSourceFiltersOnTraceLevel() |
16 | { | 16 | { |
17 | DutilInitialize(&DutilTestTraceError); | 17 | DutilInitialize(&DutilTestTraceError); |
@@ -21,7 +21,8 @@ namespace DutilTests | |||
21 | Dutil_TraceSetLevel(REPORT_DEBUG, FALSE); | 21 | Dutil_TraceSetLevel(REPORT_DEBUG, FALSE); |
22 | 22 | ||
23 | Action^ action = gcnew Action(this, &DUtil::CallDutilTraceErrorSource); | 23 | Action^ action = gcnew Action(this, &DUtil::CallDutilTraceErrorSource); |
24 | Assert::Throws<Exception^>(action); | 24 | // See the comments in WixBuildTools.WixAssert for details. |
25 | WixAssert::Throws<Exception^>(action); | ||
25 | 26 | ||
26 | DutilUninitialize(); | 27 | DutilUninitialize(); |
27 | } | 28 | } |