@@ -680,7 +680,7 @@ extension HelpGenerationTests {
680
680
static let configuration = CommandConfiguration (
681
681
commandName: " parserBug " ,
682
682
subcommands: [ Sub . self] )
683
-
683
+
684
684
struct CommonOptions : ParsableCommand {
685
685
@Flag ( help: " example flag " )
686
686
var example : Bool = false
@@ -689,12 +689,12 @@ extension HelpGenerationTests {
689
689
struct Sub : ParsableCommand {
690
690
@OptionGroup ( )
691
691
var commonOptions : CommonOptions
692
-
692
+
693
693
@Argument ( help: " Non-mandatory argument " )
694
694
var argument : String ?
695
695
}
696
696
}
697
-
697
+
698
698
func testIssue278( ) {
699
699
AssertHelp ( . default, for: ParserBug . Sub. self, root: ParserBug . self, equals: """
700
700
USAGE: parserBug sub [--example] [<argument>]
@@ -708,42 +708,87 @@ extension HelpGenerationTests {
708
708
709
709
""" )
710
710
}
711
+ }
712
+
713
+ extension HelpGenerationTests {
714
+ struct NonCustomUsage : ParsableCommand {
715
+ struct ExampleSubcommand : ParsableCommand {
716
+ static let configuration = CommandConfiguration ( )
717
+ @Argument var output : String
718
+ }
719
+
720
+ static let configuration = CommandConfiguration (
721
+ subcommands: [ ExampleSubcommand . self] )
722
+
723
+ @Argument var file : String
724
+ @Flag var verboseMode = false
725
+ }
711
726
712
727
struct CustomUsageShort : ParsableCommand {
713
- static var configuration : CommandConfiguration {
714
- CommandConfiguration ( usage: """
728
+ static let configuration = CommandConfiguration (
729
+ usage: """
715
730
example [--verbose] <file-name>
716
731
""" )
717
- }
718
-
732
+
719
733
@Argument var file : String
720
734
@Flag var verboseMode = false
721
735
}
722
736
723
737
struct CustomUsageLong : ParsableCommand {
724
- static var configuration : CommandConfiguration {
725
- CommandConfiguration ( usage: """
738
+ static let configuration = CommandConfiguration (
739
+ usage: """
726
740
example <file-name>
727
741
example --verbose <file-name>
728
742
example --help
729
743
""" )
730
- }
731
-
744
+
732
745
@Argument var file : String
733
746
@Flag var verboseMode = false
734
747
}
735
748
736
749
struct CustomUsageHidden : ParsableCommand {
737
- static var configuration : CommandConfiguration {
738
- CommandConfiguration ( usage: " " )
739
- }
750
+ static let configuration = CommandConfiguration ( usage: " " )
740
751
741
752
@Argument var file : String
742
753
@Flag var verboseMode = false
743
754
}
744
755
745
- func testCustomUsageHelp( ) {
746
- XCTAssertEqual ( CustomUsageShort . helpMessage ( columns: 80 ) , """
756
+ func test_usageCustomization_helpMessage( ) {
757
+ AssertEqualStrings (
758
+ actual: NonCustomUsage . helpMessage ( columns: 80 ) ,
759
+ expected: """
760
+ USAGE: non-custom-usage <file> [--verbose-mode] <subcommand>
761
+
762
+ ARGUMENTS:
763
+ <file>
764
+
765
+ OPTIONS:
766
+ --verbose-mode
767
+ -h, --help Show help information.
768
+
769
+ SUBCOMMANDS:
770
+ example-subcommand
771
+
772
+ See 'non-custom-usage help <subcommand>' for detailed help.
773
+ """ )
774
+
775
+ AssertEqualStrings (
776
+ actual: NonCustomUsage . helpMessage (
777
+ for: NonCustomUsage . ExampleSubcommand. self, columns: 80 ) ,
778
+ expected: """
779
+ USAGE: non-custom-usage example-subcommand <output>
780
+
781
+ ARGUMENTS:
782
+ <output>
783
+
784
+ OPTIONS:
785
+ -h, --help Show help information.
786
+
787
+ """ )
788
+
789
+ AssertEqualStrings (
790
+ actual: CustomUsageShort . helpMessage ( columns: 80 ) ,
791
+ expected: """
747
792
USAGE: example [--verbose] <file-name>
748
793
749
794
ARGUMENTS:
@@ -755,7 +800,9 @@ extension HelpGenerationTests {
755
800
756
801
""" )
757
802
758
- XCTAssertEqual ( CustomUsageLong . helpMessage ( columns: 80 ) , """
803
+ AssertEqualStrings (
804
+ actual: CustomUsageLong . helpMessage ( columns: 80 ) ,
805
+ expected: """
759
806
USAGE: example <file-name>
760
807
example --verbose <file-name>
761
808
example --help
@@ -769,7 +816,9 @@ extension HelpGenerationTests {
769
816
770
817
""" )
771
818
772
- XCTAssertEqual ( CustomUsageHidden . helpMessage ( columns: 80 ) , """
819
+ AssertEqualStrings (
820
+ actual: CustomUsageHidden . helpMessage ( columns: 80 ) ,
821
+ expected: """
773
822
ARGUMENTS:
774
823
<file>
775
824
@@ -780,24 +829,74 @@ extension HelpGenerationTests {
780
829
""" )
781
830
}
782
831
783
- func testCustomUsageError( ) {
784
- XCTAssertEqual ( CustomUsageShort . fullMessage ( for: ValidationError ( " Test " ) ) , """
832
+ func test_usageCustomization_fullMessage( ) {
833
+ AssertEqualStrings (
834
+ actual: NonCustomUsage . fullMessage ( for: ValidationError ( " Test " ) ) ,
835
+ expected: """
836
+ Error: Test
837
+ Usage: non-custom-usage <file> [--verbose-mode] <subcommand>
838
+ See 'non-custom-usage --help' for more information.
839
+ """ )
840
+
841
+ AssertEqualStrings (
842
+ actual: CustomUsageShort . fullMessage ( for: ValidationError ( " Test " ) ) ,
843
+ expected: """
785
844
Error: Test
786
845
Usage: example [--verbose] <file-name>
787
846
See 'custom-usage-short --help' for more information.
788
847
""" )
789
- XCTAssertEqual ( CustomUsageLong . fullMessage ( for: ValidationError ( " Test " ) ) , """
848
+
849
+ AssertEqualStrings (
850
+ actual: CustomUsageLong . fullMessage ( for: ValidationError ( " Test " ) ) ,
851
+ expected: """
790
852
Error: Test
791
853
Usage: example <file-name>
792
854
example --verbose <file-name>
793
855
example --help
794
856
See 'custom-usage-long --help' for more information.
795
857
""" )
796
- XCTAssertEqual ( CustomUsageHidden . fullMessage ( for: ValidationError ( " Test " ) ) , """
858
+
859
+ AssertEqualStrings (
860
+ actual: CustomUsageHidden . fullMessage ( for: ValidationError ( " Test " ) ) ,
861
+ expected: """
797
862
Error: Test
798
863
See 'custom-usage-hidden --help' for more information.
799
864
""" )
800
865
}
866
+
867
+ func test_usageCustomization_usageString( ) {
868
+ AssertEqualStrings (
869
+ actual: NonCustomUsage . usageString ( ) ,
870
+ expected: """
871
+ non-custom-usage <file> [--verbose-mode] <subcommand>
872
+ """ )
873
+
874
+ AssertEqualStrings (
875
+ actual: NonCustomUsage . usageString (
876
+ for: NonCustomUsage . ExampleSubcommand. self) ,
877
+ expected: """
878
+ non-custom-usage example-subcommand <output>
879
+ """ )
880
+
881
+ AssertEqualStrings (
882
+ actual: CustomUsageShort . usageString ( ) ,
883
+ expected: """
884
+ example [--verbose] <file-name>
885
+ """ )
886
+
887
+ AssertEqualStrings (
888
+ actual: CustomUsageLong . usageString ( ) ,
889
+ expected: """
890
+ example <file-name>
891
+ example --verbose <file-name>
892
+ example --help
893
+ """ )
894
+
895
+ AssertEqualStrings (
896
+ actual: CustomUsageHidden . usageString ( ) ,
897
+ expected: """
898
+ """ )
899
+ }
801
900
}
802
901
803
902
extension HelpGenerationTests {
0 commit comments