diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2022-05-13 11:40:45 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-05-13 12:35:15 -0500 |
commit | 031991f32f059b64374e6d257cbe573304dd577f (patch) | |
tree | 9d11ebb5d8595bf45c507f38d637b14915af7630 /src/internal/WixBuildTools.TestSupport/WixAssert.cs | |
parent | ad6d2636f60b04ee68656f99fb3bd56a86ba5983 (diff) | |
download | wix-031991f32f059b64374e6d257cbe573304dd577f.tar.gz wix-031991f32f059b64374e6d257cbe573304dd577f.tar.bz2 wix-031991f32f059b64374e6d257cbe573304dd577f.zip |
Add ability to skip tests at runtime, and skip long running cache tests
6665
Diffstat (limited to 'src/internal/WixBuildTools.TestSupport/WixAssert.cs')
-rw-r--r-- | src/internal/WixBuildTools.TestSupport/WixAssert.cs | 142 |
1 files changed, 0 insertions, 142 deletions
diff --git a/src/internal/WixBuildTools.TestSupport/WixAssert.cs b/src/internal/WixBuildTools.TestSupport/WixAssert.cs deleted file mode 100644 index 1db842c3..00000000 --- a/src/internal/WixBuildTools.TestSupport/WixAssert.cs +++ /dev/null | |||
@@ -1,142 +0,0 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixBuildTools.TestSupport | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Linq; | ||
8 | using System.Xml.Linq; | ||
9 | using Xunit; | ||
10 | |||
11 | public class WixAssert : Assert | ||
12 | { | ||
13 | public static void CompareLineByLine(string[] expectedLines, string[] actualLines) | ||
14 | { | ||
15 | var lineNumber = 0; | ||
16 | |||
17 | for (; lineNumber < expectedLines.Length && lineNumber < actualLines.Length; ++lineNumber) | ||
18 | { | ||
19 | WixAssert.StringEqual($"{lineNumber}: {expectedLines[lineNumber]}", $"{lineNumber}: {actualLines[lineNumber]}"); | ||
20 | } | ||
21 | |||
22 | var additionalExpectedLines = expectedLines.Length > lineNumber ? String.Join(Environment.NewLine, expectedLines.Skip(lineNumber).Select((s, i) => $"{lineNumber + i}: {s}")) : $"Missing {actualLines.Length - lineNumber} lines"; | ||
23 | var additionalActualLines = actualLines.Length > lineNumber ? String.Join(Environment.NewLine, actualLines.Skip(lineNumber).Select((s, i) => $"{lineNumber + i}: {s}")) : $"Missing {expectedLines.Length - lineNumber} lines"; | ||
24 | |||
25 | WixAssert.StringEqual(additionalExpectedLines, additionalActualLines); | ||
26 | } | ||
27 | |||
28 | public static void CompareXml(XContainer xExpected, XContainer xActual) | ||
29 | { | ||
30 | var expecteds = xExpected.Descendants().Select(x => $"{x.Name.LocalName}:{String.Join(",", x.Attributes().OrderBy(a => a.Name.LocalName).Select(a => $"{a.Name.LocalName}={a.Value}"))}"); | ||
31 | var actuals = xActual.Descendants().Select(x => $"{x.Name.LocalName}:{String.Join(",", x.Attributes().OrderBy(a => a.Name.LocalName).Select(a => $"{a.Name.LocalName}={a.Value}"))}"); | ||
32 | |||
33 | CompareLineByLine(expecteds.OrderBy(s => s).ToArray(), actuals.OrderBy(s => s).ToArray()); | ||
34 | } | ||
35 | |||
36 | public static void CompareXml(string expectedPath, string actualPath) | ||
37 | { | ||
38 | var expectedDoc = XDocument.Load(expectedPath, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo); | ||
39 | var actualDoc = XDocument.Load(actualPath, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo); | ||
40 | |||
41 | CompareXml(expectedDoc, actualDoc); | ||
42 | } | ||
43 | |||
44 | public static void Succeeded(int hr, string format, params object[] formatArgs) | ||
45 | { | ||
46 | if (0 > hr) | ||
47 | { | ||
48 | throw new SucceededException(hr, String.Format(format, formatArgs)); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | public static void StringCollectionEmpty(IList<string> collection) | ||
53 | { | ||
54 | if (collection.Count > 0) | ||
55 | { | ||
56 | Assert.True(false, $"The collection was expected to be empty, but instead was [{Environment.NewLine}\"{String.Join($"\", {Environment.NewLine}\"", collection)}\"{Environment.NewLine}]"); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | public static void StringEqual(string expected, string actual, bool ignoreCase = false) | ||
61 | { | ||
62 | var comparer = ignoreCase ? StringObjectEqualityComparer.InvariantCultureIgnoreCase : StringObjectEqualityComparer.InvariantCulture; | ||
63 | Assert.Equal<object>(expected, actual, comparer); | ||
64 | } | ||
65 | |||
66 | public static void NotStringEqual(string expected, string actual, bool ignoreCase = false) | ||
67 | { | ||
68 | var comparer = ignoreCase ? StringObjectEqualityComparer.InvariantCultureIgnoreCase : StringObjectEqualityComparer.InvariantCulture; | ||
69 | Assert.NotEqual<object>(expected, actual, comparer); | ||
70 | } | ||
71 | |||
72 | private class StringObjectEqualityComparer : IEqualityComparer<object> | ||
73 | { | ||
74 | public static readonly StringObjectEqualityComparer InvariantCultureIgnoreCase = new StringObjectEqualityComparer(true); | ||
75 | public static readonly StringObjectEqualityComparer InvariantCulture = new StringObjectEqualityComparer(false); | ||
76 | |||
77 | private readonly StringComparer stringComparer; | ||
78 | |||
79 | public StringObjectEqualityComparer(bool ignoreCase) | ||
80 | { | ||
81 | this.stringComparer = ignoreCase ? StringComparer.InvariantCultureIgnoreCase : StringComparer.InvariantCulture; | ||
82 | } | ||
83 | |||
84 | public new bool Equals(object x, object y) | ||
85 | { | ||
86 | return this.stringComparer.Equals((string)x,(string)y); | ||
87 | } | ||
88 | |||
89 | public int GetHashCode(object obj) | ||
90 | { | ||
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 | } | ||