From df40c2722e4a41e01cf326353e2583ae82ccc9a4 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sat, 2 Jan 2021 20:05:54 -0600 Subject: Fix TryGetNextNonSwitchArgumentOrError. --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 2 +- .../CommandLine/CommandLineParser.cs | 3 +- .../BadInputFixture.cs | 44 ++++++++++++++++++++++ .../BundleFixture.cs | 29 -------------- 4 files changed, 47 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 072accc3..fed95958 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -578,7 +578,7 @@ namespace WixToolset.Core.CommandLine case "bindpath": { var value = parser.GetNextArgumentOrError(arg); - if (this.TryParseBindPath(value, out var bindPath)) + if (value != null && this.TryParseBindPath(value, out var bindPath)) { this.BindPaths.Add(bindPath); return true; diff --git a/src/WixToolset.Core/CommandLine/CommandLineParser.cs b/src/WixToolset.Core/CommandLine/CommandLineParser.cs index 1438d820..e78da47e 100644 --- a/src/WixToolset.Core/CommandLine/CommandLineParser.cs +++ b/src/WixToolset.Core/CommandLine/CommandLineParser.cs @@ -138,9 +138,10 @@ namespace WixToolset.Core.CommandLine { var result = this.TryGetNextSwitchOrArgument(out arg); - if (!result && !this.IsSwitch(arg)) + if (!result || this.IsSwitch(arg)) { this.ErrorArgument = arg ?? CommandLineParser.ExpectedArgument; + return false; } return result; diff --git a/src/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs b/src/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs index 02422cf7..874151e4 100644 --- a/src/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs @@ -6,10 +6,54 @@ namespace WixToolsetTest.CoreIntegration using System.IO; using WixBuildTools.TestSupport; using WixToolset.Core.TestPackage; + using WixToolset.Data; using Xunit; public class BadInputFixture { + [Fact] + public void SwitchIsNotConsideredAnArgument() + { + var result = WixRunner.Execute(new[] + { + "build", + "-bindpath", "-thisisaswitchnotanarg", + }); + + Assert.Single(result.Messages, m => m.Id == (int)ErrorMessages.Ids.ExpectedArgument); + // TODO: when CantBuildSingleExeBundleWithInvalidArgument is fixed, uncomment: + //Assert.Equal((int)ErrorMessages.Ids.ExpectedArgument, result.ExitCode); + } + + [Fact(Skip = "Test demonstrates failure")] + public void CantBuildSingleExeBundleWithInvalidArgument() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var exePath = Path.Combine(baseFolder, @"bin\test.exe"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "SingleExeBundle", "SingleExePackageGroup.wxs"), + Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", exePath, + "-nonexistentswitch", "param", + }); + + Assert.NotEqual(0, result.ExitCode); + + Assert.False(File.Exists(exePath)); + } + } + [Fact] public void RegistryKeyWithoutAttributesDoesntCrash() { diff --git a/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs b/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs index 1e3f1e24..fae2ff4c 100644 --- a/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs @@ -189,35 +189,6 @@ namespace WixToolsetTest.CoreIntegration } } - [Fact(Skip = "Test demonstrates failure")] - public void CantBuildSingleExeBundleWithInvalidArgument() - { - var folder = TestData.Get(@"TestData"); - - using (var fs = new DisposableFileSystem()) - { - var baseFolder = fs.GetFolder(); - var intermediateFolder = Path.Combine(baseFolder, "obj"); - var exePath = Path.Combine(baseFolder, @"bin\test.exe"); - - var result = WixRunner.Execute(new[] - { - "build", - Path.Combine(folder, "SingleExeBundle", "SingleExePackageGroup.wxs"), - Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), - "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), - "-bindpath", Path.Combine(folder, ".Data"), - "-intermediateFolder", intermediateFolder, - "-o", exePath, - "-nonexistentswitch", "param", - }); - - Assert.NotEqual(0, result.ExitCode); - - Assert.False(File.Exists(exePath)); - } - } - [Fact] public void CanBuildSingleExeRemotePayloadBundle() { -- cgit v1.2.3-55-g6feb