CommandInterpreter: Add simple unit test for the NPE bug
MODIFY
WalletWasabi.Gui/CommandLine/CommandInterpreter.cs
WalletWasabi.Gui/CommandLine/CommandInterpreter.cs
@@ -2,17 +2,21 @@ using Mono.Options;
using System;
using System.IO;
using System.Linq;
-using System.Runtime.InteropServices;
using System.Threading.Tasks;
using WalletWasabi.Helpers;
-using WalletWasabi.Logging;
namespace WalletWasabi.Gui.CommandLine
{
public class CommandInterpreter
{
+ public CommandInterpreter(TextWriter textWriter)
+ {
+ TextWriter = textWriter;
+ }
+ public TextWriter TextWriter { get; }
+
/// <returns>If the GUI should run or not.</returns>
- public async Task<bool> ExecuteCommandsAsync(string[] args, MixerCommand mixerCommand, PasswordFinderCommand passwordFinderCommand)
+ public async Task<bool> ExecuteCommandsAsync(string[] args, Command mixerCommand, Command passwordFinderCommand)
{
var showHelp = false;
var showVersion = false;
@@ -81,7 +85,7 @@ namespace WalletWasabi.Gui.CommandLine
Console.WriteLine("Launches Wasabi Wallet.");
Console.WriteLine();
Console.WriteLine("Options:");
- p.WriteOptionDescriptions(Console.Out);
+ p.WriteOptionDescriptions(TextWriter);
}
}
}

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -37,7 +37,7 @@ namespace WalletWasabi.Gui
var daemon = new Daemon(Global);
var mixerCommand = new MixerCommand(daemon);
var passwordFinderCommand = new PasswordFinderCommand(Global.WalletManager);
- runGui = new CommandInterpreter().ExecuteCommandsAsync(args, mixerCommand, passwordFinderCommand).GetAwaiter().GetResult();
+ runGui = new CommandInterpreter(Console.Out).ExecuteCommandsAsync(args, mixerCommand, passwordFinderCommand).GetAwaiter().GetResult();
if (!runGui)
{

ADD
WalletWasabi.Tests/UnitTests/GUI/CommandInterpreterTest.cs
+using Mono.Options;
+using System.IO;
+using WalletWasabi.Gui.CommandLine;
+using Xunit;
+
+namespace WalletWasabi.Tests.UnitTests
+{
+ public class CommandInterpreterTest
+ {
+ [Fact]
+ public async void CommandInterpreterShowsHelpAsync()
+ {
+ var textWriter = new StringWriter();
+ var c = new CommandInterpreter(textWriter);
+ await c.ExecuteCommandsAsync(new string[] { "wassabee", "--help" }, new Command("mixer"), new Command("findpassword"));
+
+ Assert.Equal(
+ @"Usage: wassabee [OPTIONS]+
+Launches Wasabi Wallet.
+
+ -h, --help Displays help page and exit.
+ -v, --version Displays Wasabi version and exit.
+
+Available commands are:
+
+ mixer
+ findpassword
+",
+ textWriter.ToString()
+ );
+ }
+ }
+}

CommandInterpreter: Add simple unit test for the NPE bug