diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2018-09-02 16:12:29 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2018-09-13 12:05:57 -0500 |
| commit | 244b46cf7f3252d6dc3884ce184be901d1d173e5 (patch) | |
| tree | bd6fb4349b926001138d1a3415f93370d64e538f /src/test | |
| parent | 026d0af96fac5cd2d3d84ade657949ddc7144b99 (diff) | |
| download | wix-244b46cf7f3252d6dc3884ce184be901d1d173e5.tar.gz wix-244b46cf7f3252d6dc3884ce184be901d1d173e5.tar.bz2 wix-244b46cf7f3252d6dc3884ce184be901d1d173e5.zip | |
Migrate WixCop into Tools from wix4.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/wixcop/ConverterFixture.cs | 418 | ||||
| -rw-r--r-- | src/test/wixcop/TestData/SingleFile/ConvertedSingleFile.wxs | 60 | ||||
| -rw-r--r-- | src/test/wixcop/TestData/SingleFile/SingleFile.wxs | 61 | ||||
| -rw-r--r-- | src/test/wixcop/WixCopFixture.cs | 107 | ||||
| -rw-r--r-- | src/test/wixcop/WixCopTests.csproj | 41 |
5 files changed, 687 insertions, 0 deletions
diff --git a/src/test/wixcop/ConverterFixture.cs b/src/test/wixcop/ConverterFixture.cs new file mode 100644 index 00000000..45ccc33e --- /dev/null +++ b/src/test/wixcop/ConverterFixture.cs | |||
| @@ -0,0 +1,418 @@ | |||
| 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 WixTest.WixUnitTest | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.IO; | ||
| 7 | using System.Text; | ||
| 8 | using System.Xml.Linq; | ||
| 9 | using WixCop; | ||
| 10 | using WixToolset; | ||
| 11 | using WixToolset.Data; | ||
| 12 | using WixToolset.Extensibility; | ||
| 13 | using WixToolset.Extensibility.Services; | ||
| 14 | using Xunit; | ||
| 15 | |||
| 16 | public class ConverterFixture | ||
| 17 | { | ||
| 18 | private static readonly XNamespace Wix4Namespace = "http://wixtoolset.org/schemas/v4/wxs"; | ||
| 19 | |||
| 20 | [Fact] | ||
| 21 | public void EnsuresDeclaration() | ||
| 22 | { | ||
| 23 | string parse = String.Join(Environment.NewLine, | ||
| 24 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 25 | " <Fragment />", | ||
| 26 | "</Wix>"); | ||
| 27 | |||
| 28 | string expected = String.Join(Environment.NewLine, | ||
| 29 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 30 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 31 | " <Fragment />", | ||
| 32 | "</Wix>"); | ||
| 33 | |||
| 34 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 35 | |||
| 36 | var messaging = new DummyMessaging(); | ||
| 37 | Converter converter = new Converter(messaging, 2, null, null); | ||
| 38 | |||
| 39 | int errors = converter.ConvertDocument(document); | ||
| 40 | |||
| 41 | string actual = UnformattedDocumentString(document); | ||
| 42 | |||
| 43 | Assert.Equal(1, errors); | ||
| 44 | Assert.Equal(expected, actual); | ||
| 45 | } | ||
| 46 | |||
| 47 | [Fact] | ||
| 48 | public void EnsuresUtf8Declaration() | ||
| 49 | { | ||
| 50 | string parse = String.Join(Environment.NewLine, | ||
| 51 | "<?xml version='1.0'?>", | ||
| 52 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 53 | " <Fragment />", | ||
| 54 | "</Wix>"); | ||
| 55 | |||
| 56 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 57 | |||
| 58 | var messaging = new DummyMessaging(); | ||
| 59 | Converter converter = new Converter(messaging, 4, null, null); | ||
| 60 | |||
| 61 | int errors = converter.ConvertDocument(document); | ||
| 62 | |||
| 63 | Assert.Equal(1, errors); | ||
| 64 | Assert.Equal("1.0", document.Declaration.Version); | ||
| 65 | Assert.Equal("utf-8", document.Declaration.Encoding); | ||
| 66 | } | ||
| 67 | |||
| 68 | [Fact] | ||
| 69 | public void CanFixWhitespace() | ||
| 70 | { | ||
| 71 | string parse = String.Join(Environment.NewLine, | ||
| 72 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 73 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 74 | " <Fragment>", | ||
| 75 | " <Property Id='Prop'", | ||
| 76 | " Value='Val'>", | ||
| 77 | " </Property>", | ||
| 78 | " </Fragment>", | ||
| 79 | "</Wix>"); | ||
| 80 | |||
| 81 | string expected = String.Join(Environment.NewLine, | ||
| 82 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 83 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 84 | " <Fragment>", | ||
| 85 | " <Property Id=\"Prop\" Value=\"Val\" />", | ||
| 86 | " </Fragment>", | ||
| 87 | "</Wix>"); | ||
| 88 | |||
| 89 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 90 | |||
| 91 | var messaging = new DummyMessaging(); | ||
| 92 | Converter converter = new Converter(messaging, 4, null, null); | ||
| 93 | |||
| 94 | int errors = converter.ConvertDocument(document); | ||
| 95 | |||
| 96 | string actual = UnformattedDocumentString(document); | ||
| 97 | |||
| 98 | Assert.Equal(4, errors); | ||
| 99 | Assert.Equal(expected, actual); | ||
| 100 | } | ||
| 101 | |||
| 102 | [Fact] | ||
| 103 | public void CanFixCdataWhitespace() | ||
| 104 | { | ||
| 105 | string parse = String.Join(Environment.NewLine, | ||
| 106 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 107 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 108 | " <Fragment>", | ||
| 109 | " <Property Id='Prop'>", | ||
| 110 | " <![CDATA[1<2]]>", | ||
| 111 | " </Property>", | ||
| 112 | " </Fragment>", | ||
| 113 | "</Wix>"); | ||
| 114 | |||
| 115 | string expected = String.Join(Environment.NewLine, | ||
| 116 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 117 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 118 | " <Fragment>", | ||
| 119 | " <Property Id=\"Prop\"><![CDATA[1<2]]></Property>", | ||
| 120 | " </Fragment>", | ||
| 121 | "</Wix>"); | ||
| 122 | |||
| 123 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 124 | |||
| 125 | var messaging = new DummyMessaging(); | ||
| 126 | Converter converter = new Converter(messaging, 2, null, null); | ||
| 127 | |||
| 128 | int errors = converter.ConvertDocument(document); | ||
| 129 | |||
| 130 | string actual = UnformattedDocumentString(document); | ||
| 131 | |||
| 132 | Assert.Equal(2, errors); | ||
| 133 | Assert.Equal(expected, actual); | ||
| 134 | } | ||
| 135 | |||
| 136 | [Fact] | ||
| 137 | public void CanConvertMainNamespace() | ||
| 138 | { | ||
| 139 | string parse = String.Join(Environment.NewLine, | ||
| 140 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 141 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", | ||
| 142 | " <Fragment />", | ||
| 143 | "</Wix>"); | ||
| 144 | |||
| 145 | string expected = String.Join(Environment.NewLine, | ||
| 146 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 147 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 148 | " <Fragment />", | ||
| 149 | "</Wix>"); | ||
| 150 | |||
| 151 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 152 | |||
| 153 | var messaging = new DummyMessaging(); | ||
| 154 | Converter converter = new Converter(messaging, 2, null, null); | ||
| 155 | |||
| 156 | int errors = converter.ConvertDocument(document); | ||
| 157 | |||
| 158 | string actual = UnformattedDocumentString(document); | ||
| 159 | |||
| 160 | Assert.Equal(1, errors); | ||
| 161 | //Assert.Equal(Wix4Namespace, document.Root.GetDefaultNamespace()); | ||
| 162 | Assert.Equal(expected, actual); | ||
| 163 | } | ||
| 164 | |||
| 165 | [Fact] | ||
| 166 | public void CanConvertNamedMainNamespace() | ||
| 167 | { | ||
| 168 | string parse = String.Join(Environment.NewLine, | ||
| 169 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 170 | "<w:Wix xmlns:w='http://schemas.microsoft.com/wix/2006/wi'>", | ||
| 171 | " <w:Fragment />", | ||
| 172 | "</w:Wix>"); | ||
| 173 | |||
| 174 | string expected = String.Join(Environment.NewLine, | ||
| 175 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 176 | "<w:Wix xmlns:w=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 177 | " <w:Fragment />", | ||
| 178 | "</w:Wix>"); | ||
| 179 | |||
| 180 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 181 | |||
| 182 | var messaging = new DummyMessaging(); | ||
| 183 | Converter converter = new Converter(messaging, 2, null, null); | ||
| 184 | |||
| 185 | int errors = converter.ConvertDocument(document); | ||
| 186 | |||
| 187 | string actual = UnformattedDocumentString(document); | ||
| 188 | |||
| 189 | Assert.Equal(1, errors); | ||
| 190 | Assert.Equal(expected, actual); | ||
| 191 | Assert.Equal(Wix4Namespace, document.Root.GetNamespaceOfPrefix("w")); | ||
| 192 | } | ||
| 193 | |||
| 194 | [Fact] | ||
| 195 | public void CanConvertNonWixDefaultNamespace() | ||
| 196 | { | ||
| 197 | string parse = String.Join(Environment.NewLine, | ||
| 198 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 199 | "<w:Wix xmlns:w='http://schemas.microsoft.com/wix/2006/wi' xmlns='http://schemas.microsoft.com/wix/UtilExtension'>", | ||
| 200 | " <w:Fragment>", | ||
| 201 | " <Test />", | ||
| 202 | " </w:Fragment>", | ||
| 203 | "</w:Wix>"); | ||
| 204 | |||
| 205 | string expected = String.Join(Environment.NewLine, | ||
| 206 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 207 | "<w:Wix xmlns:w=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns=\"http://wixtoolset.org/schemas/v4/wxs/util\">", | ||
| 208 | " <w:Fragment>", | ||
| 209 | " <Test />", | ||
| 210 | " </w:Fragment>", | ||
| 211 | "</w:Wix>"); | ||
| 212 | |||
| 213 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 214 | |||
| 215 | var messaging = new DummyMessaging(); | ||
| 216 | Converter converter = new Converter(messaging, 2, null, null); | ||
| 217 | |||
| 218 | int errors = converter.ConvertDocument(document); | ||
| 219 | |||
| 220 | string actual = UnformattedDocumentString(document); | ||
| 221 | |||
| 222 | Assert.Equal(2, errors); | ||
| 223 | Assert.Equal(expected, actual); | ||
| 224 | Assert.Equal(Wix4Namespace, document.Root.GetNamespaceOfPrefix("w")); | ||
| 225 | Assert.Equal("http://wixtoolset.org/schemas/v4/wxs/util", document.Root.GetDefaultNamespace()); | ||
| 226 | } | ||
| 227 | |||
| 228 | [Fact] | ||
| 229 | public void CanConvertExtensionNamespace() | ||
| 230 | { | ||
| 231 | string parse = String.Join(Environment.NewLine, | ||
| 232 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 233 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>", | ||
| 234 | " <Fragment />", | ||
| 235 | "</Wix>"); | ||
| 236 | |||
| 237 | string expected = String.Join(Environment.NewLine, | ||
| 238 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 239 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">", | ||
| 240 | " <Fragment />", | ||
| 241 | "</Wix>"); | ||
| 242 | |||
| 243 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 244 | |||
| 245 | var messaging = new DummyMessaging(); | ||
| 246 | Converter converter = new Converter(messaging, 2, null, null); | ||
| 247 | |||
| 248 | int errors = converter.ConvertDocument(document); | ||
| 249 | |||
| 250 | string actual = UnformattedDocumentString(document); | ||
| 251 | |||
| 252 | Assert.Equal(2, errors); | ||
| 253 | Assert.Equal(expected, actual); | ||
| 254 | Assert.Equal(Wix4Namespace, document.Root.GetDefaultNamespace()); | ||
| 255 | } | ||
| 256 | |||
| 257 | [Fact] | ||
| 258 | public void CanConvertMissingNamespace() | ||
| 259 | { | ||
| 260 | string parse = String.Join(Environment.NewLine, | ||
| 261 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 262 | "<Wix>", | ||
| 263 | " <Fragment />", | ||
| 264 | "</Wix>"); | ||
| 265 | |||
| 266 | string expected = String.Join(Environment.NewLine, | ||
| 267 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 268 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 269 | " <Fragment />", | ||
| 270 | "</Wix>"); | ||
| 271 | |||
| 272 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 273 | |||
| 274 | var messaging = new DummyMessaging(); | ||
| 275 | Converter converter = new Converter(messaging, 2, null, null); | ||
| 276 | |||
| 277 | int errors = converter.ConvertDocument(document); | ||
| 278 | |||
| 279 | string actual = UnformattedDocumentString(document); | ||
| 280 | |||
| 281 | Assert.Equal(1, errors); | ||
| 282 | Assert.Equal(expected, actual); | ||
| 283 | Assert.Equal(Wix4Namespace, document.Root.GetDefaultNamespace()); | ||
| 284 | } | ||
| 285 | |||
| 286 | [Fact] | ||
| 287 | public void CanConvertAnonymousFile() | ||
| 288 | { | ||
| 289 | string parse = String.Join(Environment.NewLine, | ||
| 290 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 291 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 292 | " <File Source='path\\to\\foo.txt' />", | ||
| 293 | "</Wix>"); | ||
| 294 | |||
| 295 | string expected = String.Join(Environment.NewLine, | ||
| 296 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 297 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 298 | " <File Id=\"foo.txt\" Source=\"path\\to\\foo.txt\" />", | ||
| 299 | "</Wix>"); | ||
| 300 | |||
| 301 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 302 | |||
| 303 | var messaging = new DummyMessaging(); | ||
| 304 | Converter converter = new Converter(messaging, 2, null, null); | ||
| 305 | |||
| 306 | int errors = converter.ConvertDocument(document); | ||
| 307 | |||
| 308 | string actual = UnformattedDocumentString(document); | ||
| 309 | |||
| 310 | Assert.Equal(1, errors); | ||
| 311 | Assert.Equal(expected, actual); | ||
| 312 | } | ||
| 313 | |||
| 314 | [Fact] | ||
| 315 | public void CanConvertSuppressSignatureValidationNo() | ||
| 316 | { | ||
| 317 | string parse = String.Join(Environment.NewLine, | ||
| 318 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 319 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 320 | " <MsiPackage SuppressSignatureValidation='no' />", | ||
| 321 | "</Wix>"); | ||
| 322 | |||
| 323 | string expected = String.Join(Environment.NewLine, | ||
| 324 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 325 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 326 | " <MsiPackage EnableSignatureValidation=\"yes\" />", | ||
| 327 | "</Wix>"); | ||
| 328 | |||
| 329 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 330 | |||
| 331 | var messaging = new DummyMessaging(); | ||
| 332 | Converter converter = new Converter(messaging, 2, null, null); | ||
| 333 | |||
| 334 | int errors = converter.ConvertDocument(document); | ||
| 335 | |||
| 336 | string actual = UnformattedDocumentString(document); | ||
| 337 | |||
| 338 | Assert.Equal(1, errors); | ||
| 339 | Assert.Equal(expected, actual); | ||
| 340 | } | ||
| 341 | |||
| 342 | [Fact] | ||
| 343 | public void CanConvertSuppressSignatureValidationYes() | ||
| 344 | { | ||
| 345 | string parse = String.Join(Environment.NewLine, | ||
| 346 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 347 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 348 | " <Payload SuppressSignatureValidation='yes' />", | ||
| 349 | "</Wix>"); | ||
| 350 | |||
| 351 | string expected = String.Join(Environment.NewLine, | ||
| 352 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 353 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 354 | " <Payload />", | ||
| 355 | "</Wix>"); | ||
| 356 | |||
| 357 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 358 | |||
| 359 | var messaging = new DummyMessaging(); | ||
| 360 | Converter converter = new Converter(messaging, 2, null, null); | ||
| 361 | |||
| 362 | int errors = converter.ConvertDocument(document); | ||
| 363 | |||
| 364 | string actual = UnformattedDocumentString(document); | ||
| 365 | |||
| 366 | Assert.Equal(1, errors); | ||
| 367 | Assert.Equal(expected, actual); | ||
| 368 | } | ||
| 369 | |||
| 370 | private static string UnformattedDocumentString(XDocument document) | ||
| 371 | { | ||
| 372 | StringBuilder sb = new StringBuilder(); | ||
| 373 | |||
| 374 | using (StringWriter writer = new StringWriter(sb)) | ||
| 375 | { | ||
| 376 | document.Save(writer, SaveOptions.DisableFormatting | SaveOptions.OmitDuplicateNamespaces); | ||
| 377 | } | ||
| 378 | |||
| 379 | return sb.ToString(); | ||
| 380 | } | ||
| 381 | |||
| 382 | private class DummyMessaging : IMessaging | ||
| 383 | { | ||
| 384 | public bool EncounteredError { get; set; } | ||
| 385 | |||
| 386 | public int LastErrorNumber { get; set; } | ||
| 387 | |||
| 388 | public bool ShowVerboseMessages { get; set; } | ||
| 389 | public bool SuppressAllWarnings { get; set; } | ||
| 390 | public bool WarningsAsError { get; set; } | ||
| 391 | |||
| 392 | public void ElevateWarningMessage(int warningNumber) | ||
| 393 | { | ||
| 394 | } | ||
| 395 | |||
| 396 | public string FormatMessage(Message message) | ||
| 397 | { | ||
| 398 | return ""; | ||
| 399 | } | ||
| 400 | |||
| 401 | public void SetListener(IMessageListener listener) | ||
| 402 | { | ||
| 403 | } | ||
| 404 | |||
| 405 | public void SuppressWarningMessage(int warningNumber) | ||
| 406 | { | ||
| 407 | } | ||
| 408 | |||
| 409 | public void Write(Message message) | ||
| 410 | { | ||
| 411 | } | ||
| 412 | |||
| 413 | public void Write(string message, bool verbose = false) | ||
| 414 | { | ||
| 415 | } | ||
| 416 | } | ||
| 417 | } | ||
| 418 | } | ||
diff --git a/src/test/wixcop/TestData/SingleFile/ConvertedSingleFile.wxs b/src/test/wixcop/TestData/SingleFile/ConvertedSingleFile.wxs new file mode 100644 index 00000000..aacb68fa --- /dev/null +++ b/src/test/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/wixcop/TestData/SingleFile/SingleFile.wxs b/src/test/wixcop/TestData/SingleFile/SingleFile.wxs new file mode 100644 index 00000000..310ae811 --- /dev/null +++ b/src/test/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/wixcop/WixCopFixture.cs b/src/test/wixcop/WixCopFixture.cs new file mode 100644 index 00000000..12863959 --- /dev/null +++ b/src/test/wixcop/WixCopFixture.cs | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | using System; | ||
| 2 | using System.Collections.Generic; | ||
| 3 | using System.IO; | ||
| 4 | using System.Linq; | ||
| 5 | using WixBuildTools.TestSupport; | ||
| 6 | using WixCop.CommandLine; | ||
| 7 | using WixCop.Interfaces; | ||
| 8 | using WixToolset.Core; | ||
| 9 | using WixToolset.Core.TestPackage; | ||
| 10 | using WixToolset.Extensibility; | ||
| 11 | using WixToolset.Extensibility.Services; | ||
| 12 | using Xunit; | ||
| 13 | |||
| 14 | namespace WixCopTests | ||
| 15 | { | ||
| 16 | public class WixCopFixture | ||
| 17 | { | ||
| 18 | [Fact] | ||
| 19 | public void CanConvertSingleFile() | ||
| 20 | { | ||
| 21 | const string beforeFileName = "SingleFile.wxs"; | ||
| 22 | const string afterFileName = "ConvertedSingleFile.wxs"; | ||
| 23 | var folder = TestData.Get(@"TestData\SingleFile"); | ||
| 24 | |||
| 25 | using (var fs = new DisposableFileSystem()) | ||
| 26 | { | ||
| 27 | var baseFolder = fs.GetFolder(true); | ||
| 28 | var targetFile = Path.Combine(baseFolder, beforeFileName); | ||
| 29 | File.Copy(Path.Combine(folder, beforeFileName), Path.Combine(baseFolder, beforeFileName)); | ||
| 30 | |||
| 31 | var runner = new WixCopRunner | ||
| 32 | { | ||
| 33 | FixErrors = true, | ||
| 34 | SearchPatterns = | ||
| 35 | { | ||
| 36 | targetFile, | ||
| 37 | }, | ||
| 38 | }; | ||
| 39 | |||
| 40 | var result = runner.Execute(out var messages); | ||
| 41 | |||
| 42 | Assert.Equal(2, result); | ||
| 43 | |||
| 44 | var actualLines = File.ReadAllLines(targetFile); | ||
| 45 | var expectedLines = File.ReadAllLines(Path.Combine(folder, afterFileName)); | ||
| 46 | Assert.Equal(expectedLines, actualLines); | ||
| 47 | |||
| 48 | var runner2 = new WixCopRunner | ||
| 49 | { | ||
| 50 | FixErrors = true, | ||
| 51 | SearchPatterns = | ||
| 52 | { | ||
| 53 | targetFile, | ||
| 54 | }, | ||
| 55 | }; | ||
| 56 | |||
| 57 | var result2 = runner2.Execute(out var messages2); | ||
| 58 | |||
| 59 | Assert.Equal(0, result2); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | private class WixCopRunner | ||
| 64 | { | ||
| 65 | public bool FixErrors { get; set; } | ||
| 66 | |||
| 67 | public List<string> SearchPatterns { get; } = new List<string>(); | ||
| 68 | |||
| 69 | public int Execute(out List<string> messages) | ||
| 70 | { | ||
| 71 | var argList = new List<string>(); | ||
| 72 | if (this.FixErrors) | ||
| 73 | { | ||
| 74 | argList.Add("-f"); | ||
| 75 | } | ||
| 76 | |||
| 77 | foreach (string searchPattern in this.SearchPatterns) | ||
| 78 | { | ||
| 79 | argList.Add(searchPattern); | ||
| 80 | } | ||
| 81 | |||
| 82 | return WixCopRunner.Execute(argList.ToArray(), out messages); | ||
| 83 | } | ||
| 84 | |||
| 85 | public static int Execute(string[] args, out List<string> messages) | ||
| 86 | { | ||
| 87 | var listener = new TestMessageListener(); | ||
| 88 | |||
| 89 | var serviceProvider = new WixToolsetServiceProvider(); | ||
| 90 | serviceProvider.AddService<IMessageListener>((x, y) => listener); | ||
| 91 | serviceProvider.AddService<IWixCopCommandLineParser>((x, y) => new WixCopCommandLineParser(x)); | ||
| 92 | |||
| 93 | var result = Execute(serviceProvider, args); | ||
| 94 | |||
| 95 | var messaging = serviceProvider.GetService<IMessaging>(); | ||
| 96 | messages = listener.Messages.Select(x => messaging.FormatMessage(x)).ToList(); | ||
| 97 | return result; | ||
| 98 | } | ||
| 99 | |||
| 100 | public static int Execute(IServiceProvider serviceProvider, string[] args) | ||
| 101 | { | ||
| 102 | var wixcop = new WixCop.Program(); | ||
| 103 | return wixcop.Run(serviceProvider, args); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||
diff --git a/src/test/wixcop/WixCopTests.csproj b/src/test/wixcop/WixCopTests.csproj new file mode 100644 index 00000000..0ae50dc8 --- /dev/null +++ b/src/test/wixcop/WixCopTests.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 | <ItemGroup> | ||
| 11 | <None Remove="TestData\SingleFile\ConvertedSingleFile.wxs" /> | ||
| 12 | <None Remove="TestData\SingleFile\SingleFile.wxs" /> | ||
| 13 | </ItemGroup> | ||
| 14 | <ItemGroup> | ||
| 15 | <Content Include="TestData\SingleFile\ConvertedSingleFile.wxs"> | ||
| 16 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| 17 | </Content> | ||
| 18 | <Content Include="TestData\SingleFile\SingleFile.wxs"> | ||
| 19 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| 20 | </Content> | ||
| 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> | ||
