[f82f07e] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
| 6 | //
|
---|
| 7 | // configs/usage.cfa
|
---|
| 8 | // Testing printing of usage for arguments
|
---|
| 9 | //
|
---|
| 10 | // Author : Thierry Delisle
|
---|
| 11 | // Created On : Wed Oct 12 15:28:01 2022
|
---|
[0b6089f] | 12 | // Last Modified By : Peter A. Buhr
|
---|
| 13 | // Last Modified On : Sun Feb 11 09:29:51 2024
|
---|
| 14 | // Update Count : 1
|
---|
[f82f07e] | 15 | //
|
---|
| 16 |
|
---|
| 17 | #include <fstream.hfa>
|
---|
[9e042d8] | 18 | #include "../meta/fork+exec.hfa"
|
---|
[d1abc63c] | 19 | #include <parseargs.hfa>
|
---|
[f82f07e] | 20 |
|
---|
| 21 |
|
---|
| 22 | int main() {
|
---|
| 23 | char * fake_argv[] = { "./usage" };
|
---|
| 24 |
|
---|
| 25 | sout | "No args, no errors";
|
---|
[0b6089f] | 26 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
[d1abc63c] | 27 | array( cfa_option, 0 ) opts;
|
---|
[0b6089f] | 28 | print_args_usage(1, fake_argv, opts, "Test usage", false );
|
---|
| 29 | } else {
|
---|
| 30 | int status = do_wait( child );
|
---|
| 31 | print_status( status );
|
---|
| 32 | } // if
|
---|
[f82f07e] | 33 |
|
---|
| 34 | sout | "No args, with errors";
|
---|
[0b6089f] | 35 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
[d1abc63c] | 36 | array( cfa_option, 0 ) opts;
|
---|
[0b6089f] | 37 | print_args_usage(1, fake_argv, opts, "Test usage", true );
|
---|
| 38 | } else {
|
---|
| 39 | int status = do_wait( child );
|
---|
| 40 | print_status( status );
|
---|
| 41 | } // if
|
---|
[f82f07e] | 42 |
|
---|
| 43 | sout | "Args with short names only:";
|
---|
[0b6089f] | 44 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
[f82f07e] | 45 | int a, b, c;
|
---|
[d1abc63c] | 46 | array( cfa_option, 3 ) opts;
|
---|
| 47 | opts[0] = (cfa_option){'a', "", "First arg", a };
|
---|
| 48 | opts[1] = (cfa_option){'b', "", "Second arg", b };
|
---|
| 49 | opts[2] = (cfa_option){'c', "", "Third arg", c };
|
---|
[0b6089f] | 50 | print_args_usage(1, fake_argv, opts, "Test usage", false );
|
---|
| 51 | } else {
|
---|
| 52 | int status = do_wait( child );
|
---|
| 53 | print_status( status );
|
---|
| 54 | } // if
|
---|
[f82f07e] | 55 |
|
---|
| 56 | sout | "Args with long names only:";
|
---|
[0b6089f] | 57 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
[f82f07e] | 58 | int a, b, c;
|
---|
[d1abc63c] | 59 | array( cfa_option, 3 ) opts;
|
---|
| 60 | opts[0] = (cfa_option){'\0', "AA", "First arg", a };
|
---|
| 61 | opts[1] = (cfa_option){'\0', "BB", "Second arg", b };
|
---|
| 62 | opts[2] = (cfa_option){'\0', "CC", "Third arg", c };
|
---|
[0b6089f] | 63 | print_args_usage(1, fake_argv, opts, "Test usage", false );
|
---|
| 64 | } else {
|
---|
| 65 | int status = do_wait( child );
|
---|
| 66 | print_status( status );
|
---|
| 67 | } // if
|
---|
[f82f07e] | 68 |
|
---|
| 69 | sout | "Mix of short and long args:";
|
---|
[0b6089f] | 70 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
[f82f07e] | 71 | int a, b, c;
|
---|
[d1abc63c] | 72 | array( cfa_option, 3 ) opts;
|
---|
| 73 | opts[0] = (cfa_option){'a', "", "First arg", a };
|
---|
| 74 | opts[1] = (cfa_option){'b', "BBBB", "Second arg", b };
|
---|
| 75 | opts[2] = (cfa_option){'\0', "CC", "Third arg", c };
|
---|
[0b6089f] | 76 | print_args_usage(1, fake_argv, opts, "Test usage", false );
|
---|
| 77 | } else {
|
---|
| 78 | int status = do_wait( child );
|
---|
| 79 | print_status( status );
|
---|
| 80 | } // if
|
---|
[f82f07e] | 81 |
|
---|
| 82 | sout | "Mix of short and long and some missing description:";
|
---|
[0b6089f] | 83 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
[f82f07e] | 84 | int a, b, c;
|
---|
[d1abc63c] | 85 | array( cfa_option, 3 ) opts;
|
---|
| 86 | opts[0] = (cfa_option){'a', "", "First arg", a };
|
---|
| 87 | opts[1] = (cfa_option){'b', "BBBB", "", b };
|
---|
| 88 | opts[2] = (cfa_option){'\0', "CC", "Third arg", c };
|
---|
[0b6089f] | 89 | print_args_usage(1, fake_argv, opts, "Test usage", false );
|
---|
| 90 | } else {
|
---|
| 91 | int status = do_wait( child );
|
---|
| 92 | print_status( status );
|
---|
| 93 | } // if
|
---|
[f82f07e] | 94 |
|
---|
| 95 | sout | "Mix of short and long and some long description:";
|
---|
[0b6089f] | 96 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
[f82f07e] | 97 | int a, b, c;
|
---|
[d1abc63c] | 98 | array( cfa_option, 3 ) opts;
|
---|
| 99 | opts[0] = (cfa_option){'a', "", "First arg\nThe description has multiple lines,\n...for some reason", a };
|
---|
| 100 | opts[1] = (cfa_option){'b', "BBBB", "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", b };
|
---|
| 101 | opts[2] = (cfa_option){'\0', "CC", "Third arg", c };
|
---|
[0b6089f] | 102 | print_args_usage(1, fake_argv, opts, "Test usage", false );
|
---|
| 103 | } else {
|
---|
| 104 | int status = do_wait( child );
|
---|
| 105 | print_status( status );
|
---|
| 106 | } // if
|
---|
[f82f07e] | 107 | }
|
---|
| 108 |
|
---|
| 109 | // no used
|
---|
[bada452] | 110 | static int true_main( const char *, const char * []) { return 0; }
|
---|
| 111 | __attribute__((unused)) static void check_main(const char *);
|
---|