aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-01-07 23:12:49 -0800
committerRob Mensching <rob@firegiant.com>2021-01-08 15:47:31 -0800
commite35ee2e8c58bf55da5f3d04915d588fb04d6809d (patch)
tree4bf0cfd782ec990b6a5d4ac9aec390d44dee097b
parent458ff7ce24b33f6df46ae8ef728685c555d55ff7 (diff)
downloadwix-e35ee2e8c58bf55da5f3d04915d588fb04d6809d.tar.gz
wix-e35ee2e8c58bf55da5f3d04915d588fb04d6809d.tar.bz2
wix-e35ee2e8c58bf55da5f3d04915d588fb04d6809d.zip
Report invalid command line arguments as errors
Fixes wixtoolset/issues#6313
-rw-r--r--src/WixToolset.Core/CommandLine/BuildCommand.cs6
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLine.cs6
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLineParser.cs8
-rw-r--r--src/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs3
-rw-r--r--src/test/WixToolsetTest.CoreIntegration/CustomTableFixture.cs2
-rw-r--r--src/test/WixToolsetTest.CoreIntegration/DecompileFixture.cs2
6 files changed, 15 insertions, 12 deletions
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs
index fed95958..065467bd 100644
--- a/src/WixToolset.Core/CommandLine/BuildCommand.cs
+++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs
@@ -841,8 +841,7 @@ namespace WixToolset.Core.CommandLine
841 } 841 }
842 else 842 else
843 { 843 {
844 this.Messaging.Write(ErrorMessages.IllegalSuppressWarningId(paramArg)); 844 parser.ReportErrorArgument(parameter, ErrorMessages.IllegalSuppressWarningId(paramArg));
845 parser.ErrorArgument = parameter;
846 } 845 }
847 } 846 }
848 847
@@ -859,8 +858,7 @@ namespace WixToolset.Core.CommandLine
859 } 858 }
860 else 859 else
861 { 860 {
862 this.Messaging.Write(ErrorMessages.IllegalSuppressWarningId(paramArg)); 861 parser.ReportErrorArgument(parameter, ErrorMessages.IllegalSuppressWarningId(paramArg));
863 parser.ErrorArgument = parameter;
864 } 862 }
865 } 863 }
866 } 864 }
diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs
index 5439eb39..0c21eaaa 100644
--- a/src/WixToolset.Core/CommandLine/CommandLine.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLine.cs
@@ -97,19 +97,19 @@ namespace WixToolset.Core.CommandLine
97 { 97 {
98 if (!this.TryParseCommand(arg, parser, extensions, out command)) 98 if (!this.TryParseCommand(arg, parser, extensions, out command))
99 { 99 {
100 parser.ErrorArgument = arg; 100 parser.ReportErrorArgument(arg);
101 } 101 }
102 } 102 }
103 else if (parser.IsSwitch(arg)) 103 else if (parser.IsSwitch(arg))
104 { 104 {
105 if (!command.TryParseArgument(parser, arg) && !TryParseCommandLineArgumentWithExtension(arg, parser, extensions)) 105 if (!command.TryParseArgument(parser, arg) && !TryParseCommandLineArgumentWithExtension(arg, parser, extensions))
106 { 106 {
107 parser.ErrorArgument = arg; 107 parser.ReportErrorArgument(arg);
108 } 108 }
109 } 109 }
110 else if (!TryParseCommandLineArgumentWithExtension(arg, parser, extensions) && !command.TryParseArgument(parser, arg)) 110 else if (!TryParseCommandLineArgumentWithExtension(arg, parser, extensions) && !command.TryParseArgument(parser, arg))
111 { 111 {
112 parser.ErrorArgument = arg; 112 parser.ReportErrorArgument(arg);
113 } 113 }
114 } 114 }
115 115
diff --git a/src/WixToolset.Core/CommandLine/CommandLineParser.cs b/src/WixToolset.Core/CommandLine/CommandLineParser.cs
index e78da47e..015d3e62 100644
--- a/src/WixToolset.Core/CommandLine/CommandLineParser.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLineParser.cs
@@ -12,7 +12,7 @@ namespace WixToolset.Core.CommandLine
12 { 12 {
13 private const string ExpectedArgument = "expected argument"; 13 private const string ExpectedArgument = "expected argument";
14 14
15 public string ErrorArgument { get; set; } 15 public string ErrorArgument { get; private set; }
16 16
17 private Queue<string> RemainingArguments { get; } 17 private Queue<string> RemainingArguments { get; }
18 18
@@ -122,6 +122,12 @@ namespace WixToolset.Core.CommandLine
122 return false; 122 return false;
123 } 123 }
124 124
125 public void ReportErrorArgument(string argument, Message message = null)
126 {
127 this.Messaging.Write(message ?? ErrorMessages.AdditionalArgumentUnexpected(argument));
128 this.ErrorArgument = argument;
129 }
130
125 public bool TryGetNextSwitchOrArgument(out string arg) 131 public bool TryGetNextSwitchOrArgument(out string arg)
126 { 132 {
127 if (this.RemainingArguments.Count > 0) 133 if (this.RemainingArguments.Count > 0)
diff --git a/src/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs b/src/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs
index c5168856..62ffe1eb 100644
--- a/src/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs
+++ b/src/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs
@@ -48,7 +48,7 @@ namespace WixToolsetTest.CoreIntegration
48 } 48 }
49 } 49 }
50 50
51 [Fact(Skip = "Test demonstrates failure")] 51 [Fact]
52 public void CantBuildSingleExeBundleWithInvalidArgument() 52 public void CantBuildSingleExeBundleWithInvalidArgument()
53 { 53 {
54 var folder = TestData.Get(@"TestData"); 54 var folder = TestData.Get(@"TestData");
@@ -72,7 +72,6 @@ namespace WixToolsetTest.CoreIntegration
72 }); 72 });
73 73
74 Assert.NotEqual(0, result.ExitCode); 74 Assert.NotEqual(0, result.ExitCode);
75
76 Assert.False(File.Exists(exePath)); 75 Assert.False(File.Exists(exePath));
77 } 76 }
78 } 77 }
diff --git a/src/test/WixToolsetTest.CoreIntegration/CustomTableFixture.cs b/src/test/WixToolsetTest.CoreIntegration/CustomTableFixture.cs
index 4a5cf544..3ee88640 100644
--- a/src/test/WixToolsetTest.CoreIntegration/CustomTableFixture.cs
+++ b/src/test/WixToolsetTest.CoreIntegration/CustomTableFixture.cs
@@ -216,7 +216,7 @@ namespace WixToolsetTest.CoreIntegration
216 result.AssertSuccess(); 216 result.AssertSuccess();
217 Assert.True(File.Exists(msiPath)); 217 Assert.True(File.Exists(msiPath));
218 218
219 result = WixRunner.Execute(new[] 219 result = WixRunner.Execute(false, new[]
220 { 220 {
221 "decompile", msiPath, 221 "decompile", msiPath,
222 "-intermediateFolder", intermediateFolder, 222 "-intermediateFolder", intermediateFolder,
diff --git a/src/test/WixToolsetTest.CoreIntegration/DecompileFixture.cs b/src/test/WixToolsetTest.CoreIntegration/DecompileFixture.cs
index b07f5bda..924337ba 100644
--- a/src/test/WixToolsetTest.CoreIntegration/DecompileFixture.cs
+++ b/src/test/WixToolsetTest.CoreIntegration/DecompileFixture.cs
@@ -20,7 +20,7 @@ namespace WixToolsetTest.CoreIntegration
20 var intermediateFolder = fs.GetFolder(); 20 var intermediateFolder = fs.GetFolder();
21 var outputPath = Path.Combine(intermediateFolder, @"Actual.wxs"); 21 var outputPath = Path.Combine(intermediateFolder, @"Actual.wxs");
22 22
23 var result = WixRunner.Execute(new[] 23 var result = WixRunner.Execute(false, new[]
24 { 24 {
25 "decompile", 25 "decompile",
26 Path.Combine(folder, msiName), 26 Path.Combine(folder, msiName),