From 941c7cae67823ed7da82d5f6f43233b7364eefc9 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Wed, 2 Sep 2020 20:24:16 -0400 Subject: Converters fixes and cleanup. - Support keeping the XML declaration. - Parse settings files earlier so they...work. - Fix typo. --- .../ConvertSymbols.cs | 2 +- src/WixToolset.Converters/ConvertCommand.cs | 4 ++-- src/WixToolset.Converters/WixConverter.cs | 26 +++++++++----------- .../BaseConverterFixture.cs | 18 ++++---------- .../BootstrapperApplicationFixture.cs | 4 ++-- .../WixToolsetTest.Converters/ConditionFixture.cs | 13 +++++----- .../WixToolsetTest.Converters/ConverterFixture.cs | 28 ++++++++++++++++++++++ .../CustomTableFixture.cs | 9 +++---- .../WixToolsetTest.Converters/FeatureFixture.cs | 7 +++--- .../FirewallExtensionFixture.cs | 5 ++-- .../WixToolsetTest.Converters/IncludeFixture.cs | 5 ++-- .../WixToolsetTest.Converters/SequenceFixture.cs | 3 ++- .../UtilExtensionFixture.cs | 5 ++-- .../Wix4ConversionFixture.cs | 3 ++- 14 files changed, 77 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/WixToolset.Converters.Symbolizer/ConvertSymbols.cs b/src/WixToolset.Converters.Symbolizer/ConvertSymbols.cs index ca75d3c2..4fb891f9 100644 --- a/src/WixToolset.Converters.Symbolizer/ConvertSymbols.cs +++ b/src/WixToolset.Converters.Symbolizer/ConvertSymbols.cs @@ -315,7 +315,7 @@ namespace WixToolset.Converters.Symbolizer Section = FieldAsString(row, 3), Key = FieldAsString(row, 4), Value = FieldAsString(row, 5), - Action = action == 3 ? InifFileActionType.AddTag : action == 1 ? InifFileActionType.CreateLine : InifFileActionType.AddLine, + Action = action == 3 ? IniFileActionType.AddTag : action == 1 ? IniFileActionType.CreateLine : IniFileActionType.AddLine, ComponentRef = FieldAsString(row, 7), }; diff --git a/src/WixToolset.Converters/ConvertCommand.cs b/src/WixToolset.Converters/ConvertCommand.cs index 50ca7249..e29b176e 100644 --- a/src/WixToolset.Converters/ConvertCommand.cs +++ b/src/WixToolset.Converters/ConvertCommand.cs @@ -26,10 +26,10 @@ namespace WixToolset.Converters return Task.FromResult(-1); } - var converter = new WixConverter(this.Messaging, this.IndentationAmount, this.ErrorsAsWarnings, this.IgnoreErrors); - this.ParseSettings(SettingsFileDefault); + var converter = new WixConverter(this.Messaging, this.IndentationAmount, this.ErrorsAsWarnings, this.IgnoreErrors); + var errors = base.Inspect(Inspector, cancellationToken); return Task.FromResult(errors); diff --git a/src/WixToolset.Converters/WixConverter.cs b/src/WixToolset.Converters/WixConverter.cs index f10875f1..5f6ee2df 100644 --- a/src/WixToolset.Converters/WixConverter.cs +++ b/src/WixToolset.Converters/WixConverter.cs @@ -237,16 +237,13 @@ namespace WixToolset.Converters this.Operation = ConvertOperation.Convert; // Remove the declaration. - if (null != document.Declaration) + if (null != document.Declaration + && this.OnError(ConverterTestType.DeclarationPresent, null, "This file contains an XML declaration on the first line.")) { - if (this.OnError(ConverterTestType.DeclarationPresent, null, "This file contains an XML declaration on the first line.")) - { - document.Declaration = null; - } + document.Declaration = null; + TrimLeadingText(document); } - TrimLeadingText(document); - // Start converting the nodes at the top. this.ConvertNodes(document.Nodes(), 0); @@ -292,16 +289,13 @@ namespace WixToolset.Converters this.Operation = ConvertOperation.Format; // Remove the declaration. - if (null != document.Declaration) + if (null != document.Declaration + && this.OnError(ConverterTestType.DeclarationPresent, null, "This file contains an XML declaration on the first line.")) { - if (this.OnError(ConverterTestType.DeclarationPresent, null, "This file contains an XML declaration on the first line.")) - { - document.Declaration = null; - } + document.Declaration = null; + TrimLeadingText(document); } - TrimLeadingText(document); - // Start converting the nodes at the top. this.ConvertNodes(document.Nodes(), 0); @@ -326,9 +320,11 @@ namespace WixToolset.Converters private void SaveDocument(XDocument document) { + var ignoreDeclarationError = this.IgnoreErrors.Contains(ConverterTestType.DeclarationPresent); + try { - using (var writer = XmlWriter.Create(this.SourceFile, new XmlWriterSettings { OmitXmlDeclaration = true })) + using (var writer = XmlWriter.Create(this.SourceFile, new XmlWriterSettings { OmitXmlDeclaration = !ignoreDeclarationError })) { document.Save(writer); } diff --git a/src/test/WixToolsetTest.Converters/BaseConverterFixture.cs b/src/test/WixToolsetTest.Converters/BaseConverterFixture.cs index 2cd4119b..2421d73b 100644 --- a/src/test/WixToolsetTest.Converters/BaseConverterFixture.cs +++ b/src/test/WixToolsetTest.Converters/BaseConverterFixture.cs @@ -11,12 +11,12 @@ namespace WixToolsetTest.Converters public abstract class BaseConverterFixture { - protected static string UnformattedDocumentString(XDocument document) + protected static string UnformattedDocumentString(XDocument document, bool omitXmlDeclaration = true) { var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) - using (var xml = XmlWriter.Create(writer, new XmlWriterSettings { OmitXmlDeclaration = true })) + using (var xml = XmlWriter.Create(writer, new XmlWriterSettings { OmitXmlDeclaration = omitXmlDeclaration })) { document.Save(xml); } @@ -24,20 +24,10 @@ namespace WixToolsetTest.Converters return sb.ToString().TrimStart(); } - protected static string[] UnformattedDocumentLines(XDocument document) + protected static string[] UnformattedDocumentLines(XDocument document, bool omitXmlDeclaration = true) { - var unformatted = UnformattedDocumentString(document); + var unformatted = UnformattedDocumentString(document, omitXmlDeclaration); return unformatted.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); } - - protected static void CompareLineByLine(string[] expectedLines, string[] actualLines) - { - for (var i = 0; i < expectedLines.Length; ++i) - { - Assert.True(actualLines.Length > i, $"{i}: Expected file longer than actual file"); - Assert.Equal($"{i}: {expectedLines[i]}", $"{i}: {actualLines[i]}"); - } - Assert.True(expectedLines.Length == actualLines.Length, "Actual file longer than expected file"); - } } } diff --git a/src/test/WixToolsetTest.Converters/BootstrapperApplicationFixture.cs b/src/test/WixToolsetTest.Converters/BootstrapperApplicationFixture.cs index 1551077b..68a8afc8 100644 --- a/src/test/WixToolsetTest.Converters/BootstrapperApplicationFixture.cs +++ b/src/test/WixToolsetTest.Converters/BootstrapperApplicationFixture.cs @@ -39,7 +39,7 @@ namespace WixToolsetTest.Converters Assert.Equal(2, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -70,7 +70,7 @@ namespace WixToolsetTest.Converters Assert.Equal(0, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } } } diff --git a/src/test/WixToolsetTest.Converters/ConditionFixture.cs b/src/test/WixToolsetTest.Converters/ConditionFixture.cs index d8e5b392..65fa6734 100644 --- a/src/test/WixToolsetTest.Converters/ConditionFixture.cs +++ b/src/test/WixToolsetTest.Converters/ConditionFixture.cs @@ -4,6 +4,7 @@ namespace WixToolsetTest.Converters { using System; using System.Xml.Linq; + using WixBuildTools.TestSupport; using WixToolset.Converters; using WixToolsetTest.Converters.Mocks; using Xunit; @@ -53,7 +54,7 @@ namespace WixToolsetTest.Converters Assert.Equal(4, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -99,7 +100,7 @@ namespace WixToolsetTest.Converters Assert.Equal(5, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -135,7 +136,7 @@ namespace WixToolsetTest.Converters Assert.Equal(3, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -171,7 +172,7 @@ namespace WixToolsetTest.Converters Assert.Equal(3, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -209,7 +210,7 @@ namespace WixToolsetTest.Converters Assert.Equal(4, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -250,7 +251,7 @@ namespace WixToolsetTest.Converters Assert.Equal(3, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } } } diff --git a/src/test/WixToolsetTest.Converters/ConverterFixture.cs b/src/test/WixToolsetTest.Converters/ConverterFixture.cs index cf89ba7e..29f34412 100644 --- a/src/test/WixToolsetTest.Converters/ConverterFixture.cs +++ b/src/test/WixToolsetTest.Converters/ConverterFixture.cs @@ -39,6 +39,34 @@ namespace WixToolsetTest.Converters Assert.Equal(expected, actual); } + [Fact] + public void EnsuresDeclarationWhenIgnored() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + ""); + + var expected = String.Join(Environment.NewLine, + "", + "", + " ", + ""); + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new WixConverter(messaging, 2, ignoreErrors: new[] { "DeclarationPresent" } ); + + var errors = converter.ConvertDocument(document); + + var actual = UnformattedDocumentString(document, omitXmlDeclaration: false); + + Assert.Equal(0, errors); + Assert.Equal(expected, actual); + } + [Fact] public void CanConvertMainNamespace() { diff --git a/src/test/WixToolsetTest.Converters/CustomTableFixture.cs b/src/test/WixToolsetTest.Converters/CustomTableFixture.cs index 4470a2ff..c51d1923 100644 --- a/src/test/WixToolsetTest.Converters/CustomTableFixture.cs +++ b/src/test/WixToolsetTest.Converters/CustomTableFixture.cs @@ -4,6 +4,7 @@ namespace WixToolsetTest.Converters { using System; using System.Xml.Linq; + using WixBuildTools.TestSupport; using WixToolset.Converters; using WixToolsetTest.Converters.Mocks; using Xunit; @@ -43,7 +44,7 @@ namespace WixToolsetTest.Converters Assert.Equal(4, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -85,7 +86,7 @@ namespace WixToolsetTest.Converters Assert.Equal(3, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -128,7 +129,7 @@ namespace WixToolsetTest.Converters Assert.Equal(2, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -164,7 +165,7 @@ namespace WixToolsetTest.Converters Assert.Equal(2, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] diff --git a/src/test/WixToolsetTest.Converters/FeatureFixture.cs b/src/test/WixToolsetTest.Converters/FeatureFixture.cs index 8240945d..1df94a81 100644 --- a/src/test/WixToolsetTest.Converters/FeatureFixture.cs +++ b/src/test/WixToolsetTest.Converters/FeatureFixture.cs @@ -4,6 +4,7 @@ namespace WixToolsetTest.Converters { using System; using System.Xml.Linq; + using WixBuildTools.TestSupport; using WixToolset.Converters; using WixToolsetTest.Converters.Mocks; using Xunit; @@ -39,7 +40,7 @@ namespace WixToolsetTest.Converters Assert.Equal(4, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -71,7 +72,7 @@ namespace WixToolsetTest.Converters Assert.Equal(3, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -103,7 +104,7 @@ namespace WixToolsetTest.Converters Assert.Equal(3, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } } } diff --git a/src/test/WixToolsetTest.Converters/FirewallExtensionFixture.cs b/src/test/WixToolsetTest.Converters/FirewallExtensionFixture.cs index 72571cd8..e6ec8568 100644 --- a/src/test/WixToolsetTest.Converters/FirewallExtensionFixture.cs +++ b/src/test/WixToolsetTest.Converters/FirewallExtensionFixture.cs @@ -4,6 +4,7 @@ namespace WixToolsetTest.Converters { using System; using System.Xml.Linq; + using WixBuildTools.TestSupport; using WixToolset.Converters; using WixToolsetTest.Converters.Mocks; using Xunit; @@ -40,7 +41,7 @@ namespace WixToolsetTest.Converters Assert.Equal(3, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -73,7 +74,7 @@ namespace WixToolsetTest.Converters Assert.Equal(3, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } } } diff --git a/src/test/WixToolsetTest.Converters/IncludeFixture.cs b/src/test/WixToolsetTest.Converters/IncludeFixture.cs index 7be2c030..2fd8244f 100644 --- a/src/test/WixToolsetTest.Converters/IncludeFixture.cs +++ b/src/test/WixToolsetTest.Converters/IncludeFixture.cs @@ -4,6 +4,7 @@ namespace WixToolsetTest.Converters { using System; using System.Xml.Linq; + using WixBuildTools.TestSupport; using WixToolset.Converters; using WixToolsetTest.Converters.Mocks; using Xunit; @@ -34,7 +35,7 @@ namespace WixToolsetTest.Converters Assert.Equal(1, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -61,7 +62,7 @@ namespace WixToolsetTest.Converters Assert.Equal(1, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } } } diff --git a/src/test/WixToolsetTest.Converters/SequenceFixture.cs b/src/test/WixToolsetTest.Converters/SequenceFixture.cs index 2fbc4d4a..ec6c709b 100644 --- a/src/test/WixToolsetTest.Converters/SequenceFixture.cs +++ b/src/test/WixToolsetTest.Converters/SequenceFixture.cs @@ -4,6 +4,7 @@ namespace WixToolsetTest.Converters { using System; using System.Xml.Linq; + using WixBuildTools.TestSupport; using WixToolset.Converters; using WixToolsetTest.Converters.Mocks; using Xunit; @@ -42,7 +43,7 @@ namespace WixToolsetTest.Converters Assert.Equal(2, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } } } diff --git a/src/test/WixToolsetTest.Converters/UtilExtensionFixture.cs b/src/test/WixToolsetTest.Converters/UtilExtensionFixture.cs index d9c58160..9d55af79 100644 --- a/src/test/WixToolsetTest.Converters/UtilExtensionFixture.cs +++ b/src/test/WixToolsetTest.Converters/UtilExtensionFixture.cs @@ -4,6 +4,7 @@ namespace WixToolsetTest.Converters { using System; using System.Xml.Linq; + using WixBuildTools.TestSupport; using WixToolset.Converters; using WixToolsetTest.Converters.Mocks; using Xunit; @@ -40,7 +41,7 @@ namespace WixToolsetTest.Converters Assert.Equal(3, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } [Fact] @@ -73,7 +74,7 @@ namespace WixToolsetTest.Converters Assert.Equal(3, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } } } diff --git a/src/test/WixToolsetTest.Converters/Wix4ConversionFixture.cs b/src/test/WixToolsetTest.Converters/Wix4ConversionFixture.cs index a3f2adc8..16a68895 100644 --- a/src/test/WixToolsetTest.Converters/Wix4ConversionFixture.cs +++ b/src/test/WixToolsetTest.Converters/Wix4ConversionFixture.cs @@ -4,6 +4,7 @@ namespace WixToolsetTest.Converters { using System; using System.Xml.Linq; + using WixBuildTools.TestSupport; using WixToolset.Converters; using WixToolsetTest.Converters.Mocks; using Xunit; @@ -47,7 +48,7 @@ namespace WixToolsetTest.Converters Assert.Equal(1, errors); var actualLines = UnformattedDocumentLines(document); - CompareLineByLine(expected, actualLines); + WixAssert.CompareLineByLine(expected, actualLines); } } } -- cgit v1.2.3-55-g6feb