Skip to content

Commit

Permalink
Remove argc precondition to permit no arg operation with stream
Browse files Browse the repository at this point in the history
  • Loading branch information
marcransome committed Sep 28, 2024
1 parent 8f6a0d2 commit 08d8637
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ struct FlogConfigData {

FlogConfig *
flog_config_new(int argc, char *argv[], FlogError *error) {
assert(argc > 1);
assert(argv != NULL);
assert(error != NULL);

Expand Down
21 changes: 4 additions & 17 deletions test/test_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,21 @@

#define UNUSED(x) (void)(x)

static void
flog_config_new_with_zero_arg_count_fails(void **state) {
UNUSED(state);

FlogError error; // should pass non-null assertion (&error)
int mock_argc = 0; // should fail >1 assertion
char *mock_argv[] = {}; // should pass non-null assertion

expect_assert_failure(flog_config_new(mock_argc, mock_argv, &error));
}

static void
flog_config_new_with_null_arg_values_fails(void **state) {
UNUSED(state);

FlogError error; // should pass non-null assertion (&error)
int mock_argc = 2; // should pass >1 assertion
int mock_argc = 0;
char **mock_argv = NULL; // should fail non-null assertion
FlogError error; // should pass non-null assertion (&error)

expect_assert_failure(flog_config_new(mock_argc, mock_argv, &error));
}

static void test_new_config_with_no_error_ptr_calls_assert(void **state) {
UNUSED(state);

int mock_argc = 2; // should pass >1 assertion
int mock_argc = 0;
char *mock_argv[] = {}; // should pass non-null assertion

expect_assert_failure(flog_config_new(mock_argc, mock_argv, NULL));
Expand Down Expand Up @@ -687,8 +676,7 @@ flog_config_new_with_message_from_stream_succeeds(void **state) {

FlogError error = TEST_ERROR;
MOCK_ARGS(
TEST_PROGRAM_NAME,
TEST_MESSAGE
TEST_PROGRAM_NAME
)

char *message = "0123456789ABCDEF";
Expand Down Expand Up @@ -1354,7 +1342,6 @@ int main(void) {

const struct CMUnitTest tests[] = {
// flog_config_new() precondition tests
cmocka_unit_test(flog_config_new_with_zero_arg_count_fails),
cmocka_unit_test(flog_config_new_with_null_arg_values_fails),

// flog_config_new() failure tests
Expand Down

0 comments on commit 08d8637

Please sign in to comment.