public void TestPrintHelReturnTheGoodVersionFormat() { CLILogsCheckValues.SurchargeLogs(); using var commandLineParser = new CommandLine.Parser(); ParserUsage helpUsage = new ParserUsage(); var argv = new string[] { "--version" }; var parser = commandLineParser.ParseArguments <Options.DefaultJob>(argv); List <CommandLine.Error> errs = new List <CommandLine.Error>() { new CommandLineWrapError(CommandLine.ErrorType.VersionRequestedError) }; try { helpUsage.PrintHelp(parser, errs, argv); } catch { string input = CLILogsCheckValues.AllMessages; string datePattern = @"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z"; string pattern = @"\w+-(\d+\.){3}\d+-[0-9a-f]{7}-" + datePattern + @"-[A-Za-z0-9\.]+"; Console.WriteLine(input); Console.WriteLine(pattern); Assert.IsTrue(Regex.Match(input, pattern, RegexOptions.IgnoreCase).Success); return; } throw new Exception("A version must be throw"); }
public void TestPrintHelReturnTheGoodVersionInformation() { CLILogsCheckValues.SurchargeLogs(); var argv = new string[] { "--version" }; using var commandLineParser = new CommandLine.Parser(); ParserUsage helpUsage = new ParserUsage(new AssemblyAttributesTester()); var parser = commandLineParser.ParseArguments <Options.DefaultJob>(argv); List <CommandLine.Error> errs = new List <CommandLine.Error>() { new CommandLineWrapError(CommandLine.ErrorType.VersionRequestedError) }; try { helpUsage.PrintHelp(parser, errs, argv); } catch { string input = CLILogsCheckValues.AllMessages; string versionWaitted = "qarnot-12.43.5.54-0129abf-2020-04-29T17:22:47Z-NET.Core"; Assert.AreEqual(input, versionWaitted); return; } throw new Exception("A version must be throw"); }
public void UsageThrowVerbHelpException() { ParserUsage helpUsage = new ParserUsage(); List<CommandLine.Error> errs = new List<CommandLine.Error>() { new CommandLineWrapError(CommandLine.ErrorType.HelpVerbRequestedError), }; ParseHelpException ex = Assert.Throws<ParseHelpException>(() => helpUsage.PrintHelp(Parser, errs, new string[] {})); Assert.IsNotNull(ex); }
public void UsageThrowHelpRequestExceptionWhenVerbHelpAsk() { ParserUsage helpUsage = new ParserUsage(); List<CommandLine.Error> errs = new List<CommandLine.Error>() { // https://github.com/commandlineparser/commandline/blob/master/src/CommandLine/Error.cs new CommandLineWrapError(CommandLine.ErrorType.BadVerbSelectedError), }; ParseHelpException ex = Assert.Throws<ParseHelpException>(() => helpUsage.PrintHelp(Parser, errs, new string[] {"pool", "help" })); Assert.IsNotNull(ex); }
public void TestPrintHelpThrowParsExceptionIfBadVerb() { // https://github.com/commandlineparser/commandline/blob/master/src/CommandLine/Error.cs var commandLineParser = new CommandLine.Parser(); var parser = commandLineParser.ParseArguments <Options.DefaultJob>(new string[] { }); CommandLineParser parserObj = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater()); ParserUsage helpUsage = new ParserUsage(); List <CommandLine.Error> errs = new List <CommandLine.Error>(); CommandLine.Error err = new CommandLineWrapError(CommandLine.ErrorType.BadVerbSelectedError); errs.Add(err); ParseException ex = Assert.Throws <ParseException>(() => helpUsage.PrintHelp(parser, errs, new string[] {})); Assert.IsNotNull(ex); commandLineParser.Dispose(); }
public void TaskWithTagAndTagIntersectThrowAnExcption() { var commandLineParser = new CommandLine.Parser(); CommandLineParser parserObj = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater()); string[] argv = new string[] { "task info", "--tags", "t1", "t2", "--exclusive-tags", "t3", "t4" }; ParseException ex = null; var converter = new OptionConverter(null); var usage = new ParserUsage(); var parser = commandLineParser.ParseArguments <Options.InfoTaskOptions>(argv); ex = Assert.Throws <ParseException>(() => parser.MapResult( (Options.InfoTaskOptions o) => converter.ConvertGenericGetterOption(ConfigType.Task, CommandApi.Info, o), err => throw new ParseException(usage.PrintHelp(parser, err, argv)))); Assert.IsNotNull(ex); commandLineParser.Dispose(); }