Skip to content

Commit dba9f45

Browse files
Nenad Vicenticarturcic
authored andcommitted
Additional options for command-line switch /overrideconfig. GitVersion.yml options with simple prperty type (string, enum, int, bool) are now supported - 21 in total.
1 parent 076bbec commit dba9f45

File tree

5 files changed

+568
-33
lines changed

5 files changed

+568
-33
lines changed

src/GitVersion.App.Tests/ArgumentParserTests.cs

Lines changed: 226 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
using System.Collections.Generic;
12
using System.IO;
2-
using GitTools.Testing;
3+
using GitVersion.Core.Tests.Helpers;
4+
using GitVersion.Extensions;
35
using GitVersion.Logging;
46
using GitVersion.Model;
5-
using GitVersion.Core.Tests.Helpers;
7+
using GitVersion.Model.Configuration;
8+
using GitTools.Testing;
69
using Microsoft.Extensions.DependencyInjection;
710
using NUnit.Framework;
811
using Shouldly;
@@ -364,26 +367,232 @@ public void OverrideconfigWithNoOptions()
364367
arguments.OverrideConfig.ShouldBeNull();
365368
}
366369

367-
[Test]
368-
public void OverrideconfigWithSingleTagprefixOption()
369-
{
370-
var arguments = argumentParser.ParseArguments("/overrideconfig tag-prefix=sample");
371-
arguments.OverrideConfig.TagPrefix.ShouldBe("sample");
372-
}
373-
374-
[TestCase("tag-prefix=sample;tag-prefix=other")]
375-
[TestCase("tag-prefix=sample;param2=other")]
376-
public void OverrideconfigWithSeveralOptions(string options)
370+
[TestCaseSource(nameof(OverrideconfigWithInvalidOptionTestData))]
371+
public string OverrideconfigWithInvalidOption(string options)
377372
{
378373
var exception = Assert.Throws<WarningException>(() => argumentParser.ParseArguments($"/overrideconfig {options}"));
379-
exception.Message.ShouldContain("Can't specify multiple /overrideconfig options");
374+
return exception.Message;
380375
}
381376

382-
[TestCase("tag-prefix=sample=asdf")]
383-
public void OverrideconfigWithInvalidOption(string options)
377+
private static IEnumerable<TestCaseData> OverrideconfigWithInvalidOptionTestData()
384378
{
385-
var exception = Assert.Throws<WarningException>(() => argumentParser.ParseArguments($"/overrideconfig {options}"));
386-
exception.Message.ShouldContain("Could not parse /overrideconfig option");
379+
yield return new TestCaseData("tag-prefix=sample=asdf")
380+
{
381+
ExpectedResult = "Could not parse /overrideconfig option: tag-prefix=sample=asdf. Ensure it is in format 'key=value'."
382+
};
383+
yield return new TestCaseData("unknown-option=25")
384+
{
385+
ExpectedResult = "Could not parse /overrideconfig option: unknown-option=25. Unsuported 'key'."
386+
};
387+
yield return new TestCaseData("update-build-number=1")
388+
{
389+
ExpectedResult = "Could not parse /overrideconfig option: update-build-number=1. Ensure that 'value' is 'true' or 'false'."
390+
};
391+
yield return new TestCaseData("tag-pre-release-weight=invalid-value")
392+
{
393+
ExpectedResult = "Could not parse /overrideconfig option: tag-pre-release-weight=invalid-value. Ensure that 'value' is valid integer number."
394+
};
395+
yield return new TestCaseData("assembly-versioning-scheme=WrongEnumValue")
396+
{
397+
ExpectedResult = "Could not parse /overrideconfig option: assembly-versioning-scheme=WrongEnumValue. Ensure that 'value' is valid for specified 'key' enumeration: \r\nMajorMinorPatchTag\r\nMajorMinorPatch\r\nMajorMinor\r\nMajor\r\nNone\r\n"
398+
};
399+
}
400+
401+
[TestCaseSource(nameof(OverrideconfigWithSingleOptionTestData))]
402+
public void OverrideconfigWithSingleOptions(string options, Config expected)
403+
{
404+
var arguments = argumentParser.ParseArguments($"/overrideconfig {options}");
405+
arguments.OverrideConfig.ShouldBeEquivalentTo(expected);
406+
}
407+
408+
private static IEnumerable<TestCaseData> OverrideconfigWithSingleOptionTestData()
409+
{
410+
yield return new TestCaseData(
411+
"assembly-versioning-scheme=MajorMinor",
412+
new Config
413+
{
414+
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinor,
415+
}
416+
);
417+
yield return new TestCaseData(
418+
"assembly-file-versioning-scheme=\"MajorMinorPatch\"",
419+
new Config
420+
{
421+
AssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch,
422+
}
423+
);
424+
yield return new TestCaseData(
425+
"assembly-informational-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"",
426+
new Config
427+
{
428+
AssemblyInformationalFormat = "{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}",
429+
}
430+
);
431+
yield return new TestCaseData(
432+
"assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"",
433+
new Config
434+
{
435+
AssemblyVersioningFormat = "{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}",
436+
}
437+
);
438+
yield return new TestCaseData(
439+
"assembly-file-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"",
440+
new Config
441+
{
442+
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}",
443+
}
444+
);
445+
yield return new TestCaseData(
446+
"mode=ContinuousDelivery",
447+
new Config
448+
{
449+
VersioningMode = GitVersion.VersionCalculation.VersioningMode.ContinuousDelivery
450+
}
451+
);
452+
yield return new TestCaseData(
453+
"tag-prefix=sample",
454+
new Config
455+
{
456+
TagPrefix = "sample"
457+
}
458+
);
459+
yield return new TestCaseData(
460+
"continuous-delivery-fallback-tag=cd-tag",
461+
new Config
462+
{
463+
ContinuousDeploymentFallbackTag = "cd-tag"
464+
}
465+
);
466+
yield return new TestCaseData(
467+
"next-version=1",
468+
new Config
469+
{
470+
NextVersion = "1"
471+
}
472+
);
473+
yield return new TestCaseData(
474+
"major-version-bump-message=\"This is major version bump message.\"",
475+
new Config
476+
{
477+
MajorVersionBumpMessage = "This is major version bump message."
478+
}
479+
);
480+
yield return new TestCaseData(
481+
"minor-version-bump-message=\"This is minor version bump message.\"",
482+
new Config
483+
{
484+
MinorVersionBumpMessage = "This is minor version bump message."
485+
}
486+
);
487+
yield return new TestCaseData(
488+
"patch-version-bump-message=\"This is patch version bump message.\"",
489+
new Config
490+
{
491+
PatchVersionBumpMessage = "This is patch version bump message."
492+
}
493+
);
494+
yield return new TestCaseData(
495+
"no-bump-message=\"This is no bump message.\"",
496+
new Config
497+
{
498+
NoBumpMessage = "This is no bump message."
499+
}
500+
);
501+
yield return new TestCaseData(
502+
"legacy-semver-padding=99",
503+
new Config
504+
{
505+
LegacySemVerPadding = 99
506+
}
507+
);
508+
yield return new TestCaseData(
509+
"build-metadata-padding=30",
510+
new Config
511+
{
512+
BuildMetaDataPadding = 30
513+
}
514+
);
515+
yield return new TestCaseData(
516+
"commits-since-version-source-padding=5",
517+
new Config
518+
{
519+
CommitsSinceVersionSourcePadding = 5
520+
}
521+
);
522+
yield return new TestCaseData(
523+
"tag-pre-release-weight=2",
524+
new Config
525+
{
526+
TagPreReleaseWeight = 2
527+
}
528+
);
529+
yield return new TestCaseData(
530+
"commit-message-incrementing=MergeMessageOnly",
531+
new Config
532+
{
533+
CommitMessageIncrementing = CommitMessageIncrementMode.MergeMessageOnly
534+
}
535+
);
536+
yield return new TestCaseData(
537+
"increment=Minor",
538+
new Config
539+
{
540+
Increment = IncrementStrategy.Minor
541+
}
542+
);
543+
yield return new TestCaseData(
544+
"commit-date-format=\"MM/dd/yyyy h:mm tt\"",
545+
new Config
546+
{
547+
CommitDateFormat = "MM/dd/yyyy h:mm tt"
548+
}
549+
);
550+
yield return new TestCaseData(
551+
"update-build-number=true",
552+
new Config
553+
{
554+
UpdateBuildNumber = true
555+
}
556+
);
557+
}
558+
559+
[TestCaseSource(nameof(OverrideconfigWithMultipleOptionsTestData))]
560+
public void OverrideconfigWithMultipleOptions(string options, Config expected)
561+
{
562+
var arguments = argumentParser.ParseArguments($"/overrideconfig {options}");
563+
arguments.OverrideConfig.ShouldBeEquivalentTo(expected);
564+
}
565+
566+
private static IEnumerable<TestCaseData> OverrideconfigWithMultipleOptionsTestData()
567+
{
568+
yield return new TestCaseData(
569+
"tag-prefix=sample;assembly-versioning-scheme=MajorMinor",
570+
new Config
571+
{
572+
TagPrefix = "sample",
573+
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinor,
574+
}
575+
);
576+
yield return new TestCaseData(
577+
"tag-prefix=sample;assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"",
578+
new Config
579+
{
580+
TagPrefix = "sample",
581+
AssemblyVersioningFormat = "{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}"
582+
}
583+
);
584+
yield return new TestCaseData(
585+
"tag-prefix=sample;assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\";update-build-number=true;assembly-versioning-scheme=MajorMinorPatchTag;mode=ContinuousDelivery;tag-pre-release-weight=4",
586+
new Config
587+
{
588+
TagPrefix = "sample",
589+
AssemblyVersioningFormat = "{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}",
590+
UpdateBuildNumber = true,
591+
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag,
592+
VersioningMode = GitVersion.VersionCalculation.VersioningMode.ContinuousDelivery,
593+
TagPreReleaseWeight = 4
594+
}
595+
);
387596
}
388597

389598
[Test]
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using GitVersion;
2+
using NUnit.Framework;
3+
using System.Collections.Generic;
4+
5+
namespace GitVersionExe.Tests
6+
{
7+
[TestFixture]
8+
public class QuotedStringHelpersTests
9+
{
10+
[TestCaseSource(nameof(SplitUnquotedTestData))]
11+
public string[] SplitUnquotedTests(string input, char splitChar)
12+
{
13+
return QuotedStringHelpers.SplitUnquoted(input, splitChar);
14+
}
15+
16+
private static IEnumerable<TestCaseData> SplitUnquotedTestData()
17+
{
18+
yield return new TestCaseData(null, ' ')
19+
{
20+
ExpectedResult = System.Array.Empty<string>()
21+
};
22+
yield return new TestCaseData("one two three", ' ')
23+
{
24+
ExpectedResult = new []{ "one", "two", "three" }
25+
};
26+
yield return new TestCaseData("one \"two three\"", ' ')
27+
{
28+
ExpectedResult = new[] { "one", "\"two three\"" }
29+
};
30+
yield return new TestCaseData("one \"two three", ' ')
31+
{
32+
ExpectedResult = new[] { "one", "\"two three" }
33+
};
34+
yield return new TestCaseData("/overrideconfig tag-prefix=Sample", ' ')
35+
{
36+
ExpectedResult = new[]
37+
{
38+
"/overrideconfig",
39+
"tag-prefix=Sample"
40+
}
41+
};
42+
yield return new TestCaseData("/overrideconfig tag-prefix=Sample 2", ' ')
43+
{
44+
ExpectedResult = new[]
45+
{
46+
"/overrideconfig",
47+
"tag-prefix=Sample",
48+
"2"
49+
}
50+
};
51+
yield return new TestCaseData("/overrideconfig tag-prefix=\"Sample 2\"", ' ')
52+
{
53+
ExpectedResult = new[]
54+
{
55+
"/overrideconfig",
56+
"tag-prefix=\"Sample 2\""
57+
}
58+
};
59+
yield return new TestCaseData("/overrideconfig tag-prefix=\"Sample \\\"quoted\\\"\"", ' ')
60+
{
61+
ExpectedResult = new[]
62+
{
63+
"/overrideconfig",
64+
"tag-prefix=\"Sample \\\"quoted\\\"\""
65+
}
66+
};
67+
yield return new TestCaseData("/overrideconfig tag-prefix=sample;assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"", ' ')
68+
{
69+
ExpectedResult = new[]
70+
{
71+
"/overrideconfig",
72+
"tag-prefix=sample;assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\""
73+
}
74+
};
75+
yield return new TestCaseData("tag-prefix=sample;assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"", ';')
76+
{
77+
ExpectedResult = new[]
78+
{
79+
"tag-prefix=sample",
80+
"assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\""
81+
}
82+
};
83+
yield return new TestCaseData("assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"", '=')
84+
{
85+
ExpectedResult = new[]
86+
{
87+
"assembly-versioning-format",
88+
"\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\""
89+
}
90+
};
91+
}
92+
93+
[TestCaseSource(nameof(RemoveEmptyEntriesTestData))]
94+
public string[] SplitUnquotedRemovesEmptyEntries(string input, char splitChar)
95+
{
96+
return QuotedStringHelpers.SplitUnquoted(input, splitChar);
97+
}
98+
99+
private static IEnumerable<TestCaseData> RemoveEmptyEntriesTestData()
100+
{
101+
yield return new TestCaseData(" /switch1 value1 /switch2 ", ' ')
102+
{
103+
ExpectedResult = new[]
104+
{
105+
"/switch1",
106+
"value1",
107+
"/switch2"
108+
}
109+
};
110+
}
111+
112+
[TestCaseSource(nameof(UnquoteTextTestData))]
113+
public string UnquoteTextTextTests(string input)
114+
{
115+
return QuotedStringHelpers.UnquoteText(input);
116+
}
117+
118+
private static IEnumerable<TestCaseData> UnquoteTextTestData()
119+
{
120+
yield return new TestCaseData("\"sample\"")
121+
{
122+
ExpectedResult = "sample"
123+
};
124+
yield return new TestCaseData("\"escaped \\\"quote\"")
125+
{
126+
ExpectedResult = "escaped \"quote"
127+
};
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)