Fix converting empty inner text.
Add failing test for commented inner text.
Sean Hall committed
Aug 3, 2022 at 13:56 UTC
a896fec453056aa5e1ad803b04a672d2dceda981
9 files changed
+178
-4
src/wix/WixToolset.Converters/WixConverter.cs
+5
-3
@@ -2274,15 +2274,17 @@ namespace WixToolset.Converters
2274
private static bool TryGetInnerText(XElement element, out string value)
2275
{
2276
value = null;
2277
+ var found = false;
2278
2278
- var nodes = element.Nodes();
2279
+ var nodes = element.Nodes().ToList();
2280
2280
- if (nodes.All(e => e.NodeType == XmlNodeType.Text || e.NodeType == XmlNodeType.CDATA))
2281
+ if (nodes.Any() && nodes.All(e => e.NodeType == XmlNodeType.Text || e.NodeType == XmlNodeType.CDATA))
2282
{
2283
value = String.Join(String.Empty, nodes.Cast<XText>().Select(TrimTextValue));
2284
+ found = true;
2285
}
2286
2285
- return !String.IsNullOrEmpty(value);
2287
+ return found;
2288
}
2289
2290
private static bool IsTextNode(XNode node, out XText text)
src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs
+109
@@ -139,6 +139,115 @@ namespace WixToolsetTest.Converters
139
WixAssert.CompareLineByLine(expected, actualLines);
140
}
141
142
+ [Fact]
143
+ public void FixEmptyCondition()
144
+ {
145
+ var parse = String.Join(Environment.NewLine,
146
+ "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
147
+ "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
148
+ " <Fragment>",
149
+ " <Condition Message='Empty new line'>",
150
+ " </Condition>",
151
+ " <Condition Message='Empty cdata'><![CDATA[]]></Condition>",
152
+ " </Fragment>",
153
+ "</Wix>");
154
+
155
+ var expected = new[]
156
+ {
157
+ "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
158
+ " <Fragment>",
159
+ " <Launch Condition=\"\" Message=\"Empty new line\" />",
160
+ " <Launch Condition=\"\" Message=\"Empty cdata\" />",
161
+ " </Fragment>",
162
+ "</Wix>"
163
+ };
164
+
165
+ var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
166
+
167
+ var messaging = new MockMessaging();
168
+ var converter = new WixConverter(messaging, 2, null, null);
169
+
170
+ var errors = converter.ConvertDocument(document);
171
+
172
+ var actualLines = UnformattedDocumentLines(document);
173
+ WixAssert.CompareLineByLine(expected, actualLines);
174
+
175
+ Assert.Equal(4, errors);
176
+ }
177
+
178
+ [Fact(Skip = "Test demonstrates failure")]
179
+ public void FixConditionWithComment()
180
+ {
181
+ var parse = String.Join(Environment.NewLine,
182
+ "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
183
+ "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
184
+ " <Fragment>",
185
+ " <Condition Message='commented cdata'>",
186
+ " <!-- commented condition -->",
187
+ " <![CDATA[cdatacontent]]>",
188
+ " </Condition>",
189
+ " </Fragment>",
190
+ "</Wix>");
191
+
192
+ //TODO: expected value is not set in stone but must have replaced Condition element with Launch and should have kept the comment.
193
+ var expected = new[]
194
+ {
195
+ "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
196
+ " <Fragment>",
197
+ " <Launch Condition=\"cdatacontent\" Message=\"commented cdata\" />",
198
+ " <!-- commented condition -->",
199
+ " </Fragment>",
200
+ "</Wix>"
201
+ };
202
+
203
+ var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
204
+
205
+ var messaging = new MockMessaging();
206
+ var converter = new WixConverter(messaging, 2, null, null);
207
+
208
+ var errors = converter.ConvertDocument(document);
209
+
210
+ var actualLines = UnformattedDocumentLines(document);
211
+ WixAssert.CompareLineByLine(expected, actualLines);
212
+
213
+ Assert.Equal(2, errors);
214
+ }
215
+
216
+ [Fact]
217
+ public void FixConditionFromWxi()
218
+ {
219
+ var parse = String.Join(Environment.NewLine,
220
+ "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
221
+ "<Include xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
222
+ " <Fragment>",
223
+ " <Condition Message='from wxi'>",
224
+ " wxicondition",
225
+ " </Condition>",
226
+ " </Fragment>",
227
+ "</Include>");
228
+
229
+ var expected = new[]
230
+ {
231
+ "<Include xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
232
+ " <Fragment>",
233
+ " <Launch Condition=\"wxicondition\" Message=\"from wxi\" />",
234
+ " </Fragment>",
235
+ "</Include>"
236
+ };
237
+
238
+ var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
239
+
240
+ var messaging = new MockMessaging();
241
+ var converter = new WixConverter(messaging, 2, null, null);
242
+
243
+ var errors = converter.ConvertDocument(document);
244
+
245
+ var actualLines = UnformattedDocumentLines(document);
246
+ WixAssert.CompareLineByLine(expected, actualLines);
247
+
248
+ Assert.Equal(3, errors);
249
+ }
250
+
251
[Fact]
252
public void FixFeatureCondition()
253
{
src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs
+37
@@ -306,6 +306,43 @@ namespace WixToolsetTest.CoreIntegration
306
}
307
}
308
309
+ [Fact]
310
+ public void CanBuildSimpleBundleUsingInclude()
311
+ {
312
+ var folder = TestData.Get(@"TestData", "IncludePath");
313
+ var dataFolder = TestData.Get(@"TestData", "SimpleBundle", "data");
314
+
315
+ using (var fs = new DisposableFileSystem())
316
+ {
317
+ var baseFolder = fs.GetFolder();
318
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
319
+ var exePath = Path.Combine(baseFolder, @"bin\test.exe");
320
+ var pdbPath = Path.Combine(baseFolder, @"bin\test.wixpdb");
321
+
322
+ var result = WixRunner.Execute(new[]
323
+ {
324
+ "build",
325
+ Path.Combine(folder, "Bundle.wxs"),
326
+ "-loc", Path.Combine(folder, "Bundle.en-us.wxl"),
327
+ "-bindpath", dataFolder,
328
+ "-intermediateFolder", intermediateFolder,
329
+ "-o", exePath,
330
+ });
331
+
332
+ result.AssertSuccess();
333
+
334
+ using (var wixOutput = WixOutput.Read(pdbPath))
335
+ {
336
+
337
+ var intermediate = Intermediate.Load(wixOutput);
338
+ var section = intermediate.Sections.Single();
339
+
340
+ var bundleSymbol = section.Symbols.OfType<WixBundleSymbol>().Single();
341
+ WixAssert.StringEqual("~IncludeTestBundle", bundleSymbol.Name);
342
+ }
343
+ }
344
+ }
345
+
346
[Fact]
347
public void CanBuildSingleExeBundle()
348
{
src/wix/test/WixToolsetTest.CoreIntegration/MsiFixture.cs
+3
@@ -535,6 +535,9 @@ namespace WixToolsetTest.CoreIntegration
535
var fileSymbol = section.Symbols.OfType<FileSymbol>().Single();
536
WixAssert.StringEqual(Path.Combine(folder, @"data\test.txt"), fileSymbol[FileSymbolFields.Source].AsPath().Path);
537
WixAssert.StringEqual(@"test.txt", fileSymbol[FileSymbolFields.Source].PreviousValue.AsPath().Path);
538
+
539
+ var featureSymbol = Assert.Single(section.Symbols.OfType<FeatureSymbol>());
540
+ WixAssert.StringEqual("MsiPackage", featureSymbol.Title);
541
}
542
}
543
src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.en-us.wxl
new
+6
@@ -0,0 +1,6 @@
1
+<WixLocalization xmlns="http://wixtoolset.org/schemas/v4/wxl" Culture="en-US">
2
+
3
+ <String Id="BundleName">~IncludeTestBundle</String>
4
+ <String Id="BundleInProgressName">~InProgressTestBundle</String>
5
+
6
+</WixLocalization>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.wxs
new
+13
@@ -0,0 +1,13 @@
1
+<?include data\Bundle.wxi ?>
2
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3
+ <Bundle Name="$(var.BundleLocName)" InProgressName="!(loc.BundleInProgressName)" Version="!(bind.packageVersion.test.msi)" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
4
+ <BootstrapperApplication>
5
+ <BootstrapperApplicationDll SourceFile="fakeba.dll" />
6
+ </BootstrapperApplication>
7
+ <Chain>
8
+ <MsiPackage SourceFile="test.msi">
9
+ <MsiProperty Name="TEST" Value="1" />
10
+ </MsiPackage>
11
+ </Chain>
12
+ </Bundle>
13
+</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Package.wxs
+1
-1
@@ -5,7 +5,7 @@
5
6
<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />
7
8
- <Feature Id="ProductFeature" Title="!(loc.FeatureTitle)">
8
+ <Feature Id="ProductFeature" Title="$(var.FeatureTitleName)">
9
<ComponentGroupRef Id="ProductComponents" />
10
</Feature>
11
</Package>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Bundle.wxi
new
+3
@@ -0,0 +1,3 @@
1
+<Include xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
+ <?define BundleLocName = "!(loc.BundleName)" ?>
3
+</Include>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Package.wxi
+1
@@ -1,4 +1,5 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<Include xmlns="http://wixtoolset.org/schemas/v4/wxs">
3
<?define ProductVersion = "1.2.3" ?>
4
+ <?define FeatureTitleName = "!(loc.FeatureTitle)" ?>
5
</Include>