aboutsummaryrefslogtreecommitdiff
path: root/clap/tests/help.rs
blob: 4b15281f4b989e77f82bf995887ec927f05023c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
#[macro_use]
extern crate clap;
extern crate regex;

include!("../clap-test.rs");

use clap::{App, AppSettings, SubCommand, ErrorKind, Arg};

static REQUIRE_DELIM_HELP: &'static str = "test 1.3
Kevin K.
tests stuff

USAGE:
    test --fake <some>:<val>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -f, --fake <some>:<val>    some help";

static HELP: &'static str = "clap-test v1.4.8
Kevin K. <kbknapp@gmail.com>
tests clap library

USAGE:
    clap-test [FLAGS] [OPTIONS] [ARGS] [SUBCOMMAND]

FLAGS:
    -f, --flag       tests flags
    -F               tests flags with exclusions
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -O, --Option <option3>           specific vals [possible values: fast, slow]
        --long-option-2 <option2>    tests long options with exclusions
        --maxvals3 <maxvals>...      Tests 3 max vals
        --minvals2 <minvals>...      Tests 2 min vals
        --multvals <one> <two>       Tests multiple values, not mult occs
        --multvalsmo <one> <two>     Tests multiple values, and mult occs
    -o, --option <opt>...            tests options

ARGS:
    <positional>        tests positionals
    <positional2>       tests positionals with exclusions
    <positional3>...    tests specific values [possible values: vi, emacs]

SUBCOMMANDS:
    help      Prints this message or the help of the given subcommand(s)
    subcmd    tests subcommands";

static SC_NEGATES_REQS: &'static str = "prog 1.0

USAGE:
    prog --opt <FILE> [PATH]
    prog [PATH] <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -o, --opt <FILE>    tests options

ARGS:
    <PATH>    help

SUBCOMMANDS:
    help    Prints this message or the help of the given subcommand(s)
    test";

static ARGS_NEGATE_SC: &'static str = "prog 1.0

USAGE:
    prog [FLAGS] [OPTIONS] [PATH]
    prog <SUBCOMMAND>

FLAGS:
    -f, --flag       testing flags
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -o, --opt <FILE>    tests options

ARGS:
    <PATH>    help

SUBCOMMANDS:
    help    Prints this message or the help of the given subcommand(s)
    test";

static AFTER_HELP: &'static str = "some text that comes before the help

clap-test v1.4.8
tests clap library

USAGE:
    clap-test

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

some text that comes after the help";

static HIDDEN_ARGS: &'static str = "prog 1.0

USAGE:
    prog [FLAGS] [OPTIONS]

FLAGS:
    -f, --flag       testing flags
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -o, --opt <FILE>    tests options";

static SC_HELP: &'static str = "clap-test-subcmd 0.1
Kevin K. <kbknapp@gmail.com>
tests subcommands

USAGE:
    clap-test subcmd [FLAGS] [OPTIONS] [--] [scpositional]

FLAGS:
    -f, --flag       tests flags
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -o, --option <scoption>...     tests options
    -s, --subcmdarg <subcmdarg>    tests other args

ARGS:
    <scpositional>    tests positionals";

static ISSUE_1046_HIDDEN_SCS: &'static str = "prog 1.0

USAGE:
    prog [FLAGS] [OPTIONS] [PATH]

FLAGS:
    -f, --flag       testing flags
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -o, --opt <FILE>    tests options

ARGS:
    <PATH>    some";

// Using number_of_values(1) with multiple(true) misaligns help message
static ISSUE_760: &'static str = "ctest 0.1

USAGE:
    ctest [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -O, --opt <opt>             tests options
    -o, --option <option>...    tests options";

static RIPGREP_USAGE: &'static str = "ripgrep 0.5

USAGE:
    rg [OPTIONS] <pattern> [<path> ...]
    rg [OPTIONS] [-e PATTERN | -f FILE ]... [<path> ...]
    rg [OPTIONS] --files [<path> ...]
    rg [OPTIONS] --type-list

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information";


static MULTI_SC_HELP: &'static str = "ctest-subcmd-multi 0.1
Kevin K. <kbknapp@gmail.com>
tests subcommands

USAGE:
    ctest subcmd multi [FLAGS] [OPTIONS]

FLAGS:
    -f, --flag       tests flags
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -o, --option <scoption>...    tests options";

static ISSUE_626_CUTOFF: &'static str = "ctest 0.1

USAGE:
    ctest [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -c, --cafe <FILE>    A coffeehouse, coffee shop, or café is an
                         establishment which primarily serves hot
                         coffee, related coffee beverages (e.g., café
                         latte, cappuccino, espresso), tea, and other
                         hot beverages. Some coffeehouses also serve
                         cold beverages such as iced coffee and iced
                         tea. Many cafés also serve some type of food,
                         such as light snacks, muffins, or pastries.";

static ISSUE_626_PANIC: &'static str = "ctest 0.1

USAGE:
    ctest [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -c, --cafe <FILE>
            La culture du café est très développée
            dans de nombreux pays à climat chaud
            d\'Amérique, d\'Afrique et d\'Asie, dans
            des plantations qui sont cultivées pour
            les marchés d\'exportation. Le café est
            souvent une contribution majeure aux
            exportations des régions productrices.";

static HIDE_POS_VALS: &'static str = "ctest 0.1

USAGE:
    ctest [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -c, --cafe <FILE>    A coffeehouse, coffee shop, or café.
    -p, --pos <VAL>      Some vals [possible values: fast, slow]";

static FINAL_WORD_WRAPPING: &'static str = "ctest 0.1

USAGE:
    ctest

FLAGS:
    -h, --help
            Prints help
            information
    -V, --version
            Prints
            version
            information";

static OLD_NEWLINE_CHARS: &'static str = "ctest 0.1

USAGE:
    ctest [FLAGS]

FLAGS:
    -h, --help       Prints help information
    -m               Some help with some wrapping
                     (Defaults to something)
    -V, --version    Prints version information";

static WRAPPING_NEWLINE_CHARS: &'static str = "ctest 0.1

USAGE:
    ctest [mode]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <mode>    x, max, maximum   20 characters, contains
              symbols.
              l, long           Copy-friendly, 14
              characters, contains symbols.
              m, med, medium    Copy-friendly, 8
              characters, contains symbols.";

static ISSUE_688: &'static str = "ctest 0.1

USAGE:
    ctest [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
        --filter <filter>    Sets the filter, or sampling method, to use for interpolation when resizing the particle
                             images. The default is Linear (Bilinear). [possible values: Nearest, Linear, Cubic,
                             Gaussian, Lanczos3]";

static ISSUE_702: &'static str = "myapp 1.0
foo
bar

USAGE:
    myapp [OPTIONS] [--] [ARGS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -l, --label <label>...    a label
    -o, --other <other>       some other option
    -s, --some <some>         some option

ARGS:
    <arg1>       some option
    <arg2>...    some option";

static ISSUE_777: &'static str = "A app with a crazy very long long
long name hahaha 1.0
Some Very Long Name and crazy long
email <email@server.com>
Show how the about text is not
wrapped

USAGE:
    ctest

FLAGS:
    -h, --help
            Prints help information

    -V, --version
            Prints version
            information";

static CUSTOM_VERSION_AND_HELP: &'static str = "customize 0.1
Nobody <odysseus@example.com>
You can customize the version and help text

USAGE:
    customize

FLAGS:
    -H, --help       Print help information
    -v, --version    Print version information";

static LAST_ARG: &'static str = "last 0.1

USAGE:
    last <TARGET> [CORPUS] [-- <ARGS>...]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <TARGET>     some
    <CORPUS>     some
    <ARGS>...    some";

static LAST_ARG_SC: &'static str = "last 0.1

USAGE:
    last <TARGET> [CORPUS] [-- <ARGS>...]
    last <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <TARGET>     some
    <CORPUS>     some
    <ARGS>...    some

SUBCOMMANDS:
    help    Prints this message or the help of the given subcommand(s)
    test    some";

static LAST_ARG_REQ: &'static str = "last 0.1

USAGE:
    last <TARGET> [CORPUS] -- <ARGS>...

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <TARGET>     some
    <CORPUS>     some
    <ARGS>...    some";

static LAST_ARG_REQ_SC: &'static str = "last 0.1

USAGE:
    last <TARGET> [CORPUS] -- <ARGS>...
    last <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <TARGET>     some
    <CORPUS>     some
    <ARGS>...    some

SUBCOMMANDS:
    help    Prints this message or the help of the given subcommand(s)
    test    some";

static HIDE_DEFAULT_VAL: &'static str = "default 0.1

USAGE:
    default [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
        --arg <argument>    Pass an argument to the program. [default: default-argument]";

static LAST_ARG_USAGE: &'static str = "flamegraph 0.1

USAGE:
    flamegraph [FLAGS] [OPTIONS] [BINFILE] [-- <ARGS>...]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
    -v, --verbose    Prints out more stuff.

OPTIONS:
    -f, --frequency <HERTZ>    The sampling frequency.
    -t, --timeout <SECONDS>    Timeout in seconds.

ARGS:
    <BINFILE>    The path of the binary to be profiled. for a binary.
    <ARGS>...    Any arguments you wish to pass to the being profiled.";

static LAST_ARG_REQ_MULT: &'static str = "example 1.0

USAGE:
    example <FIRST>... [--] <SECOND>...

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <FIRST>...     First
    <SECOND>...    Second";

static DEFAULT_HELP: &'static str = "ctest 1.0

USAGE:
    ctest

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information";

static LONG_ABOUT: &'static str = "myapp 1.0
foo
something really really long, with
multiple lines of text
that should be displayed

USAGE:
    myapp [arg1]

FLAGS:
    -h, --help       
            Prints help information

    -V, --version    
            Prints version information


ARGS:
    <arg1>    
            some option";

static HIDE_ENV_VALS: &'static str = "ctest 0.1

USAGE:
    ctest [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -c, --cafe <FILE>    A coffeehouse, coffee shop, or café. [env: ENVVAR]
    -p, --pos <VAL>      Some vals [possible values: fast, slow]";

static SHOW_ENV_VALS: &'static str = "ctest 0.1

USAGE:
    ctest [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -c, --cafe <FILE>    A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
    -p, --pos <VAL>      Some vals [possible values: fast, slow]";

fn setup() -> App<'static, 'static> {
    App::new("test")
        .author("Kevin K.")
        .about("tests stuff")
        .version("1.3")
}

#[test]
fn help_short() {
    let m = setup()
        .get_matches_from_safe(vec!["myprog", "-h"]);

    assert!(m.is_err());
    assert_eq!(m.unwrap_err().kind, ErrorKind::HelpDisplayed);
}

#[test]
fn help_long() {
    let m = setup()
        .get_matches_from_safe(vec!["myprog", "--help"]);

    assert!(m.is_err());
    assert_eq!(m.unwrap_err().kind, ErrorKind::HelpDisplayed);
}

#[test]
fn help_no_subcommand() {
    let m = setup() 
        .get_matches_from_safe(vec!["myprog", "help"]);

    assert!(m.is_err());
    assert_eq!(m.unwrap_err().kind, ErrorKind::UnknownArgument);
}

#[test]
fn help_subcommand() {
    let m = setup()
        .subcommand(SubCommand::with_name("test")
            .about("tests things")
            .arg_from_usage("-v --verbose 'with verbosity'"))
        .get_matches_from_safe(vec!["myprog", "help"]);

    assert!(m.is_err());
    assert_eq!(m.unwrap_err().kind, ErrorKind::HelpDisplayed);
}

#[test]
fn req_last_arg_usage() {
    let app = clap_app!(example =>
        (version: "1.0")
        (@arg FIRST: ... * "First")
        (@arg SECOND: ... * +last "Second")
    );
    assert!(test::compare_output(app, "example --help", LAST_ARG_REQ_MULT, false));
}

#[test]
fn args_with_last_usage() {
    let app = App::new("flamegraph")
        .version("0.1")
        .setting(AppSettings::TrailingVarArg)
        .arg(Arg::with_name("verbose")
            .help("Prints out more stuff.")
            .short("v")
            .long("verbose")
            .multiple(true)
        )
        .arg(Arg::with_name("timeout")
            .help("Timeout in seconds.")
            .short("t")
            .long("timeout")
            .value_name("SECONDS")
            .takes_value(true)
        )
        .arg(Arg::with_name("frequency")
            .help("The sampling frequency.")
            .short("f")
            .long("frequency")
            .value_name("HERTZ")
            .takes_value(true)
        )
        .arg(Arg::with_name("binary path")
            .help("The path of the binary to be profiled. for a binary.")
            .takes_value(true)
            .value_name("BINFILE")
        )
        .arg(Arg::with_name("pass through args")
            .help("Any arguments you wish to pass to the being profiled.")
            .value_name("ARGS")
            .last(true)
            .multiple(true)
        );
    assert!(test::compare_output(app, "flamegraph --help", LAST_ARG_USAGE, false));
}

#[test]
fn subcommand_short_help() {
    let m = test::complex_app().get_matches_from_safe(vec!["clap-test", "subcmd", "-h"]);

    assert!(m.is_err());
    assert_eq!(m.unwrap_err().kind, ErrorKind::HelpDisplayed);
}

#[test]
fn subcommand_long_help() {
    let m = test::complex_app().get_matches_from_safe(vec!["clap-test", "subcmd", "--help"]);

    assert!(m.is_err());
    assert_eq!(m.unwrap_err().kind, ErrorKind::HelpDisplayed);
}

#[test]
fn subcommand_help_rev() {
    let m = test::complex_app().get_matches_from_safe(vec!["clap-test", "help", "subcmd"]);

    assert!(m.is_err());
    assert_eq!(m.unwrap_err().kind, ErrorKind::HelpDisplayed);
}

#[test]
fn complex_help_output() {
    assert!(test::compare_output(test::complex_app(), "clap-test --help", HELP, false));
}

#[test]
fn after_and_before_help_output() {
    let app = App::new("clap-test")
        .version("v1.4.8")
        .about("tests clap library")
        .before_help("some text that comes before the help")
        .after_help("some text that comes after the help");
    assert!(test::compare_output(app, "clap-test --help", AFTER_HELP, false));
}

#[test]
fn multi_level_sc_help() {
    let app = App::new("ctest")
        .subcommand(SubCommand::with_name("subcmd").subcommand(SubCommand::with_name("multi")
            .about("tests subcommands")
            .author("Kevin K. <kbknapp@gmail.com>")
            .version("0.1")
            .args_from_usage("
                    -f, --flag                    'tests flags'
                    -o, --option [scoption]...    'tests options'
                ")));
    assert!(test::compare_output(app, "ctest help subcmd multi", MULTI_SC_HELP, false));
}

#[test]
fn no_wrap_help() {
    let app = App::new("ctest")
        .set_term_width(0)
        .help(MULTI_SC_HELP);
    assert!(test::compare_output(app, "ctest --help", MULTI_SC_HELP, false));
}

#[test]
fn no_wrap_default_help() {
    let app = App::new("ctest").version("1.0").set_term_width(0);
    assert!(test::compare_output(app, "ctest --help", DEFAULT_HELP, false));
}

#[test]
fn complex_subcommand_help_output() {
    let a = test::complex_app();
    assert!(test::compare_output(a, "clap-test subcmd --help", SC_HELP, false));
}


#[test]
fn issue_626_unicode_cutoff() {
    let app = App::new("ctest")
        .version("0.1")
        .set_term_width(70)
        .arg(Arg::with_name("cafe")
            .short("c")
            .long("cafe")
            .value_name("FILE")
            .help("A coffeehouse, coffee shop, or café is an establishment \
           which primarily serves hot coffee, related coffee beverages \
           (e.g., café latte, cappuccino, espresso), tea, and other hot \
           beverages. Some coffeehouses also serve cold beverages such as \
           iced coffee and iced tea. Many cafés also serve some type of \
           food, such as light snacks, muffins, or pastries.")
            .takes_value(true));
    assert!(test::compare_output(app, "ctest --help", ISSUE_626_CUTOFF, false));
}

#[test]
fn hide_possible_vals() {
    let app = App::new("ctest")
        .version("0.1")
        .arg(Arg::with_name("pos")
            .short("p")
            .long("pos")
            .value_name("VAL")
            .possible_values(&["fast", "slow"])
            .help("Some vals")
            .takes_value(true))
        .arg(Arg::with_name("cafe")
            .short("c")
            .long("cafe")
            .value_name("FILE")
            .hide_possible_values(true)
            .possible_values(&["fast", "slow"])
            .help("A coffeehouse, coffee shop, or café.")
            .takes_value(true));
    assert!(test::compare_output(app, "ctest --help", HIDE_POS_VALS, false));
}

#[test]
fn issue_626_panic() {
    let app = App::new("ctest")
        .version("0.1")
        .set_term_width(52)
        .arg(Arg::with_name("cafe")
           .short("c")
           .long("cafe")
           .value_name("FILE")
           .help("La culture du café est très développée dans de nombreux pays à climat chaud d'Amérique, \
           d'Afrique et d'Asie, dans des plantations qui sont cultivées pour les marchés d'exportation. \
           Le café est souvent une contribution majeure aux exportations des régions productrices.")
           .takes_value(true));
    assert!(test::compare_output(app, "ctest --help", ISSUE_626_PANIC, false));
}

#[test]
fn issue_626_variable_panic() {
    for i in 10..320 {
        let _ = App::new("ctest")
            .version("0.1")
            .set_term_width(i)
            .arg(Arg::with_name("cafe")
               .short("c")
               .long("cafe")
               .value_name("FILE")
               .help("La culture du café est très développée dans de nombreux pays à climat chaud d'Amérique, \
               d'Afrique et d'Asie, dans des plantations qui sont cultivées pour les marchés d'exportation. \
               Le café est souvent une contribution majeure aux exportations des régions productrices.")
               .takes_value(true))
            .get_matches_from_safe(vec!["ctest", "--help"]);
    }
}

#[test]
fn final_word_wrapping() {
    let app = App::new("ctest").version("0.1").set_term_width(24);
    assert!(test::compare_output(app, "ctest --help", FINAL_WORD_WRAPPING, false));
}

#[test]
fn wrapping_newline_chars() {
    let app = App::new("ctest")
        .version("0.1")
		.set_term_width(60)
        .arg(Arg::with_name("mode")
             .help("x, max, maximum   20 characters, contains symbols.{n}\
                    l, long           Copy-friendly, 14 characters, contains symbols.{n}\
                    m, med, medium    Copy-friendly, 8 characters, contains symbols.{n}"));
    assert!(test::compare_output(app, "ctest --help", WRAPPING_NEWLINE_CHARS, false));
}

#[test]
fn old_newline_chars() {
    let app = App::new("ctest")
        .version("0.1")
        .arg(Arg::with_name("mode")
            .short("m")
            .help("Some help with some wrapping{n}(Defaults to something)"));
    assert!(test::compare_output(app, "ctest --help", OLD_NEWLINE_CHARS, false));
}

#[test]
fn issue_688_hidden_pos_vals() {
    let filter_values = ["Nearest", "Linear", "Cubic", "Gaussian", "Lanczos3"];

    let app1 = App::new("ctest")
            .version("0.1")
			.set_term_width(120)
			.setting(AppSettings::HidePossibleValuesInHelp)
			.arg(Arg::with_name("filter")
				.help("Sets the filter, or sampling method, to use for interpolation when resizing the particle \
                images. The default is Linear (Bilinear). [possible values: Nearest, Linear, Cubic, Gaussian, Lanczos3]")
				.long("filter")
				.possible_values(&filter_values)
				.takes_value(true));
    assert!(test::compare_output(app1, "ctest --help", ISSUE_688, false));

    let app2 = App::new("ctest")
            .version("0.1")
			.set_term_width(120)
			.arg(Arg::with_name("filter")
				.help("Sets the filter, or sampling method, to use for interpolation when resizing the particle \
                images. The default is Linear (Bilinear).")
				.long("filter")
				.possible_values(&filter_values)
				.takes_value(true));
    assert!(test::compare_output(app2, "ctest --help", ISSUE_688, false));

    let app3 = App::new("ctest")
            .version("0.1")
			.set_term_width(120)
			.arg(Arg::with_name("filter")
				.help("Sets the filter, or sampling method, to use for interpolation when resizing the particle \
                images. The default is Linear (Bilinear). [possible values: Nearest, Linear, Cubic, Gaussian, Lanczos3]")
				.long("filter")
				.takes_value(true));
    assert!(test::compare_output(app3, "ctest --help", ISSUE_688, false));
}

#[test]
fn issue_702_multiple_values() {
    let app = App::new("myapp")
        .version("1.0")
        .author("foo")
        .about("bar")
        .arg(Arg::with_name("arg1").help("some option"))
        .arg(Arg::with_name("arg2")
            .multiple(true)
            .help("some option"))
        .arg(Arg::with_name("some")
            .help("some option")
            .short("s")
            .long("some")
            .takes_value(true))
        .arg(Arg::with_name("other")
            .help("some other option")
            .short("o")
            .long("other")
            .takes_value(true))
        .arg(Arg::with_name("label")
            .help("a label")
            .short("l")
            .long("label")
            .multiple(true)
            .takes_value(true));
    assert!(test::compare_output(app, "myapp --help", ISSUE_702, false));
}

#[test]
fn long_about() {
    let app = App::new("myapp")
        .version("1.0")
        .author("foo")
        .about("bar")
        .long_about("something really really long, with\nmultiple lines of text\nthat should be displayed")
        .arg(Arg::with_name("arg1").help("some option"));
    assert!(test::compare_output(app, "myapp --help", LONG_ABOUT, false));
}

#[test]
fn issue_760() {
    let app = App::new("ctest")
        .version("0.1")
        .arg(Arg::with_name("option")
            .help("tests options")
            .short("o")
            .long("option")
            .takes_value(true)
            .multiple(true)
            .number_of_values(1))
        .arg(Arg::with_name("opt")
            .help("tests options")
            .short("O")
            .long("opt")
            .takes_value(true));
    assert!(test::compare_output(app, "ctest --help", ISSUE_760, false));
}

#[test]
fn ripgrep_usage() {
    let app = App::new("ripgrep")
        .version("0.5")
        .usage("rg [OPTIONS] <pattern> [<path> ...]
    rg [OPTIONS] [-e PATTERN | -f FILE ]... [<path> ...]
    rg [OPTIONS] --files [<path> ...]
    rg [OPTIONS] --type-list");

    assert!(test::compare_output(app, "rg --help", RIPGREP_USAGE, false));
}

#[test]
fn ripgrep_usage_using_templates() {
    let app = App::new("ripgrep")
        .version("0.5")
        .usage("
    rg [OPTIONS] <pattern> [<path> ...]
    rg [OPTIONS] [-e PATTERN | -f FILE ]... [<path> ...]
    rg [OPTIONS] --files [<path> ...]
    rg [OPTIONS] --type-list")
        .template("\
{bin} {version}

USAGE:{usage}

FLAGS:
{flags}");

    assert!(test::compare_output(app, "rg --help", RIPGREP_USAGE, false));
}

#[test]
fn sc_negates_reqs() {
    let app = App::new("prog")
        .version("1.0")
        .setting(AppSettings::SubcommandsNegateReqs)
        .arg_from_usage("-o, --opt <FILE> 'tests options'")
        .arg(Arg::with_name("PATH").help("help"))
        .subcommand(SubCommand::with_name("test"));
    assert!(test::compare_output(app, "prog --help", SC_NEGATES_REQS, false));
}

#[test]
fn hidden_args() {
    let app = App::new("prog")
        .version("1.0")
        .args_from_usage("-f, --flag 'testing flags'
                          -o, --opt [FILE] 'tests options'")
        .arg(Arg::with_name("pos").hidden(true));
    assert!(test::compare_output(app, "prog --help", HIDDEN_ARGS, false));
}

#[test]
fn args_negate_sc() {
    let app = App::new("prog")
        .version("1.0")
        .setting(AppSettings::ArgsNegateSubcommands)
        .args_from_usage("-f, --flag 'testing flags'
                          -o, --opt [FILE] 'tests options'")
        .arg(Arg::with_name("PATH").help("help"))
        .subcommand(SubCommand::with_name("test"));
    assert!(test::compare_output(app, "prog --help", ARGS_NEGATE_SC, false));
}

#[test]
fn issue_1046_hidden_scs() {
    let app = App::new("prog")
        .version("1.0")
        .args_from_usage("-f, --flag 'testing flags'
                          -o, --opt [FILE] 'tests options'")
        .arg(Arg::with_name("PATH").help("some"))
        .subcommand(SubCommand::with_name("test").setting(AppSettings::Hidden));
    assert!(test::compare_output(app, "prog --help", ISSUE_1046_HIDDEN_SCS, false));
}

#[test]
fn issue_777_wrap_all_things() {
    let app = App::new("A app with a crazy very long long long name hahaha")
        .version("1.0")
        .author("Some Very Long Name and crazy long email <email@server.com>")
        .about("Show how the about text is not wrapped")
        .set_term_width(35);
    assert!(test::compare_output(app, "ctest --help", ISSUE_777, false));
}

#[test]
fn customize_version_and_help() {
    let app = App::new("customize")
        .version("0.1")
        .author("Nobody <odysseus@example.com>")
        .about("You can customize the version and help text")
        .help_short("H")
        .help_message("Print help information")
        .version_short("v")
        .version_message("Print version information");
    assert!(test::compare_output(app, "customize --help", CUSTOM_VERSION_AND_HELP, false));
}

#[test]
fn last_arg_mult_usage() {
    let app = App::new("last")
            .version("0.1")
            .arg(Arg::with_name("TARGET").required(true).help("some"))
            .arg(Arg::with_name("CORPUS").help("some"))
            .arg(Arg::with_name("ARGS").multiple(true).last(true).help("some"));
    assert!(test::compare_output(app, "last --help", LAST_ARG, false));
}

#[test]
fn last_arg_mult_usage_req() {
    let app = App::new("last")
            .version("0.1")
            .arg(Arg::with_name("TARGET").required(true).help("some"))
            .arg(Arg::with_name("CORPUS").help("some"))
            .arg(Arg::with_name("ARGS").multiple(true).last(true).required(true).help("some"));
    assert!(test::compare_output(app, "last --help", LAST_ARG_REQ, false));
}

#[test]
fn last_arg_mult_usage_req_with_sc() {
    let app = App::new("last")
            .version("0.1")
            .setting(AppSettings::SubcommandsNegateReqs)
            .arg(Arg::with_name("TARGET").required(true).help("some"))
            .arg(Arg::with_name("CORPUS").help("some"))
            .arg(Arg::with_name("ARGS").multiple(true).last(true).required(true).help("some"))
            .subcommand(SubCommand::with_name("test").about("some"));
    assert!(test::compare_output(app, "last --help", LAST_ARG_REQ_SC, false));
}

#[test]
fn last_arg_mult_usage_with_sc() {
    let app = App::new("last")
            .version("0.1")
            .setting(AppSettings::ArgsNegateSubcommands)
            .arg(Arg::with_name("TARGET").required(true).help("some"))
            .arg(Arg::with_name("CORPUS").help("some"))
            .arg(Arg::with_name("ARGS").multiple(true).last(true).help("some"))
            .subcommand(SubCommand::with_name("test").about("some"));
    assert!(test::compare_output(app, "last --help", LAST_ARG_SC, false));
}


#[test]
fn hidden_default_val() {
    let app1 = App::new("default")
        .version("0.1")
        .set_term_width(120)
        .arg(Arg::with_name("argument")
             .help("Pass an argument to the program. [default: default-argument]")
             .long("arg")
             .default_value("default-argument")
             .hide_default_value(true));
    assert!(test::compare_output(app1, "default --help", HIDE_DEFAULT_VAL, false));

    let app2 = App::new("default")
        .version("0.1")
        .set_term_width(120)
        .arg(Arg::with_name("argument")
             .help("Pass an argument to the program.")
             .long("arg")
             .default_value("default-argument"));
    assert!(test::compare_output(app2, "default --help", HIDE_DEFAULT_VAL, false));
}

fn issue_1112_setup() -> App<'static, 'static> {
    App::new("test")
        .author("Kevin K.")
        .about("tests stuff")
        .version("1.3")
        .arg(Arg::from_usage("-h, --help 'some help'"))
        .subcommand(SubCommand::with_name("foo")
            .arg(Arg::from_usage("-h, --help 'some help'")))
}

#[test]
fn issue_1112_override_help_long() {
    let m = issue_1112_setup()
        .get_matches_from_safe(vec!["test", "--help"]);

    assert!(m.is_ok());
    assert!(m.unwrap().is_present("help"));
}

#[test]
fn issue_1112_override_help_short() {
    let m = issue_1112_setup()
        .get_matches_from_safe(vec!["test", "-h"]);

    assert!(m.is_ok());
    assert!(m.unwrap().is_present("help"));
}

#[test]
fn issue_1112_override_help_subcmd_long() {
    let m = issue_1112_setup()
        .get_matches_from_safe(vec!["test", "foo", "--help"]);

    assert!(m.is_ok());
    assert!(m.unwrap().subcommand_matches("foo").unwrap().is_present("help"));
}

#[test]
fn issue_1112_override_help_subcmd_short() {
    let m = issue_1112_setup()
        .get_matches_from_safe(vec!["test", "foo", "-h"]);

    assert!(m.is_ok());
    assert!(m.unwrap().subcommand_matches("foo").unwrap().is_present("help"));
}

#[test]
fn issue_1052_require_delim_help() {
    let app = App::new("test")
        .author("Kevin K.")
        .about("tests stuff")
        .version("1.3")
        .arg(Arg::from_usage("-f, --fake <some> <val> 'some help'").require_delimiter(true).value_delimiter(":"));

    assert!(test::compare_output(app, "test --help", REQUIRE_DELIM_HELP, false));
}

#[test]
fn hide_env_vals() {
    use std::env;

    env::set_var("ENVVAR", "MYVAL");
    let app = App::new("ctest")
        .version("0.1")
        .arg(Arg::with_name("pos")
            .short("p")
            .long("pos")
            .value_name("VAL")
            .possible_values(&["fast", "slow"])
            .help("Some vals")
            .takes_value(true))
        .arg(Arg::with_name("cafe")
            .short("c")
            .long("cafe")
            .value_name("FILE")
            .hide_env_values(true)
            .env("ENVVAR")
            .help("A coffeehouse, coffee shop, or café.")
            .takes_value(true));
    assert!(test::compare_output(app, "ctest --help", HIDE_ENV_VALS, false));
}

#[test]
fn show_env_vals() {
    use std::env;

    env::set_var("ENVVAR", "MYVAL");
    let app = App::new("ctest")
        .version("0.1")
        .arg(Arg::with_name("pos")
            .short("p")
            .long("pos")
            .value_name("VAL")
            .possible_values(&["fast", "slow"])
            .help("Some vals")
            .takes_value(true))
        .arg(Arg::with_name("cafe")
            .short("c")
            .long("cafe")
            .value_name("FILE")
            .hide_possible_values(true)
            .env("ENVVAR")
            .help("A coffeehouse, coffee shop, or café.")
            .takes_value(true));
    assert!(test::compare_output(app, "ctest --help", SHOW_ENV_VALS, false));
}

static ISSUE_897: &'static str = "ctest-foo 0.1
Long about foo

USAGE:
    ctest foo

FLAGS:
    -h, --help       
            Prints help information

    -V, --version    
            Prints version information";

#[test]
fn show_long_about_issue_897() {
    let app = App::new("ctest")
        .version("0.1")
        .subcommand(SubCommand::with_name("foo")
            .version("0.1")
            .about("About foo")
            .long_about("Long about foo"));
    assert!(test::compare_output(app, "ctest foo --help", ISSUE_897, false));
}

static ISSUE_897_SHORT: &'static str = "ctest-foo 0.1
Long about foo

USAGE:
    ctest foo

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information";

#[test]
fn show_short_about_issue_897() {
    let app = App::new("ctest")
        .version("0.1")
        .subcommand(SubCommand::with_name("foo")
            .version("0.1")
            .about("About foo")
            .long_about("Long about foo"));
    assert!(test::compare_output(app, "ctest foo -h", ISSUE_897_SHORT, false));
}