From f9139404275e963e3fa18448c9c742ba8073b34f Mon Sep 17 00:00:00 2001 From: Snaipe Date: Tue, 8 Dec 2015 02:36:23 +0100 Subject: [PATCH] Fixed decoupling for parameterized tests and fixed missing definitions --- CMakeLists.txt | 1 + include/criterion/abort.h | 2 + include/criterion/internal/parameterized.h | 3 +- include/criterion/internal/test.h | 108 ++++++++++----------- src/core/abort.h | 2 - src/core/test.c | 1 + 6 files changed, 60 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67dfe4e..830c5d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,6 +147,7 @@ set(SOURCE_FILES src/core/stats.c src/core/stats.h src/core/ordered-set.c + src/core/test.c src/compat/internal.h src/compat/pipe.c src/compat/pipe.h diff --git a/include/criterion/abort.h b/include/criterion/abort.h index d6a649e..9cfc925 100644 --- a/include/criterion/abort.h +++ b/include/criterion/abort.h @@ -31,6 +31,8 @@ CR_BEGIN_C_API CR_API CR_NORETURN void criterion_abort_test(void); CR_INLINE static void criterion_continue_test(void) {} +CR_API void criterion_test_die(const char *msg, ...); + CR_END_C_API #endif /* !CRITERION_ABORT_H_ */ diff --git a/include/criterion/internal/parameterized.h b/include/criterion/internal/parameterized.h index 4fbd511..c08ee0d 100644 --- a/include/criterion/internal/parameterized.h +++ b/include/criterion/internal/parameterized.h @@ -79,6 +79,7 @@ struct criterion_test_params { # define CR_PARAM_TEST_BASE(Param, Category, Name, ...) \ CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name); \ + CR_TEST_TRAMPOLINE_(Category, Name) \ struct criterion_test_extra_data CR_IDENTIFIER_(Category, Name, extra) = \ CR_EXPAND(CRITERION_MAKE_STRUCT(criterion_test_extra_data, \ .lang_ = CR_LANG, \ @@ -92,7 +93,7 @@ struct criterion_test_params { struct criterion_test CR_IDENTIFIER_(Category, Name, meta) = { \ #Name, \ #Category, \ - (void(*)(void)) CR_IDENTIFIER_(Category, Name, impl), \ + CR_IDENTIFIER_(Category, Name, jmp), \ &CR_IDENTIFIER_(Category, Name, extra) \ }; \ CR_SECTION_("cr_tst") \ diff --git a/include/criterion/internal/test.h b/include/criterion/internal/test.h index 9a2f526..35b49ae 100644 --- a/include/criterion/internal/test.h +++ b/include/criterion/internal/test.h @@ -79,65 +79,65 @@ static const char *const cr_msg_test_fini_std_exception = "Caught an unexpected static const char *const cr_msg_test_fini_other_exception = "Caught some unexpected exception during the test finalization."; # ifdef __cplusplus -# define CR_TEST_TRAMPOLINE_(Category, Name) \ - static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ - try { \ - criterion_internal_test_setup(); \ - } catch (const std::exception &e) { \ - criterion_test_die(cr_msg_test_init_std_exception, e.what()); \ - } catch (...) { \ - criterion_test_die(cr_msg_test_init_other_exception); \ - } \ - try { \ - criterion_internal_test_main(CR_IDENTIFIER_(Category, Name, impl)); \ - } catch (const std::exception &e) { \ - criterion_test_die(cr_msg_test_main_std_exception, e.what()); \ - } catch (...) { \ - criterion_test_die(cr_msg_test_main_other_exception); \ - } \ - try { \ - criterion_internal_test_teardown(); \ - } catch (const std::exception &e) { \ - criterion_test_die(cr_msg_test_fini_std_exception, e.what()); \ - } catch (...) { \ - criterion_test_die(cr_msg_test_fini_other_exception); \ - } \ +# define CR_TEST_TRAMPOLINE_(Category, Name) \ + static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ + try { \ + criterion_internal_test_setup(); \ + } catch (const std::exception &e) { \ + criterion_test_die(cr_msg_test_init_std_exception, e.what()); \ + } catch (...) { \ + criterion_test_die(cr_msg_test_init_other_exception); \ + } \ + try { \ + criterion_internal_test_main((void(*)(void)) CR_IDENTIFIER_(Category, Name, impl)); \ + } catch (const std::exception &e) { \ + criterion_test_die(cr_msg_test_main_std_exception, e.what()); \ + } catch (...) { \ + criterion_test_die(cr_msg_test_main_other_exception); \ + } \ + try { \ + criterion_internal_test_teardown(); \ + } catch (const std::exception &e) { \ + criterion_test_die(cr_msg_test_fini_std_exception, e.what()); \ + } catch (...) { \ + criterion_test_die(cr_msg_test_fini_other_exception); \ + } \ } # else # if defined(__OBJC__) && defined(__EXCEPTIONS) -# define CR_TEST_TRAMPOLINE_(Category, Name) \ - static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ - @try { \ - criterion_internal_test_setup(); \ - } @catch (NSException *e) { \ - NSString *reason = [e reason]; \ - criterion_test_die(cr_msg_test_init_std_exception, [reason UTF8String]); \ - } @catch (...) { \ - criterion_test_die(cr_msg_test_init_other_exception); \ - } \ - @try { \ - criterion_internal_test_main(CR_IDENTIFIER_(Category, Name, impl)); \ - } @catch (NSException *e) { \ - NSString *reason = [e reason]; \ - criterion_test_die(cr_msg_test_main_std_exception, [reason UTF8String]); \ - } @catch (...) { \ - criterion_test_die(cr_msg_test_main_other_exception); \ - } \ - @try { \ - criterion_internal_test_teardown(); \ - } @catch (NSException *e) { \ - NSString *reason = [e reason]; \ - criterion_test_die(cr_msg_test_fini_std_exception, [reason UTF8String]); \ - } @catch (...) { \ - criterion_test_die(cr_msg_test_fini_other_exception); \ - } \ +# define CR_TEST_TRAMPOLINE_(Category, Name) \ + static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ + @try { \ + criterion_internal_test_setup(); \ + } @catch (NSException *e) { \ + NSString *reason = [e reason]; \ + criterion_test_die(cr_msg_test_init_std_exception, [reason UTF8String]); \ + } @catch (...) { \ + criterion_test_die(cr_msg_test_init_other_exception); \ + } \ + @try { \ + criterion_internal_test_main((void(*)(void)) CR_IDENTIFIER_(Category, Name, impl)); \ + } @catch (NSException *e) { \ + NSString *reason = [e reason]; \ + criterion_test_die(cr_msg_test_main_std_exception, [reason UTF8String]); \ + } @catch (...) { \ + criterion_test_die(cr_msg_test_main_other_exception); \ + } \ + @try { \ + criterion_internal_test_teardown(); \ + } @catch (NSException *e) { \ + NSString *reason = [e reason]; \ + criterion_test_die(cr_msg_test_fini_std_exception, [reason UTF8String]); \ + } @catch (...) { \ + criterion_test_die(cr_msg_test_fini_other_exception); \ + } \ } # else -# define CR_TEST_TRAMPOLINE_(Category, Name) \ - static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ - criterion_internal_test_setup(); \ - criterion_internal_test_main(CR_IDENTIFIER_(Category, Name, impl)); \ - criterion_internal_test_teardown(); \ +# define CR_TEST_TRAMPOLINE_(Category, Name) \ + static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ + criterion_internal_test_setup(); \ + criterion_internal_test_main((void(*)(void)) CR_IDENTIFIER_(Category, Name, impl)); \ + criterion_internal_test_teardown(); \ } # endif # endif diff --git a/src/core/abort.h b/src/core/abort.h index 401f09b..064fe67 100644 --- a/src/core/abort.h +++ b/src/core/abort.h @@ -29,6 +29,4 @@ extern jmp_buf g_pre_test; -void criterion_test_die(const char *msg, ...); - #endif /* !ABORT_H_ */ diff --git a/src/core/test.c b/src/core/test.c index 02a4578..4295360 100644 --- a/src/core/test.c +++ b/src/core/test.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "criterion/internal/test.h" #include "core/abort.h" #include "core/stats.h" #include "core/worker.h"