From a896fec453056aa5e1ad803b04a672d2dceda981 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 3 Aug 2022 13:56:54 -0500 Subject: Fix converting empty inner text. Add failing test for commented inner text. --- src/wix/WixToolset.Converters/WixConverter.cs | 8 +- .../WixToolsetTest.Converters/ConditionFixture.cs | 109 +++++++++++++++++++++ .../BundleFixture.cs | 37 +++++++ .../WixToolsetTest.CoreIntegration/MsiFixture.cs | 3 + .../TestData/IncludePath/Bundle.en-us.wxl | 6 ++ .../TestData/IncludePath/Bundle.wxs | 13 +++ .../TestData/IncludePath/Package.wxs | 2 +- .../TestData/IncludePath/data/Bundle.wxi | 3 + .../TestData/IncludePath/data/Package.wxi | 1 + 9 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.en-us.wxl create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.wxs create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Bundle.wxi diff --git a/src/wix/WixToolset.Converters/WixConverter.cs b/src/wix/WixToolset.Converters/WixConverter.cs index 57069902..9b0bebc1 100644 --- a/src/wix/WixToolset.Converters/WixConverter.cs +++ b/src/wix/WixToolset.Converters/WixConverter.cs @@ -2274,15 +2274,17 @@ namespace WixToolset.Converters private static bool TryGetInnerText(XElement element, out string value) { value = null; + var found = false; - var nodes = element.Nodes(); + var nodes = element.Nodes().ToList(); - if (nodes.All(e => e.NodeType == XmlNodeType.Text || e.NodeType == XmlNodeType.CDATA)) + if (nodes.Any() && nodes.All(e => e.NodeType == XmlNodeType.Text || e.NodeType == XmlNodeType.CDATA)) { value = String.Join(String.Empty, nodes.Cast().Select(TrimTextValue)); + found = true; } - return !String.IsNullOrEmpty(value); + return found; } private static bool IsTextNode(XNode node, out XText text) diff --git a/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs b/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs index d3f65aeb..daf66a8b 100644 --- a/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs +++ b/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs @@ -139,6 +139,115 @@ namespace WixToolsetTest.Converters WixAssert.CompareLineByLine(expected, actualLines); } + [Fact] + public void FixEmptyCondition() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new WixConverter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + + var actualLines = UnformattedDocumentLines(document); + WixAssert.CompareLineByLine(expected, actualLines); + + Assert.Equal(4, errors); + } + + [Fact(Skip = "Test demonstrates failure")] + public void FixConditionWithComment() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + " ", + " ", + ""); + + //TODO: expected value is not set in stone but must have replaced Condition element with Launch and should have kept the comment. + var expected = new[] + { + "", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new WixConverter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + + var actualLines = UnformattedDocumentLines(document); + WixAssert.CompareLineByLine(expected, actualLines); + + Assert.Equal(2, errors); + } + + [Fact] + public void FixConditionFromWxi() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " wxicondition", + " ", + " ", + ""); + + var expected = new[] + { + "", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new WixConverter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + + var actualLines = UnformattedDocumentLines(document); + WixAssert.CompareLineByLine(expected, actualLines); + + Assert.Equal(3, errors); + } + [Fact] public void FixFeatureCondition() { diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs index 132e93e6..c7dd4cfa 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs @@ -306,6 +306,43 @@ namespace WixToolsetTest.CoreIntegration } } + [Fact] + public void CanBuildSimpleBundleUsingInclude() + { + var folder = TestData.Get(@"TestData", "IncludePath"); + var dataFolder = TestData.Get(@"TestData", "SimpleBundle", "data"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var exePath = Path.Combine(baseFolder, @"bin\test.exe"); + var pdbPath = Path.Combine(baseFolder, @"bin\test.wixpdb"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "Bundle.wxs"), + "-loc", Path.Combine(folder, "Bundle.en-us.wxl"), + "-bindpath", dataFolder, + "-intermediateFolder", intermediateFolder, + "-o", exePath, + }); + + result.AssertSuccess(); + + using (var wixOutput = WixOutput.Read(pdbPath)) + { + + var intermediate = Intermediate.Load(wixOutput); + var section = intermediate.Sections.Single(); + + var bundleSymbol = section.Symbols.OfType().Single(); + WixAssert.StringEqual("~IncludeTestBundle", bundleSymbol.Name); + } + } + } + [Fact] public void CanBuildSingleExeBundle() { diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/MsiFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/MsiFixture.cs index c1c07952..0c01fa5e 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/MsiFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/MsiFixture.cs @@ -535,6 +535,9 @@ namespace WixToolsetTest.CoreIntegration var fileSymbol = section.Symbols.OfType().Single(); WixAssert.StringEqual(Path.Combine(folder, @"data\test.txt"), fileSymbol[FileSymbolFields.Source].AsPath().Path); WixAssert.StringEqual(@"test.txt", fileSymbol[FileSymbolFields.Source].PreviousValue.AsPath().Path); + + var featureSymbol = Assert.Single(section.Symbols.OfType()); + WixAssert.StringEqual("MsiPackage", featureSymbol.Title); } } diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.en-us.wxl b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.en-us.wxl new file mode 100644 index 00000000..fb2131ce --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.en-us.wxl @@ -0,0 +1,6 @@ + + + ~IncludeTestBundle + ~InProgressTestBundle + + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.wxs new file mode 100644 index 00000000..5e001c9a --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.wxs @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Package.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Package.wxs index 0bd80c50..2f789908 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Package.wxs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Package.wxs @@ -5,7 +5,7 @@ - + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Bundle.wxi b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Bundle.wxi new file mode 100644 index 00000000..0ad96e6c --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Bundle.wxi @@ -0,0 +1,3 @@ + + + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Package.wxi b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Package.wxi index f2df3b86..76ebfad6 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Package.wxi +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Package.wxi @@ -1,4 +1,5 @@ + -- cgit v1.2.3-55-g6feb