source: tests/configs/parsenums.cfa @ d96f7c4

Last change on this file since d96f7c4 was 10b5970, checked in by Michael Brooks <mlbrooks@…>, 4 weeks ago

Fix many test-suite- and libcfa-caused unused variable warnings.

In scope are easy fixes among tests whose sole warnings were unused variable. Reduces the wflags lax list by 40%.

  • Property mode set to 100644
File size: 6.2 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/parsenums.cfa
8// Testing parsing of integer 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
19#include "../meta/fork+exec.hfa"
20
21// last as workaround to parser bug
22#include <parseargs.hfa>
23
24#if __SIZEOF_LONG__ == 4
25        #define BIG_UNSIGNED_LONG "4294967295"
26        #define TOO_BIG_UNSIGNED_LONG "4294967296"
27#elif  __SIZEOF_LONG__ == 8
28        #define BIG_UNSIGNED_LONG "18446744073709551615"
29        #define TOO_BIG_UNSIGNED_LONG "18446744073709551616"
30#else
31        #error unexpected size of long
32#endif
33
34int true_main( const char * exec );
35
36int main( int argc, char * argv[]) {
37        if ( argc == 0 ) abort( "Test requires a command-line argument" );
38        check_main( argv[0] );
39
40        int i = -3;
41        unsigned u = 3;
42        unsigned long ul = 3;
43        unsigned long long ull = 3;
44        double d = 3.3;
45
46
47        array( cfa_option, 5 ) options;
48        options[0] = (cfa_option){ 'i', "int",              "test int",                i   };
49        options[1] = (cfa_option){ 'u', "unsigned",         "test unsigned",           u   };
50        options[2] = (cfa_option){ 'l', "unsignedlong",     "test unsigned long",      ul  };
51        options[3] = (cfa_option){ 'L', "unsignedlonglong", "test unsigned long long", ull };
52        options[4] = (cfa_option){ 'd', "double",           "test double",             d   };
53
54        char **left;
55        parse_args( options, "[OPTIONS]...\ntesting bool parameters", left );
56
57        sout | "int                :" | i;
58        sout | "unsigned           :" | u;
59        sout | "unsigned long      :" | ul;
60        sout | "unsigned long long :" | ull;
61        sout | "double             :" | d;
62}
63
64int true_main( const char * path, const char * env[] ) {
65        printf( "no arg:\n" );
66        if ( pid_t child = strict_fork(); child == 0 ) {
67                int ret = execle( path, "parsenums", (const char*)0p, env );
68                if ( ret < 0 ) {
69                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
70                        exit( 1 );
71                } // if
72        } else {
73                int status = do_wait( child );
74                print_status( status );
75        } // if
76
77        printf( "all 0 arg:\n" );
78        if ( pid_t child = strict_fork(); child == 0 ) {
79                int ret = execle( path, "parsenums", "-i=0", "-u=0", "-l=0", "-L=0", "-d=0", (const char*)0p, env );
80                if ( ret < 0 ) {
81                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
82                        exit( 1 );
83                } // if
84        } else {
85                int status = do_wait( child );
86                print_status( status );
87        } // if
88
89        printf( "negative vals arg:\n" );
90        if ( pid_t child = strict_fork(); child == 0 ) {
91                int ret = execle( path, "parsenums", "-i=-1", "-d=-1", (const char*)0p, env );
92                if ( ret < 0 ) {
93                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
94                        exit( 1 );
95                } // if
96        } else {
97                int status = do_wait( child );
98                print_status( status );
99        } // if
100
101        printf( "funky notation arg:\n" );
102        if ( pid_t child = strict_fork(); child == 0 ) {
103                int ret = execle( path, "parsenums", "-i=0x10", "-u=0x20", "-l=0x300", "-L=0x4000", "-d=5e6", (const char*)0p, env );
104                if ( ret < 0 ) {
105                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
106                        exit( 1 );
107                } // if
108        } else {
109                int status = do_wait( child );
110                print_status( status );
111        } // if
112
113        printf( "big values arg:\n" );
114        if ( pid_t child = strict_fork(); child == 0 ) {
115                int ret = execle( path, "parsenums", "-i=2147483647", "-u=4294967295", "-l=" BIG_UNSIGNED_LONG, "-L=18446744073709551615", "-d=5e6", (const char*)0p, env );
116                if ( ret < 0 ) {
117                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
118                        exit( 1 );
119                } // if
120        } else {
121                int status = do_wait( child );
122                print_status( status );
123        } // if
124
125        printf( "too big values arg:\n" );
126        if ( pid_t child = strict_fork(); child == 0 ) {
127                int ret = execle( path, "parsenums", "-i=2147483648", (const char*)0p, env );
128                if ( ret < 0 ) {
129                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
130                        exit( 1 );
131                } // if
132        } else {
133                int status = do_wait( child );
134                print_status( status );
135        } // if
136
137        if ( pid_t child = strict_fork(); child == 0 ) {
138                int ret = execle( path, "parsenums", "-u=4294967296", (const char*)0p, env );
139                if ( ret < 0 ) {
140                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
141                        exit( 1 );
142                } // if
143        } else {
144                int status = do_wait( child );
145                print_status( status );
146        } // if
147
148        if ( pid_t child = strict_fork(); child == 0 ) {
149                int ret = execle( path, "parsenums", "-l=" TOO_BIG_UNSIGNED_LONG, (const char*)0p, env );
150                if ( ret < 0 ) {
151                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
152                        exit( 1 );
153                } // if
154        } else {
155                int status = do_wait( child );
156                print_status( status );
157        } // if
158
159        if ( pid_t child = strict_fork(); child == 0 ) {
160                int ret = execle( path, "parsenums", "-L=18446744073709551616", (const char*)0p, env );
161                if ( ret < 0 ) {
162                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
163                        exit( 1 );
164                } // if
165        } else {
166                int status = do_wait( child );
167                print_status( status );
168        } // if
169
170        printf( "negative errors arg:\n" );
171        if ( pid_t child = strict_fork(); child == 0 ) {
172                int ret = execle( path, "parsenums", "-u=-1", (const char*)0p, env );
173                if ( ret < 0 ) {
174                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
175                        exit( 1 );
176                } // if
177        } else {
178                int status = do_wait( child );
179                print_status( status );
180        } // if
181
182        if ( pid_t child = strict_fork(); child == 0 ) {
183                int ret = execle( path, "parsenums", "-l=-1", (const char*)0p, env );
184                if ( ret < 0 ) {
185                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
186                        exit( 1 );
187                } // if
188        } else {
189                int status = do_wait( child );
190                print_status( status );
191        } // if
192
193        if ( pid_t child = strict_fork(); child == 0 ) {
194                int ret = execle( path, "parsenums", "-L=-1", (const char*)0p, env );
195                if ( ret < 0 ) {
196                        fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
197                        exit( 1 );
198                } // if
199        } else {
200                int status = do_wait( child );
201                print_status( status );
202        } // if
203
204        printf( "All Done!\n" );
205
206        return 0;
207}
Note: See TracBrowser for help on using the repository browser.