source: tests/configs/usage.cfa @ c8238c0

ADTast-experimental
Last change on this file since c8238c0 was 9e042d8, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Moved around some headers to avoid the parsing bug

  • Property mode set to 100644
File size: 3.4 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 :
13// Last Modified On :
14// Update Count     :
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        }
30        else {
31                int status = do_wait(child);
32                print_status(status);
33        }
34
35        sout | "No args, with errors";
36        if(pid_t child = strict_fork(); child == 0) {
37                array( cfa_option, 0 ) opts;
38                print_args_usage(1, fake_argv, opts, "Test usage", true);
39        }
40        else {
41                int status = do_wait(child);
42                print_status(status);
43        }
44
45        sout | "Args with short names only:";
46        if(pid_t child = strict_fork(); child == 0) {
47                int a, b, c;
48                array( cfa_option, 3 ) opts;
49                opts[0] = (cfa_option){'a', "", "First arg", a };
50                opts[1] = (cfa_option){'b', "", "Second arg", b };
51                opts[2] = (cfa_option){'c', "", "Third arg", c };
52                print_args_usage(1, fake_argv, opts, "Test usage", false);
53        }
54        else {
55                int status = do_wait(child);
56                print_status(status);
57        }
58
59        sout | "Args with long names only:";
60        if(pid_t child = strict_fork(); child == 0) {
61                int a, b, c;
62                array( cfa_option, 3 ) opts;
63                opts[0] = (cfa_option){'\0', "AA", "First arg", a };
64                opts[1] = (cfa_option){'\0', "BB", "Second arg", b };
65                opts[2] = (cfa_option){'\0', "CC", "Third arg", c };
66                print_args_usage(1, fake_argv, opts, "Test usage", false);
67        }
68        else {
69                int status = do_wait(child);
70                print_status(status);
71        }
72
73        sout | "Mix of short and long args:";
74        if(pid_t child = strict_fork(); child == 0) {
75                int a, b, c;
76                array( cfa_option, 3 ) opts;
77                opts[0] = (cfa_option){'a', "", "First arg", a };
78                opts[1] = (cfa_option){'b', "BBBB", "Second arg", b };
79                opts[2] = (cfa_option){'\0', "CC", "Third arg", c };
80                print_args_usage(1, fake_argv, opts, "Test usage", false);
81        }
82        else {
83                int status = do_wait(child);
84                print_status(status);
85        }
86
87        sout | "Mix of short and long and some missing description:";
88        if(pid_t child = strict_fork(); child == 0) {
89                int a, b, c;
90                array( cfa_option, 3 ) opts;
91                opts[0] = (cfa_option){'a', "", "First arg", a };
92                opts[1] = (cfa_option){'b', "BBBB", "", b };
93                opts[2] = (cfa_option){'\0', "CC", "Third arg", c };
94                print_args_usage(1, fake_argv, opts, "Test usage", false);
95        }
96        else {
97                int status = do_wait(child);
98                print_status(status);
99        }
100
101        sout | "Mix of short and long and some long description:";
102        if(pid_t child = strict_fork(); child == 0) {
103                int a, b, c;
104                array( cfa_option, 3 ) opts;
105                opts[0] = (cfa_option){'a', "", "First arg\nThe description has multiple lines,\n...for some reason", a };
106                opts[1] = (cfa_option){'b', "BBBB", "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", b };
107                opts[2] = (cfa_option){'\0', "CC", "Third arg", c };
108                print_args_usage(1, fake_argv, opts, "Test usage", false);
109        }
110        else {
111                int status = do_wait(child);
112                print_status(status);
113        }
114}
115
116// no used
117static int true_main(const char * path, char * env[]) { return 0; }
Note: See TracBrowser for help on using the repository browser.