Skip to content

Commit 970f178

Browse files
committed
Use TestConsole in all tests
1 parent 63b7dbb commit 970f178

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

test/CommandLineUtils.Tests/AttributeValidatorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private void OnExecute() { }
7373
[InlineData("[email protected]", 0)]
7474
public void ValidatesEmailArgument(string email, int exitCode)
7575
{
76-
Assert.Equal(exitCode, CommandLineApplication.Execute<EmailArgumentApp>(email));
76+
Assert.Equal(exitCode, CommandLineApplication.Execute<EmailArgumentApp>(new TestConsole(_output), email));
7777
}
7878

7979
private class OptionBuilderApp : CommandLineApplication

test/CommandLineUtils.Tests/CommandLineApplicationOfTTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using Xunit;
5+
using Xunit.Abstractions;
56

67
namespace McMaster.Extensions.CommandLineUtils.Tests
78
{
89
public class CommandLineApplicationOfTTests
910
{
11+
private readonly ITestOutputHelper _output;
12+
13+
public CommandLineApplicationOfTTests(ITestOutputHelper output)
14+
{
15+
_output = output;
16+
}
17+
1018
private class AttributesNotUsedClass
1119
{
1220
public int OptionA { get; set; }
@@ -60,7 +68,7 @@ public void InitializesTypeWithAttributes()
6068
public void ThrowsForArgumentsWithoutMatchingAttribute()
6169
{
6270
var ex = Assert.Throws<CommandParsingException>(
63-
() => CommandLineParser.ParseArgs<SimpleProgram>("-f"));
71+
() => CommandLineParser.ParseArgs<SimpleProgram>(_output, "-f"));
6472
Assert.StartsWith("Unrecognized option '-f'", ex.Message);
6573
}
6674
}

test/CommandLineUtils.Tests/Utilities/CommandLineParser.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.IO;
5+
using McMaster.Extensions.CommandLineUtils.Tests;
6+
using Xunit.Abstractions;
57

68
namespace McMaster.Extensions.CommandLineUtils
79
{
@@ -12,8 +14,14 @@ internal static class CommandLineParser
1214
{
1315
public static T ParseArgs<T>(params string[] args)
1416
where T : class
17+
=> ParseArgsImpl<T>(NullConsole.Singleton, args);
18+
19+
public static T ParseArgs<T>(ITestOutputHelper output, params string[] args)
20+
where T : class => ParseArgsImpl<T>(new TestConsole(output), args);
21+
22+
private static T ParseArgsImpl<T>(IConsole console, string[] args) where T : class
1523
{
16-
var app = new CommandLineApplication<T>(NullConsole.Singleton, Directory.GetCurrentDirectory(), true);
24+
var app = new CommandLineApplication<T>(console, Directory.GetCurrentDirectory(), true);
1725
app.Conventions.UseDefaultConventions();
1826
app.Parse(args);
1927
return app.Model;

0 commit comments

Comments
 (0)