diff options
Diffstat (limited to 'src')
16 files changed, 316 insertions, 245 deletions
diff --git a/src/test/wixcop/ConverterFixture.cs b/src/test/WixToolsetTest.WixCop/ConverterFixture.cs index 45ccc33e..86931d5a 100644 --- a/src/test/wixcop/ConverterFixture.cs +++ b/src/test/WixToolsetTest.WixCop/ConverterFixture.cs | |||
| @@ -1,16 +1,15 @@ | |||
| 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. | 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 | 2 | ||
| 3 | namespace WixTest.WixUnitTest | 3 | namespace WixToolsetTest.WixCop |
| 4 | { | 4 | { |
| 5 | using System; | 5 | using System; |
| 6 | using System.IO; | 6 | using System.IO; |
| 7 | using System.Text; | 7 | using System.Text; |
| 8 | using System.Xml.Linq; | 8 | using System.Xml.Linq; |
| 9 | using WixCop; | ||
| 10 | using WixToolset; | ||
| 11 | using WixToolset.Data; | 9 | using WixToolset.Data; |
| 12 | using WixToolset.Extensibility; | 10 | using WixToolset.Extensibility; |
| 13 | using WixToolset.Extensibility.Services; | 11 | using WixToolset.Extensibility.Services; |
| 12 | using WixToolset.Tools.WixCop; | ||
| 14 | using Xunit; | 13 | using Xunit; |
| 15 | 14 | ||
| 16 | public class ConverterFixture | 15 | public class ConverterFixture |
| @@ -20,25 +19,25 @@ namespace WixTest.WixUnitTest | |||
| 20 | [Fact] | 19 | [Fact] |
| 21 | public void EnsuresDeclaration() | 20 | public void EnsuresDeclaration() |
| 22 | { | 21 | { |
| 23 | string parse = String.Join(Environment.NewLine, | 22 | var parse = String.Join(Environment.NewLine, |
| 24 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | 23 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 25 | " <Fragment />", | 24 | " <Fragment />", |
| 26 | "</Wix>"); | 25 | "</Wix>"); |
| 27 | 26 | ||
| 28 | string expected = String.Join(Environment.NewLine, | 27 | var expected = String.Join(Environment.NewLine, |
| 29 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | 28 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 30 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | 29 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 31 | " <Fragment />", | 30 | " <Fragment />", |
| 32 | "</Wix>"); | 31 | "</Wix>"); |
| 33 | 32 | ||
| 34 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 33 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 35 | 34 | ||
| 36 | var messaging = new DummyMessaging(); | 35 | var messaging = new DummyMessaging(); |
| 37 | Converter converter = new Converter(messaging, 2, null, null); | 36 | var converter = new Converter(messaging, 2, null, null); |
| 38 | 37 | ||
| 39 | int errors = converter.ConvertDocument(document); | 38 | var errors = converter.ConvertDocument(document); |
| 40 | 39 | ||
| 41 | string actual = UnformattedDocumentString(document); | 40 | var actual = UnformattedDocumentString(document); |
| 42 | 41 | ||
| 43 | Assert.Equal(1, errors); | 42 | Assert.Equal(1, errors); |
| 44 | Assert.Equal(expected, actual); | 43 | Assert.Equal(expected, actual); |
| @@ -47,18 +46,18 @@ namespace WixTest.WixUnitTest | |||
| 47 | [Fact] | 46 | [Fact] |
| 48 | public void EnsuresUtf8Declaration() | 47 | public void EnsuresUtf8Declaration() |
| 49 | { | 48 | { |
| 50 | string parse = String.Join(Environment.NewLine, | 49 | var parse = String.Join(Environment.NewLine, |
| 51 | "<?xml version='1.0'?>", | 50 | "<?xml version='1.0'?>", |
| 52 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | 51 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 53 | " <Fragment />", | 52 | " <Fragment />", |
| 54 | "</Wix>"); | 53 | "</Wix>"); |
| 55 | 54 | ||
| 56 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 55 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 57 | 56 | ||
| 58 | var messaging = new DummyMessaging(); | 57 | var messaging = new DummyMessaging(); |
| 59 | Converter converter = new Converter(messaging, 4, null, null); | 58 | var converter = new Converter(messaging, 4, null, null); |
| 60 | 59 | ||
| 61 | int errors = converter.ConvertDocument(document); | 60 | var errors = converter.ConvertDocument(document); |
| 62 | 61 | ||
| 63 | Assert.Equal(1, errors); | 62 | Assert.Equal(1, errors); |
| 64 | Assert.Equal("1.0", document.Declaration.Version); | 63 | Assert.Equal("1.0", document.Declaration.Version); |
| @@ -68,7 +67,7 @@ namespace WixTest.WixUnitTest | |||
| 68 | [Fact] | 67 | [Fact] |
| 69 | public void CanFixWhitespace() | 68 | public void CanFixWhitespace() |
| 70 | { | 69 | { |
| 71 | string parse = String.Join(Environment.NewLine, | 70 | var parse = String.Join(Environment.NewLine, |
| 72 | "<?xml version='1.0' encoding='utf-8'?>", | 71 | "<?xml version='1.0' encoding='utf-8'?>", |
| 73 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | 72 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 74 | " <Fragment>", | 73 | " <Fragment>", |
| @@ -78,7 +77,7 @@ namespace WixTest.WixUnitTest | |||
| 78 | " </Fragment>", | 77 | " </Fragment>", |
| 79 | "</Wix>"); | 78 | "</Wix>"); |
| 80 | 79 | ||
| 81 | string expected = String.Join(Environment.NewLine, | 80 | var expected = String.Join(Environment.NewLine, |
| 82 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | 81 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 83 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | 82 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 84 | " <Fragment>", | 83 | " <Fragment>", |
| @@ -86,14 +85,14 @@ namespace WixTest.WixUnitTest | |||
| 86 | " </Fragment>", | 85 | " </Fragment>", |
| 87 | "</Wix>"); | 86 | "</Wix>"); |
| 88 | 87 | ||
| 89 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 88 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 90 | 89 | ||
| 91 | var messaging = new DummyMessaging(); | 90 | var messaging = new DummyMessaging(); |
| 92 | Converter converter = new Converter(messaging, 4, null, null); | 91 | var converter = new Converter(messaging, 4, null, null); |
| 93 | 92 | ||
| 94 | int errors = converter.ConvertDocument(document); | 93 | var errors = converter.ConvertDocument(document); |
| 95 | 94 | ||
| 96 | string actual = UnformattedDocumentString(document); | 95 | var actual = UnformattedDocumentString(document); |
| 97 | 96 | ||
| 98 | Assert.Equal(4, errors); | 97 | Assert.Equal(4, errors); |
| 99 | Assert.Equal(expected, actual); | 98 | Assert.Equal(expected, actual); |
| @@ -102,7 +101,7 @@ namespace WixTest.WixUnitTest | |||
| 102 | [Fact] | 101 | [Fact] |
| 103 | public void CanFixCdataWhitespace() | 102 | public void CanFixCdataWhitespace() |
| 104 | { | 103 | { |
| 105 | string parse = String.Join(Environment.NewLine, | 104 | var parse = String.Join(Environment.NewLine, |
| 106 | "<?xml version='1.0' encoding='utf-8'?>", | 105 | "<?xml version='1.0' encoding='utf-8'?>", |
| 107 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | 106 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 108 | " <Fragment>", | 107 | " <Fragment>", |
| @@ -112,7 +111,7 @@ namespace WixTest.WixUnitTest | |||
| 112 | " </Fragment>", | 111 | " </Fragment>", |
| 113 | "</Wix>"); | 112 | "</Wix>"); |
| 114 | 113 | ||
| 115 | string expected = String.Join(Environment.NewLine, | 114 | var expected = String.Join(Environment.NewLine, |
| 116 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | 115 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 117 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | 116 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 118 | " <Fragment>", | 117 | " <Fragment>", |
| @@ -120,42 +119,78 @@ namespace WixTest.WixUnitTest | |||
| 120 | " </Fragment>", | 119 | " </Fragment>", |
| 121 | "</Wix>"); | 120 | "</Wix>"); |
| 122 | 121 | ||
| 123 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 122 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 124 | 123 | ||
| 125 | var messaging = new DummyMessaging(); | 124 | var messaging = new DummyMessaging(); |
| 126 | Converter converter = new Converter(messaging, 2, null, null); | 125 | var converter = new Converter(messaging, 2, null, null); |
| 127 | 126 | ||
| 128 | int errors = converter.ConvertDocument(document); | 127 | var errors = converter.ConvertDocument(document); |
| 129 | 128 | ||
| 130 | string actual = UnformattedDocumentString(document); | 129 | var actual = UnformattedDocumentString(document); |
| 131 | 130 | ||
| 131 | Assert.Equal(expected, actual); | ||
| 132 | Assert.Equal(2, errors); | 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 | |||
| 133 | Assert.Equal(expected, actual); | 167 | Assert.Equal(expected, actual); |
| 168 | Assert.Equal(2, errors); | ||
| 134 | } | 169 | } |
| 135 | 170 | ||
| 136 | [Fact] | 171 | [Fact] |
| 137 | public void CanConvertMainNamespace() | 172 | public void CanConvertMainNamespace() |
| 138 | { | 173 | { |
| 139 | string parse = String.Join(Environment.NewLine, | 174 | var parse = String.Join(Environment.NewLine, |
| 140 | "<?xml version='1.0' encoding='utf-8'?>", | 175 | "<?xml version='1.0' encoding='utf-8'?>", |
| 141 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", | 176 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 142 | " <Fragment />", | 177 | " <Fragment />", |
| 143 | "</Wix>"); | 178 | "</Wix>"); |
| 144 | 179 | ||
| 145 | string expected = String.Join(Environment.NewLine, | 180 | var expected = String.Join(Environment.NewLine, |
| 146 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | 181 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 147 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | 182 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 148 | " <Fragment />", | 183 | " <Fragment />", |
| 149 | "</Wix>"); | 184 | "</Wix>"); |
| 150 | 185 | ||
| 151 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 186 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 152 | 187 | ||
| 153 | var messaging = new DummyMessaging(); | 188 | var messaging = new DummyMessaging(); |
| 154 | Converter converter = new Converter(messaging, 2, null, null); | 189 | var converter = new Converter(messaging, 2, null, null); |
| 155 | 190 | ||
| 156 | int errors = converter.ConvertDocument(document); | 191 | var errors = converter.ConvertDocument(document); |
| 157 | 192 | ||
| 158 | string actual = UnformattedDocumentString(document); | 193 | var actual = UnformattedDocumentString(document); |
| 159 | 194 | ||
| 160 | Assert.Equal(1, errors); | 195 | Assert.Equal(1, errors); |
| 161 | //Assert.Equal(Wix4Namespace, document.Root.GetDefaultNamespace()); | 196 | //Assert.Equal(Wix4Namespace, document.Root.GetDefaultNamespace()); |
| @@ -165,26 +200,26 @@ namespace WixTest.WixUnitTest | |||
| 165 | [Fact] | 200 | [Fact] |
| 166 | public void CanConvertNamedMainNamespace() | 201 | public void CanConvertNamedMainNamespace() |
| 167 | { | 202 | { |
| 168 | string parse = String.Join(Environment.NewLine, | 203 | var parse = String.Join(Environment.NewLine, |
| 169 | "<?xml version='1.0' encoding='utf-8'?>", | 204 | "<?xml version='1.0' encoding='utf-8'?>", |
| 170 | "<w:Wix xmlns:w='http://schemas.microsoft.com/wix/2006/wi'>", | 205 | "<w:Wix xmlns:w='http://schemas.microsoft.com/wix/2006/wi'>", |
| 171 | " <w:Fragment />", | 206 | " <w:Fragment />", |
| 172 | "</w:Wix>"); | 207 | "</w:Wix>"); |
| 173 | 208 | ||
| 174 | string expected = String.Join(Environment.NewLine, | 209 | var expected = String.Join(Environment.NewLine, |
| 175 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | 210 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 176 | "<w:Wix xmlns:w=\"http://wixtoolset.org/schemas/v4/wxs\">", | 211 | "<w:Wix xmlns:w=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 177 | " <w:Fragment />", | 212 | " <w:Fragment />", |
| 178 | "</w:Wix>"); | 213 | "</w:Wix>"); |
| 179 | 214 | ||
| 180 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 215 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 181 | 216 | ||
| 182 | var messaging = new DummyMessaging(); | 217 | var messaging = new DummyMessaging(); |
| 183 | Converter converter = new Converter(messaging, 2, null, null); | 218 | var converter = new Converter(messaging, 2, null, null); |
| 184 | 219 | ||
| 185 | int errors = converter.ConvertDocument(document); | 220 | var errors = converter.ConvertDocument(document); |
| 186 | 221 | ||
| 187 | string actual = UnformattedDocumentString(document); | 222 | var actual = UnformattedDocumentString(document); |
| 188 | 223 | ||
| 189 | Assert.Equal(1, errors); | 224 | Assert.Equal(1, errors); |
| 190 | Assert.Equal(expected, actual); | 225 | Assert.Equal(expected, actual); |
| @@ -194,7 +229,7 @@ namespace WixTest.WixUnitTest | |||
| 194 | [Fact] | 229 | [Fact] |
| 195 | public void CanConvertNonWixDefaultNamespace() | 230 | public void CanConvertNonWixDefaultNamespace() |
| 196 | { | 231 | { |
| 197 | string parse = String.Join(Environment.NewLine, | 232 | var parse = String.Join(Environment.NewLine, |
| 198 | "<?xml version='1.0' encoding='utf-8'?>", | 233 | "<?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'>", | 234 | "<w:Wix xmlns:w='http://schemas.microsoft.com/wix/2006/wi' xmlns='http://schemas.microsoft.com/wix/UtilExtension'>", |
| 200 | " <w:Fragment>", | 235 | " <w:Fragment>", |
| @@ -202,7 +237,7 @@ namespace WixTest.WixUnitTest | |||
| 202 | " </w:Fragment>", | 237 | " </w:Fragment>", |
| 203 | "</w:Wix>"); | 238 | "</w:Wix>"); |
| 204 | 239 | ||
| 205 | string expected = String.Join(Environment.NewLine, | 240 | var expected = String.Join(Environment.NewLine, |
| 206 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | 241 | "<?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\">", | 242 | "<w:Wix xmlns:w=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns=\"http://wixtoolset.org/schemas/v4/wxs/util\">", |
| 208 | " <w:Fragment>", | 243 | " <w:Fragment>", |
| @@ -210,17 +245,17 @@ namespace WixTest.WixUnitTest | |||
| 210 | " </w:Fragment>", | 245 | " </w:Fragment>", |
| 211 | "</w:Wix>"); | 246 | "</w:Wix>"); |
| 212 | 247 | ||
| 213 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 248 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 214 | 249 | ||
| 215 | var messaging = new DummyMessaging(); | 250 | var messaging = new DummyMessaging(); |
| 216 | Converter converter = new Converter(messaging, 2, null, null); | 251 | var converter = new Converter(messaging, 2, null, null); |
| 217 | 252 | ||
| 218 | int errors = converter.ConvertDocument(document); | 253 | var errors = converter.ConvertDocument(document); |
| 219 | 254 | ||
| 220 | string actual = UnformattedDocumentString(document); | 255 | var actual = UnformattedDocumentString(document); |
| 221 | 256 | ||
| 222 | Assert.Equal(2, errors); | ||
| 223 | Assert.Equal(expected, actual); | 257 | Assert.Equal(expected, actual); |
| 258 | Assert.Equal(2, errors); | ||
| 224 | Assert.Equal(Wix4Namespace, document.Root.GetNamespaceOfPrefix("w")); | 259 | Assert.Equal(Wix4Namespace, document.Root.GetNamespaceOfPrefix("w")); |
| 225 | Assert.Equal("http://wixtoolset.org/schemas/v4/wxs/util", document.Root.GetDefaultNamespace()); | 260 | Assert.Equal("http://wixtoolset.org/schemas/v4/wxs/util", document.Root.GetDefaultNamespace()); |
| 226 | } | 261 | } |
| @@ -228,26 +263,26 @@ namespace WixTest.WixUnitTest | |||
| 228 | [Fact] | 263 | [Fact] |
| 229 | public void CanConvertExtensionNamespace() | 264 | public void CanConvertExtensionNamespace() |
| 230 | { | 265 | { |
| 231 | string parse = String.Join(Environment.NewLine, | 266 | var parse = String.Join(Environment.NewLine, |
| 232 | "<?xml version='1.0' encoding='utf-8'?>", | 267 | "<?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'>", | 268 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>", |
| 234 | " <Fragment />", | 269 | " <Fragment />", |
| 235 | "</Wix>"); | 270 | "</Wix>"); |
| 236 | 271 | ||
| 237 | string expected = String.Join(Environment.NewLine, | 272 | var expected = String.Join(Environment.NewLine, |
| 238 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | 273 | "<?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\">", | 274 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">", |
| 240 | " <Fragment />", | 275 | " <Fragment />", |
| 241 | "</Wix>"); | 276 | "</Wix>"); |
| 242 | 277 | ||
| 243 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 278 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 244 | 279 | ||
| 245 | var messaging = new DummyMessaging(); | 280 | var messaging = new DummyMessaging(); |
| 246 | Converter converter = new Converter(messaging, 2, null, null); | 281 | var converter = new Converter(messaging, 2, null, null); |
| 247 | 282 | ||
| 248 | int errors = converter.ConvertDocument(document); | 283 | var errors = converter.ConvertDocument(document); |
| 249 | 284 | ||
| 250 | string actual = UnformattedDocumentString(document); | 285 | var actual = UnformattedDocumentString(document); |
| 251 | 286 | ||
| 252 | Assert.Equal(2, errors); | 287 | Assert.Equal(2, errors); |
| 253 | Assert.Equal(expected, actual); | 288 | Assert.Equal(expected, actual); |
| @@ -257,26 +292,26 @@ namespace WixTest.WixUnitTest | |||
| 257 | [Fact] | 292 | [Fact] |
| 258 | public void CanConvertMissingNamespace() | 293 | public void CanConvertMissingNamespace() |
| 259 | { | 294 | { |
| 260 | string parse = String.Join(Environment.NewLine, | 295 | var parse = String.Join(Environment.NewLine, |
| 261 | "<?xml version='1.0' encoding='utf-8'?>", | 296 | "<?xml version='1.0' encoding='utf-8'?>", |
| 262 | "<Wix>", | 297 | "<Wix>", |
| 263 | " <Fragment />", | 298 | " <Fragment />", |
| 264 | "</Wix>"); | 299 | "</Wix>"); |
| 265 | 300 | ||
| 266 | string expected = String.Join(Environment.NewLine, | 301 | var expected = String.Join(Environment.NewLine, |
| 267 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | 302 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 268 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | 303 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 269 | " <Fragment />", | 304 | " <Fragment />", |
| 270 | "</Wix>"); | 305 | "</Wix>"); |
| 271 | 306 | ||
| 272 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 307 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 273 | 308 | ||
| 274 | var messaging = new DummyMessaging(); | 309 | var messaging = new DummyMessaging(); |
| 275 | Converter converter = new Converter(messaging, 2, null, null); | 310 | var converter = new Converter(messaging, 2, null, null); |
| 276 | 311 | ||
| 277 | int errors = converter.ConvertDocument(document); | 312 | var errors = converter.ConvertDocument(document); |
| 278 | 313 | ||
| 279 | string actual = UnformattedDocumentString(document); | 314 | var actual = UnformattedDocumentString(document); |
| 280 | 315 | ||
| 281 | Assert.Equal(1, errors); | 316 | Assert.Equal(1, errors); |
| 282 | Assert.Equal(expected, actual); | 317 | Assert.Equal(expected, actual); |
| @@ -286,26 +321,26 @@ namespace WixTest.WixUnitTest | |||
| 286 | [Fact] | 321 | [Fact] |
| 287 | public void CanConvertAnonymousFile() | 322 | public void CanConvertAnonymousFile() |
| 288 | { | 323 | { |
| 289 | string parse = String.Join(Environment.NewLine, | 324 | var parse = String.Join(Environment.NewLine, |
| 290 | "<?xml version='1.0' encoding='utf-8'?>", | 325 | "<?xml version='1.0' encoding='utf-8'?>", |
| 291 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | 326 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 292 | " <File Source='path\\to\\foo.txt' />", | 327 | " <File Source='path\\to\\foo.txt' />", |
| 293 | "</Wix>"); | 328 | "</Wix>"); |
| 294 | 329 | ||
| 295 | string expected = String.Join(Environment.NewLine, | 330 | var expected = String.Join(Environment.NewLine, |
| 296 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | 331 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 297 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | 332 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 298 | " <File Id=\"foo.txt\" Source=\"path\\to\\foo.txt\" />", | 333 | " <File Id=\"foo.txt\" Source=\"path\\to\\foo.txt\" />", |
| 299 | "</Wix>"); | 334 | "</Wix>"); |
| 300 | 335 | ||
| 301 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 336 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 302 | 337 | ||
| 303 | var messaging = new DummyMessaging(); | 338 | var messaging = new DummyMessaging(); |
| 304 | Converter converter = new Converter(messaging, 2, null, null); | 339 | var converter = new Converter(messaging, 2, null, null); |
| 305 | 340 | ||
| 306 | int errors = converter.ConvertDocument(document); | 341 | var errors = converter.ConvertDocument(document); |
| 307 | 342 | ||
| 308 | string actual = UnformattedDocumentString(document); | 343 | var actual = UnformattedDocumentString(document); |
| 309 | 344 | ||
| 310 | Assert.Equal(1, errors); | 345 | Assert.Equal(1, errors); |
| 311 | Assert.Equal(expected, actual); | 346 | Assert.Equal(expected, actual); |
| @@ -314,26 +349,26 @@ namespace WixTest.WixUnitTest | |||
| 314 | [Fact] | 349 | [Fact] |
| 315 | public void CanConvertSuppressSignatureValidationNo() | 350 | public void CanConvertSuppressSignatureValidationNo() |
| 316 | { | 351 | { |
| 317 | string parse = String.Join(Environment.NewLine, | 352 | var parse = String.Join(Environment.NewLine, |
| 318 | "<?xml version='1.0' encoding='utf-8'?>", | 353 | "<?xml version='1.0' encoding='utf-8'?>", |
| 319 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | 354 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 320 | " <MsiPackage SuppressSignatureValidation='no' />", | 355 | " <MsiPackage SuppressSignatureValidation='no' />", |
| 321 | "</Wix>"); | 356 | "</Wix>"); |
| 322 | 357 | ||
| 323 | string expected = String.Join(Environment.NewLine, | 358 | var expected = String.Join(Environment.NewLine, |
| 324 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | 359 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 325 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | 360 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 326 | " <MsiPackage EnableSignatureValidation=\"yes\" />", | 361 | " <MsiPackage EnableSignatureValidation=\"yes\" />", |
| 327 | "</Wix>"); | 362 | "</Wix>"); |
| 328 | 363 | ||
| 329 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 364 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 330 | 365 | ||
| 331 | var messaging = new DummyMessaging(); | 366 | var messaging = new DummyMessaging(); |
| 332 | Converter converter = new Converter(messaging, 2, null, null); | 367 | var converter = new Converter(messaging, 2, null, null); |
| 333 | 368 | ||
| 334 | int errors = converter.ConvertDocument(document); | 369 | var errors = converter.ConvertDocument(document); |
| 335 | 370 | ||
| 336 | string actual = UnformattedDocumentString(document); | 371 | var actual = UnformattedDocumentString(document); |
| 337 | 372 | ||
| 338 | Assert.Equal(1, errors); | 373 | Assert.Equal(1, errors); |
| 339 | Assert.Equal(expected, actual); | 374 | Assert.Equal(expected, actual); |
| @@ -342,26 +377,26 @@ namespace WixTest.WixUnitTest | |||
| 342 | [Fact] | 377 | [Fact] |
| 343 | public void CanConvertSuppressSignatureValidationYes() | 378 | public void CanConvertSuppressSignatureValidationYes() |
| 344 | { | 379 | { |
| 345 | string parse = String.Join(Environment.NewLine, | 380 | var parse = String.Join(Environment.NewLine, |
| 346 | "<?xml version='1.0' encoding='utf-8'?>", | 381 | "<?xml version='1.0' encoding='utf-8'?>", |
| 347 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | 382 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 348 | " <Payload SuppressSignatureValidation='yes' />", | 383 | " <Payload SuppressSignatureValidation='yes' />", |
| 349 | "</Wix>"); | 384 | "</Wix>"); |
| 350 | 385 | ||
| 351 | string expected = String.Join(Environment.NewLine, | 386 | var expected = String.Join(Environment.NewLine, |
| 352 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | 387 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 353 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | 388 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 354 | " <Payload />", | 389 | " <Payload />", |
| 355 | "</Wix>"); | 390 | "</Wix>"); |
| 356 | 391 | ||
| 357 | XDocument document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | 392 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 358 | 393 | ||
| 359 | var messaging = new DummyMessaging(); | 394 | var messaging = new DummyMessaging(); |
| 360 | Converter converter = new Converter(messaging, 2, null, null); | 395 | var converter = new Converter(messaging, 2, null, null); |
| 361 | 396 | ||
| 362 | int errors = converter.ConvertDocument(document); | 397 | var errors = converter.ConvertDocument(document); |
| 363 | 398 | ||
| 364 | string actual = UnformattedDocumentString(document); | 399 | var actual = UnformattedDocumentString(document); |
| 365 | 400 | ||
| 366 | Assert.Equal(1, errors); | 401 | Assert.Equal(1, errors); |
| 367 | Assert.Equal(expected, actual); | 402 | Assert.Equal(expected, actual); |
| @@ -369,11 +404,11 @@ namespace WixTest.WixUnitTest | |||
| 369 | 404 | ||
| 370 | private static string UnformattedDocumentString(XDocument document) | 405 | private static string UnformattedDocumentString(XDocument document) |
| 371 | { | 406 | { |
| 372 | StringBuilder sb = new StringBuilder(); | 407 | var sb = new StringBuilder(); |
| 373 | 408 | ||
| 374 | using (StringWriter writer = new StringWriter(sb)) | 409 | using (var writer = new StringWriter(sb)) |
| 375 | { | 410 | { |
| 376 | document.Save(writer, SaveOptions.DisableFormatting | SaveOptions.OmitDuplicateNamespaces); | 411 | document.Save(writer, SaveOptions.DisableFormatting); |
| 377 | } | 412 | } |
| 378 | 413 | ||
| 379 | return sb.ToString(); | 414 | return sb.ToString(); |
| @@ -386,17 +421,16 @@ namespace WixTest.WixUnitTest | |||
| 386 | public int LastErrorNumber { get; set; } | 421 | public int LastErrorNumber { get; set; } |
| 387 | 422 | ||
| 388 | public bool ShowVerboseMessages { get; set; } | 423 | public bool ShowVerboseMessages { get; set; } |
| 424 | |||
| 389 | public bool SuppressAllWarnings { get; set; } | 425 | public bool SuppressAllWarnings { get; set; } |
| 426 | |||
| 390 | public bool WarningsAsError { get; set; } | 427 | public bool WarningsAsError { get; set; } |
| 391 | 428 | ||
| 392 | public void ElevateWarningMessage(int warningNumber) | 429 | public void ElevateWarningMessage(int warningNumber) |
| 393 | { | 430 | { |
| 394 | } | 431 | } |
| 395 | 432 | ||
| 396 | public string FormatMessage(Message message) | 433 | public string FormatMessage(Message message) => String.Empty; |
| 397 | { | ||
| 398 | return ""; | ||
| 399 | } | ||
| 400 | 434 | ||
| 401 | public void SetListener(IMessageListener listener) | 435 | public void SetListener(IMessageListener listener) |
| 402 | { | 436 | { |
diff --git a/src/test/wixcop/TestData/Preprocessor/ConvertedPreprocessor.wxs b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/ConvertedPreprocessor.wxs index d6280185..d6280185 100644 --- a/src/test/wixcop/TestData/Preprocessor/ConvertedPreprocessor.wxs +++ b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/ConvertedPreprocessor.wxs | |||
diff --git a/src/test/wixcop/TestData/Preprocessor/Preprocessor.wxs b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/Preprocessor.wxs index 2eb908c2..2eb908c2 100644 --- a/src/test/wixcop/TestData/Preprocessor/Preprocessor.wxs +++ b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/Preprocessor.wxs | |||
diff --git a/src/test/wixcop/TestData/Preprocessor/wixcop.settings.xml b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/wixcop.settings.xml index 9d3ad496..9d3ad496 100644 --- a/src/test/wixcop/TestData/Preprocessor/wixcop.settings.xml +++ b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/wixcop.settings.xml | |||
diff --git a/src/test/wixcop/TestData/SingleFile/ConvertedSingleFile.wxs b/src/test/WixToolsetTest.WixCop/TestData/SingleFile/ConvertedSingleFile.wxs index aacb68fa..aacb68fa 100644 --- a/src/test/wixcop/TestData/SingleFile/ConvertedSingleFile.wxs +++ b/src/test/WixToolsetTest.WixCop/TestData/SingleFile/ConvertedSingleFile.wxs | |||
diff --git a/src/test/wixcop/TestData/SingleFile/SingleFile.wxs b/src/test/WixToolsetTest.WixCop/TestData/SingleFile/SingleFile.wxs index 310ae811..310ae811 100644 --- a/src/test/wixcop/TestData/SingleFile/SingleFile.wxs +++ b/src/test/WixToolsetTest.WixCop/TestData/SingleFile/SingleFile.wxs | |||
diff --git a/src/test/wixcop/WixCopFixture.cs b/src/test/WixToolsetTest.WixCop/WixCopFixture.cs index 1fa49be9..1025eac8 100644 --- a/src/test/wixcop/WixCopFixture.cs +++ b/src/test/WixToolsetTest.WixCop/WixCopFixture.cs | |||
| @@ -1,18 +1,11 @@ | |||
| 1 | using System; | 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 | using System.Collections.Generic; | 2 | |
| 3 | using System.IO; | 3 | namespace WixToolsetTest.WixCop |
| 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 | { | 4 | { |
| 5 | using System.IO; | ||
| 6 | using WixBuildTools.TestSupport; | ||
| 7 | using Xunit; | ||
| 8 | |||
| 16 | public class WixCopFixture | 9 | public class WixCopFixture |
| 17 | { | 10 | { |
| 18 | [Fact] | 11 | [Fact] |
| @@ -37,13 +30,18 @@ namespace WixCopTests | |||
| 37 | }, | 30 | }, |
| 38 | }; | 31 | }; |
| 39 | 32 | ||
| 40 | var result = runner.Execute(out var messages); | 33 | var result = runner.Execute(); |
| 41 | 34 | ||
| 42 | Assert.Equal(2, result); | 35 | Assert.Equal(2, result.ExitCode); |
| 43 | 36 | ||
| 44 | var actualLines = File.ReadAllLines(targetFile); | 37 | var actualLines = File.ReadAllLines(targetFile); |
| 45 | var expectedLines = File.ReadAllLines(Path.Combine(folder, afterFileName)); | 38 | var expectedLines = File.ReadAllLines(Path.Combine(folder, afterFileName)); |
| 46 | Assert.Equal(expectedLines, actualLines); | 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); | ||
| 47 | 45 | ||
| 48 | var runner2 = new WixCopRunner | 46 | var runner2 = new WixCopRunner |
| 49 | { | 47 | { |
| @@ -54,9 +52,9 @@ namespace WixCopTests | |||
| 54 | }, | 52 | }, |
| 55 | }; | 53 | }; |
| 56 | 54 | ||
| 57 | var result2 = runner2.Execute(out var messages2); | 55 | var result2 = runner2.Execute(); |
| 58 | 56 | ||
| 59 | Assert.Equal(0, result2); | 57 | Assert.Equal(0, result2.ExitCode); |
| 60 | } | 58 | } |
| 61 | } | 59 | } |
| 62 | 60 | ||
| @@ -83,9 +81,9 @@ namespace WixCopTests | |||
| 83 | }, | 81 | }, |
| 84 | }; | 82 | }; |
| 85 | 83 | ||
| 86 | var result = runner.Execute(out var messages); | 84 | var result = runner.Execute(); |
| 87 | 85 | ||
| 88 | Assert.Equal(2, result); | 86 | Assert.Equal(2, result.ExitCode); |
| 89 | 87 | ||
| 90 | var actualLines = File.ReadAllLines(targetFile); | 88 | var actualLines = File.ReadAllLines(targetFile); |
| 91 | var expectedLines = File.ReadAllLines(Path.Combine(folder, afterFileName)); | 89 | var expectedLines = File.ReadAllLines(Path.Combine(folder, afterFileName)); |
| @@ -101,61 +99,9 @@ namespace WixCopTests | |||
| 101 | }, | 99 | }, |
| 102 | }; | 100 | }; |
| 103 | 101 | ||
| 104 | var result2 = runner2.Execute(out var messages2); | 102 | var result2 = runner2.Execute(); |
| 105 | |||
| 106 | Assert.Equal(0, result2); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | 103 | ||
| 110 | private class WixCopRunner | 104 | Assert.Equal(0, result2.ExitCode); |
| 111 | { | ||
| 112 | public bool FixErrors { get; set; } | ||
| 113 | |||
| 114 | public List<string> SearchPatterns { get; } = new List<string>(); | ||
| 115 | |||
| 116 | public string SettingFile1 { get; set; } | ||
| 117 | |||
| 118 | public int Execute(out List<string> messages) | ||
| 119 | { | ||
| 120 | var argList = new List<string>(); | ||
| 121 | |||
| 122 | if (this.FixErrors) | ||
| 123 | { | ||
| 124 | argList.Add("-f"); | ||
| 125 | } | ||
| 126 | |||
| 127 | if (!String.IsNullOrEmpty(this.SettingFile1)) | ||
| 128 | { | ||
| 129 | argList.Add($"-set1{this.SettingFile1}"); | ||
| 130 | } | ||
| 131 | |||
| 132 | foreach (string searchPattern in this.SearchPatterns) | ||
| 133 | { | ||
| 134 | argList.Add(searchPattern); | ||
| 135 | } | ||
| 136 | |||
| 137 | return WixCopRunner.Execute(argList.ToArray(), out messages); | ||
| 138 | } | ||
| 139 | |||
| 140 | public static int Execute(string[] args, out List<string> messages) | ||
| 141 | { | ||
| 142 | var listener = new TestMessageListener(); | ||
| 143 | |||
| 144 | var serviceProvider = new WixToolsetServiceProvider(); | ||
| 145 | serviceProvider.AddService<IMessageListener>((x, y) => listener); | ||
| 146 | serviceProvider.AddService<IWixCopCommandLineParser>((x, y) => new WixCopCommandLineParser(x)); | ||
| 147 | |||
| 148 | var result = Execute(serviceProvider, args); | ||
| 149 | |||
| 150 | var messaging = serviceProvider.GetService<IMessaging>(); | ||
| 151 | messages = listener.Messages.Select(x => messaging.FormatMessage(x)).ToList(); | ||
| 152 | return result; | ||
| 153 | } | ||
| 154 | |||
| 155 | public static int Execute(IServiceProvider serviceProvider, string[] args) | ||
| 156 | { | ||
| 157 | var wixcop = new WixCop.Program(); | ||
| 158 | return wixcop.Run(serviceProvider, args); | ||
| 159 | } | 105 | } |
| 160 | } | 106 | } |
| 161 | } | 107 | } |
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/wixcop/WixCopTests.csproj b/src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.csproj index 012ef4db..6b41b6b6 100644 --- a/src/test/wixcop/WixCopTests.csproj +++ b/src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.csproj | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | <IsPackable>false</IsPackable> | 7 | <IsPackable>false</IsPackable> |
| 8 | <DebugType>embedded</DebugType> | 8 | <DebugType>embedded</DebugType> |
| 9 | </PropertyGroup> | 9 | </PropertyGroup> |
| 10 | |||
| 10 | <ItemGroup> | 11 | <ItemGroup> |
| 11 | <None Remove="TestData\SingleFile\ConvertedSingleFile.wxs" /> | 12 | <None Remove="TestData\SingleFile\ConvertedSingleFile.wxs" /> |
| 12 | <None Remove="TestData\SingleFile\SingleFile.wxs" /> | 13 | <None Remove="TestData\SingleFile\SingleFile.wxs" /> |
diff --git a/src/wixcop/CommandLine/ConvertCommand.cs b/src/wixcop/CommandLine/ConvertCommand.cs index 6af7d4ca..ab7cd359 100644 --- a/src/wixcop/CommandLine/ConvertCommand.cs +++ b/src/wixcop/CommandLine/ConvertCommand.cs | |||
| @@ -1,13 +1,14 @@ | |||
| 1 | using System; | 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 | using System.Collections.Generic; | 2 | |
| 3 | using System.IO; | 3 | namespace WixToolset.Tools.WixCop.CommandLine |
| 4 | using System.Linq; | ||
| 5 | using System.Xml; | ||
| 6 | using WixToolset.Extensibility.Data; | ||
| 7 | using WixToolset.Extensibility.Services; | ||
| 8 | |||
| 9 | namespace WixCop.CommandLine | ||
| 10 | { | 4 | { |
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using System.IO; | ||
| 8 | using System.Xml; | ||
| 9 | using WixToolset.Extensibility.Data; | ||
| 10 | using WixToolset.Extensibility.Services; | ||
| 11 | |||
| 11 | internal class ConvertCommand : ICommandLineCommand | 12 | internal class ConvertCommand : ICommandLineCommand |
| 12 | { | 13 | { |
| 13 | private const string SettingsFileDefault = "wixcop.settings.xml"; | 14 | private const string SettingsFileDefault = "wixcop.settings.xml"; |
| @@ -69,7 +70,7 @@ namespace WixCop.CommandLine | |||
| 69 | 70 | ||
| 70 | var errors = this.InspectSubDirectories(converter, Path.GetFullPath(".")); | 71 | var errors = this.InspectSubDirectories(converter, Path.GetFullPath(".")); |
| 71 | 72 | ||
| 72 | foreach (string searchPattern in this.SearchPatterns) | 73 | foreach (var searchPattern in this.SearchPatterns) |
| 73 | { | 74 | { |
| 74 | if (!this.SearchPatternResults.Contains(searchPattern)) | 75 | if (!this.SearchPatternResults.Contains(searchPattern)) |
| 75 | { | 76 | { |
diff --git a/src/wixcop/CommandLine/HelpCommand.cs b/src/wixcop/CommandLine/HelpCommand.cs index a75dac5c..bfb784b0 100644 --- a/src/wixcop/CommandLine/HelpCommand.cs +++ b/src/wixcop/CommandLine/HelpCommand.cs | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | using System; | 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 | using WixToolset.Extensibility.Data; | ||
| 3 | 2 | ||
| 4 | namespace WixCop.CommandLine | 3 | namespace WixToolset.Tools.WixCop.CommandLine |
| 5 | { | 4 | { |
| 5 | using System; | ||
| 6 | using WixToolset.Extensibility.Data; | ||
| 7 | |||
| 6 | internal class HelpCommand : ICommandLineCommand | 8 | internal class HelpCommand : ICommandLineCommand |
| 7 | { | 9 | { |
| 8 | public int Execute() | 10 | public int Execute() |
diff --git a/src/wixcop/CommandLine/WixCopCommandLineParser.cs b/src/wixcop/CommandLine/WixCopCommandLineParser.cs index 53012cfd..ae826d4f 100644 --- a/src/wixcop/CommandLine/WixCopCommandLineParser.cs +++ b/src/wixcop/CommandLine/WixCopCommandLineParser.cs | |||
| @@ -1,12 +1,14 @@ | |||
| 1 | using System; | 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 | using System.Collections.Generic; | ||
| 3 | using WixCop.Interfaces; | ||
| 4 | using WixToolset.Core; | ||
| 5 | using WixToolset.Extensibility.Data; | ||
| 6 | using WixToolset.Extensibility.Services; | ||
| 7 | 2 | ||
| 8 | namespace WixCop.CommandLine | 3 | namespace WixToolset.Tools.WixCop.CommandLine |
| 9 | { | 4 | { |
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using WixToolset.Core; | ||
| 8 | using WixToolset.Extensibility.Data; | ||
| 9 | using WixToolset.Extensibility.Services; | ||
| 10 | using WixToolset.Tools.WixCop.Interfaces; | ||
| 11 | |||
| 10 | public sealed class WixCopCommandLineParser : IWixCopCommandLineParser | 12 | public sealed class WixCopCommandLineParser : IWixCopCommandLineParser |
| 11 | { | 13 | { |
| 12 | private bool fixErrors; | 14 | private bool fixErrors; |
| @@ -89,43 +91,43 @@ namespace WixCop.CommandLine | |||
| 89 | 91 | ||
| 90 | switch (parameter.ToLowerInvariant()) | 92 | switch (parameter.ToLowerInvariant()) |
| 91 | { | 93 | { |
| 92 | case "?": | 94 | case "?": |
| 93 | this.showHelp = true; | 95 | this.showHelp = true; |
| 94 | return true; | 96 | return true; |
| 95 | case "f": | 97 | case "f": |
| 96 | this.fixErrors = true; | 98 | this.fixErrors = true; |
| 97 | return true; | 99 | return true; |
| 98 | case "nologo": | 100 | case "nologo": |
| 99 | this.showLogo = false; | 101 | this.showLogo = false; |
| 100 | return true; | 102 | return true; |
| 101 | case "s": | 103 | case "s": |
| 102 | this.subDirectories = true; | 104 | this.subDirectories = true; |
| 103 | return true; | 105 | return true; |
| 104 | default: // other parameters | 106 | default: // other parameters |
| 105 | if (parameter.StartsWith("set1", StringComparison.Ordinal)) | 107 | if (parameter.StartsWith("set1", StringComparison.Ordinal)) |
| 106 | { | 108 | { |
| 107 | this.settingsFile1 = parameter.Substring(4); | 109 | this.settingsFile1 = parameter.Substring(4); |
| 108 | } | 110 | } |
| 109 | else if (parameter.StartsWith("set2", StringComparison.Ordinal)) | 111 | else if (parameter.StartsWith("set2", StringComparison.Ordinal)) |
| 110 | { | 112 | { |
| 111 | this.settingsFile2 = parameter.Substring(4); | 113 | this.settingsFile2 = parameter.Substring(4); |
| 112 | } | 114 | } |
| 113 | else if (parameter.StartsWith("indent:", StringComparison.Ordinal)) | 115 | else if (parameter.StartsWith("indent:", StringComparison.Ordinal)) |
| 116 | { | ||
| 117 | try | ||
| 114 | { | 118 | { |
| 115 | try | 119 | this.indentationAmount = Convert.ToInt32(parameter.Substring(7)); |
| 116 | { | ||
| 117 | this.indentationAmount = Convert.ToInt32(parameter.Substring(7)); | ||
| 118 | } | ||
| 119 | catch | ||
| 120 | { | ||
| 121 | throw new ArgumentException("Invalid numeric argument.", parameter); | ||
| 122 | } | ||
| 123 | } | 120 | } |
| 124 | else | 121 | catch |
| 125 | { | 122 | { |
| 126 | throw new ArgumentException("Invalid argument.", parameter); | 123 | throw new ArgumentException("Invalid numeric argument.", parameter); |
| 127 | } | 124 | } |
| 128 | return true; | 125 | } |
| 126 | else | ||
| 127 | { | ||
| 128 | throw new ArgumentException("Invalid argument.", parameter); | ||
| 129 | } | ||
| 130 | return true; | ||
| 129 | } | 131 | } |
| 130 | } | 132 | } |
| 131 | } | 133 | } |
diff --git a/src/wixcop/Converter.cs b/src/wixcop/Converter.cs index a204ebe0..7e8486ab 100644 --- a/src/wixcop/Converter.cs +++ b/src/wixcop/Converter.cs | |||
| @@ -1,6 +1,6 @@ | |||
| 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. | 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 | 2 | ||
| 3 | namespace WixCop | 3 | namespace WixToolset.Tools.WixCop |
| 4 | { | 4 | { |
| 5 | using System; | 5 | using System; |
| 6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
| @@ -141,7 +141,7 @@ namespace WixCop | |||
| 141 | { | 141 | { |
| 142 | try | 142 | try |
| 143 | { | 143 | { |
| 144 | using (StreamWriter writer = File.CreateText(this.SourceFile)) | 144 | using (var writer = File.CreateText(this.SourceFile)) |
| 145 | { | 145 | { |
| 146 | document.Save(writer, SaveOptions.DisableFormatting | SaveOptions.OmitDuplicateNamespaces); | 146 | document.Save(writer, SaveOptions.DisableFormatting | SaveOptions.OmitDuplicateNamespaces); |
| 147 | } | 147 | } |
| @@ -162,7 +162,7 @@ namespace WixCop | |||
| 162 | /// <returns>The number of errors found.</returns> | 162 | /// <returns>The number of errors found.</returns> |
| 163 | public int ConvertDocument(XDocument document) | 163 | public int ConvertDocument(XDocument document) |
| 164 | { | 164 | { |
| 165 | XDeclaration declaration = document.Declaration; | 165 | var declaration = document.Declaration; |
| 166 | 166 | ||
| 167 | // Convert the declaration. | 167 | // Convert the declaration. |
| 168 | if (null != declaration) | 168 | if (null != declaration) |
| @@ -206,7 +206,7 @@ namespace WixCop | |||
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | // Convert this node if it is an element. | 208 | // Convert this node if it is an element. |
| 209 | XElement element = node as XElement; | 209 | var element = node as XElement; |
| 210 | 210 | ||
| 211 | if (null != element) | 211 | if (null != element) |
| 212 | { | 212 | { |
| @@ -215,7 +215,7 @@ namespace WixCop | |||
| 215 | // Convert all children of this element. | 215 | // Convert all children of this element. |
| 216 | IEnumerable<XNode> children = element.Nodes().ToList(); | 216 | IEnumerable<XNode> children = element.Nodes().ToList(); |
| 217 | 217 | ||
| 218 | foreach (XNode child in children) | 218 | foreach (var child in children) |
| 219 | { | 219 | { |
| 220 | this.ConvertNode(child, level + 1); | 220 | this.ConvertNode(child, level + 1); |
| 221 | } | 221 | } |
| @@ -225,9 +225,9 @@ namespace WixCop | |||
| 225 | private void ConvertElement(XElement element) | 225 | private void ConvertElement(XElement element) |
| 226 | { | 226 | { |
| 227 | // Gather any deprecated namespaces, then update this element tree based on those deprecations. | 227 | // Gather any deprecated namespaces, then update this element tree based on those deprecations. |
| 228 | Dictionary<XNamespace, XNamespace> deprecatedToUpdatedNamespaces = new Dictionary<XNamespace, XNamespace>(); | 228 | var deprecatedToUpdatedNamespaces = new Dictionary<XNamespace, XNamespace>(); |
| 229 | 229 | ||
| 230 | foreach (XAttribute declaration in element.Attributes().Where(a => a.IsNamespaceDeclaration)) | 230 | foreach (var declaration in element.Attributes().Where(a => a.IsNamespaceDeclaration)) |
| 231 | { | 231 | { |
| 232 | XNamespace ns; | 232 | XNamespace ns; |
| 233 | 233 | ||
| @@ -258,7 +258,7 @@ namespace WixCop | |||
| 258 | { | 258 | { |
| 259 | if (null == element.Attribute("Id")) | 259 | if (null == element.Attribute("Id")) |
| 260 | { | 260 | { |
| 261 | XAttribute attribute = element.Attribute("Name"); | 261 | var attribute = element.Attribute("Name"); |
| 262 | 262 | ||
| 263 | if (null == attribute) | 263 | if (null == attribute) |
| 264 | { | 264 | { |
| @@ -267,7 +267,7 @@ namespace WixCop | |||
| 267 | 267 | ||
| 268 | if (null != attribute) | 268 | if (null != attribute) |
| 269 | { | 269 | { |
| 270 | string name = Path.GetFileName(attribute.Value); | 270 | var name = Path.GetFileName(attribute.Value); |
| 271 | 271 | ||
| 272 | if (this.OnError(ConverterTestType.AssignAnonymousFileId, element, "The file id is being updated to '{0}' to ensure it remains the same as the default", name)) | 272 | if (this.OnError(ConverterTestType.AssignAnonymousFileId, element, "The file id is being updated to '{0}' to ensure it remains the same as the default", name)) |
| 273 | { | 273 | { |
| @@ -282,7 +282,7 @@ namespace WixCop | |||
| 282 | 282 | ||
| 283 | private void ConvertSuppressSignatureValidation(XElement element) | 283 | private void ConvertSuppressSignatureValidation(XElement element) |
| 284 | { | 284 | { |
| 285 | XAttribute suppressSignatureValidation = element.Attribute("SuppressSignatureValidation"); | 285 | var suppressSignatureValidation = element.Attribute("SuppressSignatureValidation"); |
| 286 | 286 | ||
| 287 | if (null != suppressSignatureValidation) | 287 | if (null != suppressSignatureValidation) |
| 288 | { | 288 | { |
| @@ -311,7 +311,7 @@ namespace WixCop | |||
| 311 | 311 | ||
| 312 | element.Add(new XAttribute("xmlns", WixNamespace.NamespaceName)); // set the default namespace. | 312 | element.Add(new XAttribute("xmlns", WixNamespace.NamespaceName)); // set the default namespace. |
| 313 | 313 | ||
| 314 | foreach (XElement elementWithoutNamespace in element.Elements().Where(e => XNamespace.None == e.Name.Namespace)) | 314 | foreach (var elementWithoutNamespace in element.Elements().Where(e => XNamespace.None == e.Name.Namespace)) |
| 315 | { | 315 | { |
| 316 | elementWithoutNamespace.Name = WixNamespace.GetName(elementWithoutNamespace.Name.LocalName); | 316 | elementWithoutNamespace.Name = WixNamespace.GetName(elementWithoutNamespace.Name.LocalName); |
| 317 | } | 317 | } |
| @@ -326,9 +326,7 @@ namespace WixCop | |||
| 326 | private void ConvertWhitespace(XNode node, int level) | 326 | private void ConvertWhitespace(XNode node, int level) |
| 327 | { | 327 | { |
| 328 | // Fix the whitespace before this node. | 328 | // Fix the whitespace before this node. |
| 329 | XText whitespace = node.PreviousNode as XText; | 329 | if (node.PreviousNode is XText whitespace) |
| 330 | |||
| 331 | if (null != whitespace) | ||
| 332 | { | 330 | { |
| 333 | if (XmlNodeType.CDATA == node.NodeType) | 331 | if (XmlNodeType.CDATA == node.NodeType) |
| 334 | { | 332 | { |
| @@ -351,9 +349,7 @@ namespace WixCop | |||
| 351 | } | 349 | } |
| 352 | 350 | ||
| 353 | // Fix the whitespace after CDATA nodes. | 351 | // Fix the whitespace after CDATA nodes. |
| 354 | XCData cdata = node as XCData; | 352 | if (node is XCData cdata) |
| 355 | |||
| 356 | if (null != cdata) | ||
| 357 | { | 353 | { |
| 358 | whitespace = cdata.NextNode as XText; | 354 | whitespace = cdata.NextNode as XText; |
| 359 | 355 | ||
| @@ -368,9 +364,7 @@ namespace WixCop | |||
| 368 | else | 364 | else |
| 369 | { | 365 | { |
| 370 | // Fix the whitespace inside and after this node (except for Error which may contain just whitespace). | 366 | // Fix the whitespace inside and after this node (except for Error which may contain just whitespace). |
| 371 | XElement element = node as XElement; | 367 | if (node is XElement element && "Error" != element.Name.LocalName) |
| 372 | |||
| 373 | if (null != element && "Error" != element.Name.LocalName) | ||
| 374 | { | 368 | { |
| 375 | if (!element.HasElements && !element.IsEmpty && String.IsNullOrEmpty(element.Value.Trim())) | 369 | if (!element.HasElements && !element.IsEmpty && String.IsNullOrEmpty(element.Value.Trim())) |
| 376 | { | 370 | { |
| @@ -403,7 +397,7 @@ namespace WixCop | |||
| 403 | { | 397 | { |
| 404 | if (null != types) | 398 | if (null != types) |
| 405 | { | 399 | { |
| 406 | foreach (string type in types) | 400 | foreach (var type in types) |
| 407 | { | 401 | { |
| 408 | ConverterTestType itt; | 402 | ConverterTestType itt; |
| 409 | 403 | ||
| @@ -421,7 +415,7 @@ namespace WixCop | |||
| 421 | 415 | ||
| 422 | private static void UpdateElementsWithDeprecatedNamespaces(IEnumerable<XElement> elements, Dictionary<XNamespace, XNamespace> deprecatedToUpdatedNamespaces) | 416 | private static void UpdateElementsWithDeprecatedNamespaces(IEnumerable<XElement> elements, Dictionary<XNamespace, XNamespace> deprecatedToUpdatedNamespaces) |
| 423 | { | 417 | { |
| 424 | foreach (XElement element in elements) | 418 | foreach (var element in elements) |
| 425 | { | 419 | { |
| 426 | XNamespace ns; | 420 | XNamespace ns; |
| 427 | 421 | ||
| @@ -434,9 +428,9 @@ namespace WixCop | |||
| 434 | IEnumerable<XAttribute> attributes = element.Attributes().ToList(); | 428 | IEnumerable<XAttribute> attributes = element.Attributes().ToList(); |
| 435 | element.RemoveAttributes(); | 429 | element.RemoveAttributes(); |
| 436 | 430 | ||
| 437 | foreach (XAttribute attribute in attributes) | 431 | foreach (var attribute in attributes) |
| 438 | { | 432 | { |
| 439 | XAttribute convertedAttribute = attribute; | 433 | var convertedAttribute = attribute; |
| 440 | 434 | ||
| 441 | if (attribute.IsNamespaceDeclaration) | 435 | if (attribute.IsNamespaceDeclaration) |
| 442 | { | 436 | { |
| @@ -477,7 +471,7 @@ namespace WixCop | |||
| 477 | } | 471 | } |
| 478 | 472 | ||
| 479 | // check the spaces | 473 | // check the spaces |
| 480 | foreach (char character in whitespace) | 474 | foreach (var character in whitespace) |
| 481 | { | 475 | { |
| 482 | if (' ' != character) | 476 | if (' ' != character) |
| 483 | { | 477 | { |
| @@ -496,9 +490,9 @@ namespace WixCop | |||
| 496 | /// <param name="whitespace">The whitespace node to fix.</param> | 490 | /// <param name="whitespace">The whitespace node to fix.</param> |
| 497 | private static void FixWhitespace(int indentationAmount, int level, XText whitespace) | 491 | private static void FixWhitespace(int indentationAmount, int level, XText whitespace) |
| 498 | { | 492 | { |
| 499 | int newLineCount = 0; | 493 | var newLineCount = 0; |
| 500 | 494 | ||
| 501 | for (int i = 0; i + 1 < whitespace.Value.Length; ++i) | 495 | for (var i = 0; i + 1 < whitespace.Value.Length; ++i) |
| 502 | { | 496 | { |
| 503 | if (XDocumentNewLine == whitespace.Value.Substring(i, 2)) | 497 | if (XDocumentNewLine == whitespace.Value.Substring(i, 2)) |
| 504 | { | 498 | { |
| @@ -516,7 +510,7 @@ namespace WixCop | |||
| 516 | whitespace.Value = String.Empty; | 510 | whitespace.Value = String.Empty; |
| 517 | 511 | ||
| 518 | // add the correct number of newlines | 512 | // add the correct number of newlines |
| 519 | for (int i = 0; i < newLineCount; ++i) | 513 | for (var i = 0; i < newLineCount; ++i) |
| 520 | { | 514 | { |
| 521 | whitespace.Value = String.Concat(whitespace.Value, XDocumentNewLine); | 515 | whitespace.Value = String.Concat(whitespace.Value, XDocumentNewLine); |
| 522 | } | 516 | } |
| @@ -543,9 +537,9 @@ namespace WixCop | |||
| 543 | // Increase the error count. | 537 | // Increase the error count. |
| 544 | this.Errors++; | 538 | this.Errors++; |
| 545 | 539 | ||
| 546 | SourceLineNumber sourceLine = (null == node) ? new SourceLineNumber(this.SourceFile ?? "wixcop.exe") : new SourceLineNumber(this.SourceFile, ((IXmlLineInfo)node).LineNumber); | 540 | var sourceLine = (null == node) ? new SourceLineNumber(this.SourceFile ?? "wixcop.exe") : new SourceLineNumber(this.SourceFile, ((IXmlLineInfo)node).LineNumber); |
| 547 | bool warning = this.ErrorsAsWarnings.Contains(converterTestType); | 541 | var warning = this.ErrorsAsWarnings.Contains(converterTestType); |
| 548 | string display = String.Format(CultureInfo.CurrentCulture, message, args); | 542 | var display = String.Format(CultureInfo.CurrentCulture, message, args); |
| 549 | 543 | ||
| 550 | var msg = new Message(sourceLine, warning ? MessageLevel.Warning : MessageLevel.Error, (int)converterTestType, "{0} ({1})", display, converterTestType.ToString()); | 544 | var msg = new Message(sourceLine, warning ? MessageLevel.Warning : MessageLevel.Error, (int)converterTestType, "{0} ({1})", display, converterTestType.ToString()); |
| 551 | 545 | ||
diff --git a/src/wixcop/Interfaces/IWixCopCommandLineParser.cs b/src/wixcop/Interfaces/IWixCopCommandLineParser.cs index 2093f5d8..44c75289 100644 --- a/src/wixcop/Interfaces/IWixCopCommandLineParser.cs +++ b/src/wixcop/Interfaces/IWixCopCommandLineParser.cs | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | using WixToolset.Extensibility.Data; | 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 | 2 | ||
| 3 | namespace WixCop.Interfaces | 3 | namespace WixToolset.Tools.WixCop.Interfaces |
| 4 | { | 4 | { |
| 5 | using WixToolset.Extensibility.Data; | ||
| 6 | |||
| 5 | public interface IWixCopCommandLineParser | 7 | public interface IWixCopCommandLineParser |
| 6 | { | 8 | { |
| 7 | ICommandLineArguments Arguments { get; set; } | 9 | ICommandLineArguments Arguments { get; set; } |
diff --git a/src/wixcop/Program.cs b/src/wixcop/Program.cs index b26bd6c9..8e9534f6 100644 --- a/src/wixcop/Program.cs +++ b/src/wixcop/Program.cs | |||
| @@ -1,15 +1,15 @@ | |||
| 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. | 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 | 2 | ||
| 3 | namespace WixCop | 3 | namespace WixToolset.Tools.WixCop |
| 4 | { | 4 | { |
| 5 | using System; | 5 | using System; |
| 6 | using WixCop.CommandLine; | ||
| 7 | using WixCop.Interfaces; | ||
| 8 | using WixToolset.Core; | 6 | using WixToolset.Core; |
| 9 | using WixToolset.Extensibility; | 7 | using WixToolset.Extensibility; |
| 10 | using WixToolset.Extensibility.Data; | 8 | using WixToolset.Extensibility.Data; |
| 11 | using WixToolset.Extensibility.Services; | 9 | using WixToolset.Extensibility.Services; |
| 12 | using WixToolset.Tools.Core; | 10 | using WixToolset.Tools.Core; |
| 11 | using WixToolset.Tools.WixCop.CommandLine; | ||
| 12 | using WixToolset.Tools.WixCop.Interfaces; | ||
| 13 | 13 | ||
| 14 | /// <summary> | 14 | /// <summary> |
| 15 | /// Wix source code style inspector and converter. | 15 | /// Wix source code style inspector and converter. |
