diff --git a/tests/CommandLine.Tests/Unit/Issue389_Tests.cs b/tests/CommandLine.Tests/Unit/Issue389_Tests.cs new file mode 100644 index 00000000..19d6b259 --- /dev/null +++ b/tests/CommandLine.Tests/Unit/Issue389_Tests.cs @@ -0,0 +1,78 @@ +using CommandLine.Text; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; + +namespace CommandLine.Tests.Unit +{ + + public class Issue389_Tests + { + + private const int ERROR_SUCCESS = 0; + + // Test method (xUnit) which fails + [Fact] + public void CallMain_GiveHelpArgument_ExpectSuccess() + { + var result = Program.__Main(new[] { "--help" }); + + Assert.Equal(ERROR_SUCCESS, result); + } + + // main program + internal class Program + { + + + internal static int __Main(string[] args) + { + bool hasError = false; + bool helpOrVersionRequested = false; + + ParserResult parsedOptions = Parser.Default.ParseArguments(args) + .WithNotParsed(errors => { + helpOrVersionRequested = errors.Any( + x => x.Tag == ErrorType.HelpRequestedError + || x.Tag == ErrorType.VersionRequestedError); + hasError = true; + }); + + if(helpOrVersionRequested) + { + return ERROR_SUCCESS; + } + + // Execute as a normal call + // ... + return ERROR_SUCCESS; + } + + } + + // Options + internal class Options + { + + [Option('c', "connectionString", Required = true, HelpText = "Texts.ExplainConnection")] + public string ConnectionString { get; set; } + + [Option('j', "jobId", Required = true, HelpText = "Texts.ExplainJob")] + public int JobId { get; set; } + + [Usage(ApplicationAlias = "Importer.exe")] + public static IEnumerable Examples + { + get => new[] { + new Example("Texts.ExplainExampleExecution", new Options() { + ConnectionString="Server=MyServer;Database=MyDatabase", + JobId = 5 + }), + }; + } + + } + } +}