Skip to content

Commit ca604a1

Browse files
committed
Tests for parsing option /overrideconfig
1 parent 764ee79 commit ca604a1

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

src/GitVersionExe.Tests/ArgumentParserTests.cs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
41
using GitVersion;
52
using NUnit.Framework;
63
using Shouldly;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.ComponentModel;
77

88
[TestFixture]
99
public class ArgumentParserTests
@@ -199,7 +199,7 @@ public void update_assembly_info_false(string command)
199199
public void create_mulitple_assembly_info_protected(string command)
200200
{
201201
var exception = Assert.Throws<WarningException>(() => ArgumentParser.ParseArguments(command));
202-
exception.Message.ShouldBe("Can't specify multiple assembly info files when using -ensureassemblyinfo switch, either use a single assembly info file or do not specify -ensureassemblyinfo and create assembly info files manually");
202+
exception.Message.ShouldBe("Can't specify multiple assembly info files when using /ensureassemblyinfo switch, either use a single assembly info file or do not specify /ensureassemblyinfo and create assembly info files manually");
203203
}
204204

205205
[Test]
@@ -220,6 +220,37 @@ public void update_assembly_info_with_multiple_filenames()
220220
arguments.UpdateAssemblyInfoFileName.ShouldContain("VersionAssemblyInfo.cs");
221221
}
222222

223+
[Test]
224+
public void overrideconfig_with_no_options()
225+
{
226+
var arguments = ArgumentParser.ParseArguments("/overrideconfig");
227+
arguments.HasOverrideConfig.ShouldBe(false);
228+
arguments.OverrideConfig.ShouldNotBeNull();
229+
}
230+
231+
[Test]
232+
public void overrideconfig_with_single_tagprefix_option()
233+
{
234+
var arguments = ArgumentParser.ParseArguments("/overrideconfig tag-prefix=sample");
235+
arguments.HasOverrideConfig.ShouldBe(true);
236+
arguments.OverrideConfig.TagPrefix.ShouldBe("sample");
237+
}
238+
239+
[TestCase("tag-prefix=sample;tag-prefix=other")]
240+
[TestCase("tag-prefix=sample;param2=other")]
241+
public void overrideconfig_with_several_options(string options)
242+
{
243+
var exception = Assert.Throws<WarningException>(() => ArgumentParser.ParseArguments(string.Format("/overrideconfig {0}", options)));
244+
exception.Message.ShouldContain("Can't specify multiple /overrideconfig options");
245+
}
246+
247+
[TestCase("tag-prefix=sample=asdf")]
248+
public void overrideconfig_with_invalid_option(string options)
249+
{
250+
var exception = Assert.Throws<WarningException>(() => ArgumentParser.ParseArguments(string.Format("/overrideconfig {0}", options)));
251+
exception.Message.ShouldContain("Could not parse /overrideconfig option");
252+
}
253+
223254
[Test]
224255
public void update_assembly_info_with_relative_filename()
225256
{
@@ -248,7 +279,7 @@ public void ensure_assembly_info_false()
248279
var arguments = ArgumentParser.ParseArguments("-ensureAssemblyInfo false");
249280
arguments.EnsureAssemblyInfo.ShouldBe(false);
250281
}
251-
282+
252283
[Test]
253284
public void dynamicRepoLocation()
254285
{

src/GitVersionExe/ArgumentParser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
270270

271271
if (name.IsSwitch("overrideconfig"))
272272
{
273-
var keyValueOptions = value.Split(';');
273+
var keyValueOptions = (value ?? "").Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
274274
if (keyValueOptions.Length == 0)
275275
{
276276
continue;
@@ -286,8 +286,8 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
286286
// key=value
287287
foreach (var keyValueOption in keyValueOptions)
288288
{
289-
var keyAndValue = keyValueOption.Split('=');
290-
if (keyAndValue.Length > 1)
289+
var keyAndValue = keyValueOption.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
290+
if (keyAndValue.Length != 2)
291291
{
292292
throw new WarningException(string.Format("Could not parse /overrideconfig option: {0}. Ensure it is in format 'key=value'", keyValueOption));
293293
}

src/GitVersionExe/HelpWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ path The directory containing .git. If not defined current directory
2525
eg /output json /showvariable SemVer - will output `1.2.3+beta.4`
2626
/l Path to logfile.
2727
/showconfig Outputs the effective GitVersion config (defaults + custom from GitVersion.yml) in yaml format
28-
/overrideconfig Overrides GitVersion config values inline (semicolon-separated key value pairs e.g. /overrideconfig:tag-prefix=Foo)
28+
/overrideconfig Overrides GitVersion config values inline (semicolon-separated key value pairs e.g. /overrideconfig tag-prefix=Foo)
2929
Currently supported config overrides: tag-prefix
3030
3131
# AssemblyInfo updating

0 commit comments

Comments
 (0)