aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2020-10-05 13:49:41 +0200
committerAndreas Schneider <asn@cryptomilk.org>2020-10-12 08:25:26 +0200
commit1003e764721d82c09bb3584b244e50cd657c8de9 (patch)
tree3da1cb786ec56cf666d0a07181e7196da67f7a92
parentae89bfa145ebcb3d92c9cc96e681974689b17dee (diff)
downloadcmocka-1003e764721d82c09bb3584b244e50cd657c8de9.tar.gz
cmocka-1003e764721d82c09bb3584b244e50cd657c8de9.tar.xz
cmocka-1003e764721d82c09bb3584b244e50cd657c8de9.zip
cmocka: Remove deprecated functions and cmockery legacy support
-rw-r--r--DefineOptions.cmake1
-rw-r--r--include/CMakeLists.txt10
-rw-r--r--include/cmocka.h37
-rw-r--r--include/cmockery/cmockery.h1
-rw-r--r--include/cmockery/pbc.h1
-rw-r--r--src/cmocka.c391
-rw-r--r--src/cmocka.def2
-rw-r--r--tests/CMakeLists.txt6
-rw-r--r--tests/cmocka_test.cmake1
-rw-r--r--tests/ctest-default.cmake2
-rw-r--r--tests/meson.build1
-rw-r--r--tests/test_cmockery.c33
12 files changed, 1 insertions, 485 deletions
diff --git a/DefineOptions.cmake b/DefineOptions.cmake
index 986fe47..e6b876f 100644
--- a/DefineOptions.cmake
+++ b/DefineOptions.cmake
@@ -1,5 +1,4 @@
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
-option(WITH_CMOCKERY_SUPPORT "Install a cmockery header" OFF)
option(WITH_EXAMPLES "Build examples" ON)
option(UNIT_TESTING "Build with unit testing" OFF)
option(PICKY_DEVELOPER "Build with picky developer flags" OFF)
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 4e38547..2bc73f0 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -7,13 +7,3 @@ install(FILES
${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT
${PROJECT_NAME})
-
-if (WITH_CMOCKERY_SUPPORT)
- install(FILES
- cmockery/cmockery.h
- cmockery/pbc.h
- DESTINATION
- ${CMAKE_INSTALL_INCLUDEDIR}/cmockery
- COMPONENT
- ${PROJECT_NAME})
-endif()
diff --git a/include/cmocka.h b/include/cmocka.h
index abdf9ec..502cc89 100644
--- a/include/cmocka.h
+++ b/include/cmocka.h
@@ -1621,31 +1621,6 @@ void fail_msg(const char *msg, ...);
} while (0)
#endif
-#ifdef DOXYGEN
-/**
- * @brief Generic method to run a single test.
- *
- * @deprecated This function was deprecated in favor of cmocka_run_group_tests
- *
- * @param[in] #function The function to test.
- *
- * @return 0 on success, 1 if an error occured.
- *
- * @code
- * // A test case that does nothing and succeeds.
- * void null_test_success(void **state) {
- * }
- *
- * int main(void) {
- * return run_test(null_test_success);
- * }
- * @endcode
- */
-int run_test(#function);
-#else
-#define run_test(f) _run_test(#f, f, NULL, UNIT_TEST_FUNCTION_TYPE_TEST, NULL)
-#endif
-
static inline void _unit_test_dummy(void **state) {
(void)state;
}
@@ -1740,9 +1715,6 @@ static inline void _unit_test_dummy(void **state) {
*/
#define cmocka_unit_test_prestate_setup_teardown(f, setup, teardown, state) { #f, f, setup, teardown, state }
-#define run_tests(tests) _run_tests(tests, sizeof(tests) / sizeof((tests)[0]))
-#define run_group_tests(tests) _run_group_tests(tests, sizeof(tests) / sizeof((tests)[0]))
-
#ifdef DOXYGEN
/**
* @brief Run tests specified by an array of CMUnitTest structures.
@@ -2291,15 +2263,6 @@ CMOCKA_NORETURN void _fail(const char * const file, const int line);
CMOCKA_NORETURN void _skip(const char * const file, const int line);
-int _run_test(
- const char * const function_name, const UnitTestFunction Function,
- void ** const volatile state, const UnitTestFunctionType function_type,
- const void* const heap_check_point);
-CMOCKA_DEPRECATED int _run_tests(const UnitTest * const tests,
- const size_t number_of_tests);
-CMOCKA_DEPRECATED int _run_group_tests(const UnitTest * const tests,
- const size_t number_of_tests);
-
/* Test runner */
int _cmocka_run_group_tests(const char *group_name,
const struct CMUnitTest * const tests,
diff --git a/include/cmockery/cmockery.h b/include/cmockery/cmockery.h
deleted file mode 100644
index a252a5f..0000000
--- a/include/cmockery/cmockery.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <cmocka.h>
diff --git a/include/cmockery/pbc.h b/include/cmockery/pbc.h
deleted file mode 100644
index 50bac87..0000000
--- a/include/cmockery/pbc.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <cmocka_pbc.h>
diff --git a/src/cmocka.c b/src/cmocka.c
index 0783c4d..479587a 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -3274,394 +3274,3 @@ int _cmocka_run_group_tests(const char *group_name,
return (int)(total_failed + total_errors);
}
-
-/****************************************************************************
- * DEPRECATED TEST RUNNER
- ****************************************************************************/
-
-int _run_test(
- const char * const function_name, const UnitTestFunction Function,
- void ** const volatile state, const UnitTestFunctionType function_type,
- const void* const heap_check_point) {
- const ListNode * const volatile check_point = (const ListNode*)
- (heap_check_point ?
- heap_check_point : check_point_allocated_blocks());
- void *current_state = NULL;
- volatile int rc = 1;
- int handle_exceptions = 1;
-#ifdef _WIN32
- handle_exceptions = !IsDebuggerPresent();
-#endif /* _WIN32 */
-#ifdef UNIT_TESTING_DEBUG
- handle_exceptions = 0;
-#endif /* UNIT_TESTING_DEBUG */
-
- cm_error_message_enabled = 0;
-
- if (handle_exceptions) {
-#ifndef _WIN32
- unsigned int i;
- for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
- default_signal_functions[i] = signal(
- exception_signals[i], exception_handler);
- }
-#else /* _WIN32 */
- previous_exception_filter = SetUnhandledExceptionFilter(
- exception_filter);
-#endif /* !_WIN32 */
- }
-
- if (function_type == UNIT_TEST_FUNCTION_TYPE_TEST) {
- print_message("[ RUN ] %s\n", function_name);
- }
- initialize_testing(function_name);
- global_running_test = 1;
- if (cm_setjmp(global_run_test_env) == 0) {
- Function(state ? state : &current_state);
- fail_if_leftover_values(function_name);
-
- /* If this is a setup function then ignore any allocated blocks
- * only ensure they're deallocated on tear down. */
- if (function_type != UNIT_TEST_FUNCTION_TYPE_SETUP) {
- fail_if_blocks_allocated(check_point, function_name);
- }
-
- global_running_test = 0;
-
- if (function_type == UNIT_TEST_FUNCTION_TYPE_TEST) {
- print_message("[ OK ] %s\n", function_name);
- }
- rc = 0;
- } else {
- global_running_test = 0;
- print_message("[ FAILED ] %s\n", function_name);
- }
- teardown_testing(function_name);
-
- if (handle_exceptions) {
-#ifndef _WIN32
- unsigned int i;
- for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
- signal(exception_signals[i], default_signal_functions[i]);
- }
-#else /* _WIN32 */
- if (previous_exception_filter) {
- SetUnhandledExceptionFilter(previous_exception_filter);
- previous_exception_filter = NULL;
- }
-#endif /* !_WIN32 */
- }
-
- return rc;
-}
-
-
-int _run_tests(const UnitTest * const tests, const size_t number_of_tests) {
- /* Whether to execute the next test. */
- int run_next_test = 1;
- /* Whether the previous test failed. */
- int previous_test_failed = 0;
- /* Whether the previous setup failed. */
- int previous_setup_failed = 0;
- /* Check point of the heap state. */
- const ListNode * const check_point = check_point_allocated_blocks();
- /* Current test being executed. */
- size_t current_test = 0;
- /* Number of tests executed. */
- size_t tests_executed = 0;
- /* Number of failed tests. */
- size_t total_failed = 0;
- /* Number of setup functions. */
- size_t setups = 0;
- /* Number of teardown functions. */
- size_t teardowns = 0;
- size_t i;
- /*
- * A stack of test states. A state is pushed on the stack
- * when a test setup occurs and popped on tear down.
- */
- TestState* test_states =
- (TestState*)malloc(number_of_tests * sizeof(*test_states));
- /* The number of test states which should be 0 at the end */
- long number_of_test_states = 0;
- /* Names of the tests that failed. */
- const char** failed_names = (const char**)malloc(number_of_tests *
- sizeof(*failed_names));
- void **current_state = NULL;
-
- /* Count setup and teardown functions */
- for (i = 0; i < number_of_tests; i++) {
- const UnitTest * const test = &tests[i];
-
- if (test->function_type == UNIT_TEST_FUNCTION_TYPE_SETUP) {
- setups++;
- }
-
- if (test->function_type == UNIT_TEST_FUNCTION_TYPE_TEARDOWN) {
- teardowns++;
- }
- }
-
- print_message("[==========] Running %"PRIdS " test(s).\n",
- number_of_tests - setups - teardowns);
-
- /* Make sure uintmax_t is at least the size of a pointer. */
- assert_true(sizeof(uintmax_t) >= sizeof(void*));
-
- while (current_test < number_of_tests) {
- const ListNode *test_check_point = NULL;
- TestState *current_TestState;
- const UnitTest * const test = &tests[current_test++];
- if (!test->function) {
- continue;
- }
-
- switch (test->function_type) {
- case UNIT_TEST_FUNCTION_TYPE_TEST:
- if (! previous_setup_failed) {
- run_next_test = 1;
- }
- break;
- case UNIT_TEST_FUNCTION_TYPE_SETUP: {
- /* Checkpoint the heap before the setup. */
- current_TestState = &test_states[number_of_test_states++];
- current_TestState->check_point = check_point_allocated_blocks();
- test_check_point = current_TestState->check_point;
- current_state = &current_TestState->state;
- *current_state = NULL;
- run_next_test = 1;
- break;
- }
- case UNIT_TEST_FUNCTION_TYPE_TEARDOWN:
- /* Check the heap based on the last setup checkpoint. */
- assert_true(number_of_test_states);
- current_TestState = &test_states[--number_of_test_states];
- test_check_point = current_TestState->check_point;
- current_state = &current_TestState->state;
- break;
- default:
- print_error("Invalid unit test function type %d\n",
- test->function_type);
- exit_test(1);
- break;
- }
-
- if (run_next_test) {
- int failed = _run_test(test->name, test->function, current_state,
- test->function_type, test_check_point);
- if (failed) {
- failed_names[total_failed] = test->name;
- }
-
- switch (test->function_type) {
- case UNIT_TEST_FUNCTION_TYPE_TEST:
- previous_test_failed = failed;
- total_failed += failed;
- tests_executed ++;
- break;
-
- case UNIT_TEST_FUNCTION_TYPE_SETUP:
- if (failed) {
- total_failed ++;
- tests_executed ++;
- /* Skip forward until the next test or setup function. */
- run_next_test = 0;
- previous_setup_failed = 1;
- }
- previous_test_failed = 0;
- break;
-
- case UNIT_TEST_FUNCTION_TYPE_TEARDOWN:
- /* If this test failed. */
- if (failed && !previous_test_failed) {
- total_failed ++;
- }
- break;
- default:
-#ifndef _HPUX
- assert_null("BUG: shouldn't be here!");
-#endif
- break;
- }
- }
- }
-
- print_message("[==========] %"PRIdS " test(s) run.\n", tests_executed);
- print_error("[ PASSED ] %"PRIdS " test(s).\n", tests_executed - total_failed);
-
- if (total_failed > 0) {
- print_error("[ FAILED ] %"PRIdS " test(s), listed below:\n", total_failed);
- for (i = 0; i < total_failed; i++) {
- print_error("[ FAILED ] %s\n", failed_names[i]);
- }
- } else {
- print_error("\n %"PRIdS " FAILED TEST(S)\n", total_failed);
- }
-
- if (number_of_test_states != 0) {
- print_error("[ ERROR ] Mismatched number of setup %"PRIdS " and "
- "teardown %"PRIdS " functions\n", setups, teardowns);
- total_failed = (size_t)-1;
- }
-
- free(test_states);
- free((void*)failed_names);
-
- fail_if_blocks_allocated(check_point, "run_tests");
- return (int)total_failed;
-}
-
-int _run_group_tests(const UnitTest * const tests, const size_t number_of_tests)
-{
- UnitTestFunction setup = NULL;
- const char *setup_name = NULL;
- size_t num_setups = 0;
- UnitTestFunction teardown = NULL;
- const char *teardown_name = NULL;
- size_t num_teardowns = 0;
- size_t current_test = 0;
- size_t i;
-
- /* Number of tests executed. */
- size_t tests_executed = 0;
- /* Number of failed tests. */
- size_t total_failed = 0;
- /* Check point of the heap state. */
- const ListNode * const check_point = check_point_allocated_blocks();
- const char **failed_names = NULL;
- void **current_state = NULL;
- TestState group_state = {
- .check_point = NULL,
- };
-
- if (number_of_tests == 0) {
- return -1;
- }
-
- failed_names = (const char **)malloc(number_of_tests *
- sizeof(*failed_names));
- if (failed_names == NULL) {
- return -2;
- }
-
- /* Find setup and teardown function */
- for (i = 0; i < number_of_tests; i++) {
- const UnitTest * const test = &tests[i];
-
- if (test->function_type == UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP) {
- if (setup == NULL) {
- setup = test->function;
- setup_name = test->name;
- num_setups = 1;
- } else {
- print_error("[ ERROR ] More than one group setup function detected\n");
- exit_test(1);
- }
- }
-
- if (test->function_type == UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN) {
- if (teardown == NULL) {
- teardown = test->function;
- teardown_name = test->name;
- num_teardowns = 1;
- } else {
- print_error("[ ERROR ] More than one group teardown function detected\n");
- exit_test(1);
- }
- }
- }
-
- print_message("[==========] Running %"PRIdS " test(s).\n",
- number_of_tests - num_setups - num_teardowns);
-
- if (setup != NULL) {
- int failed;
-
- group_state.check_point = check_point_allocated_blocks();
- current_state = &group_state.state;
- *current_state = NULL;
- failed = _run_test(setup_name,
- setup,
- current_state,
- UNIT_TEST_FUNCTION_TYPE_SETUP,
- group_state.check_point);
- if (failed) {
- failed_names[total_failed] = setup_name;
- }
-
- total_failed += failed;
- tests_executed++;
- }
-
- while (current_test < number_of_tests) {
- int run_test = 0;
- const UnitTest * const test = &tests[current_test++];
- if (test->function == NULL) {
- continue;
- }
-
- switch (test->function_type) {
- case UNIT_TEST_FUNCTION_TYPE_TEST:
- run_test = 1;
- break;
- case UNIT_TEST_FUNCTION_TYPE_SETUP:
- case UNIT_TEST_FUNCTION_TYPE_TEARDOWN:
- case UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP:
- case UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN:
- break;
- default:
- print_error("Invalid unit test function type %d\n",
- test->function_type);
- break;
- }
-
- if (run_test) {
- int failed;
-
- failed = _run_test(test->name,
- test->function,
- current_state,
- test->function_type,
- NULL);
- if (failed) {
- failed_names[total_failed] = test->name;
- }
-
- total_failed += failed;
- tests_executed++;
- }
- }
-
- if (teardown != NULL) {
- int failed;
-
- failed = _run_test(teardown_name,
- teardown,
- current_state,
- UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN,
- group_state.check_point);
- if (failed) {
- failed_names[total_failed] = teardown_name;
- }
-
- total_failed += failed;
- tests_executed++;
- }
-
- print_message("[==========] %"PRIdS " test(s) run.\n", tests_executed);
- print_error("[ PASSED ] %"PRIdS " test(s).\n", tests_executed - total_failed);
-
- if (total_failed) {
- print_error("[ FAILED ] %"PRIdS " test(s), listed below:\n", total_failed);
- for (i = 0; i < total_failed; i++) {
- print_error("[ FAILED ] %s\n", failed_names[i]);
- }
- } else {
- print_error("\n %"PRIdS " FAILED TEST(S)\n", total_failed);
- }
-
- free((void*)failed_names);
- fail_if_blocks_allocated(check_point, "run_group_tests");
-
- return (int)total_failed;
-}
diff --git a/src/cmocka.def b/src/cmocka.def
index 1c2c653..67a55da 100644
--- a/src/cmocka.def
+++ b/src/cmocka.def
@@ -34,8 +34,6 @@ EXPORTS
_fail
_function_called
_mock
- _run_test
- _run_tests
_skip
_test_calloc
_test_free
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a1b31d4..96a850a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -30,7 +30,6 @@ set(CMOCKA_TESTS
test_string
test_wildcard
test_skip_filter
- test_cmockery
)
if (TEST_EXCEPTION_HANDLER)
@@ -48,11 +47,6 @@ foreach(_CMOCKA_TEST ${CMOCKA_TESTS})
add_cmocka_test_environment(${_CMOCKA_TEST})
endforeach()
-### Special Cases
-if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
- set_source_files_properties(test_cmockery.c PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations")
-endif()
-
### Exceptions
# test_skip
diff --git a/tests/cmocka_test.cmake b/tests/cmocka_test.cmake
index 53ffcca..d660979 100644
--- a/tests/cmocka_test.cmake
+++ b/tests/cmocka_test.cmake
@@ -155,7 +155,6 @@ endif()
### Add project default build options here !!!
add_cmake_cache_entry(UNIT_TESTING ON)
-add_cmake_cache_entry(WITH_CMOCKERY_SUPPORT ON)
### Add project default build options here ^^^
diff --git a/tests/ctest-default.cmake b/tests/ctest-default.cmake
index e21e93c..95c751a 100644
--- a/tests/ctest-default.cmake
+++ b/tests/ctest-default.cmake
@@ -13,7 +13,7 @@ set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
set(CTEST_BUILD_CONFIGURATION "Debug")
## The build options for the project
-set(CTEST_BUILD_OPTIONS "-DUNIT_TESTING=ON -DWITH_CMOCKERY_SUPPORT=ON")
+set(CTEST_BUILD_OPTIONS "-DUNIT_TESTING=ON)
#set(CTEST_CUSTOM_MEMCHECK_IGNORE torture_rand)
diff --git a/tests/meson.build b/tests/meson.build
index b49066b..aeb43b2 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -18,7 +18,6 @@ tests = {
'returns_fail': true,
'wildcard': false,
'skip_filter': false,
- 'cmockery': false
}
foreach name, should_fail: tests
diff --git a/tests/test_cmockery.c b/tests/test_cmockery.c
deleted file mode 100644
index 027b1ac..0000000
--- a/tests/test_cmockery.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2008 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <stdint.h>
-#include <cmockery/cmockery.h>
-
-/* A test case that does nothing and succeeds. */
-static void null_test_success(void **state) {
- (void) state; /* unused */
-}
-
-int main(void) {
- const UnitTest tests[] = {
- unit_test(null_test_success),
- };
- return run_tests(tests);
-}