PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tests/Text/VerbsHelpTextFixture.cs

https://github.com/sflanker/commandline
C# | 121 lines | 79 code | 14 blank | 28 comment | 0 complexity | e0e23d47dc76a03b8e15008d390a82e7 MD5 | raw file
Possible License(s): Apache-2.0
  1. #region License
  2. //
  3. // Command Line Library: VerbsFixture.cs
  4. //
  5. // Author:
  6. // Giacomo Stelluti Scala (gsscoder@gmail.com)
  7. //
  8. // Copyright (C) 2005 - 2013 Giacomo Stelluti Scala
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining a copy
  11. // of this software and associated documentation files (the "Software"), to deal
  12. // in the Software without restriction, including without limitation the rights
  13. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. // copies of the Software, and to permit persons to whom the Software is
  15. // furnished to do so, subject to the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be included in
  18. // all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. // THE SOFTWARE.
  27. //
  28. #endregion
  29. #region Using Directives
  30. using System;
  31. using System.IO;
  32. using System.Reflection;
  33. using CommandLine.Tests;
  34. using CommandLine.Tests.Mocks;
  35. using CommandLine.Helpers;
  36. using Xunit;
  37. using FluentAssertions;
  38. #endregion
  39. namespace CommandLine.Text.Tests
  40. {
  41. public class VerbsHelpTextFixture : ParserBaseFixture
  42. {
  43. [Fact]
  44. public void Failed_parsing_prints_help_index()
  45. {
  46. DoCoreTestForIndex(new string[] {});
  47. }
  48. [Fact]
  49. public void Requesting_help_prints_help_index()
  50. {
  51. DoCoreTestForIndex(new string[] {"help"});
  52. }
  53. [Fact]
  54. public void Requesting_bad_help_prints_help_index()
  55. {
  56. DoCoreTestForIndex(new string[] { "help", "undefined" });
  57. }
  58. [Fact]
  59. public void Failed_verb_parsing_prints_particular_help_screen()
  60. {
  61. var options = new OptionsWithVerbsHelp();
  62. var testWriter = new StringWriter();
  63. ReflectionUtil.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly();
  64. var parser = new Parser();
  65. var result = parser.ParseArguments(new string[] { "clone", "--no_hardlinks" }, options, testWriter);
  66. result.Should().BeFalse();
  67. var helpText = testWriter.ToString();
  68. Console.WriteLine(helpText);
  69. var lines = helpText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
  70. // Verify just significant output
  71. lines[5].Trim().Should().Be("--no-hardlinks Optimize the cloning process from a repository on a local");
  72. lines[6].Trim().Should().Be("filesystem by copying files.");
  73. lines[7].Trim().Should().Be("-q, --quiet Suppress summary message.");
  74. }
  75. #region https://github.com/gsscoder/commandline/issues/45
  76. [Fact]
  77. public void Requesting_help_of_particular_verb_without_instance_should_work()
  78. {
  79. var options = new OptionsWithVerbsHelp();
  80. var testWriter = new StringWriter();
  81. ReflectionUtil.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly();
  82. var parser = new Parser();
  83. var result = parser.ParseArguments(new string[] {"help", "add"}, options, testWriter);
  84. result.Should().BeFalse();
  85. var helpText = testWriter.ToString();
  86. Console.WriteLine(helpText);
  87. var lines = helpText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
  88. }
  89. #endregion
  90. private void DoCoreTestForIndex(string[] args)
  91. {
  92. var options = new OptionsWithVerbsHelp();
  93. var testWriter = new StringWriter();
  94. ReflectionUtil.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly();
  95. var parser = new Parser();
  96. var result = parser.ParseArguments(args, options, testWriter);
  97. result.Should().BeFalse();
  98. var helpText = testWriter.ToString();
  99. Console.WriteLine(helpText);
  100. var lines = helpText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
  101. // Verify just significant output
  102. lines[5].Trim().Should().Be("add Add file contents to the index.");
  103. lines[6].Trim().Should().Be("commit Record changes to the repository.");
  104. lines[7].Trim().Should().Be("clone Clone a repository into a new directory.");
  105. }
  106. }
  107. }