Fix "flaky" DUtil test.
Ron Martin committed
Apr 8, 2022 at 20:05 UTC
68e54edc630099137b30ab946a80a8231a0d3d44
2 files changed
+50
-2
src/internal/WixBuildTools.TestSupport/WixAssert.cs
+47
@@ -91,5 +91,52 @@ namespace WixBuildTools.TestSupport
91
return this.stringComparer.GetHashCode((string)obj);
92
}
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
+ }
141
}
142
}
src/libs/dutil/test/DUtilUnitTest/DUtilTests.cpp
+3
-2
@@ -11,7 +11,7 @@ namespace DutilTests
11
public ref class DUtil
12
{
13
public:
14
- [Fact(Skip = "Flaky")]
14
+ [Fact]
15
void DUtilTraceErrorSourceFiltersOnTraceLevel()
16
{
17
DutilInitialize(&DutilTestTraceError);
@@ -21,7 +21,8 @@ namespace DutilTests
21
Dutil_TraceSetLevel(REPORT_DEBUG, FALSE);
22
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);
26
27
DutilUninitialize();
28
}