diff options
| author | Rob Mensching <rob@firegiant.com> | 2018-10-04 13:33:08 -0700 |
|---|---|---|
| committer | Bob Arnson <bob@firegiant.com> | 2018-10-04 18:20:52 -0400 |
| commit | 240f3594db6f633ece6818afd28dde1e1ef6b36c (patch) | |
| tree | ab75f516217afa280944b2198a42c69b9a1b9cc0 /src/test/WixToolsetTest.WixCop | |
| parent | 917bfd43985af3afaac0b3a1d97a89a58bde1f2f (diff) | |
| download | wix-240f3594db6f633ece6818afd28dde1e1ef6b36c.tar.gz wix-240f3594db6f633ece6818afd28dde1e1ef6b36c.tar.bz2 wix-240f3594db6f633ece6818afd28dde1e1ef6b36c.zip | |
Fix WixCop namespaces and some C# modernization
Diffstat (limited to 'src/test/WixToolsetTest.WixCop')
10 files changed, 945 insertions, 0 deletions
diff --git a/src/test/WixToolsetTest.WixCop/ConverterFixture.cs b/src/test/WixToolsetTest.WixCop/ConverterFixture.cs new file mode 100644 index 00000000..86931d5a --- /dev/null +++ b/src/test/WixToolsetTest.WixCop/ConverterFixture.cs | |||
| @@ -0,0 +1,452 @@ | |||
| 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 WixToolsetTest.WixCop | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.IO; | ||
| 7 | using System.Text; | ||
| 8 | using System.Xml.Linq; | ||
| 9 | using WixToolset.Data; | ||
| 10 | using WixToolset.Extensibility; | ||
| 11 | using WixToolset.Extensibility.Services; | ||
| 12 | using WixToolset.Tools.WixCop; | ||
| 13 | using Xunit; | ||
| 14 | |||
| 15 | public class ConverterFixture | ||
| 16 | { | ||
| 17 | private static readonly XNamespace Wix4Namespace = "http://wixtoolset.org/schemas/v4/wxs"; | ||
| 18 | |||
| 19 | [Fact] | ||
| 20 | public void EnsuresDeclaration() | ||
| 21 | { | ||
| 22 | var parse = String.Join(Environment.NewLine, | ||
| 23 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 24 | " <Fragment />", | ||
| 25 | "</Wix>"); | ||
| 26 | |||
| 27 | var expected = String.Join(Environment.NewLine, | ||
| 28 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 29 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 30 | " <Fragment />", | ||
| 31 | "</Wix>"); | ||
| 32 | |||
| 33 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 34 | |||
| 35 | var messaging = new DummyMessaging(); | ||
| 36 | var converter = new Converter(messaging, 2, null, null); | ||
| 37 | |||
| 38 | var errors = converter.ConvertDocument(document); | ||
| 39 | |||
| 40 | var actual = UnformattedDocumentString(document); | ||
| 41 | |||
| 42 | Assert.Equal(1, errors); | ||
| 43 | Assert.Equal(expected, actual); | ||
| 44 | } | ||
| 45 | |||
| 46 | [Fact] | ||
| 47 | public void EnsuresUtf8Declaration() | ||
| 48 | { | ||
| 49 | var parse = String.Join(Environment.NewLine, | ||
| 50 | "<?xml version='1.0'?>", | ||
| 51 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 52 | " <Fragment />", | ||
| 53 | "</Wix>"); | ||
| 54 | |||
| 55 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 56 | |||
| 57 | var messaging = new DummyMessaging(); | ||
| 58 | var converter = new Converter(messaging, 4, null, null); | ||
| 59 | |||
| 60 | var errors = converter.ConvertDocument(document); | ||
| 61 | |||
| 62 | Assert.Equal(1, errors); | ||
| 63 | Assert.Equal("1.0", document.Declaration.Version); | ||
| 64 | Assert.Equal("utf-8", document.Declaration.Encoding); | ||
| 65 | } | ||
| 66 | |||
| 67 | [Fact] | ||
| 68 | public void CanFixWhitespace() | ||
| 69 | { | ||
| 70 | var parse = String.Join(Environment.NewLine, | ||
| 71 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 72 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 73 | " <Fragment>", | ||
| 74 | " <Property Id='Prop'", | ||
| 75 | " Value='Val'>", | ||
| 76 | " </Property>", | ||
| 77 | " </Fragment>", | ||
| 78 | "</Wix>"); | ||
| 79 | |||
| 80 | var expected = String.Join(Environment.NewLine, | ||
| 81 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 82 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 83 | " <Fragment>", | ||
| 84 | " <Property Id=\"Prop\" Value=\"Val\" />", | ||
| 85 | " </Fragment>", | ||
| 86 | "</Wix>"); | ||
| 87 | |||
| 88 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 89 | |||
| 90 | var messaging = new DummyMessaging(); | ||
| 91 | var converter = new Converter(messaging, 4, null, null); | ||
| 92 | |||
| 93 | var errors = converter.ConvertDocument(document); | ||
| 94 | |||
| 95 | var actual = UnformattedDocumentString(document); | ||
| 96 | |||
| 97 | Assert.Equal(4, errors); | ||
| 98 | Assert.Equal(expected, actual); | ||
| 99 | } | ||
| 100 | |||
| 101 | [Fact] | ||
| 102 | public void CanFixCdataWhitespace() | ||
| 103 | { | ||
| 104 | var parse = String.Join(Environment.NewLine, | ||
| 105 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 106 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 107 | " <Fragment>", | ||
| 108 | " <Property Id='Prop'>", | ||
| 109 | " <![CDATA[1<2]]>", | ||
| 110 | " </Property>", | ||
| 111 | " </Fragment>", | ||
| 112 | "</Wix>"); | ||
| 113 | |||
| 114 | var expected = String.Join(Environment.NewLine, | ||
| 115 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 116 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 117 | " <Fragment>", | ||
| 118 | " <Property Id=\"Prop\"><![CDATA[1<2]]></Property>", | ||
| 119 | " </Fragment>", | ||
| 120 | "</Wix>"); | ||
| 121 | |||
| 122 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 123 | |||
| 124 | var messaging = new DummyMessaging(); | ||
| 125 | var converter = new Converter(messaging, 2, null, null); | ||
| 126 | |||
| 127 | var errors = converter.ConvertDocument(document); | ||
| 128 | |||
| 129 | var actual = UnformattedDocumentString(document); | ||
| 130 | |||
| 131 | Assert.Equal(expected, actual); | ||
| 132 | Assert.Equal(2, errors); | ||
| 133 | } | ||
| 134 | |||
| 135 | [Fact] | ||
| 136 | public void CanFixCdataWithWhitespace() | ||
| 137 | { | ||
| 138 | var parse = String.Join(Environment.NewLine, | ||
| 139 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 140 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 141 | " <Fragment>", | ||
| 142 | " <Property Id='Prop'>", | ||
| 143 | " <![CDATA[", | ||
| 144 | " 1<2", | ||
| 145 | " ]]>", | ||
| 146 | " </Property>", | ||
| 147 | " </Fragment>", | ||
| 148 | "</Wix>"); | ||
| 149 | |||
| 150 | var expected = String.Join(Environment.NewLine, | ||
| 151 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 152 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 153 | " <Fragment>", | ||
| 154 | " <Property Id=\"Prop\"><![CDATA[1<2]]></Property>", | ||
| 155 | " </Fragment>", | ||
| 156 | "</Wix>"); | ||
| 157 | |||
| 158 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 159 | |||
| 160 | var messaging = new DummyMessaging(); | ||
| 161 | var converter = new Converter(messaging, 2, null, null); | ||
| 162 | |||
| 163 | var errors = converter.ConvertDocument(document); | ||
| 164 | |||
| 165 | var actual = UnformattedDocumentString(document); | ||
| 166 | |||
| 167 | Assert.Equal(expected, actual); | ||
| 168 | Assert.Equal(2, errors); | ||
| 169 | } | ||
| 170 | |||
| 171 | [Fact] | ||
| 172 | public void CanConvertMainNamespace() | ||
| 173 | { | ||
| 174 | var parse = String.Join(Environment.NewLine, | ||
| 175 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 176 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", | ||
| 177 | " <Fragment />", | ||
| 178 | "</Wix>"); | ||
| 179 | |||
| 180 | var expected = String.Join(Environment.NewLine, | ||
| 181 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 182 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 183 | " <Fragment />", | ||
| 184 | "</Wix>"); | ||
| 185 | |||
| 186 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 187 | |||
| 188 | var messaging = new DummyMessaging(); | ||
| 189 | var converter = new Converter(messaging, 2, null, null); | ||
| 190 | |||
| 191 | var errors = converter.ConvertDocument(document); | ||
| 192 | |||
| 193 | var actual = UnformattedDocumentString(document); | ||
| 194 | |||
| 195 | Assert.Equal(1, errors); | ||
| 196 | //Assert.Equal(Wix4Namespace, document.Root.GetDefaultNamespace()); | ||
| 197 | Assert.Equal(expected, actual); | ||
| 198 | } | ||
| 199 | |||
| 200 | [Fact] | ||
| 201 | public void CanConvertNamedMainNamespace() | ||
| 202 | { | ||
| 203 | var parse = String.Join(Environment.NewLine, | ||
| 204 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 205 | "<w:Wix xmlns:w='http://schemas.microsoft.com/wix/2006/wi'>", | ||
| 206 | " <w:Fragment />", | ||
| 207 | "</w:Wix>"); | ||
| 208 | |||
| 209 | var expected = String.Join(Environment.NewLine, | ||
| 210 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 211 | "<w:Wix xmlns:w=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 212 | " <w:Fragment />", | ||
| 213 | "</w:Wix>"); | ||
| 214 | |||
| 215 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 216 | |||
| 217 | var messaging = new DummyMessaging(); | ||
| 218 | var converter = new Converter(messaging, 2, null, null); | ||
| 219 | |||
| 220 | var errors = converter.ConvertDocument(document); | ||
| 221 | |||
| 222 | var actual = UnformattedDocumentString(document); | ||
| 223 | |||
| 224 | Assert.Equal(1, errors); | ||
| 225 | Assert.Equal(expected, actual); | ||
| 226 | Assert.Equal(Wix4Namespace, document.Root.GetNamespaceOfPrefix("w")); | ||
| 227 | } | ||
| 228 | |||
| 229 | [Fact] | ||
| 230 | public void CanConvertNonWixDefaultNamespace() | ||
| 231 | { | ||
| 232 | var parse = String.Join(Environment.NewLine, | ||
| 233 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 234 | "<w:Wix xmlns:w='http://schemas.microsoft.com/wix/2006/wi' xmlns='http://schemas.microsoft.com/wix/UtilExtension'>", | ||
| 235 | " <w:Fragment>", | ||
| 236 | " <Test />", | ||
| 237 | " </w:Fragment>", | ||
| 238 | "</w:Wix>"); | ||
| 239 | |||
| 240 | var expected = String.Join(Environment.NewLine, | ||
| 241 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 242 | "<w:Wix xmlns:w=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns=\"http://wixtoolset.org/schemas/v4/wxs/util\">", | ||
| 243 | " <w:Fragment>", | ||
| 244 | " <Test />", | ||
| 245 | " </w:Fragment>", | ||
| 246 | "</w:Wix>"); | ||
| 247 | |||
| 248 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 249 | |||
| 250 | var messaging = new DummyMessaging(); | ||
| 251 | var converter = new Converter(messaging, 2, null, null); | ||
| 252 | |||
| 253 | var errors = converter.ConvertDocument(document); | ||
| 254 | |||
| 255 | var actual = UnformattedDocumentString(document); | ||
| 256 | |||
| 257 | Assert.Equal(expected, actual); | ||
| 258 | Assert.Equal(2, errors); | ||
| 259 | Assert.Equal(Wix4Namespace, document.Root.GetNamespaceOfPrefix("w")); | ||
| 260 | Assert.Equal("http://wixtoolset.org/schemas/v4/wxs/util", document.Root.GetDefaultNamespace()); | ||
| 261 | } | ||
| 262 | |||
| 263 | [Fact] | ||
| 264 | public void CanConvertExtensionNamespace() | ||
| 265 | { | ||
| 266 | var parse = String.Join(Environment.NewLine, | ||
| 267 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 268 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>", | ||
| 269 | " <Fragment />", | ||
| 270 | "</Wix>"); | ||
| 271 | |||
| 272 | var expected = String.Join(Environment.NewLine, | ||
| 273 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 274 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">", | ||
| 275 | " <Fragment />", | ||
| 276 | "</Wix>"); | ||
| 277 | |||
| 278 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 279 | |||
| 280 | var messaging = new DummyMessaging(); | ||
| 281 | var converter = new Converter(messaging, 2, null, null); | ||
| 282 | |||
| 283 | var errors = converter.ConvertDocument(document); | ||
| 284 | |||
| 285 | var actual = UnformattedDocumentString(document); | ||
| 286 | |||
| 287 | Assert.Equal(2, errors); | ||
| 288 | Assert.Equal(expected, actual); | ||
| 289 | Assert.Equal(Wix4Namespace, document.Root.GetDefaultNamespace()); | ||
| 290 | } | ||
| 291 | |||
| 292 | [Fact] | ||
| 293 | public void CanConvertMissingNamespace() | ||
| 294 | { | ||
| 295 | var parse = String.Join(Environment.NewLine, | ||
| 296 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 297 | "<Wix>", | ||
| 298 | " <Fragment />", | ||
| 299 | "</Wix>"); | ||
| 300 | |||
| 301 | var expected = String.Join(Environment.NewLine, | ||
| 302 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 303 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 304 | " <Fragment />", | ||
| 305 | "</Wix>"); | ||
| 306 | |||
| 307 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 308 | |||
| 309 | var messaging = new DummyMessaging(); | ||
| 310 | var converter = new Converter(messaging, 2, null, null); | ||
| 311 | |||
| 312 | var errors = converter.ConvertDocument(document); | ||
| 313 | |||
| 314 | var actual = UnformattedDocumentString(document); | ||
| 315 | |||
| 316 | Assert.Equal(1, errors); | ||
| 317 | Assert.Equal(expected, actual); | ||
| 318 | Assert.Equal(Wix4Namespace, document.Root.GetDefaultNamespace()); | ||
| 319 | } | ||
| 320 | |||
| 321 | [Fact] | ||
| 322 | public void CanConvertAnonymousFile() | ||
| 323 | { | ||
| 324 | var parse = String.Join(Environment.NewLine, | ||
| 325 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 326 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 327 | " <File Source='path\\to\\foo.txt' />", | ||
| 328 | "</Wix>"); | ||
| 329 | |||
| 330 | var expected = String.Join(Environment.NewLine, | ||
| 331 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 332 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 333 | " <File Id=\"foo.txt\" Source=\"path\\to\\foo.txt\" />", | ||
| 334 | "</Wix>"); | ||
| 335 | |||
| 336 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 337 | |||
| 338 | var messaging = new DummyMessaging(); | ||
| 339 | var converter = new Converter(messaging, 2, null, null); | ||
| 340 | |||
| 341 | var errors = converter.ConvertDocument(document); | ||
| 342 | |||
| 343 | var actual = UnformattedDocumentString(document); | ||
| 344 | |||
| 345 | Assert.Equal(1, errors); | ||
| 346 | Assert.Equal(expected, actual); | ||
| 347 | } | ||
| 348 | |||
| 349 | [Fact] | ||
| 350 | public void CanConvertSuppressSignatureValidationNo() | ||
| 351 | { | ||
| 352 | var parse = String.Join(Environment.NewLine, | ||
| 353 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 354 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 355 | " <MsiPackage SuppressSignatureValidation='no' />", | ||
| 356 | "</Wix>"); | ||
| 357 | |||
| 358 | var expected = String.Join(Environment.NewLine, | ||
| 359 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 360 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 361 | " <MsiPackage EnableSignatureValidation=\"yes\" />", | ||
| 362 | "</Wix>"); | ||
| 363 | |||
| 364 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 365 | |||
| 366 | var messaging = new DummyMessaging(); | ||
| 367 | var converter = new Converter(messaging, 2, null, null); | ||
| 368 | |||
| 369 | var errors = converter.ConvertDocument(document); | ||
| 370 | |||
| 371 | var actual = UnformattedDocumentString(document); | ||
| 372 | |||
| 373 | Assert.Equal(1, errors); | ||
| 374 | Assert.Equal(expected, actual); | ||
| 375 | } | ||
| 376 | |||
| 377 | [Fact] | ||
| 378 | public void CanConvertSuppressSignatureValidationYes() | ||
| 379 | { | ||
| 380 | var parse = String.Join(Environment.NewLine, | ||
| 381 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 382 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 383 | " <Payload SuppressSignatureValidation='yes' />", | ||
| 384 | "</Wix>"); | ||
| 385 | |||
| 386 | var expected = String.Join(Environment.NewLine, | ||
| 387 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 388 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 389 | " <Payload />", | ||
| 390 | "</Wix>"); | ||
| 391 | |||
| 392 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 393 | |||
| 394 | var messaging = new DummyMessaging(); | ||
| 395 | var converter = new Converter(messaging, 2, null, null); | ||
| 396 | |||
| 397 | var errors = converter.ConvertDocument(document); | ||
| 398 | |||
| 399 | var actual = UnformattedDocumentString(document); | ||
| 400 | |||
| 401 | Assert.Equal(1, errors); | ||
| 402 | Assert.Equal(expected, actual); | ||
| 403 | } | ||
| 404 | |||
| 405 | private static string UnformattedDocumentString(XDocument document) | ||
| 406 | { | ||
| 407 | var sb = new StringBuilder(); | ||
| 408 | |||
| 409 | using (var writer = new StringWriter(sb)) | ||
| 410 | { | ||
| 411 | document.Save(writer, SaveOptions.DisableFormatting); | ||
| 412 | } | ||
| 413 | |||
| 414 | return sb.ToString(); | ||
| 415 | } | ||
| 416 | |||
| 417 | private class DummyMessaging : IMessaging | ||
| 418 | { | ||
| 419 | public bool EncounteredError { get; set; } | ||
| 420 | |||
| 421 | public int LastErrorNumber { get; set; } | ||
| 422 | |||
| 423 | public bool ShowVerboseMessages { get; set; } | ||
| 424 | |||
| 425 | public bool SuppressAllWarnings { get; set; } | ||
| 426 | |||
| 427 | public bool WarningsAsError { get; set; } | ||
| 428 | |||
| 429 | public void ElevateWarningMessage(int warningNumber) | ||
| 430 | { | ||
| 431 | } | ||
| 432 | |||
| 433 | public string FormatMessage(Message message) => String.Empty; | ||
| 434 | |||
| 435 | public void SetListener(IMessageListener listener) | ||
| 436 | { | ||
| 437 | } | ||
| 438 | |||
| 439 | public void SuppressWarningMessage(int warningNumber) | ||
| 440 | { | ||
| 441 | } | ||
| 442 | |||
| 443 | public void Write(Message message) | ||
| 444 | { | ||
| 445 | } | ||
| 446 | |||
| 447 | public void Write(string message, bool verbose = false) | ||
| 448 | { | ||
| 449 | } | ||
| 450 | } | ||
| 451 | } | ||
| 452 | } | ||
diff --git a/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/ConvertedPreprocessor.wxs b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/ConvertedPreprocessor.wxs new file mode 100644 index 00000000..d6280185 --- /dev/null +++ b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/ConvertedPreprocessor.wxs | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <!-- 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. --> | ||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | <?include WixVer.wxi ?> | ||
| 7 | |||
| 8 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:swid="http://wixtoolset.org/schemas/v4/wxs/tag" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"> | ||
| 9 | <Product Id="*" Name="!(loc.ShortProduct) v$(var.WixMajorMinor) Core" Language="1033" Manufacturer="!(loc.Company)" Version="$(var.WixMsiProductVersion)" UpgradeCode="3618724B-2523-44F9-A908-866AA619504D"> | ||
| 10 | <Package Compressed="yes" InstallerVersion="200" SummaryCodepage="1252" InstallScope="perMachine" /> | ||
| 11 | <swid:Tag Regid="!(loc.Regid)" InstallDirectory="INSTALLFOLDER" /> | ||
| 12 | |||
| 13 | <MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed." /> | ||
| 14 | |||
| 15 | <MediaTemplate CabinetTemplate="core{0}.cab" /> | ||
| 16 | |||
| 17 | <Feature Id="Feature_WiX" Title="WiX Toolset" Level="1"> | ||
| 18 | <Component Id="Licensing" Directory="INSTALLFOLDER"> | ||
| 19 | <File Id="LICENSE.TXT" Source="LICENSE.TXT" /> | ||
| 20 | </Component> | ||
| 21 | |||
| 22 | <Component Id="ProductRegistration" Directory="INSTALLFOLDER"> | ||
| 23 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajorMinor)"> | ||
| 24 | <RegistryValue Name="InstallFolder" Value="[INSTALLFOLDER]" Type="string" /> | ||
| 25 | </RegistryKey> | ||
| 26 | </Component> | ||
| 27 | |||
| 28 | <Component Id="ProductFamilyRegistration" Directory="INSTALLFOLDER"> | ||
| 29 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajor).x"> | ||
| 30 | <RegistryValue Name="v$(var.WixMajorMinor)" Value="[INSTALLFOLDER]" Type="string" /> | ||
| 31 | </RegistryKey> | ||
| 32 | </Component> | ||
| 33 | |||
| 34 | <Component Id="ProductInformation" Directory="BinFolder"> | ||
| 35 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajorMinor)"> | ||
| 36 | <RegistryValue Name="InstallRoot" Value="[BinFolder]" Type="string" /> | ||
| 37 | <RegistryValue Name="ProductVersion" Value="[ProductVersion]" Type="string" /> | ||
| 38 | </RegistryKey> | ||
| 39 | |||
| 40 | <RemoveFolder Id="CleanupShortcutFolder" Directory="ShortcutFolder" On="uninstall" /> | ||
| 41 | </Component> | ||
| 42 | |||
| 43 | <Component Directory="BinFolder"> | ||
| 44 | <File Source="common\wixtoolset.org.ico"> | ||
| 45 | <?include ComRegistration.wxi ?> | ||
| 46 | </File> | ||
| 47 | <util:InternetShortcut Id="wixtoolset.org" Directory="ShortcutFolder" Name="WiX Home Page" Target="http://wixtoolset.org/" IconFile="file://[#wixtoolset.org.ico]" /> | ||
| 48 | </Component> | ||
| 49 | |||
| 50 | <ComponentGroupRef Id="ToolsetComponents" /> | ||
| 51 | <ComponentGroupRef Id="ExtensionComponents" /> | ||
| 52 | <ComponentGroupRef Id="LuxComponents" /> | ||
| 53 | <ComponentGroupRef Id="DocComponents" /> | ||
| 54 | </Feature> | ||
| 55 | |||
| 56 | <FeatureRef Id="Feature_MSBuild" /> | ||
| 57 | <FeatureRef Id="Feature_Intellisense2010" /> | ||
| 58 | <FeatureRef Id="Feature_Intellisense2012" /> | ||
| 59 | <FeatureRef Id="Feature_Intellisense2013" /> | ||
| 60 | <FeatureRef Id="Feature_Intellisense2015" /> | ||
| 61 | </Product> | ||
| 62 | </Wix> | ||
diff --git a/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/Preprocessor.wxs b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/Preprocessor.wxs new file mode 100644 index 00000000..2eb908c2 --- /dev/null +++ b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/Preprocessor.wxs | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <!-- 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. --> | ||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | <?include WixVer.wxi ?> | ||
| 7 | |||
| 8 | <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:swid="http://schemas.microsoft.com/wix/TagExtension" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"> | ||
| 9 | <Product Id="*" Name="!(loc.ShortProduct) v$(var.WixMajorMinor) Core" Language="1033" Manufacturer="!(loc.Company)" | ||
| 10 | Version="$(var.WixMsiProductVersion)" UpgradeCode="3618724B-2523-44F9-A908-866AA619504D"> | ||
| 11 | <Package Compressed="yes" InstallerVersion="200" SummaryCodepage="1252" InstallScope="perMachine" /> | ||
| 12 | <swid:Tag Regid="!(loc.Regid)" InstallDirectory="INSTALLFOLDER" /> | ||
| 13 | |||
| 14 | <MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed." /> | ||
| 15 | |||
| 16 | <MediaTemplate CabinetTemplate="core{0}.cab" /> | ||
| 17 | |||
| 18 | <Feature Id="Feature_WiX" Title="WiX Toolset" Level="1"> | ||
| 19 | <Component Id="Licensing" Directory="INSTALLFOLDER"> | ||
| 20 | <File Source="LICENSE.TXT" /> | ||
| 21 | </Component> | ||
| 22 | |||
| 23 | <Component Id="ProductRegistration" Directory="INSTALLFOLDER"> | ||
| 24 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajorMinor)"> | ||
| 25 | <RegistryValue Name="InstallFolder" Value="[INSTALLFOLDER]" Type="string" /> | ||
| 26 | </RegistryKey> | ||
| 27 | </Component> | ||
| 28 | |||
| 29 | <Component Id="ProductFamilyRegistration" Directory="INSTALLFOLDER"> | ||
| 30 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajor).x"> | ||
| 31 | <RegistryValue Name="v$(var.WixMajorMinor)" Value="[INSTALLFOLDER]" Type="string" /> | ||
| 32 | </RegistryKey> | ||
| 33 | </Component> | ||
| 34 | |||
| 35 | <Component Id="ProductInformation" Directory="BinFolder"> | ||
| 36 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajorMinor)"> | ||
| 37 | <RegistryValue Name="InstallRoot" Value="[BinFolder]" Type="string"/> | ||
| 38 | <RegistryValue Name="ProductVersion" Value="[ProductVersion]" Type="string" /> | ||
| 39 | </RegistryKey> | ||
| 40 | |||
| 41 | <RemoveFolder Id="CleanupShortcutFolder" Directory="ShortcutFolder" On="uninstall" /> | ||
| 42 | </Component> | ||
| 43 | |||
| 44 | <Component Directory="BinFolder"> | ||
| 45 | <File Source="common\wixtoolset.org.ico"> | ||
| 46 | <?include ComRegistration.wxi ?> | ||
| 47 | </File> | ||
| 48 | <util:InternetShortcut Id="wixtoolset.org" Directory="ShortcutFolder" Name="WiX Home Page" Target="http://wixtoolset.org/" IconFile="file://[#wixtoolset.org.ico]" /> | ||
| 49 | </Component> | ||
| 50 | |||
| 51 | <ComponentGroupRef Id="ToolsetComponents" /> | ||
| 52 | <ComponentGroupRef Id="ExtensionComponents" /> | ||
| 53 | <ComponentGroupRef Id="LuxComponents" /> | ||
| 54 | <ComponentGroupRef Id="DocComponents" /> | ||
| 55 | </Feature> | ||
| 56 | |||
| 57 | <FeatureRef Id="Feature_MSBuild" /> | ||
| 58 | <FeatureRef Id="Feature_Intellisense2010" /> | ||
| 59 | <FeatureRef Id="Feature_Intellisense2012" /> | ||
| 60 | <FeatureRef Id="Feature_Intellisense2013" /> | ||
| 61 | <FeatureRef Id="Feature_Intellisense2015" /> | ||
| 62 | </Product> | ||
| 63 | </Wix> | ||
diff --git a/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/wixcop.settings.xml b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/wixcop.settings.xml new file mode 100644 index 00000000..9d3ad496 --- /dev/null +++ b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/wixcop.settings.xml | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | <?xml version="1.0"?> | ||
| 2 | <Settings> | ||
| 3 | <IgnoreErrors> | ||
| 4 | <Test Id="WhitespacePrecedingNodeWrong"/> | ||
| 5 | <Test Id="WhitespacePrecedingEndElementWrong"/> | ||
| 6 | </IgnoreErrors> | ||
| 7 | <ErrorsAsWarnings/> | ||
| 8 | <ExemptFiles/> | ||
| 9 | </Settings> \ No newline at end of file | ||
diff --git a/src/test/WixToolsetTest.WixCop/TestData/SingleFile/ConvertedSingleFile.wxs b/src/test/WixToolsetTest.WixCop/TestData/SingleFile/ConvertedSingleFile.wxs new file mode 100644 index 00000000..aacb68fa --- /dev/null +++ b/src/test/WixToolsetTest.WixCop/TestData/SingleFile/ConvertedSingleFile.wxs | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <!-- 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. --> | ||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | <?include WixVer.wxi ?> | ||
| 7 | |||
| 8 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:swid="http://wixtoolset.org/schemas/v4/wxs/tag" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"> | ||
| 9 | <Product Id="*" Name="!(loc.ShortProduct) v$(var.WixMajorMinor) Core" Language="1033" Manufacturer="!(loc.Company)" Version="$(var.WixMsiProductVersion)" UpgradeCode="3618724B-2523-44F9-A908-866AA619504D"> | ||
| 10 | <Package Compressed="yes" InstallerVersion="200" SummaryCodepage="1252" InstallScope="perMachine" /> | ||
| 11 | <swid:Tag Regid="!(loc.Regid)" InstallDirectory="INSTALLFOLDER" /> | ||
| 12 | |||
| 13 | <MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed." /> | ||
| 14 | |||
| 15 | <MediaTemplate CabinetTemplate="core{0}.cab" /> | ||
| 16 | |||
| 17 | <Feature Id="Feature_WiX" Title="WiX Toolset" Level="1"> | ||
| 18 | <Component Id="Licensing" Directory="INSTALLFOLDER"> | ||
| 19 | <File Id="LICENSE.TXT" Source="LICENSE.TXT" /> | ||
| 20 | </Component> | ||
| 21 | |||
| 22 | <Component Id="ProductRegistration" Directory="INSTALLFOLDER"> | ||
| 23 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajorMinor)"> | ||
| 24 | <RegistryValue Name="InstallFolder" Value="[INSTALLFOLDER]" Type="string" /> | ||
| 25 | </RegistryKey> | ||
| 26 | </Component> | ||
| 27 | |||
| 28 | <Component Id="ProductFamilyRegistration" Directory="INSTALLFOLDER"> | ||
| 29 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajor).x"> | ||
| 30 | <RegistryValue Name="v$(var.WixMajorMinor)" Value="[INSTALLFOLDER]" Type="string" /> | ||
| 31 | </RegistryKey> | ||
| 32 | </Component> | ||
| 33 | |||
| 34 | <Component Id="ProductInformation" Directory="BinFolder"> | ||
| 35 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajorMinor)"> | ||
| 36 | <RegistryValue Name="InstallRoot" Value="[BinFolder]" Type="string" /> | ||
| 37 | <RegistryValue Name="ProductVersion" Value="[ProductVersion]" Type="string" /> | ||
| 38 | </RegistryKey> | ||
| 39 | |||
| 40 | <RemoveFolder Id="CleanupShortcutFolder" Directory="ShortcutFolder" On="uninstall" /> | ||
| 41 | </Component> | ||
| 42 | |||
| 43 | <Component Directory="BinFolder"> | ||
| 44 | <File Id="wixtoolset.org.ico" Source="common\wixtoolset.org.ico" /> | ||
| 45 | <util:InternetShortcut Id="wixtoolset.org" Directory="ShortcutFolder" Name="WiX Home Page" Target="http://wixtoolset.org/" IconFile="file://[#wixtoolset.org.ico]" /> | ||
| 46 | </Component> | ||
| 47 | |||
| 48 | <ComponentGroupRef Id="ToolsetComponents" /> | ||
| 49 | <ComponentGroupRef Id="ExtensionComponents" /> | ||
| 50 | <ComponentGroupRef Id="LuxComponents" /> | ||
| 51 | <ComponentGroupRef Id="DocComponents" /> | ||
| 52 | </Feature> | ||
| 53 | |||
| 54 | <FeatureRef Id="Feature_MSBuild" /> | ||
| 55 | <FeatureRef Id="Feature_Intellisense2010" /> | ||
| 56 | <FeatureRef Id="Feature_Intellisense2012" /> | ||
| 57 | <FeatureRef Id="Feature_Intellisense2013" /> | ||
| 58 | <FeatureRef Id="Feature_Intellisense2015" /> | ||
| 59 | </Product> | ||
| 60 | </Wix> | ||
diff --git a/src/test/WixToolsetTest.WixCop/TestData/SingleFile/SingleFile.wxs b/src/test/WixToolsetTest.WixCop/TestData/SingleFile/SingleFile.wxs new file mode 100644 index 00000000..310ae811 --- /dev/null +++ b/src/test/WixToolsetTest.WixCop/TestData/SingleFile/SingleFile.wxs | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <!-- 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. --> | ||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | <?include WixVer.wxi ?> | ||
| 7 | |||
| 8 | <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:swid="http://schemas.microsoft.com/wix/TagExtension" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"> | ||
| 9 | <Product Id="*" Name="!(loc.ShortProduct) v$(var.WixMajorMinor) Core" Language="1033" Manufacturer="!(loc.Company)" | ||
| 10 | Version="$(var.WixMsiProductVersion)" UpgradeCode="3618724B-2523-44F9-A908-866AA619504D"> | ||
| 11 | <Package Compressed="yes" InstallerVersion="200" SummaryCodepage="1252" InstallScope="perMachine" /> | ||
| 12 | <swid:Tag Regid="!(loc.Regid)" InstallDirectory="INSTALLFOLDER" /> | ||
| 13 | |||
| 14 | <MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed." /> | ||
| 15 | |||
| 16 | <MediaTemplate CabinetTemplate="core{0}.cab" /> | ||
| 17 | |||
| 18 | <Feature Id="Feature_WiX" Title="WiX Toolset" Level="1"> | ||
| 19 | <Component Id="Licensing" Directory="INSTALLFOLDER"> | ||
| 20 | <File Source="LICENSE.TXT" /> | ||
| 21 | </Component> | ||
| 22 | |||
| 23 | <Component Id="ProductRegistration" Directory="INSTALLFOLDER"> | ||
| 24 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajorMinor)"> | ||
| 25 | <RegistryValue Name="InstallFolder" Value="[INSTALLFOLDER]" Type="string" /> | ||
| 26 | </RegistryKey> | ||
| 27 | </Component> | ||
| 28 | |||
| 29 | <Component Id="ProductFamilyRegistration" Directory="INSTALLFOLDER"> | ||
| 30 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajor).x"> | ||
| 31 | <RegistryValue Name="v$(var.WixMajorMinor)" Value="[INSTALLFOLDER]" Type="string" /> | ||
| 32 | </RegistryKey> | ||
| 33 | </Component> | ||
| 34 | |||
| 35 | <Component Id="ProductInformation" Directory="BinFolder"> | ||
| 36 | <RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajorMinor)"> | ||
| 37 | <RegistryValue Name="InstallRoot" Value="[BinFolder]" Type="string"/> | ||
| 38 | <RegistryValue Name="ProductVersion" Value="[ProductVersion]" Type="string" /> | ||
| 39 | </RegistryKey> | ||
| 40 | |||
| 41 | <RemoveFolder Id="CleanupShortcutFolder" Directory="ShortcutFolder" On="uninstall" /> | ||
| 42 | </Component> | ||
| 43 | |||
| 44 | <Component Directory="BinFolder"> | ||
| 45 | <File Source="common\wixtoolset.org.ico" /> | ||
| 46 | <util:InternetShortcut Id="wixtoolset.org" Directory="ShortcutFolder" Name="WiX Home Page" Target="http://wixtoolset.org/" IconFile="file://[#wixtoolset.org.ico]" /> | ||
| 47 | </Component> | ||
| 48 | |||
| 49 | <ComponentGroupRef Id="ToolsetComponents" /> | ||
| 50 | <ComponentGroupRef Id="ExtensionComponents" /> | ||
| 51 | <ComponentGroupRef Id="LuxComponents" /> | ||
| 52 | <ComponentGroupRef Id="DocComponents" /> | ||
| 53 | </Feature> | ||
| 54 | |||
| 55 | <FeatureRef Id="Feature_MSBuild" /> | ||
| 56 | <FeatureRef Id="Feature_Intellisense2010" /> | ||
| 57 | <FeatureRef Id="Feature_Intellisense2012" /> | ||
| 58 | <FeatureRef Id="Feature_Intellisense2013" /> | ||
| 59 | <FeatureRef Id="Feature_Intellisense2015" /> | ||
| 60 | </Product> | ||
| 61 | </Wix> | ||
diff --git a/src/test/WixToolsetTest.WixCop/WixCopFixture.cs b/src/test/WixToolsetTest.WixCop/WixCopFixture.cs new file mode 100644 index 00000000..1025eac8 --- /dev/null +++ b/src/test/WixToolsetTest.WixCop/WixCopFixture.cs | |||
| @@ -0,0 +1,108 @@ | |||
| 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 WixToolsetTest.WixCop | ||
| 4 | { | ||
| 5 | using System.IO; | ||
| 6 | using WixBuildTools.TestSupport; | ||
| 7 | using Xunit; | ||
| 8 | |||
| 9 | public class WixCopFixture | ||
| 10 | { | ||
| 11 | [Fact] | ||
| 12 | public void CanConvertSingleFile() | ||
| 13 | { | ||
| 14 | const string beforeFileName = "SingleFile.wxs"; | ||
| 15 | const string afterFileName = "ConvertedSingleFile.wxs"; | ||
| 16 | var folder = TestData.Get(@"TestData\SingleFile"); | ||
| 17 | |||
| 18 | using (var fs = new DisposableFileSystem()) | ||
| 19 | { | ||
| 20 | var baseFolder = fs.GetFolder(true); | ||
| 21 | var targetFile = Path.Combine(baseFolder, beforeFileName); | ||
| 22 | File.Copy(Path.Combine(folder, beforeFileName), Path.Combine(baseFolder, beforeFileName)); | ||
| 23 | |||
| 24 | var runner = new WixCopRunner | ||
| 25 | { | ||
| 26 | FixErrors = true, | ||
| 27 | SearchPatterns = | ||
| 28 | { | ||
| 29 | targetFile, | ||
| 30 | }, | ||
| 31 | }; | ||
| 32 | |||
| 33 | var result = runner.Execute(); | ||
| 34 | |||
| 35 | Assert.Equal(2, result.ExitCode); | ||
| 36 | |||
| 37 | var actualLines = File.ReadAllLines(targetFile); | ||
| 38 | var expectedLines = File.ReadAllLines(Path.Combine(folder, afterFileName)); | ||
| 39 | |||
| 40 | for (var i = 0; i < actualLines.Length && i < expectedLines.Length; ++i) | ||
| 41 | { | ||
| 42 | Assert.Equal(expectedLines[i], actualLines[i]); | ||
| 43 | } | ||
| 44 | Assert.Equal(expectedLines.Length, actualLines.Length); | ||
| 45 | |||
| 46 | var runner2 = new WixCopRunner | ||
| 47 | { | ||
| 48 | FixErrors = true, | ||
| 49 | SearchPatterns = | ||
| 50 | { | ||
| 51 | targetFile, | ||
| 52 | }, | ||
| 53 | }; | ||
| 54 | |||
| 55 | var result2 = runner2.Execute(); | ||
| 56 | |||
| 57 | Assert.Equal(0, result2.ExitCode); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | [Fact] | ||
| 62 | public void RetainsPreprocessorInstructions() | ||
| 63 | { | ||
| 64 | const string beforeFileName = "Preprocessor.wxs"; | ||
| 65 | const string afterFileName = "ConvertedPreprocessor.wxs"; | ||
| 66 | var folder = TestData.Get(@"TestData\Preprocessor"); | ||
| 67 | |||
| 68 | using (var fs = new DisposableFileSystem()) | ||
| 69 | { | ||
| 70 | var baseFolder = fs.GetFolder(true); | ||
| 71 | var targetFile = Path.Combine(baseFolder, beforeFileName); | ||
| 72 | File.Copy(Path.Combine(folder, beforeFileName), Path.Combine(baseFolder, beforeFileName)); | ||
| 73 | |||
| 74 | var runner = new WixCopRunner | ||
| 75 | { | ||
| 76 | FixErrors = true, | ||
| 77 | SettingFile1 = Path.Combine(folder, "wixcop.settings.xml"), | ||
| 78 | SearchPatterns = | ||
| 79 | { | ||
| 80 | targetFile, | ||
| 81 | }, | ||
| 82 | }; | ||
| 83 | |||
| 84 | var result = runner.Execute(); | ||
| 85 | |||
| 86 | Assert.Equal(2, result.ExitCode); | ||
| 87 | |||
| 88 | var actualLines = File.ReadAllLines(targetFile); | ||
| 89 | var expectedLines = File.ReadAllLines(Path.Combine(folder, afterFileName)); | ||
| 90 | Assert.Equal(expectedLines, actualLines); | ||
| 91 | |||
| 92 | var runner2 = new WixCopRunner | ||
| 93 | { | ||
| 94 | FixErrors = true, | ||
| 95 | SettingFile1 = Path.Combine(folder, "wixcop.settings.xml"), | ||
| 96 | SearchPatterns = | ||
| 97 | { | ||
| 98 | targetFile, | ||
| 99 | }, | ||
| 100 | }; | ||
| 101 | |||
| 102 | var result2 = runner2.Execute(); | ||
| 103 | |||
| 104 | Assert.Equal(0, result2.ExitCode); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||
| 108 | } | ||
diff --git a/src/test/WixToolsetTest.WixCop/WixCopRunner.cs b/src/test/WixToolsetTest.WixCop/WixCopRunner.cs new file mode 100644 index 00000000..b831baa7 --- /dev/null +++ b/src/test/WixToolsetTest.WixCop/WixCopRunner.cs | |||
| @@ -0,0 +1,67 @@ | |||
| 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 WixToolsetTest.WixCop | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using WixToolset.Core; | ||
| 8 | using WixToolset.Core.TestPackage; | ||
| 9 | using WixToolset.Extensibility; | ||
| 10 | using WixToolset.Tools.WixCop; | ||
| 11 | using WixToolset.Tools.WixCop.CommandLine; | ||
| 12 | using WixToolset.Tools.WixCop.Interfaces; | ||
| 13 | |||
| 14 | public class WixCopRunner | ||
| 15 | { | ||
| 16 | public bool FixErrors { get; set; } | ||
| 17 | |||
| 18 | public List<string> SearchPatterns { get; } = new List<string>(); | ||
| 19 | |||
| 20 | public string SettingFile1 { get; set; } | ||
| 21 | |||
| 22 | public WixCopRunnerResult Execute() | ||
| 23 | { | ||
| 24 | var argList = new List<string>(); | ||
| 25 | |||
| 26 | if (this.FixErrors) | ||
| 27 | { | ||
| 28 | argList.Add("-f"); | ||
| 29 | } | ||
| 30 | |||
| 31 | if (!String.IsNullOrEmpty(this.SettingFile1)) | ||
| 32 | { | ||
| 33 | argList.Add($"-set1{this.SettingFile1}"); | ||
| 34 | } | ||
| 35 | |||
| 36 | foreach (var searchPattern in this.SearchPatterns) | ||
| 37 | { | ||
| 38 | argList.Add(searchPattern); | ||
| 39 | } | ||
| 40 | |||
| 41 | return WixCopRunner.Execute(argList.ToArray()); | ||
| 42 | } | ||
| 43 | |||
| 44 | public static WixCopRunnerResult Execute(string[] args) | ||
| 45 | { | ||
| 46 | var listener = new TestMessageListener(); | ||
| 47 | |||
| 48 | var serviceProvider = new WixToolsetServiceProvider(); | ||
| 49 | serviceProvider.AddService<IMessageListener>((x, y) => listener); | ||
| 50 | serviceProvider.AddService<IWixCopCommandLineParser>((x, y) => new WixCopCommandLineParser(x)); | ||
| 51 | |||
| 52 | var exitCode = Execute(serviceProvider, args); | ||
| 53 | |||
| 54 | return new WixCopRunnerResult | ||
| 55 | { | ||
| 56 | ExitCode = exitCode, | ||
| 57 | Messages = listener.Messages.ToArray() | ||
| 58 | }; | ||
| 59 | } | ||
| 60 | |||
| 61 | public static int Execute(IServiceProvider serviceProvider, string[] args) | ||
| 62 | { | ||
| 63 | var wixcop = new Program(); | ||
| 64 | return wixcop.Run(serviceProvider, args); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
diff --git a/src/test/WixToolsetTest.WixCop/WixCopRunnerResult.cs b/src/test/WixToolsetTest.WixCop/WixCopRunnerResult.cs new file mode 100644 index 00000000..1b35e491 --- /dev/null +++ b/src/test/WixToolsetTest.WixCop/WixCopRunnerResult.cs | |||
| @@ -0,0 +1,22 @@ | |||
| 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 WixToolsetTest.WixCop | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Linq; | ||
| 7 | using WixToolset.Data; | ||
| 8 | using Xunit; | ||
| 9 | |||
| 10 | public class WixCopRunnerResult | ||
| 11 | { | ||
| 12 | public int ExitCode { get; set; } | ||
| 13 | |||
| 14 | public Message[] Messages { get; set; } | ||
| 15 | |||
| 16 | public WixCopRunnerResult AssertSuccess() | ||
| 17 | { | ||
| 18 | Assert.True(0 == this.ExitCode, $"WixCop failed unexpectedly. Output:\r\n{String.Join("\r\n", this.Messages.Select(m => m.ToString()).ToArray())}"); | ||
| 19 | return this; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | } | ||
diff --git a/src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.csproj b/src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.csproj new file mode 100644 index 00000000..6b41b6b6 --- /dev/null +++ b/src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.csproj | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <!-- 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. --> | ||
| 3 | |||
| 4 | <Project Sdk="Microsoft.NET.Sdk"> | ||
| 5 | <PropertyGroup> | ||
| 6 | <TargetFramework>net461</TargetFramework> | ||
| 7 | <IsPackable>false</IsPackable> | ||
| 8 | <DebugType>embedded</DebugType> | ||
| 9 | </PropertyGroup> | ||
| 10 | |||
| 11 | <ItemGroup> | ||
| 12 | <None Remove="TestData\SingleFile\ConvertedSingleFile.wxs" /> | ||
| 13 | <None Remove="TestData\SingleFile\SingleFile.wxs" /> | ||
| 14 | </ItemGroup> | ||
| 15 | <ItemGroup> | ||
| 16 | <Content Include="TestData\SingleFile\ConvertedSingleFile.wxs" CopyToOutputDirectory="PreserveNewest" /> | ||
| 17 | <Content Include="TestData\SingleFile\SingleFile.wxs" CopyToOutputDirectory="PreserveNewest" /> | ||
| 18 | <Content Include="TestData\Preprocessor\ConvertedPreprocessor.wxs" CopyToOutputDirectory="PreserveNewest" /> | ||
| 19 | <Content Include="TestData\Preprocessor\Preprocessor.wxs" CopyToOutputDirectory="PreserveNewest" /> | ||
| 20 | <Content Include="TestData\Preprocessor\wixcop.settings.xml" CopyToOutputDirectory="PreserveNewest" /> | ||
| 21 | </ItemGroup> | ||
| 22 | |||
| 23 | <ItemGroup> | ||
| 24 | <ProjectReference Include="..\..\wixcop\WixCop.csproj" /> | ||
| 25 | </ItemGroup> | ||
| 26 | |||
| 27 | <ItemGroup> | ||
| 28 | <ProjectReference Include="$(WixToolsetRootFolder)\Core\src\WixToolset.Core.TestPackage\WixToolset.Core.TestPackage.csproj" Condition=" '$(Configuration)' == 'Debug' And Exists('$(WixToolsetRootFolder)\Core\README.md') " /> | ||
| 29 | <PackageReference Include="WixToolset.Core.TestPackage" Version="4.0.*" Condition=" '$(Configuration)' == 'Release' Or !Exists('$(WixToolsetRootFolder)\Core\README.md') " /> | ||
| 30 | </ItemGroup> | ||
| 31 | |||
| 32 | <ItemGroup> | ||
| 33 | <PackageReference Include="WixBuildTools.TestSupport" Version="4.0.*" /> | ||
| 34 | </ItemGroup> | ||
| 35 | |||
| 36 | <ItemGroup> | ||
| 37 | <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" /> | ||
| 38 | <PackageReference Include="xunit" Version="2.4.0" /> | ||
| 39 | <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
| 40 | </ItemGroup> | ||
| 41 | </Project> | ||
