Skip to content

Commit

Permalink
exit code is explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
qgymib committed Dec 20, 2022
1 parent 8c09aca commit c7e181d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### BREAKING CHANGES
1. Remove x32 / x64 assertion methods
2. Hide some function that user should not use
3. Exit code is explicit: 0 is success, otherwise failure

### Fixed
1. Fix: crash on log if no hook passed
Expand Down
2 changes: 1 addition & 1 deletion include/cutest.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/**
* @brief Development version.
*/
#define CUTEST_VERSION_PREREL 6
#define CUTEST_VERSION_PREREL 7

#ifdef __cplusplus
extern "C" {
Expand Down
21 changes: 15 additions & 6 deletions src/cutest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2216,7 +2216,15 @@ static void _test_prepare(void)
g_test_ctx.counter.repeat.repeat = 1;
}

static int _test_setup(int argc, char* argv[], const cutest_hook_t* hook)
/**
* @brief Setup test context
* @param[in] argc The number of command line argument.
* @param[in] argv Command line argument list.
* @param[in] hook Global test hook.
* @param[out] b_exit Whether need to exit.
* @return 0 if success, otherwise failure.
*/
static int _test_setup(int argc, char* argv[], const cutest_hook_t* hook, int* b_exit)
{
(void)argc;

Expand Down Expand Up @@ -2287,7 +2295,8 @@ static int _test_setup(int argc, char* argv[], const cutest_hook_t* hook)
break;
case help:
_print_encoded(_get_logfile(), s_test_help_encoded);
return -1;
*b_exit = 1;
return 0;
default:
break;
}
Expand Down Expand Up @@ -2572,12 +2581,12 @@ int cutest_register_case(cutest_case_t* data)

int cutest_run_tests(int argc, char* argv[], const cutest_hook_t* hook)
{
int ret;
int ret = 0;

/* Parser parameter */
if (_test_setup(argc, argv, hook) < 0)
int b_exit = 0;
if ((ret = _test_setup(argc, argv, hook, &b_exit)) < 0 || b_exit)
{
ret = 0;
goto fin;
}

Expand All @@ -2589,7 +2598,7 @@ int cutest_run_tests(int argc, char* argv[], const cutest_hook_t* hook)
_test_hook_after_all_test();
_test_cleanup();

return ret;
return ret != 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}

void cutest_unwrap_assert_fail(const char *expr, const char *file, int line, const char *func)
Expand Down

0 comments on commit c7e181d

Please sign in to comment.