File tree 4 files changed +49
-1
lines changed
4 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -227,6 +227,10 @@ static int alignment(opt_t *result, char *optarg)
227
227
*/
228
228
static int command_line_design (opt_t * result , char * optarg )
229
229
{
230
+ if (strlen (optarg ) == 0 ) {
231
+ bx_fprintf (stderr , "%s: empty command line design definition\n" , PROJECT );
232
+ return 2 ;
233
+ }
230
234
result -> cld = (char * ) strdup (optarg );
231
235
if (result -> cld == NULL ) {
232
236
perror (PROJECT );
Original file line number Diff line number Diff line change @@ -429,4 +429,40 @@ void test_inputfiles_actual_success(void **state)
429
429
}
430
430
431
431
432
+ void test_command_line_design_empty (void * * state )
433
+ {
434
+ (void ) state ; /* unused */
435
+
436
+ opt_t * actual = act (2 , "-c" , "" );
437
+
438
+ assert_null (actual ); // invalid option, so we would need to exit with error
439
+ assert_int_equal (1 , collect_err_size );
440
+ assert_string_equal ("boxes: empty command line design definition\n" , collect_err [0 ]);
441
+ }
442
+
443
+
444
+ void test_help (void * * state )
445
+ {
446
+ (void ) state ; /* unused */
447
+
448
+ opt_t * actual = act (1 , "-h" );
449
+
450
+ assert_non_null (actual );
451
+ assert_int_equal (1 , actual -> help );
452
+ assert_int_equal (0 , actual -> version_requested );
453
+ }
454
+
455
+
456
+ void test_version_requested (void * * state )
457
+ {
458
+ (void ) state ; /* unused */
459
+
460
+ opt_t * actual = act (1 , "-v" );
461
+
462
+ assert_non_null (actual );
463
+ assert_int_equal (0 , actual -> help );
464
+ assert_int_equal (1 , actual -> version_requested );
465
+ }
466
+
467
+
432
468
/*EOF*/ /* vim: set cindent sw=4: */
Original file line number Diff line number Diff line change @@ -63,6 +63,11 @@ void test_inputfiles_stdin(void **state);
63
63
void test_inputfiles_input_nonexistent (void * * state );
64
64
void test_inputfiles_actual_success (void * * state );
65
65
66
+ void test_command_line_design_empty (void * * state );
67
+
68
+ void test_help (void * * state );
69
+ void test_version_requested (void * * state );
70
+
66
71
67
72
#endif
68
73
Original file line number Diff line number Diff line change @@ -78,7 +78,10 @@ int main(void)
78
78
cmocka_unit_test_setup (test_inputfiles_stdin_stdout , beforeTest ),
79
79
cmocka_unit_test_setup (test_inputfiles_stdin , beforeTest ),
80
80
cmocka_unit_test_setup (test_inputfiles_input_nonexistent , beforeTest ),
81
- cmocka_unit_test_setup (test_inputfiles_actual_success , beforeTest )
81
+ cmocka_unit_test_setup (test_inputfiles_actual_success , beforeTest ),
82
+ cmocka_unit_test_setup (test_command_line_design_empty , beforeTest ),
83
+ cmocka_unit_test_setup (test_help , beforeTest ),
84
+ cmocka_unit_test_setup (test_version_requested , beforeTest )
82
85
};
83
86
84
87
const struct CMUnitTest regulex_tests [] = {
You can’t perform that action at this time.
0 commit comments