Skip to content

Commit baa55fd

Browse files
committed
added output file tests
1 parent 3700f2b commit baa55fd

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

src/GitVersionExe.Tests/ArgumentParserTests.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,16 @@ public void UsernameAndPasswordCanBeParsed()
155155
public void UnknownOutputShouldThrow()
156156
{
157157
var exception = Assert.Throws<WarningException>(() => argumentParser.ParseArguments("targetDirectoryPath -output invalid_value"));
158-
exception.Message.ShouldBe("Value 'invalid_value' cannot be parsed as output type, please use 'json' or 'buildserver'");
158+
exception.Message.ShouldBe("Value 'invalid_value' cannot be parsed as output type, please use 'json', 'file' or 'buildserver'");
159159
}
160160

161161
[Test]
162162
public void OutputDefaultsToJson()
163163
{
164164
var arguments = argumentParser.ParseArguments("targetDirectoryPath");
165165
arguments.Output.ShouldContain(OutputType.Json);
166+
arguments.Output.ShouldNotContain(OutputType.BuildServer);
167+
arguments.Output.ShouldNotContain(OutputType.File);
166168
}
167169

168170
[Test]
@@ -171,6 +173,7 @@ public void OutputJsonCanBeParsed()
171173
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output json");
172174
arguments.Output.ShouldContain(OutputType.Json);
173175
arguments.Output.ShouldNotContain(OutputType.BuildServer);
176+
arguments.Output.ShouldNotContain(OutputType.File);
174177
}
175178

176179
[Test]
@@ -179,6 +182,7 @@ public void MultipleOutputJsonCanBeParsed()
179182
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output json -output json");
180183
arguments.Output.ShouldContain(OutputType.Json);
181184
arguments.Output.ShouldNotContain(OutputType.BuildServer);
185+
arguments.Output.ShouldNotContain(OutputType.File);
182186
}
183187

184188
[Test]
@@ -187,6 +191,7 @@ public void OutputBuildserverCanBeParsed()
187191
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver");
188192
arguments.Output.ShouldContain(OutputType.BuildServer);
189193
arguments.Output.ShouldNotContain(OutputType.Json);
194+
arguments.Output.ShouldNotContain(OutputType.File);
190195
}
191196

192197
[Test]
@@ -195,6 +200,25 @@ public void MultipleOutputBuildserverCanBeParsed()
195200
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver -output buildserver");
196201
arguments.Output.ShouldContain(OutputType.BuildServer);
197202
arguments.Output.ShouldNotContain(OutputType.Json);
203+
arguments.Output.ShouldNotContain(OutputType.File);
204+
}
205+
206+
[Test]
207+
public void OutputFileCanBeParsed()
208+
{
209+
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output file");
210+
arguments.Output.ShouldContain(OutputType.File);
211+
arguments.Output.ShouldNotContain(OutputType.BuildServer);
212+
arguments.Output.ShouldNotContain(OutputType.Json);
213+
}
214+
215+
[Test]
216+
public void MultipleOutputFileCanBeParsed()
217+
{
218+
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output file -output file");
219+
arguments.Output.ShouldContain(OutputType.File);
220+
arguments.Output.ShouldNotContain(OutputType.BuildServer);
221+
arguments.Output.ShouldNotContain(OutputType.Json);
198222
}
199223

200224
[Test]
@@ -203,6 +227,16 @@ public void OutputBuildserverAndJsonCanBeParsed()
203227
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver -output json");
204228
arguments.Output.ShouldContain(OutputType.BuildServer);
205229
arguments.Output.ShouldContain(OutputType.Json);
230+
arguments.Output.ShouldNotContain(OutputType.File);
231+
}
232+
233+
[Test]
234+
public void OutputBuildserverAndJsonAndFileCanBeParsed()
235+
{
236+
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver -output json -output file");
237+
arguments.Output.ShouldContain(OutputType.BuildServer);
238+
arguments.Output.ShouldContain(OutputType.Json);
239+
arguments.Output.ShouldContain(OutputType.File);
206240
}
207241

208242
[Test]
@@ -212,6 +246,16 @@ public void MultipleArgsAndFlag()
212246
arguments.Output.ShouldContain(OutputType.BuildServer);
213247
}
214248

249+
[TestCase("-output file", "GitVersion.json")]
250+
[TestCase("-output file -outputfile version.json", "version.json")]
251+
public void OutputFileArgumentCanBeParsed(string args, string outputFile)
252+
{
253+
var arguments = argumentParser.ParseArguments(args);
254+
255+
arguments.Output.ShouldContain(OutputType.File);
256+
arguments.OutputFile.ShouldBe(outputFile);
257+
}
258+
215259
[Test]
216260
public void UrlAndBranchNameCanBeParsed()
217261
{

src/GitVersionExe.Tests/HelpWriterTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public void AllArgsAreInHelp()
3131
{ nameof(Arguments.Init), "init" },
3232
{ nameof(Arguments.TargetBranch), "/b" },
3333
{ nameof(Arguments.LogFilePath) , "/l" },
34+
{ nameof(Arguments.OutputFile) , "/outputfile" },
3435
{ nameof(Arguments.DynamicRepositoryClonePath), "/dynamicRepoLocation" },
3536
{ nameof(Arguments.IsHelp), "/?" },
3637
{ nameof(Arguments.IsVersion), "/version" },

src/GitVersionExe/ArgumentParser.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class ArgumentParser : IArgumentParser
1717
private readonly ICurrentBuildAgent buildAgent;
1818
private readonly IConsole console;
1919
private readonly IGlobbingResolver globbingResolver;
20+
private const string defaultOutputFileName = "GitVersion.json";
2021

2122
public ArgumentParser(IEnvironment environment, ICurrentBuildAgent buildAgent, IConsole console, IGlobbingResolver globbingResolver)
2223
{
@@ -91,6 +92,11 @@ public Arguments ParseArguments(string[] commandLineArguments)
9192
arguments.Output.Add(OutputType.Json);
9293
}
9394

95+
if (arguments.Output.Contains(OutputType.File) && arguments.OutputFile == null)
96+
{
97+
arguments.OutputFile = defaultOutputFileName;
98+
}
99+
94100
// If the first argument is a switch, it should already have been consumed in the above loop,
95101
// or else a WarningException should have been thrown and we wouldn't end up here.
96102
arguments.TargetPath ??= firstArgumentIsSwitch

src/GitVersionExe/HelpWriter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ path The directory containing .git. If not defined current directory
3838
/h or /? Shows Help
3939
4040
/targetpath Same as 'path', but not positional
41-
/output Determines the output to the console. Can be either 'json' or 'buildserver', will default to 'json'.
41+
/output Determines the output to the console. Can be either 'json', 'file' or 'buildserver', will default to 'json'.
42+
/outputfile Path to output file. It is used in combination with /output 'file'.
4243
/showvariable Used in conjuntion with /output json, will output just a particular variable.
4344
eg /output json /showvariable SemVer - will output `1.2.3+beta.4`
4445
/l Path to logfile.

0 commit comments

Comments
 (0)