Skip to content

Commit

Permalink
Rename various macros, functions and variables for consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Piwimau committed Dec 24, 2024
1 parent 4f608e4 commit 5f5f97f
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 144 deletions.
8 changes: 4 additions & 4 deletions include/SCUnit/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
* standard `printf` family of functions, followed by any number of additional
* arguments to be written according to the format string.
*/
#define SCUNIT_TERMINATE_TEST(result, ...) \
#define SCUNIT_TEST_TERMINATE(result, ...) \
do { \
SCUnitError scunit_error; \
__VA_OPT__( \
Expand Down Expand Up @@ -132,7 +132,7 @@
* standard `printf` family of functions, followed by any number of additional
* arguments to be written according to the format string.
*/
#define SCUNIT_PASS(...) SCUNIT_TERMINATE_TEST(SCUNIT_RESULT_PASS __VA_OPT__(, __VA_ARGS__))
#define SCUNIT_PASS(...) SCUNIT_TEST_TERMINATE(SCUNIT_RESULT_PASS __VA_OPT__(, __VA_ARGS__))

/**
* @brief Causes the current test to be skipped.
Expand All @@ -144,7 +144,7 @@
* standard `printf` family of functions, followed by any number of additional
* arguments to be written according to the format string.
*/
#define SCUNIT_SKIP(...) SCUNIT_TERMINATE_TEST(SCUNIT_RESULT_SKIP __VA_OPT__(, __VA_ARGS__))
#define SCUNIT_SKIP(...) SCUNIT_TEST_TERMINATE(SCUNIT_RESULT_SKIP __VA_OPT__(, __VA_ARGS__))

/**
* @brief Causes the current test to fail immediately.
Expand All @@ -156,7 +156,7 @@
* standard `printf` family of functions, followed by any number of additional
* arguments to be written according to the format string.
*/
#define SCUNIT_FAIL(...) SCUNIT_TERMINATE_TEST(SCUNIT_RESULT_FAIL __VA_OPT__(, __VA_ARGS__))
#define SCUNIT_FAIL(...) SCUNIT_TEST_TERMINATE(SCUNIT_RESULT_FAIL __VA_OPT__(, __VA_ARGS__))

/**
* @brief Asserts that an arbitrary condition holds. If the assertion fails, writes an error message
Expand Down
14 changes: 12 additions & 2 deletions include/SCUnit/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ typedef enum SCUnitError {
/** @brief Indicates that an operation was successful (i. e. no error occurred). */
SCUNIT_ERROR_NONE,

/** @brief Indicates that one of the required arguments of a function was `nullptr`. */
/**
* @brief Indicates that one of the required arguments of a function was `nullptr`.
*
* @note This should not occur under normal circumstances. It is usually a sign of a serious
* programming error.
*/
SCUNIT_ERROR_ARGUMENT_NULL,

/** @brief Indicates that one of the arguments of a function was out of range. */
/**
* @brief Indicates that one of the arguments of a function was out of range.
*
* @note This should not occur under normal circumstances. It is usually a sign of a serious
* programming error.
*/
SCUNIT_ERROR_ARGUMENT_OUT_OF_RANGE,

/** @brief Indicates that a memory allocation failed due to an out-of-memory condition. */
Expand Down
2 changes: 1 addition & 1 deletion include/SCUnit/scunit.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ typedef struct SCUnitVersion {
*
* @return An `SCUnitVersion` containing the major, minor and patch version number of SCUnit.
*/
SCUnitVersion scunit_version();
SCUnitVersion scunit_getVersion();

/**
* @brief Registers an `SCUnitSuite` to be run automatically by SCUnit.
Expand Down
217 changes: 111 additions & 106 deletions include/SCUnit/suite.h

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions include/SCUnit/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* Before an `SCUnitTimer` can be queried for the elapsed time, it must be stopped with a call to
* `scunit_timer_stop()`. After that, both the elapsed wall and CPU time can be queried using
* `scunit_timer_wallTime()` and `scunit_timer_cpuTime()` respectively. The difference is the
* `scunit_timer_getWallTime()` and `scunit_timer_getCPUTime()` respectively. The difference is the
* following:
*
* * Wall time (also known as real or wall-clock time) measures the actual time it took for a
Expand All @@ -30,8 +30,8 @@
* one second to complete, the wall time would be around one second, while the CPU time might be
* as much as two seconds if the threads were run in parallel on two different cores.
*
* Both `scunit_timer_wallTime()` and `scunit_timer_cpuTime()` return the elapsed time as a double
* precision floating-point number. The `SCUnitTimer` automatically determines an appropriate
* Both `scunit_timer_getWallTime()` and `scunit_timer_getCPUTime()` return the elapsed time as a
* double precision floating-point number. The `SCUnitTimer` automatically determines an appropriate
* `SCUnitTimeUnit' for this value (based on certain internal thresholds).
*
* Finally, a call to `scunit_timer_free()` is required to deallocate the resources.
Expand Down Expand Up @@ -182,7 +182,10 @@ SCUnitError scunit_timer_isRunning(const SCUnitTimer* timer, bool* isRunning);
* @return `SCUNIT_ERROR_ARGUMENT_NULL` if `timer` or `wallTimeMeasurement` is `nullptr`,
* `SCUNIT_ERROR_TIMER_RUNNING` if `timer` is still running and `SCUNIT_ERROR_NONE` otherwise.
*/
SCUnitError scunit_timer_wallTime(const SCUnitTimer* timer, SCUnitMeasurement* wallTimeMeasurement);
SCUnitError scunit_timer_getWallTime(
const SCUnitTimer* timer,
SCUnitMeasurement* wallTimeMeasurement
);

/**
* @brief Returns the elapsed CPU time measured by a given `SCUnitTimer`.
Expand All @@ -192,7 +195,10 @@ SCUnitError scunit_timer_wallTime(const SCUnitTimer* timer, SCUnitMeasurement* w
* @return `SCUNIT_ERROR_ARGUMENT_NULL` if `timer` or `cpuTimeMeasurement` is `nullptr`,
* `SCUNIT_ERROR_TIMER_RUNNING` if `timer` is still running and `SCUNIT_ERROR_NONE` otherwise.
*/
SCUnitError scunit_timer_cpuTime(const SCUnitTimer* timer, SCUnitMeasurement* cpuTimeMeasurement);
SCUnitError scunit_timer_getCPUTime(
const SCUnitTimer* timer,
SCUnitMeasurement* cpuTimeMeasurement
);

/**
* @brief Deallocates any remaining resources of a given `SCUnitTimer`.
Expand Down
8 changes: 4 additions & 4 deletions src/scunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static int64_t capacity;
/** @brief Number of registered suites. */
static int64_t registeredSuites;

SCUnitVersion scunit_version() {
SCUnitVersion scunit_getVersion() {
return VERSION;
}

Expand Down Expand Up @@ -190,7 +190,7 @@ static int scunit_runSuites() {
error = scunit_suite_run(suites[registeredSuites - 1 - i], &suiteSummary);
if (error != SCUNIT_ERROR_NONE) {
const char* name;
scunit_suite_name(suites[registeredSuites - 1 - i], &name);
scunit_suite_getName(suites[registeredSuites - 1 - i], &name);
scunit_fprintfc(
stderr,
SCUNIT_COLOR_DARK_RED,
Expand Down Expand Up @@ -221,8 +221,8 @@ static int scunit_runSuites() {
}
SCUnitMeasurement wallTimeMeasurement;
SCUnitMeasurement cpuTimeMeasurement;
scunit_timer_wallTime(timer, &wallTimeMeasurement);
scunit_timer_cpuTime(timer, &cpuTimeMeasurement);
scunit_timer_getWallTime(timer, &wallTimeMeasurement);
scunit_timer_getCPUTime(timer, &cpuTimeMeasurement);
scunit_timer_free(&timer);
scunit_printf("--- ");
scunit_printfc(SCUNIT_COLOR_DARK_CYAN, SCUNIT_COLOR_DARK_DEFAULT, "Summary");
Expand Down
43 changes: 23 additions & 20 deletions src/suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ struct SCUnitSuite {
/**
* @brief Optional suite setup function to run before executing all tests in this `SCUnitSuite`.
*
* @note Each `SCUnitSuite` can only have one `SCUnitSetup` function. If equal to `nullptr`,
* nothing is registered to be run.
* @note Each `SCUnitSuite` can only have one `SCUnitSuiteSetup` function. If equal to
* `nullptr`, nothing is registered to be run.
*/
SCUnitSetup setup;
SCUnitSuiteSetup suiteSetup;

/**
* @brief Optional suite teardown function to run after executing all tests in this
* `SCUnitSuite`.
*
* @note Each `SCUnitSuite` can only have one `SCUnitTeardown` function. If equal to `nullptr`,
* nothing is registered to be run.
* @note Each `SCUnitSuite` can only have one `SCUnitSuiteTeardown` function. If equal to
* `nullptr`, nothing is registered to be run.
*/
SCUnitTeardown teardown;
SCUnitSuiteTeardown suiteTeardown;

/**
* @brief Optional test setup function to run before each individual test in this `SCUnitSuite`.
Expand Down Expand Up @@ -112,27 +112,30 @@ SCUnitError scunit_suite_new(const char* name, SCUnitSuite** suite) {
return SCUNIT_ERROR_NONE;
}

SCUnitError scunit_suite_name(const SCUnitSuite* suite, const char** name) {
SCUnitError scunit_suite_getName(const SCUnitSuite* suite, const char** name) {
if ((suite == nullptr) || (name == nullptr)) {
return SCUNIT_ERROR_ARGUMENT_NULL;
}
*name = suite->name;
return SCUNIT_ERROR_NONE;
}

SCUnitError scunit_suite_registerSetup(SCUnitSuite* suite, SCUnitSetup setup) {
SCUnitError scunit_suite_registerSuiteSetup(SCUnitSuite* suite, SCUnitSuiteSetup suiteSetup) {
if (suite == nullptr) {
return SCUNIT_ERROR_ARGUMENT_NULL;
}
suite->setup = setup;
suite->suiteSetup = suiteSetup;
return SCUNIT_ERROR_NONE;
}

SCUnitError scunit_suite_registerTeardown(SCUnitSuite* suite, SCUnitTeardown teardown) {
SCUnitError scunit_suite_registerSuiteTeardown(
SCUnitSuite* suite,
SCUnitSuiteTeardown suiteTeardown
) {
if (suite == nullptr) {
return SCUNIT_ERROR_ARGUMENT_NULL;
}
suite->teardown = teardown;
suite->suiteTeardown = suiteTeardown;
return SCUNIT_ERROR_NONE;
}

Expand All @@ -144,7 +147,7 @@ SCUnitError scunit_suite_registerTestSetup(SCUnitSuite* suite, SCUnitTestSetup t
return SCUNIT_ERROR_NONE;
}

SCUnitError scunit_suite_setTestTeardown(SCUnitSuite* suite, SCUnitTestTeardown testTeardown) {
SCUnitError scunit_suite_registerTestTeardown(SCUnitSuite* suite, SCUnitTestTeardown testTeardown) {
if (suite == nullptr) {
return SCUNIT_ERROR_ARGUMENT_NULL;
}
Expand Down Expand Up @@ -208,8 +211,8 @@ SCUnitError scunit_suite_run(const SCUnitSuite* suite, SCUnitSummary* summary) {
if (error != SCUNIT_ERROR_NONE) {
goto fail;
}
if (suite->setup != nullptr) {
suite->setup();
if (suite->suiteSetup != nullptr) {
suite->suiteSetup();
}
for (int64_t i = 0; i < suite->registeredTests; i++) {
if (suite->testSetup != nullptr) {
Expand Down Expand Up @@ -262,8 +265,8 @@ SCUnitError scunit_suite_run(const SCUnitSuite* suite, SCUnitSummary* summary) {
}
SCUnitMeasurement wallTimeMeasurement;
SCUnitMeasurement cpuTimeMeasurement;
scunit_timer_wallTime(testTimer, &wallTimeMeasurement);
scunit_timer_cpuTime(testTimer, &cpuTimeMeasurement);
scunit_timer_getWallTime(testTimer, &wallTimeMeasurement);
scunit_timer_getCPUTime(testTimer, &cpuTimeMeasurement);
scunit_fprintf(
(result == SCUNIT_RESULT_FAIL) ? stderr : stdout,
" [Wall: %.3F %s, CPU: %.3F %s]\n",
Expand All @@ -284,8 +287,8 @@ SCUnitError scunit_suite_run(const SCUnitSuite* suite, SCUnitSummary* summary) {
suite->testTeardown();
}
}
if (suite->teardown != nullptr) {
suite->teardown();
if (suite->suiteTeardown != nullptr) {
suite->suiteTeardown();
}
error = scunit_timer_stop(suiteTimer);
if (error != SCUNIT_ERROR_NONE) {
Expand All @@ -295,8 +298,8 @@ SCUnitError scunit_suite_run(const SCUnitSuite* suite, SCUnitSummary* summary) {
scunit_context_free(&context);
SCUnitMeasurement wallTimeMeasurement;
SCUnitMeasurement cpuTimeMeasurement;
scunit_timer_wallTime(suiteTimer, &wallTimeMeasurement);
scunit_timer_cpuTime(suiteTimer, &cpuTimeMeasurement);
scunit_timer_getWallTime(suiteTimer, &wallTimeMeasurement);
scunit_timer_getCPUTime(suiteTimer, &cpuTimeMeasurement);
scunit_timer_free(&suiteTimer);
scunit_printf("Tests: ");
scunit_printfc(
Expand Down
4 changes: 2 additions & 2 deletions src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static inline void scunit_adjustMeasurement(SCUnitMeasurement* elapsedTimeMeasur
elapsedTimeMeasurement->timeUnitString = TIME_UNIT_STRINGS[elapsedTimeMeasurement->timeUnit];
}

SCUnitError scunit_timer_wallTime(
SCUnitError scunit_timer_getWallTime(
const SCUnitTimer* timer,
SCUnitMeasurement* wallTimeMeasurement
) {
Expand All @@ -193,7 +193,7 @@ SCUnitError scunit_timer_wallTime(
return SCUNIT_ERROR_NONE;
}

SCUnitError scunit_timer_cpuTime(
SCUnitError scunit_timer_getCPUTime(
const SCUnitTimer* timer,
SCUnitMeasurement* cpuTimeMeasurement
) {
Expand Down

0 comments on commit 5f5f97f

Please sign in to comment.