Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions tests/CommandLine.Tests/Unit/Issue389_Tests.cs
Original file line number Diff line number Diff line change
@@ -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<Options> parsedOptions = Parser.Default.ParseArguments<Options>(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<Example> Examples
{
get => new[] {
new Example("Texts.ExplainExampleExecution", new Options() {
ConnectionString="Server=MyServer;Database=MyDatabase",
JobId = 5
}),
};
}

}
}
}