-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): print message into stdout if failed
- Loading branch information
Showing
6 changed files
with
98 additions
and
16 deletions.
There are no files selected for viewing
35 changes: 20 additions & 15 deletions
35
NineChronicles.Headless.Executable.Tests/Commands/ValidationCommandTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,44 @@ | ||
using NineChronicles.Headless.Executable.Commands; | ||
using NineChronicles.Headless.Executable.Tests.IO; | ||
using Xunit; | ||
|
||
namespace NineChronicles.Headless.Executable.Tests.Commands | ||
{ | ||
public class ValidationCommandTest | ||
{ | ||
private readonly StringIOConsole _console; | ||
private readonly ValidationCommand _command; | ||
|
||
public ValidationCommandTest() | ||
{ | ||
_command = new ValidationCommand(); | ||
_console = new StringIOConsole(); | ||
_command = new ValidationCommand(_console); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", -1)] | ||
[InlineData("invalid hexadecimal", -1)] | ||
[InlineData("0000000000000000000000000000000000000000000000000000000000000000", -1)] | ||
[InlineData("ab8d591ccdcce263c39eb1f353e44b64869f0afea2df643bf6839ebde650d244", 0)] | ||
[InlineData("d6c3e0d525dac340a132ae05aaa9f3e278d61b70d2b71326570e64aee249e566", 0)] | ||
[InlineData("761f68d68426549df5904395b5ca5bce64a3da759085d8565242db42a5a1b0b9", 0)] | ||
public void PrivateKey(string privateKeyHex, int exitCode) | ||
[InlineData("", -1, "The given private key, '', had an issue during parsing.\n")] | ||
[InlineData("invalid hexadecimal", -1, "The given private key, 'invalid hexadecimal', had an issue during parsing.\n")] | ||
[InlineData("000000000000000000000000000000000000000000000000000000000000000000", -1, "The given private key, '000000000000000000000000000000000000000000000000000000000000000000', had an issue during parsing.\n")] | ||
[InlineData("ab8d591ccdcce263c39eb1f353e44b64869f0afea2df643bf6839ebde650d244", 0, "")] | ||
[InlineData("d6c3e0d525dac340a132ae05aaa9f3e278d61b70d2b71326570e64aee249e566", 0, "")] | ||
[InlineData("761f68d68426549df5904395b5ca5bce64a3da759085d8565242db42a5a1b0b9", 0, "")] | ||
public void PrivateKey(string privateKeyHex, int exitCode, string errorOutput) | ||
{ | ||
Assert.Equal(exitCode, _command.PrivateKey(privateKeyHex)); | ||
Assert.Equal(errorOutput, _console.Error.ToString()); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", -1)] | ||
[InlineData("invalid hexadecimal", -1)] | ||
[InlineData("000000000000000000000000000000000000000000000000000000000000000000", -1)] | ||
[InlineData("03b0868d9301b30c512d307ea67af4c8bef637ef099e39d32b808a43e6b41469c5", 0)] | ||
[InlineData("03308c1618a75e85a5fb57f7e453a642c307dc6310e90a7418b1aec565d963534a", 0)] | ||
[InlineData("028a6190bf643175b20e4a2d1d86fe6c4b8f7d5fe3d163632be4e59f83335824b8", 0)] | ||
public void PublicKey(string publicKeyHex, int exitCode) | ||
[InlineData("", -1, "The given public key, '', had an issue during parsing.\n")] | ||
[InlineData("invalid hexadecimal", -1, "The given public key, 'invalid hexadecimal', had an issue during parsing.\n")] | ||
[InlineData("000000000000000000000000000000000000000000000000000000000000000000", -1, "The given public key, '000000000000000000000000000000000000000000000000000000000000000000', had an issue during parsing.\n")] | ||
[InlineData("03b0868d9301b30c512d307ea67af4c8bef637ef099e39d32b808a43e6b41469c5", 0, "")] | ||
[InlineData("03308c1618a75e85a5fb57f7e453a642c307dc6310e90a7418b1aec565d963534a", 0, "")] | ||
[InlineData("028a6190bf643175b20e4a2d1d86fe6c4b8f7d5fe3d163632be4e59f83335824b8", 0, "")] | ||
public void PublicKey(string publicKeyHex, int exitCode, string errorOutput) | ||
{ | ||
Assert.Equal(exitCode, _command.PublicKey(publicKeyHex)); | ||
Assert.Equal(errorOutput, _console.Error.ToString()); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
NineChronicles.Headless.Executable.Tests/IO/StringIOConsole.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.IO; | ||
using NineChronicles.Headless.Executable.IO; | ||
|
||
namespace NineChronicles.Headless.Executable.Tests.IO | ||
{ | ||
public sealed class StringIOConsole : IConsole | ||
{ | ||
public StringIOConsole(StringReader @in, StringWriter @out, StringWriter error) | ||
{ | ||
In = @in; | ||
Out = @out; | ||
Error = error; | ||
} | ||
|
||
public StringIOConsole(string input = "") | ||
: this(new StringReader(input), new StringWriter(), new StringWriter()) | ||
{ | ||
} | ||
|
||
public StringReader In { get; } | ||
|
||
public StringWriter Out { get; } | ||
|
||
public StringWriter Error { get; } | ||
|
||
TextReader IConsole.In => In; | ||
|
||
TextWriter IConsole.Out => Out; | ||
|
||
TextWriter IConsole.Error => Error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.IO; | ||
|
||
namespace NineChronicles.Headless.Executable.IO | ||
{ | ||
public interface IConsole | ||
{ | ||
TextReader In { get; } | ||
TextWriter Out { get; } | ||
TextWriter Error { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace NineChronicles.Headless.Executable.IO | ||
{ | ||
public class StandardConsole : IConsole | ||
{ | ||
public StandardConsole() | ||
{ | ||
In = Console.In; | ||
Out = Console.Out; | ||
Error = Console.Error; | ||
} | ||
|
||
public TextReader In { get; } | ||
|
||
public TextWriter Out { get; } | ||
|
||
public TextWriter Error { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters