source: tests/configs/usage.cfa @ 075c6d5

Last change on this file since 075c6d5 was 0b6089f, checked in by Peter A. Buhr <pabuhr@…>, 9 months ago

formatting

  • Property mode set to 100644
File size: 3.5 KB
Line 
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
12// Last Modified By : Peter A. Buhr
13// Last Modified On : Sun Feb 11 09:29:51 2024
14// Update Count     : 1
15//
16
17#include <fstream.hfa>
18#include "../meta/fork+exec.hfa"
19#include <parseargs.hfa>
20
21
22int main() {
23        char * fake_argv[] = { "./usage" };
24
25        sout | "No args, no errors";
26        if ( pid_t child = strict_fork(); child == 0 ) {
27                array( cfa_option, 0 ) opts;
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
33
34        sout | "No args, with errors";
35        if ( pid_t child = strict_fork(); child == 0 ) {
36                array( cfa_option, 0 ) opts;
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
42
43        sout | "Args with short names only:";
44        if ( pid_t child = strict_fork(); child == 0 ) {
45                int a, b, c;
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 };
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
55
56        sout | "Args with long names only:";
57        if ( pid_t child = strict_fork(); child == 0 ) {
58                int a, b, c;
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 };
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
68
69        sout | "Mix of short and long args:";
70        if ( pid_t child = strict_fork(); child == 0 ) {
71                int a, b, c;
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 };
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
81
82        sout | "Mix of short and long and some missing description:";
83        if ( pid_t child = strict_fork(); child == 0 ) {
84                int a, b, c;
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 };
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
94
95        sout | "Mix of short and long and some long description:";
96        if ( pid_t child = strict_fork(); child == 0 ) {
97                int a, b, c;
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 };
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
107}
108
109// no used
110static int true_main( const char * path, char * env[]) { return 0; }
Note: See TracBrowser for help on using the repository browser.