@joebigelow / wix / commits / df40c272

Fix TryGetNextNonSwitchArgumentOrError.

Sean Hall committed Jan 2, 2021 at 20:05 UTC df40c2722e4a41e01cf326353e2583ae82ccc9a4
4 files changed +47 -31
src/WixToolset.Core/CommandLine/BuildCommand.cs
+1 -1
@@ -578,7 +578,7 @@ namespace WixToolset.Core.CommandLine
578 case "bindpath":
579 {
580 var value = parser.GetNextArgumentOrError(arg);
581 - if (this.TryParseBindPath(value, out var bindPath))
581 + if (value != null && this.TryParseBindPath(value, out var bindPath))
582 {
583 this.BindPaths.Add(bindPath);
584 return true;
src/WixToolset.Core/CommandLine/CommandLineParser.cs
+2 -1
@@ -138,9 +138,10 @@ namespace WixToolset.Core.CommandLine
138 {
139 var result = this.TryGetNextSwitchOrArgument(out arg);
140
141 - if (!result && !this.IsSwitch(arg))
141 + if (!result || this.IsSwitch(arg))
142 {
143 this.ErrorArgument = arg ?? CommandLineParser.ExpectedArgument;
144 + return false;
145 }
146
147 return result;
src/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs
+44
@@ -6,10 +6,54 @@ namespace WixToolsetTest.CoreIntegration
6 using System.IO;
7 using WixBuildTools.TestSupport;
8 using WixToolset.Core.TestPackage;
9 + using WixToolset.Data;
10 using Xunit;
11
12 public class BadInputFixture
13 {
14 + [Fact]
15 + public void SwitchIsNotConsideredAnArgument()
16 + {
17 + var result = WixRunner.Execute(new[]
18 + {
19 + "build",
20 + "-bindpath", "-thisisaswitchnotanarg",
21 + });
22 +
23 + Assert.Single(result.Messages, m => m.Id == (int)ErrorMessages.Ids.ExpectedArgument);
24 + // TODO: when CantBuildSingleExeBundleWithInvalidArgument is fixed, uncomment:
25 + //Assert.Equal((int)ErrorMessages.Ids.ExpectedArgument, result.ExitCode);
26 + }
27 +
28 + [Fact(Skip = "Test demonstrates failure")]
29 + public void CantBuildSingleExeBundleWithInvalidArgument()
30 + {
31 + var folder = TestData.Get(@"TestData");
32 +
33 + using (var fs = new DisposableFileSystem())
34 + {
35 + var baseFolder = fs.GetFolder();
36 + var intermediateFolder = Path.Combine(baseFolder, "obj");
37 + var exePath = Path.Combine(baseFolder, @"bin\test.exe");
38 +
39 + var result = WixRunner.Execute(new[]
40 + {
41 + "build",
42 + Path.Combine(folder, "SingleExeBundle", "SingleExePackageGroup.wxs"),
43 + Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"),
44 + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"),
45 + "-bindpath", Path.Combine(folder, ".Data"),
46 + "-intermediateFolder", intermediateFolder,
47 + "-o", exePath,
48 + "-nonexistentswitch", "param",
49 + });
50 +
51 + Assert.NotEqual(0, result.ExitCode);
52 +
53 + Assert.False(File.Exists(exePath));
54 + }
55 + }
56 +
57 [Fact]
58 public void RegistryKeyWithoutAttributesDoesntCrash()
59 {
src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs
-29
@@ -189,35 +189,6 @@ namespace WixToolsetTest.CoreIntegration
189 }
190 }
191
192 - [Fact(Skip = "Test demonstrates failure")]
193 - public void CantBuildSingleExeBundleWithInvalidArgument()
194 - {
195 - var folder = TestData.Get(@"TestData");
196 -
197 - using (var fs = new DisposableFileSystem())
198 - {
199 - var baseFolder = fs.GetFolder();
200 - var intermediateFolder = Path.Combine(baseFolder, "obj");
201 - var exePath = Path.Combine(baseFolder, @"bin\test.exe");
202 -
203 - var result = WixRunner.Execute(new[]
204 - {
205 - "build",
206 - Path.Combine(folder, "SingleExeBundle", "SingleExePackageGroup.wxs"),
207 - Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"),
208 - "-bindpath", Path.Combine(folder, "SimpleBundle", "data"),
209 - "-bindpath", Path.Combine(folder, ".Data"),
210 - "-intermediateFolder", intermediateFolder,
211 - "-o", exePath,
212 - "-nonexistentswitch", "param",
213 - });
214 -
215 - Assert.NotEqual(0, result.ExitCode);
216 -
217 - Assert.False(File.Exists(exePath));
218 - }
219 - }
220 -
192 [Fact]
193 public void CanBuildSingleExeRemotePayloadBundle()
194 {