Add tests for ArgsProcessor.
MODIFY
WalletWasabi.Packager/ArgsProcessor.cs
WalletWasabi.Packager/ArgsProcessor.cs
+#nullable enable
+
using System;
-using System.Collections.Generic;
-using System.Text;
namespace WalletWasabi.Packager
{
+ /// <summary>
+ /// Class for processing program's command line arguments.
+ /// </summary>
public class ArgsProcessor
{
- public bool IsReduceOnionsMode(string[] args)
+ public ArgsProcessor(string[]? args)
{
- bool getOnions = false;
- if (args != null)
+ if (args == null)
{
- foreach (var arg in args)
+ throw new ArgumentNullException(nameof(args));
+ }
+
+ Args = args;
+ }
+
+ public string[] Args { get; }
+
+ public bool IsReduceOnionsMode()
{
- if (arg.Trim().TrimStart('-').Equals("reduceonions", StringComparison.OrdinalIgnoreCase)
- || arg.Trim().TrimStart('-').Equals("reduceonion", StringComparison.OrdinalIgnoreCase))
+ foreach (var arg in Args)
{
- getOnions = true;
- break;
- }
+ string value = arg.Trim().TrimStart('-');
+
+ if (value.Equals("reduceonions", StringComparison.OrdinalIgnoreCase)
+ || value.Equals("reduceonion", StringComparison.OrdinalIgnoreCase))
+ {
+ return true;
}
}
- return getOnions;
+ return false;
}
- public bool IsOnlyCreateDigestsMode(string[] args)
+ public bool IsOnlyCreateDigestsMode()
{
- bool onlyCreateDigests = false;
- if (args != null)
+ foreach (var arg in Args)
{
- foreach (var arg in args)
- {
- if (arg.Trim().TrimStart('-').Equals("onlycreatedigests", StringComparison.OrdinalIgnoreCase)
- || arg.Trim().TrimStart('-').Equals("onlycreatedigest", StringComparison.OrdinalIgnoreCase)
- || arg.Trim().TrimStart('-').Equals("onlydigests", StringComparison.OrdinalIgnoreCase)
- || arg.Trim().TrimStart('-').Equals("onlydigest", StringComparison.OrdinalIgnoreCase))
+ string value = arg.Trim().TrimStart('-');
+
+ if (value.Equals("onlycreatedigests", StringComparison.OrdinalIgnoreCase)
+ || value.Equals("onlycreatedigest", StringComparison.OrdinalIgnoreCase)
+ || value.Equals("onlydigests", StringComparison.OrdinalIgnoreCase)
+ || value.Equals("onlydigest", StringComparison.OrdinalIgnoreCase))
{
- onlyCreateDigests = true;
- break;
- }
+ return true;
}
}
- return onlyCreateDigests;
+ return false;
}
- public bool IsOnlyBinariesMode(string[] args)
- {
- bool onlyBinaries = false;
- if (args != null)
+ public bool IsOnlyBinariesMode()
{
- foreach (var arg in args)
+ foreach (var arg in Args)
{
if (arg.Trim().TrimStart('-').Equals("onlybinaries", StringComparison.OrdinalIgnoreCase))
{
- onlyBinaries = true;
- break;
- }
+ return true;
}
}
- return onlyBinaries;
+ return false;
}
- public bool IsGetOnionsMode(string[] args)
- {
- bool getOnions = false;
- if (args != null)
+ public bool IsGetOnionsMode()
{
- foreach (var arg in args)
+ foreach (var arg in Args)
{
- if (arg.Trim().TrimStart('-').Equals("getonions", StringComparison.OrdinalIgnoreCase)
- || arg.Trim().TrimStart('-').Equals("getonion", StringComparison.OrdinalIgnoreCase))
+ string value = arg.Trim().TrimStart('-');
+
+ if (value.Equals("getonions", StringComparison.OrdinalIgnoreCase)
+ || value.Equals("getonion", StringComparison.OrdinalIgnoreCase))
{
- getOnions = true;
- break;
- }
+ return true;
}
}
- return getOnions;
+ return false;
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Packager/Program.cs
WalletWasabi.Packager/Program.cs
@@ -63,7 +63,7 @@ namespace WalletWasabi.Packager
/// </summary>
private static void Main(string[] args)
{
- var argsProcessor = new ArgsProcessor();
+ var argsProcessor = new ArgsProcessor(args);
// For now this is enough. If you run it on macOS you want to sign.
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
@@ -73,14 +73,14 @@ namespace WalletWasabi.Packager
}
// If I want a list of up to date onions run it with '--getonions'.
- if (argsProcessor.IsGetOnionsMode(args))
+ if (argsProcessor.IsGetOnionsMode())
{
GetOnions();
return;
}
// If I want a list of up to date onions run it with '--getonions'.
- if (argsProcessor.IsReduceOnionsMode(args))
+ if (argsProcessor.IsReduceOnionsMode())
{
ReduceOnions();
return;
@@ -89,14 +89,14 @@ namespace WalletWasabi.Packager
// Start with digest creation and return if only digest creation.
CreateDigests();
- OnlyCreateDigests = argsProcessor.IsOnlyCreateDigestsMode(args);
+ OnlyCreateDigests = argsProcessor.IsOnlyCreateDigestsMode();
if (OnlyCreateDigests)
{
return;
}
// Only binaries mode is for deterministic builds.
- OnlyBinaries = argsProcessor.IsOnlyBinariesMode(args);
+ OnlyBinaries = argsProcessor.IsOnlyBinariesMode();
ReportStatus();
if (DoPublish || OnlyBinaries)

ADD
WalletWasabi.Tests/UnitTests/Packager/ArgsProcessorTests.cs
+using System;
+using WalletWasabi.Packager;
+using Xunit;
+
+namespace WalletWasabi.Tests.UnitTests.Packager
+{
+ /// <summary>
+ /// Tests for <see cref="ArgsProcessor"/> class.
+ /// </summary>
+ public class ArgsProcessorTests
+ {
+ [Theory]
+ [InlineData(new string[] { "-reduceonions" }, true)]
+ [InlineData(new string[] { "-reduceOnions" }, true)]
+ [InlineData(new string[] { "----reduceOnions" }, true)]
+ [InlineData(new string[] { "-reduce0nions" }, false)]
+ public void IsReduceOnionsModeTest(string[] input, bool expectedResult)
+ {
+ var argsProcessor = new ArgsProcessor(input);
+ Assert.Equal(expectedResult, argsProcessor.IsReduceOnionsMode());
+ }
+
+ [Theory]
+ [InlineData(new string[] { "-onlybinaries" }, true)]
+ [InlineData(new string[] { "-onlyBinaries" }, true)]
+ [InlineData(new string[] { "-OnlyBinaries" }, true)]
+ [InlineData(new string[] { "---OnlyBinaries" }, true)]
+ [InlineData(new string[] { "---0nlyBinaries" }, false)]
+ public void IsOnlyBinariesModeTest(string[] input, bool expectedResult)
+ {
+ var argsProcessor = new ArgsProcessor(input);
+ Assert.Equal(expectedResult, argsProcessor.IsOnlyBinariesMode());
+ }
+ }
+}

Add tests for ArgsProcessor.