From b9e3923b7c8e7cfa9bce797c219cac7cc16cc209 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 20:39:44 +0200 Subject: [PATCH 01/40] Removed any usage of GNU C-only macros from libcsptr, using smalloc & sfree directly instead --- src/event.c | 38 +++++++++++++++++++++------------ src/main.c | 6 ++++-- src/ordered-set.c | 14 ++++++++---- src/posix-compat.c | 24 +++++++++++++++------ src/process.c | 23 ++++++++++++++------ src/runner.c | 53 +++++++++++++++++++++++++++++++++------------- src/stats.c | 40 ++++++++++++++++++++++++---------- 7 files changed, 139 insertions(+), 59 deletions(-) diff --git a/src/event.c b/src/event.c index 6907c7c..38b25b2 100644 --- a/src/event.c +++ b/src/event.c @@ -23,7 +23,8 @@ */ #include -#include +#include +#include #include "criterion/stats.h" #include "criterion/common.h" #include "criterion/hooks.h" @@ -50,9 +51,12 @@ struct event *read_event(FILE *f) { return NULL; } - return unique_ptr(struct event, - .value = { .kind = kind, .data = buf }, - .dtor = destroy_event); + struct event *ev = smalloc( + .size = sizeof (struct event), + .dtor = destroy_event + ); + *ev = (struct event) { .kind = kind, .data = buf }; + return ev; } case THEORY_FAIL: { size_t *len = malloc(sizeof (size_t)); @@ -69,10 +73,12 @@ struct event *read_event(FILE *f) { } free(len); - return unique_ptr(struct event, - .value = { .kind = kind, .data = buf }, - .dtor = destroy_event); - + struct event *ev = smalloc( + .size = sizeof (struct event), + .dtor = destroy_event + ); + *ev = (struct event) { .kind = kind, .data = buf }; + return ev; } case POST_TEST: { double *elapsed_time = malloc(sizeof (double)); @@ -81,12 +87,18 @@ struct event *read_event(FILE *f) { return NULL; } - return unique_ptr(struct event, - .value = { .kind = kind, .data = elapsed_time }, - .dtor = destroy_event); + struct event *ev = smalloc( + .size = sizeof (struct event), + .dtor = destroy_event + ); + *ev = (struct event) { .kind = kind, .data = elapsed_time }; + return ev; + } + default: { + struct event *ev = smalloc(sizeof (struct event)); + *ev = (struct event) { .kind = kind, .data = NULL }; + return ev; } - default: - return unique_ptr(struct event, { .kind = kind, .data = NULL }); } } diff --git a/src/main.c b/src/main.c index 1faa4a3..a3ca0ac 100644 --- a/src/main.c +++ b/src/main.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include "runner.h" #include "config.h" @@ -90,7 +90,7 @@ bool is_disabled(struct criterion_suite *s, struct criterion_test *t) { } int list_tests(bool unicode) { - smart struct criterion_test_set *set = criterion_init(); + struct criterion_test_set *set = criterion_init(); const char *node = unicode ? UTF8_TREE_NODE : ASCII_TREE_NODE; const char *join = unicode ? UTF8_TREE_JOIN : ASCII_TREE_JOIN; @@ -114,6 +114,8 @@ int list_tests(bool unicode) { is_disabled(&s->suite, t) ? " (disabled)" : ""); } } + + sfree(set); return 0; } diff --git a/src/ordered-set.c b/src/ordered-set.c index 9386b59..3115ca2 100644 --- a/src/ordered-set.c +++ b/src/ordered-set.c @@ -21,9 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include #include #include -#include +#include static void destroy_ordered_set(void *ptr, UNUSED void *meta) { sfree(((struct criterion_ordered_set *) ptr)->first); @@ -42,9 +43,14 @@ static void destroy_ordered_set_node(void *ptr, void *meta) { struct criterion_ordered_set *new_ordered_set(f_criterion_cmp cmp, f_destructor dtor) { - return unique_ptr(struct criterion_ordered_set, - .value = { .cmp = cmp, .dtor = dtor }, - .dtor = destroy_ordered_set); + struct criterion_ordered_set *newset = smalloc( + .size = sizeof (struct criterion_ordered_set), + .dtor = destroy_ordered_set + ); + + struct criterion_ordered_set data = { .cmp = cmp, .dtor = dtor }; + memcpy(newset, &data, sizeof (struct criterion_ordered_set)); + return newset; } void *insert_ordered_set(struct criterion_ordered_set *l, diff --git a/src/posix-compat.c b/src/posix-compat.c index 376cd27..cebca75 100644 --- a/src/posix-compat.c +++ b/src/posix-compat.c @@ -63,7 +63,7 @@ # include #endif -#include +#include struct proc_handle { #ifdef VANILLA_WIN32 @@ -201,14 +201,19 @@ s_proc_handle *fork_process() { UnmapViewOfFile(ctx); CloseHandle(sharedMem); - return unique_ptr(s_proc_handle, { info.hProcess }); + s_proc_handle *handle = smalloc(sizeof (s_proc_handle)); + *handle = (s_proc_handle) { info.hProcess }; + return handle; #else pid_t pid = fork(); if (pid == -1) return (void *) -1; if (pid == 0) return NULL; - return unique_ptr(s_proc_handle, { pid }); + + s_proc_handle *handle = smalloc(sizeof (s_proc_handle)); + *handle = (s_proc_handle) { pid }; + return handle; #endif } @@ -294,6 +299,7 @@ FILE *pipe_out(s_pipe_handle *p) { } s_pipe_handle *stdpipe() { + s_pipe_handle *handle = smalloc(sizeof (s_pipe_handle)); #ifdef VANILLA_WIN32 HANDLE fhs[2]; SECURITY_ATTRIBUTES attr = { @@ -302,21 +308,25 @@ s_pipe_handle *stdpipe() { }; if (!CreatePipe(fhs, fhs + 1, &attr, 0)) return NULL; - return unique_ptr(s_pipe_handle, {{ fhs[0], fhs[1] }}); + *handle = (s_pipe_handle) {{ fhs[0], fhs[1] }}; + return handle; #else int fds[2] = { -1, -1 }; if (pipe(fds) == -1) return NULL; - return unique_ptr(s_pipe_handle, {{ fds[0], fds[1] }}); + *handle = (s_pipe_handle) {{ fds[0], fds[1] }}; + return handle; #endif } s_proc_handle *get_current_process() { + s_proc_handle *handle = smalloc(sizeof (s_proc_handle)); #ifdef VANILLA_WIN32 - return unique_ptr(s_proc_handle, { GetCurrentProcess() }); + *handle = (s_proc_handle) { GetCurrentProcess() }; #else - return unique_ptr(s_proc_handle, { getpid() }); + *handle = (s_proc_handle) { getpid() }; #endif + return handle; } bool is_current_process(s_proc_handle *proc) { diff --git a/src/process.c b/src/process.c index d3a5f9e..036b790 100644 --- a/src/process.c +++ b/src/process.c @@ -23,7 +23,7 @@ */ #include #include -#include +#include #include "criterion/types.h" #include "criterion/options.h" @@ -76,7 +76,7 @@ void run_worker(struct worker_context *ctx) { struct process *spawn_test_worker(struct criterion_test *test, struct criterion_suite *suite, f_worker_func func) { - smart s_pipe_handle *pipe = stdpipe(); + s_pipe_handle *pipe = stdpipe(); if (pipe == NULL) abort(); @@ -86,17 +86,26 @@ struct process *spawn_test_worker(struct criterion_test *test, .func = func, .pipe = pipe }; + + struct process *ptr = NULL; + s_proc_handle *proc = fork_process(); if (proc == (void *) -1) { - return NULL; + goto cleanup; } else if (proc == NULL) { run_worker(&g_worker_context); - return NULL; + goto cleanup; } - return unique_ptr(struct process, - .value = { .proc = proc, .in = pipe_in(pipe) }, - .dtor = close_process); + ptr = smalloc( + .size = sizeof (struct process), + .kind = UNIQUE, + .dtor = close_process); + + *ptr = (struct process) { .proc = proc, .in = pipe_in(pipe) }; +cleanup: + sfree(pipe); + return ptr; } struct process_status wait_proc(struct process *proc) { diff --git a/src/runner.c b/src/runner.c index 1341fa5..67f3ed8 100644 --- a/src/runner.c +++ b/src/runner.c @@ -23,7 +23,7 @@ */ #include #include -#include +#include #include "criterion/criterion.h" #include "criterion/options.h" #include "criterion/ordered-set.h" @@ -104,10 +104,17 @@ struct criterion_test_set *criterion_init(void) { ++nb_tests; } - return unique_ptr(struct criterion_test_set, { + struct criterion_test_set *set = smalloc( + .size = sizeof (struct criterion_test_set), + .dtor = dtor_test_set + ); + + *set = (struct criterion_test_set) { suites, nb_tests, - }, dtor_test_set); + }; + + return set; } typedef void (*f_test_run)(struct criterion_global_stats *, @@ -126,7 +133,7 @@ static void map_tests(struct criterion_test_set *set, report(PRE_SUITE, s); log(pre_suite, s); - smart struct criterion_suite_stats *suite_stats = suite_stats_init(&s->suite); + struct criterion_suite_stats *suite_stats = suite_stats_init(&s->suite); struct event ev = { .kind = PRE_SUITE }; stat_push_event(stats, suite_stats, NULL, &ev); @@ -135,13 +142,18 @@ static void map_tests(struct criterion_test_set *set, fun(stats, suite_stats, t, &s->suite); if (criterion_options.fail_fast && stats->tests_failed > 0) break; - if (!is_runner()) + if (!is_runner()) { + sfree(suite_stats); return; + } } report(POST_SUITE, suite_stats); log(post_suite, suite_stats); + + sfree(suite_stats); } + } static void run_test_child(struct criterion_test *test, @@ -191,19 +203,20 @@ static void run_test(struct criterion_global_stats *stats, struct criterion_test *test, struct criterion_suite *suite) { - smart struct criterion_test_stats *test_stats = test_stats_init(test); + struct criterion_test_stats *test_stats = test_stats_init(test); + struct process *proc = NULL; if (is_disabled(test, suite)) { stat_push_event(stats, suite_stats, test_stats, &(struct event) { .kind = PRE_INIT }); - return; + goto cleanup; } - smart struct process *proc = spawn_test_worker(test, suite, run_test_child); + proc = spawn_test_worker(test, suite, run_test_child); if (proc == NULL && !is_runner()) - return; + goto cleanup; bool test_started = false; bool normal_finish = false; @@ -257,7 +270,7 @@ static void run_test(struct criterion_global_stats *stats, test_stats, &(struct event) { .kind = TEST_CRASH }); } - return; + goto cleanup; } test_stats->signal = status.status; if (test->data->signal == 0) { @@ -279,7 +292,7 @@ static void run_test(struct criterion_global_stats *stats, test_stats, &(struct event) { .kind = TEST_CRASH }); } - return; + goto cleanup; } test_stats->exit_code = status.status; if (!normal_finish) { @@ -295,6 +308,10 @@ static void run_test(struct criterion_global_stats *stats, } } } + +cleanup: + sfree(test_stats); + sfree(proc); } #ifdef HAVE_PCRE @@ -321,7 +338,7 @@ static int criterion_run_all_tests_impl(void) { if (resume_child()) // (windows only) resume from the fork return -1; - smart struct criterion_test_set *set = criterion_init(); + struct criterion_test_set *set = criterion_init(); #ifdef HAVE_PCRE if (criterion_options.pattern) disable_unmatching(set); @@ -332,15 +349,21 @@ static int criterion_run_all_tests_impl(void) { fflush(NULL); // flush everything before forking - smart struct criterion_global_stats *stats = stats_init(); + struct criterion_global_stats *stats = stats_init(); map_tests(set, stats, run_test); + int result = is_runner() ? stats->tests_failed == 0 : -1; + if (!is_runner()) - return -1; + goto cleanup; report(POST_ALL, stats); log(post_all, stats); - return stats->tests_failed == 0; + +cleanup: + sfree(set); + sfree(stats); + return result; } int criterion_run_all_tests(void) { diff --git a/src/stats.c b/src/stats.c index cd4a83d..f46b957 100644 --- a/src/stats.c +++ b/src/stats.c @@ -21,7 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include +#include #include "criterion/common.h" #include "stats.h" @@ -48,7 +49,12 @@ static void destroy_stats(void *ptr, UNUSED void *meta) { } s_glob_stats *stats_init(void) { - return unique_ptr(s_glob_stats, .dtor = destroy_stats); + s_glob_stats *stats = smalloc( + .size = sizeof (s_glob_stats), + .dtor = destroy_stats + ); + *stats = (s_glob_stats) { .suites = NULL }; + return stats; } static void destroy_suite_stats(void *ptr, UNUSED void *meta) { @@ -60,9 +66,13 @@ static void destroy_suite_stats(void *ptr, UNUSED void *meta) { } s_suite_stats *suite_stats_init(struct criterion_suite *s) { - return shared_ptr(s_suite_stats, { - .suite = s, - }, destroy_suite_stats); + s_suite_stats *stats = smalloc( + .size = sizeof (s_suite_stats), + .kind = SHARED, + .dtor = destroy_suite_stats + ); + *stats = (s_suite_stats) { .suite = s }; + return stats; } static void destroy_test_stats(void *ptr, UNUSED void *meta) { @@ -74,11 +84,17 @@ static void destroy_test_stats(void *ptr, UNUSED void *meta) { } s_test_stats *test_stats_init(struct criterion_test *t) { - return shared_ptr(s_test_stats, { - .test = t, - .progress = t->data->line_, - .file = t->data->file_ - }, destroy_test_stats); + s_test_stats *stats = smalloc( + .size = sizeof (s_test_stats), + .kind = SHARED, + .dtor = destroy_test_stats + ); + *stats = (s_test_stats) { + .test = t, + .progress = t->data->line_, + .file = t->data->file_ + }; + return stats; } void stat_push_event(s_glob_stats *stats, @@ -140,7 +156,9 @@ static void push_assert(s_glob_stats *stats, s_suite_stats *suite, s_test_stats *test, s_assert_stats *data) { - s_assert_stats *dup = unique_ptr(s_assert_stats, (*data)); + s_assert_stats *dup = smalloc(sizeof (s_assert_stats)); + memcpy(dup, data, sizeof (s_assert_stats)); + dup->next = test->asserts; test->asserts = dup; From 289731d47d255dc4a2f366ba7add39de52c3fe8b Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 21:02:16 +0200 Subject: [PATCH 02/40] Update libcsptr to allow MSVC compilation --- .cmake/Modules/Submodules.cmake | 2 +- dependencies/libcsptr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.cmake/Modules/Submodules.cmake b/.cmake/Modules/Submodules.cmake index 7c25139..d5b2cba 100644 --- a/.cmake/Modules/Submodules.cmake +++ b/.cmake/Modules/Submodules.cmake @@ -10,7 +10,7 @@ set(GIT_SUBMODULES libcsptr dyncall) ### set each submodules's commit or tag that is to be checked out ### (leave empty if you want master) -set(GIT_SUBMODULE_VERSION_libcsptr 04cd477) +set(GIT_SUBMODULE_VERSION_libcsptr a233d68) set(GIT_SUBMODULE_VERSION_dyncall 68c57f6) ### First, get all submodules in diff --git a/dependencies/libcsptr b/dependencies/libcsptr index 04cd477..a233d68 160000 --- a/dependencies/libcsptr +++ b/dependencies/libcsptr @@ -1 +1 @@ -Subproject commit 04cd477d1f213e55d2ddecab2fcd52d1c7865dfa +Subproject commit a233d686bc6135bc8b96489364fc65ee2a25b297 From 4aa7c0729591d88474de585e4650b1a5e4ba3c22 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 21:06:18 +0200 Subject: [PATCH 03/40] Made the samples compile with MSVC --- samples/CMakeLists.txt | 4 +++- samples/asserts.c | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 7767a42..5bdb842 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,4 +1,6 @@ -set(CMAKE_C_FLAGS "-std=c99 -Wall -Wextra -pedantic") +if (NOT MSVC) + set(CMAKE_C_FLAGS "-std=c99 -Wall -Wextra -pedantic") +endif () include_directories(../include) diff --git a/samples/asserts.c b/samples/asserts.c index 627f778..6b44cb9 100644 --- a/samples/asserts.c +++ b/samples/asserts.c @@ -64,6 +64,10 @@ Test(asserts, array) { int arr1[] = {1, 2, 3, 4}; int arr2[] = {4, 3, 2, 1}; + cr_assert_arrays_eq(arr1, arr1, 4); + cr_assert_arrays_neq(arr1, arr2, 4); + +#ifdef __GNUC__ struct dummy_struct s1[] = {{4, 2}, {2, 4}}; struct dummy_struct s2[2]; memset(s2, 0xFF, sizeof(s2)); @@ -72,9 +76,7 @@ Test(asserts, array) { s2[1].a = 2; s2[1].b = 4; - cr_assert_arrays_eq(arr1, arr1, 4); - cr_assert_arrays_neq(arr1, arr2, 4); - cr_assert_arrays_neq(s1, s2, 2); cr_assert_arrays_eq_cmp(s1, s2, 2, eq_dummy); +#endif } From c56776b976b0fff331ab5581a55183a1e5ae93db Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 21:25:42 +0200 Subject: [PATCH 04/40] Updated libcsptr to latest --- .cmake/Modules/Submodules.cmake | 2 +- dependencies/libcsptr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.cmake/Modules/Submodules.cmake b/.cmake/Modules/Submodules.cmake index d5b2cba..8ab963c 100644 --- a/.cmake/Modules/Submodules.cmake +++ b/.cmake/Modules/Submodules.cmake @@ -10,7 +10,7 @@ set(GIT_SUBMODULES libcsptr dyncall) ### set each submodules's commit or tag that is to be checked out ### (leave empty if you want master) -set(GIT_SUBMODULE_VERSION_libcsptr a233d68) +set(GIT_SUBMODULE_VERSION_libcsptr 5bf0ad5) set(GIT_SUBMODULE_VERSION_dyncall 68c57f6) ### First, get all submodules in diff --git a/dependencies/libcsptr b/dependencies/libcsptr index a233d68..5bf0ad5 160000 --- a/dependencies/libcsptr +++ b/dependencies/libcsptr @@ -1 +1 @@ -Subproject commit a233d686bc6135bc8b96489364fc65ee2a25b297 +Subproject commit 5bf0ad57051a5b29d12b4daab8b233d1943c1085 From 1e9a635b97c8e69cae8723e64475f00140fe358e Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 21:42:31 +0200 Subject: [PATCH 05/40] Removed commit hashes in Submodule.cmake and updated libcsptr to latest --- .cmake/Modules/Submodules.cmake | 2 -- dependencies/libcsptr | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.cmake/Modules/Submodules.cmake b/.cmake/Modules/Submodules.cmake index 8ab963c..5183368 100644 --- a/.cmake/Modules/Submodules.cmake +++ b/.cmake/Modules/Submodules.cmake @@ -10,8 +10,6 @@ set(GIT_SUBMODULES libcsptr dyncall) ### set each submodules's commit or tag that is to be checked out ### (leave empty if you want master) -set(GIT_SUBMODULE_VERSION_libcsptr 5bf0ad5) -set(GIT_SUBMODULE_VERSION_dyncall 68c57f6) ### First, get all submodules in if(${GIT_SUBMODULES_CHECKOUT_QUIET}) diff --git a/dependencies/libcsptr b/dependencies/libcsptr index 5bf0ad5..530fb9d 160000 --- a/dependencies/libcsptr +++ b/dependencies/libcsptr @@ -1 +1 @@ -Subproject commit 5bf0ad57051a5b29d12b4daab8b233d1943c1085 +Subproject commit 530fb9d001a4ae9303816f30de6c3bf6b3084c7c From ad6f03bf7a18e5b285d58eb25b56b60518b7dee8 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 21:58:57 +0200 Subject: [PATCH 06/40] Updated libcsptr to latest --- dependencies/libcsptr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/libcsptr b/dependencies/libcsptr index 530fb9d..d7be039 160000 --- a/dependencies/libcsptr +++ b/dependencies/libcsptr @@ -1 +1 @@ -Subproject commit 530fb9d001a4ae9303816f30de6c3bf6b3084c7c +Subproject commit d7be0399f8eed62b73dd8d32a8c0708b1e78059f From 4817fb709f77b7af5525e09eff31bdf1bda33cc9 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 22:22:08 +0200 Subject: [PATCH 07/40] Updated libcsptr for latest msvc compatibility --- dependencies/libcsptr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/libcsptr b/dependencies/libcsptr index d7be039..2762164 160000 --- a/dependencies/libcsptr +++ b/dependencies/libcsptr @@ -1 +1 @@ -Subproject commit d7be0399f8eed62b73dd8d32a8c0708b1e78059f +Subproject commit 2762164acfaa712fea7dec6ed760ff88f7d2e026 From 95539c89adbaaa233a83cd374d23cf1d2acd4451 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 22:58:45 +0200 Subject: [PATCH 08/40] Removed VLA and ?: GNU extension occurences --- src/common.h | 37 +++++++++++++++++++++++++++++++++++++ src/event.c | 3 ++- src/extmatch.c | 13 +++++++------ src/i18n.c | 5 ++--- src/i18n.h | 2 ++ src/log/normal.c | 6 ++---- src/log/tap.c | 8 ++++---- src/main.c | 19 ++++++++++--------- src/ordered-set.c | 6 +++--- src/report.c | 2 +- src/report.h | 4 +++- src/runner.c | 19 ++++++++++--------- src/stats.c | 4 ++-- 13 files changed, 85 insertions(+), 43 deletions(-) create mode 100644 src/common.h diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..b9add0b --- /dev/null +++ b/src/common.h @@ -0,0 +1,37 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2015 Franklin "Snaipe" Mathieu + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef COMMON_H_ +# define COMMON_H_ + +#ifdef __GNUC__ +# define INLINE __attribute__((always_inline)) inline +#elif defined(_MSC_VER) +# define INLINE __forceinline +#else +# define INLINE +#endif + +# define DEF(X, Y) ((X) ? (X) : (Y)) + +#endif /* !COMMON_H_ */ diff --git a/src/event.c b/src/event.c index 38b25b2..83a92e0 100644 --- a/src/event.c +++ b/src/event.c @@ -103,9 +103,10 @@ struct event *read_event(FILE *f) { } void send_event(int kind, void *data, size_t size) { - unsigned char buf[sizeof (int) + size]; + unsigned char *buf = malloc(sizeof (int) + size); memcpy(buf, &kind, sizeof (int)); memcpy(buf + sizeof (int), data, size); if (fwrite(buf, sizeof (int) + size, 1, g_event_pipe) == 0) abort(); + free(buf); } diff --git a/src/extmatch.c b/src/extmatch.c index 604d418..79a7ad3 100644 --- a/src/extmatch.c +++ b/src/extmatch.c @@ -28,6 +28,7 @@ #include #include "criterion/common.h" +#include "common.h" struct context { int depth; @@ -107,20 +108,20 @@ static int is_eos(struct context *ctx) { static inline void handle_special(struct context *ctx, handler_arg strs[5]) { if (peek_char(ctx) == '(') { - if ((strs[0].validator ?: inactive)(ctx)) + if (DEF(strs[0].validator, inactive)(ctx)) copy_str(ctx, strs[0].str); dup_char(ctx); - if ((strs[1].validator ?: inactive)(ctx)) + if (DEF(strs[1].validator, inactive)(ctx)) copy_str(ctx, strs[1].str); transform_rec(ctx); - if ((strs[2].validator ?: inactive)(ctx)) + if (DEF(strs[2].validator, inactive)(ctx)) copy_str(ctx,strs[2].str); copy_char(ctx, ')'); - if ((strs[3].validator ?: inactive)(ctx)) + if (DEF(strs[3].validator, inactive)(ctx)) copy_str(ctx, strs[3].str); - } else if ((strs[4].validator ?: inactive)(ctx)) { + } else if (DEF(strs[4].validator, inactive)(ctx)) { copy_str(ctx, strs[4].str); } } @@ -191,7 +192,7 @@ void transform_impl(struct context *ctx) { if (c == ')' && ctx->depth > 0) return; - (handler ?: copy_char)(ctx, c); + (handler ? handler : copy_char)(ctx, c); if (ctx->eos) return; diff --git a/src/i18n.c b/src/i18n.c index 5b9899b..7a7c51b 100644 --- a/src/i18n.c +++ b/src/i18n.c @@ -1,8 +1,7 @@ #include "i18n.h" -#if ENABLE_NLS -__attribute__ ((constructor)) void init_i18n(void) { +#if ENABLE_NLS bindtextdomain (PACKAGE, LOCALEDIR); -} #endif +} diff --git a/src/i18n.h b/src/i18n.h index 74c159e..2657c1e 100644 --- a/src/i18n.h +++ b/src/i18n.h @@ -13,4 +13,6 @@ dngettext(PACKAGE, String, Plural, (Quantity)) # endif +void init_i18n(void); + #endif /* !I18N_H_ */ diff --git a/src/log/normal.c b/src/log/normal.c index 8116033..1ce002c 100644 --- a/src/log/normal.c +++ b/src/log/normal.c @@ -34,8 +34,7 @@ #include "config.h" #include "i18n.h" #include "posix-compat.h" - -#define USED __attribute__ ((used)) +#include "common.h" #ifdef VANILLA_WIN32 // fallback to strtok on windows since strtok_s is not available everywhere @@ -119,8 +118,7 @@ void normal_log_post_test(struct criterion_test_stats *stats) { stats->elapsed_time); } -__attribute__((always_inline)) -static inline bool is_disabled(struct criterion_test *t, +static INLINE bool is_disabled(struct criterion_test *t, struct criterion_suite *s) { return t->data->disabled || (s->data && s->data->disabled); } diff --git a/src/log/tap.c b/src/log/tap.c index 23898f4..b406ba3 100644 --- a/src/log/tap.c +++ b/src/log/tap.c @@ -32,6 +32,7 @@ #include "timer.h" #include "config.h" #include "posix-compat.h" +#include "common.h" void tap_log_pre_all(struct criterion_test_set *set) { size_t enabled_count = 0; @@ -54,8 +55,7 @@ void tap_log_pre_suite(struct criterion_suite_set *set) { set->suite.name); } -__attribute__((always_inline)) -static inline bool is_disabled(struct criterion_test *t, struct criterion_suite *s) { +static INLINE bool is_disabled(struct criterion_test *t, struct criterion_suite *s) { return t->data->disabled || (s->data && s->data->disabled); } @@ -65,7 +65,7 @@ void tap_log_post_suite(struct criterion_suite_stats *stats) { criterion_important("ok - %s::%s %s # SKIP %s is disabled\n", ts->test->category, ts->test->name, - ts->test->data->description ?: "", + DEF(ts->test->data->description, ""), ts->test->data->disabled ? "test" : "suite"); } } @@ -78,7 +78,7 @@ void tap_log_post_test(struct criterion_test_stats *stats) { stats->failed ? "not ok" : "ok", stats->test->category, stats->test->name, - stats->test->data->description ?: "", + DEF(stats->test->data->description, ""), stats->elapsed_time); for (struct criterion_assert_stats *asrt = stats->asserts; asrt; asrt = asrt->next) { if (!asrt->passed) { diff --git a/src/main.c b/src/main.c index a3ca0ac..7995b34 100644 --- a/src/main.c +++ b/src/main.c @@ -31,6 +31,7 @@ #include #include "runner.h" #include "config.h" +#include "common.h" #if ENABLE_NLS # include @@ -137,8 +138,8 @@ int main(int argc, char *argv[]) { {0, 0, 0, 0 } }; - bool use_ascii = !strcmp("1", getenv("CRITERION_USE_ASCII") ?: "0") - || !strcmp("dumb", getenv("TERM") ?: "dumb"); + bool use_ascii = !strcmp("1", DEF(getenv("CRITERION_USE_ASCII"), "0")) + || !strcmp("dumb", DEF(getenv("TERM"), "dumb")); setlocale(LC_ALL, ""); #if ENABLE_NLS @@ -146,24 +147,24 @@ int main(int argc, char *argv[]) { #endif struct criterion_options *opt = &criterion_options; - opt->always_succeed = !strcmp("1", getenv("CRITERION_ALWAYS_SUCCEED") ?: "0"); - opt->no_early_exit = !strcmp("1", getenv("CRITERION_NO_EARLY_EXIT") ?: "0"); - opt->fail_fast = !strcmp("1", getenv("CRITERION_FAIL_FAST") ?: "0"); + opt->always_succeed = !strcmp("1", DEF(getenv("CRITERION_ALWAYS_SUCCEED"), "0")); + opt->no_early_exit = !strcmp("1", DEF(getenv("CRITERION_NO_EARLY_EXIT") , "0")); + opt->fail_fast = !strcmp("1", DEF(getenv("CRITERION_FAIL_FAST") , "0")); opt->use_ascii = use_ascii; - opt->logging_threshold = atoi(getenv("CRITERION_VERBOSITY_LEVEL") ?: "2"); - opt->short_filename = !strcmp("1", getenv("CRITERION_SHORT_FILENAME") ?: "0"); + opt->logging_threshold = atoi(DEF(getenv("CRITERION_VERBOSITY_LEVEL"), "2")); + opt->short_filename = !strcmp("1", DEF(getenv("CRITERION_SHORT_FILENAME"), "0")); #ifdef HAVE_PCRE opt->pattern = getenv("CRITERION_TEST_PATTERN"); #endif - bool use_tap = !strcmp("1", getenv("CRITERION_ENABLE_TAP") ?: "0"); + bool use_tap = !strcmp("1", DEF(getenv("CRITERION_ENABLE_TAP"), "0")); bool do_list_tests = false; bool do_print_version = false; bool do_print_usage = false; for (int c; (c = getopt_long(argc, argv, "hvlfS", opts, NULL)) != -1;) { switch (c) { - case 'b': criterion_options.logging_threshold = atoi(optarg ?: "1"); break; + case 'b': criterion_options.logging_threshold = atoi(DEF(optarg, "1")); break; case 'y': criterion_options.always_succeed = true; break; case 'z': criterion_options.no_early_exit = true; break; case 'k': criterion_options.use_ascii = true; break; diff --git a/src/ordered-set.c b/src/ordered-set.c index 3115ca2..cecc87e 100644 --- a/src/ordered-set.c +++ b/src/ordered-set.c @@ -25,18 +25,18 @@ #include #include #include +#include "common.h" static void destroy_ordered_set(void *ptr, UNUSED void *meta) { sfree(((struct criterion_ordered_set *) ptr)->first); } -__attribute__ ((always_inline)) -static inline void nothing() {} +static INLINE void nothing() {} static void destroy_ordered_set_node(void *ptr, void *meta) { struct criterion_ordered_set *set = *(void **) meta; struct criterion_ordered_set_node *n = ptr; - (set->dtor ?: nothing)(n->data, NULL); + DEF(set->dtor, nothing)(n->data, NULL); sfree(((struct criterion_ordered_set_node *) ptr)->next); } diff --git a/src/report.c b/src/report.c index b839542..3b709e0 100644 --- a/src/report.c +++ b/src/report.c @@ -41,7 +41,7 @@ static inline void nothing() {} for (f_report_hook *hook = GET_SECTION_START(HOOK_SECTION(Kind)); \ hook < (f_report_hook*) GET_SECTION_END(HOOK_SECTION(Kind)); \ ++hook) { \ - (*hook ?: nothing)(data); \ + (*hook ? *hook : nothing)(data); \ } \ } diff --git a/src/report.h b/src/report.h index 02aeed9..2322267 100644 --- a/src/report.h +++ b/src/report.h @@ -45,6 +45,8 @@ DECL_CALL_REPORT_HOOKS(POST_SUITE); DECL_CALL_REPORT_HOOKS(POST_ALL); #define log(Type, Arg) \ - (criterion_options.output_provider->log_ ## Type ?: nothing)(Arg); + log_(criterion_options.output_provider->log_ ## Type, Arg); +#define log_(Log, Arg) \ + (Log ? Log : nothing)(Arg); #endif /* !REPORT_H_ */ diff --git a/src/runner.c b/src/runner.c index 67f3ed8..37342a3 100644 --- a/src/runner.c +++ b/src/runner.c @@ -37,6 +37,8 @@ #include "posix-compat.h" #include "abort.h" #include "config.h" +#include "i18n.h" +#include "common.h" #ifdef HAVE_PCRE #include "extmatch.h" @@ -49,8 +51,7 @@ IMPL_SECTION_LIMITS(struct criterion_suite, cr_sts); TestSuite(); Test(,) {}; -__attribute__ ((always_inline)) -static inline void nothing() {} +static INLINE void nothing() {} int cmp_suite(void *a, void *b) { struct criterion_suite *s1 = a, *s2 = b; @@ -161,14 +162,14 @@ static void run_test_child(struct criterion_test *test, send_event(PRE_INIT, NULL, 0); if (suite->data) - (suite->data->init ?: nothing)(); - (test->data->init ?: nothing)(); + (suite->data->init ? suite->data->init : nothing)(); + (test->data->init ? test->data->init : nothing)(); send_event(PRE_TEST, NULL, 0); struct timespec_compat ts; if (setup_abort_test()) { timer_start(&ts); - (test->test ?: nothing)(); + (test->test ? test->test : nothing)(); } double elapsed_time; @@ -176,14 +177,13 @@ static void run_test_child(struct criterion_test *test, elapsed_time = -1; send_event(POST_TEST, &elapsed_time, sizeof (double)); - (test->data->fini ?: nothing)(); + (test->data->fini ? test->data->fini : nothing)(); if (suite->data) - (suite->data->fini ?: nothing)(); + (suite->data->fini ? suite->data->fini : nothing)(); send_event(POST_FINI, NULL, 0); } -__attribute__((always_inline)) -static inline bool is_disabled(struct criterion_test *t, +static INLINE bool is_disabled(struct criterion_test *t, struct criterion_suite *s) { return t->data->disabled || (s->data && s->data->disabled); @@ -367,6 +367,7 @@ cleanup: } int criterion_run_all_tests(void) { + init_i18n(); set_runner_process(); int res = criterion_run_all_tests_impl(); unset_runner_process(); diff --git a/src/stats.c b/src/stats.c index f46b957..b017c8a 100644 --- a/src/stats.c +++ b/src/stats.c @@ -25,6 +25,7 @@ #include #include "criterion/common.h" #include "stats.h" +#include "common.h" #include @@ -130,8 +131,7 @@ static void push_pre_suite(s_glob_stats *stats, ++stats->nb_suites; } -__attribute__((always_inline)) -static inline bool is_disabled(struct criterion_test *t, +static INLINE bool is_disabled(struct criterion_test *t, struct criterion_suite *s) { return t->data->disabled || (s->data && s->data->disabled); From f67bed8dba58a686308cccb45eb64eaa56ac5fce Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 23:22:47 +0200 Subject: [PATCH 09/40] Added wingetopt to dependencies --- .gitmodules | 3 +++ CMakeLists.txt | 5 +++++ dependencies/wingetopt | 1 + 3 files changed, 9 insertions(+) create mode 160000 dependencies/wingetopt diff --git a/.gitmodules b/.gitmodules index 06e28e8..7c24be1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "dependencies/dyncall"] path = dependencies/dyncall url = https://github.com/Snaipe/dyncall.git +[submodule "dependencies/wingetopt"] + path = dependencies/wingetopt + url = https://github.com/alex85k/wingetopt.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 63388cf..8ea04d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,11 @@ include_directories( dependencies/dyncall/dyncall/ ) +if (MSVC) + add_subdirectory(dependencies/wingetopt/ EXCLUDE_FROM_ALL) + include_directories(dependencies/wingetopt/src/) +endif () + # Project setup & environment variables set(PROJECT_VERSION "1.3.1") diff --git a/dependencies/wingetopt b/dependencies/wingetopt new file mode 160000 index 0000000..76a5d1a --- /dev/null +++ b/dependencies/wingetopt @@ -0,0 +1 @@ +Subproject commit 76a5d1ab15f684d4c9479a32624d65b3bd1a726b From 8871ae946bdcc3f791900c8f0f4bccab0340af40 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 23:23:00 +0200 Subject: [PATCH 10/40] Removed VLA from theories.c --- src/theories.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/theories.c b/src/theories.c index 0431c96..7cc86d9 100644 --- a/src/theories.c +++ b/src/theories.c @@ -186,7 +186,7 @@ static void concat_arg(char (*msg)[4096], struct criterion_datapoints *dps, size void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void)) { struct criterion_theory_context *ctx = cr_theory_init(); - size_t indices[datapoints]; + size_t *indices = malloc(datapoints); memset(indices, 0, datapoints * sizeof (size_t)); bool has_next = true; @@ -237,5 +237,6 @@ void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (* } } + free(indices); cr_theory_free(ctx); } From 030fc1de19b9d99d87e4ae39efbf2ce0933e65f6 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 23:41:01 +0200 Subject: [PATCH 11/40] Added MSVC glue for missing section symbols --- src/report.c | 14 ++++++++++++++ src/runner.c | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/src/report.c b/src/report.c index 3b709e0..2f37fa0 100644 --- a/src/report.c +++ b/src/report.c @@ -45,6 +45,20 @@ static inline void nothing() {} } \ } +#ifdef _MSC_VER +f_report_hook SECTION_START_(HOOK_SECTION(PRE_ALL)); +f_report_hook SECTION_START_(HOOK_SECTION(PRE_SUITE)); +f_report_hook SECTION_START_(HOOK_SECTION(PRE_INIT)); +f_report_hook SECTION_START_(HOOK_SECTION(PRE_TEST)); +f_report_hook SECTION_START_(HOOK_SECTION(ASSERT)); +f_report_hook SECTION_START_(HOOK_SECTION(THEORY_FAIL)); +f_report_hook SECTION_START_(HOOK_SECTION(TEST_CRASH)); +f_report_hook SECTION_START_(HOOK_SECTION(POST_TEST)); +f_report_hook SECTION_START_(HOOK_SECTION(POST_FINI)); +f_report_hook SECTION_START_(HOOK_SECTION(POST_SUITE)); +f_report_hook SECTION_START_(HOOK_SECTION(POST_ALL)); +#endif + IMPL_CALL_REPORT_HOOKS(PRE_ALL); IMPL_CALL_REPORT_HOOKS(PRE_SUITE); IMPL_CALL_REPORT_HOOKS(PRE_INIT); diff --git a/src/runner.c b/src/runner.c index 37342a3..16b0405 100644 --- a/src/runner.c +++ b/src/runner.c @@ -44,6 +44,11 @@ #include "extmatch.h" #endif +#ifdef _MSC_VER +struct criterion_test SECTION_START_(cr_tst); +struct criterion_suite SECTION_START_(cr_sts); +#endif + IMPL_SECTION_LIMITS(struct criterion_test, cr_tst); IMPL_SECTION_LIMITS(struct criterion_suite, cr_sts); From 4bad96df64f15ab1324cffe696152ecd73b41c39 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 23:42:22 +0200 Subject: [PATCH 12/40] Added linking to wingetopt --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ea04d6..07fe6d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,6 +125,10 @@ include_directories(include src) add_library(criterion SHARED ${SOURCE_FILES} ${INTERFACE_FILES}) target_link_libraries(criterion csptr dyncall_s) +if (MSVC) + target_link_libraries(criterion wingetopt) +endif () + if (HAVE_CLOCK_GETTIME) target_link_libraries(criterion rt) endif() From 4ccabada4050a5fbbfb3b2c432d15dcfd86cf22e Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 23:46:27 +0200 Subject: [PATCH 13/40] Added missing section stop symbols for MSVC --- src/report.c | 12 ++++++++++++ src/runner.c | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/report.c b/src/report.c index 2f37fa0..1658d98 100644 --- a/src/report.c +++ b/src/report.c @@ -57,6 +57,18 @@ f_report_hook SECTION_START_(HOOK_SECTION(POST_TEST)); f_report_hook SECTION_START_(HOOK_SECTION(POST_FINI)); f_report_hook SECTION_START_(HOOK_SECTION(POST_SUITE)); f_report_hook SECTION_START_(HOOK_SECTION(POST_ALL)); + +f_report_hook SECTION_STOP_(HOOK_SECTION(PRE_ALL)); +f_report_hook SECTION_STOP_(HOOK_SECTION(PRE_SUITE)); +f_report_hook SECTION_STOP_(HOOK_SECTION(PRE_INIT)); +f_report_hook SECTION_STOP_(HOOK_SECTION(PRE_TEST)); +f_report_hook SECTION_STOP_(HOOK_SECTION(ASSERT)); +f_report_hook SECTION_STOP_(HOOK_SECTION(THEORY_FAIL)); +f_report_hook SECTION_STOP_(HOOK_SECTION(TEST_CRASH)); +f_report_hook SECTION_STOP_(HOOK_SECTION(POST_TEST)); +f_report_hook SECTION_STOP_(HOOK_SECTION(POST_FINI)); +f_report_hook SECTION_STOP_(HOOK_SECTION(POST_SUITE)); +f_report_hook SECTION_STOP_(HOOK_SECTION(POST_ALL)); #endif IMPL_CALL_REPORT_HOOKS(PRE_ALL); diff --git a/src/runner.c b/src/runner.c index 16b0405..2bed26a 100644 --- a/src/runner.c +++ b/src/runner.c @@ -47,6 +47,8 @@ #ifdef _MSC_VER struct criterion_test SECTION_START_(cr_tst); struct criterion_suite SECTION_START_(cr_sts); +struct criterion_test SECTION_STOP_(cr_tst); +struct criterion_suite SECTION_STOP_(cr_sts); #endif IMPL_SECTION_LIMITS(struct criterion_test, cr_tst); From da4e9ccdfc8279605c7c4077f3fd9ee04f596115 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 23:48:09 +0200 Subject: [PATCH 14/40] Disabled Safe SEH for MSVC builds --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07fe6d1..7bc0bb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,10 @@ set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS ON) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -std=gnu99") +if (MSVC) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") +endif () + if (WIN32) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-no-undefined") endif() From 5d119c607efed4c0c69f0a0947dfc3190fcdcdff Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 23:50:55 +0200 Subject: [PATCH 15/40] Fixed SECTION_STOP_ -> SECTION_END_ typo --- src/report.c | 22 +++++++++++----------- src/runner.c | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/report.c b/src/report.c index 1658d98..5809bfd 100644 --- a/src/report.c +++ b/src/report.c @@ -58,17 +58,17 @@ f_report_hook SECTION_START_(HOOK_SECTION(POST_FINI)); f_report_hook SECTION_START_(HOOK_SECTION(POST_SUITE)); f_report_hook SECTION_START_(HOOK_SECTION(POST_ALL)); -f_report_hook SECTION_STOP_(HOOK_SECTION(PRE_ALL)); -f_report_hook SECTION_STOP_(HOOK_SECTION(PRE_SUITE)); -f_report_hook SECTION_STOP_(HOOK_SECTION(PRE_INIT)); -f_report_hook SECTION_STOP_(HOOK_SECTION(PRE_TEST)); -f_report_hook SECTION_STOP_(HOOK_SECTION(ASSERT)); -f_report_hook SECTION_STOP_(HOOK_SECTION(THEORY_FAIL)); -f_report_hook SECTION_STOP_(HOOK_SECTION(TEST_CRASH)); -f_report_hook SECTION_STOP_(HOOK_SECTION(POST_TEST)); -f_report_hook SECTION_STOP_(HOOK_SECTION(POST_FINI)); -f_report_hook SECTION_STOP_(HOOK_SECTION(POST_SUITE)); -f_report_hook SECTION_STOP_(HOOK_SECTION(POST_ALL)); +f_report_hook SECTION_END_(HOOK_SECTION(PRE_ALL)); +f_report_hook SECTION_END_(HOOK_SECTION(PRE_SUITE)); +f_report_hook SECTION_END_(HOOK_SECTION(PRE_INIT)); +f_report_hook SECTION_END_(HOOK_SECTION(PRE_TEST)); +f_report_hook SECTION_END_(HOOK_SECTION(ASSERT)); +f_report_hook SECTION_END_(HOOK_SECTION(THEORY_FAIL)); +f_report_hook SECTION_END_(HOOK_SECTION(TEST_CRASH)); +f_report_hook SECTION_END_(HOOK_SECTION(POST_TEST)); +f_report_hook SECTION_END_(HOOK_SECTION(POST_FINI)); +f_report_hook SECTION_END_(HOOK_SECTION(POST_SUITE)); +f_report_hook SECTION_END_(HOOK_SECTION(POST_ALL)); #endif IMPL_CALL_REPORT_HOOKS(PRE_ALL); diff --git a/src/runner.c b/src/runner.c index 2bed26a..a9dabba 100644 --- a/src/runner.c +++ b/src/runner.c @@ -47,8 +47,8 @@ #ifdef _MSC_VER struct criterion_test SECTION_START_(cr_tst); struct criterion_suite SECTION_START_(cr_sts); -struct criterion_test SECTION_STOP_(cr_tst); -struct criterion_suite SECTION_STOP_(cr_sts); +struct criterion_test SECTION_END_(cr_tst); +struct criterion_suite SECTION_END_(cr_sts); #endif IMPL_SECTION_LIMITS(struct criterion_test, cr_tst); From 45fc69463943f95a0c053f7f8bc1b788fdc5a651 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 00:17:03 +0200 Subject: [PATCH 16/40] Marked with dllexport/import API functions --- CMakeLists.txt | 1 + include/criterion/abort.h | 2 +- include/criterion/common.h | 25 +++++++++++++++++++++++++ include/criterion/criterion.h | 2 +- include/criterion/event.h | 3 ++- include/criterion/logging.h | 6 +++--- include/criterion/ordered-set.h | 4 ++-- include/criterion/theories.h | 16 ++++++++-------- 8 files changed, 43 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bc0bb2..5378a0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ set(GettextTranslate_ALL 1) set(GettextTranslate_GMO_BINARY 1) set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS ON) +add_definitions(-DCRITERION_BUILDING_DLL=1) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -std=gnu99") diff --git a/include/criterion/abort.h b/include/criterion/abort.h index f20e300..1df05c0 100644 --- a/include/criterion/abort.h +++ b/include/criterion/abort.h @@ -26,6 +26,6 @@ # include "common.h" -NORETURN void criterion_abort_test(void); +CR_API NORETURN void criterion_abort_test(void); #endif /* !CRITERION_ABORT_H_ */ diff --git a/include/criterion/common.h b/include/criterion/common.h index 2a1a630..238a9c2 100644 --- a/include/criterion/common.h +++ b/include/criterion/common.h @@ -111,4 +111,29 @@ # define FORMAT(Archetype, Index, Ftc) # endif +# if defined _WIN32 || defined __CYGWIN__ +# ifdef CRITERION_BUILDING_DLL +# ifdef __GNUC__ +# define CR_API __attribute__ ((dllexport)) +# else +# define CR_API __declspec(dllexport) +# endif +# else +# ifdef __GNUC__ +# define CR_API __attribute__ ((dllimport)) +# else +# define CR_API __declspec(dllimport) +# endif +# endif +# define CR_LOCAL +# else +# if __GNUC__ >= 4 +# define CR_API __attribute__ ((visibility ("default"))) +# define CR_LOCAL __attribute__ ((visibility ("hidden"))) +# else +# define CR_API +# define CR_LOCAL +# endif +# endif + #endif /* !CRITERION_COMMON_H_ */ diff --git a/include/criterion/criterion.h b/include/criterion/criterion.h index e68f841..51c82fd 100644 --- a/include/criterion/criterion.h +++ b/include/criterion/criterion.h @@ -67,6 +67,6 @@ .data = &SUITE_IDENTIFIER_(Name, extra), \ } SECTION_SUFFIX_ -int criterion_run_all_tests(void); +CR_API int criterion_run_all_tests(void); #endif /* !CRITERION_H_ */ diff --git a/include/criterion/event.h b/include/criterion/event.h index 99c85c8..db6cfe3 100644 --- a/include/criterion/event.h +++ b/include/criterion/event.h @@ -26,9 +26,10 @@ # include # include +# include "common.h" extern FILE *g_event_pipe; -void send_event(int kind, void *data, size_t size); +CR_API void send_event(int kind, void *data, size_t size); #endif /* !CRITERION_EVENT_H_ */ diff --git a/include/criterion/logging.h b/include/criterion/logging.h index 667bca9..c5bea18 100644 --- a/include/criterion/logging.h +++ b/include/criterion/logging.h @@ -76,13 +76,13 @@ extern const struct criterion_prefix_data g_criterion_logging_prefixes[]; # define CRITERION_PREFIX_PASS (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_PASS ]) # define CRITERION_PREFIX_FAIL (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_FAIL ]) -void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args); +CR_API void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args); FORMAT(printf, 3, 4) -void criterion_plog(enum criterion_logging_level level, const struct criterion_prefix_data *prefix, const char *msg, ...); +CR_API void criterion_plog(enum criterion_logging_level level, const struct criterion_prefix_data *prefix, const char *msg, ...); FORMAT(printf, 2, 3) -void criterion_log(enum criterion_logging_level level, const char *msg, ...); +CR_API void criterion_log(enum criterion_logging_level level, const char *msg, ...); # define criterion_info(...) criterion_log(CRITERION_INFO, __VA_ARGS__) # define criterion_important(...) criterion_log(CRITERION_IMPORTANT, __VA_ARGS__) diff --git a/include/criterion/ordered-set.h b/include/criterion/ordered-set.h index 4b71081..514f601 100644 --- a/include/criterion/ordered-set.h +++ b/include/criterion/ordered-set.h @@ -50,10 +50,10 @@ struct criterion_test_set { size_t tests; }; -struct criterion_ordered_set *new_ordered_set(f_criterion_cmp cmp, +CR_API struct criterion_ordered_set *new_ordered_set(f_criterion_cmp cmp, void (*dtor)(void *, void *)); -void *insert_ordered_set(struct criterion_ordered_set *l, +CR_API void *insert_ordered_set(struct criterion_ordered_set *l, void *ptr, size_t size); diff --git a/include/criterion/theories.h b/include/criterion/theories.h index 3f7cd80..ab98781 100644 --- a/include/criterion/theories.h +++ b/include/criterion/theories.h @@ -29,14 +29,14 @@ struct criterion_theory_context; -struct criterion_theory_context* cr_theory_init(void); -void cr_theory_push_arg(struct criterion_theory_context *ctx, bool is_float, size_t size, void *ptr); -void cr_theory_free(struct criterion_theory_context *ctx); -void cr_theory_abort(void); -int cr_theory_mark(void); +CR_API struct criterion_theory_context* cr_theory_init(void); +CR_API void cr_theory_push_arg(struct criterion_theory_context *ctx, bool is_float, size_t size, void *ptr); +CR_API void cr_theory_free(struct criterion_theory_context *ctx); +CR_API void cr_theory_abort(void); +CR_API int cr_theory_mark(void); -void cr_theory_reset(struct criterion_theory_context *ctx); -void cr_theory_call(struct criterion_theory_context *ctx, void (*fnptr)(void)); +CR_API void cr_theory_reset(struct criterion_theory_context *ctx); +CR_API void cr_theory_call(struct criterion_theory_context *ctx, void (*fnptr)(void)); # define TheoryDataPoints(Category, Name) \ static struct criterion_datapoints IDENTIFIER_(Category, Name, dps)[] @@ -64,7 +64,7 @@ struct criterion_datapoints { cr_theory_abort(); \ } while (0); -void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void)); +CR_API void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void)); # define CR_VAARG_ID(Suffix, Category, Name, ...) \ IDENTIFIER_(Category, Name, Suffix) From 933bbefa11c757ab12260355f93b12aa9b4824c6 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 00:25:29 +0200 Subject: [PATCH 17/40] Fixed wrong allocation size for theory indices --- src/theories.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/theories.c b/src/theories.c index 7cc86d9..3bf0f5b 100644 --- a/src/theories.c +++ b/src/theories.c @@ -186,7 +186,7 @@ static void concat_arg(char (*msg)[4096], struct criterion_datapoints *dps, size void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void)) { struct criterion_theory_context *ctx = cr_theory_init(); - size_t *indices = malloc(datapoints); + size_t *indices = malloc(sizeof (size_t) * datapoints); memset(indices, 0, datapoints * sizeof (size_t)); bool has_next = true; From 785c9e279724ddd20141b24598111cdb30955357 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 00:32:07 +0200 Subject: [PATCH 18/40] Exported main as API method --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 7995b34..50a86d6 100644 --- a/src/main.c +++ b/src/main.c @@ -120,7 +120,7 @@ int list_tests(bool unicode) { return 0; } -int main(int argc, char *argv[]) { +CR_API int main(int argc, char *argv[]) { static struct option opts[] = { {"verbose", optional_argument, 0, 'b'}, {"version", no_argument, 0, 'v'}, From 211f106cae0de66392b986a4da2679b0c2f97666 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 00:41:38 +0200 Subject: [PATCH 19/40] Made the tests c99-compliant --- test/ordered-set.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/ordered-set.c b/test/ordered-set.c index c25e638..3ecdbf1 100644 --- a/test/ordered-set.c +++ b/test/ordered-set.c @@ -1,4 +1,4 @@ -#include +#include #include "criterion/criterion.h" #include "criterion/ordered-set.h" @@ -14,7 +14,7 @@ int compare_lt(void *a, void *b) { } Test(ordered_set, contract_lt) { - smart struct criterion_ordered_set *set = new_ordered_set(compare_lt, NULL); + struct criterion_ordered_set *set = new_ordered_set(compare_lt, NULL); insert_ordered_set(set, &(int[1]) { 1 }, sizeof (int)); insert_ordered_set(set, &(int[1]) { 8 }, sizeof (int)); @@ -26,10 +26,12 @@ Test(ordered_set, contract_lt) { cr_assert_lt(*prev, *e); prev = e; } + + sfree(set); } Test(ordered_set, contract_gt) { - smart struct criterion_ordered_set *set = new_ordered_set(compare_gt, NULL); + struct criterion_ordered_set *set = new_ordered_set(compare_gt, NULL); insert_ordered_set(set, &(int[1]) { 1 }, sizeof (int)); insert_ordered_set(set, &(int[1]) { 8 }, sizeof (int)); @@ -41,4 +43,6 @@ Test(ordered_set, contract_gt) { cr_assert_gt(*prev, *e); prev = e; } + + sfree(set); } From 734dad43906695c2f9d9fd4e0ece2478dcdc5b67 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 00:44:10 +0200 Subject: [PATCH 20/40] Temporarily removing uninstall goal to support IDEs cmake targets --- CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5378a0a..e7acfdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,6 @@ set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale) set(GettextTranslate_ALL 1) set(GettextTranslate_GMO_BINARY 1) -set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS ON) add_definitions(-DCRITERION_BUILDING_DLL=1) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -std=gnu99") @@ -163,10 +162,6 @@ install(TARGETS criterion ARCHIVE DESTINATION lib ) -add_custom_target(uninstall - "${CMAKE_COMMAND}" -P "${CMAKE_MODULE_PATH}/uninstall.cmake" -) - enable_testing() add_subdirectory(samples) add_subdirectory(test) From b4b6b611ea38149ff42e87b22dc4a713af8991b5 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 00:44:45 +0200 Subject: [PATCH 21/40] Restored NLS back --- CMakeLists.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7acfdb..a0fb36c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,13 +53,13 @@ endif() # Find dependencies -#find_package(Gettext) -#find_package(Libintl) -#if (GETTEXT_FOUND AND LIBINTL_LIB_FOUND) -# include(GettextTranslate) -# add_subdirectory(po) -# set(ENABLE_NLS 1) -#endif () +find_package(Gettext) +find_package(Libintl) +if (GETTEXT_FOUND AND LIBINTL_LIB_FOUND) + include(GettextTranslate) + add_subdirectory(po) + set(ENABLE_NLS 1) +endif () include(CheckLibraryExists) CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME) From 690c88e0c3053ef4f8425610f028f931195754ad Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 00:45:20 +0200 Subject: [PATCH 22/40] Removed .def file generation --- CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a0fb36c..f6005a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,12 +149,6 @@ if (COVERALLS) coveralls_setup("${SOURCE_FILES}" ${COVERALLS_UPLOAD}) endif() -if (WIN32) - set_target_properties(criterion PROPERTIES LINK_FLAGS - "-Wl,--output-def,${CMAKE_CURRENT_BINARY_DIR}/libcriterion.def") - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcriterion.def DESTINATION lib) -endif () - install(FILES ${INTERFACE_FILES} DESTINATION include/criterion) install(TARGETS criterion RUNTIME DESTINATION bin From 9499590ad42e4b38a56b84378653ab65c7443b38 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 5 Sep 2015 15:47:47 -0700 Subject: [PATCH 23/40] Don't set gcc-specific flags on VC --- CMakeLists.txt | 6 ++++-- test/CMakeLists.txt | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6005a1..02c1349 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,13 +31,15 @@ set(GettextTranslate_GMO_BINARY 1) add_definitions(-DCRITERION_BUILDING_DLL=1) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -std=gnu99") +if (NOT MSVC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -std=gnu99") +endif () if (MSVC) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") endif () -if (WIN32) +if (WIN32 AND NOT MSVC) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-no-undefined") endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e3d4704..2a575a5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,6 @@ -set(CMAKE_C_FLAGS "-std=gnu99 -Wall -Wextra") +if (NOT MSVC) + set(CMAKE_C_FLAGS "-std=gnu99 -Wall -Wextra") +endif () include_directories(../include ../src) From a630645b5ed5521dc4fdf0557493ff3cc0461db3 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 01:01:48 +0200 Subject: [PATCH 24/40] Trying to clean up appveyor config --- appveyor.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 049a066..eb11a75 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ version: 1.3.1_b{build}-{branch} -os: Windows Server 2012 +os: Visual Studio 2015 init: - git config --global core.autocrlf input @@ -13,6 +13,9 @@ environment: CI_JOB_ID: $(APPVEYOR_JOB_ID) LOCAL_INSTALL: $(APPVEYOR_BUILD_FOLDER) GCOV_PREFIX: $(APPVEYOR_BUILD_FOLDER) + matrix: + - COMPILER: msvc + - COMPILER: mingw clone_depth: 5 @@ -29,14 +32,22 @@ install: - 'git checkout -B %APPVEYOR_REPO_BRANCH%' # Configure project - 'mkdir build && cd build' - - 'cmake -DCMAKE_INSTALL_PREFIX=criterion-%APPVEYOR_REPO_TAG_NAME% -DCMAKE_PREFIX_PATH="%LOCAL_INSTALL%" -DCOVERALLS=ON -DCMAKE_BUILD_TYPE=Debug -G "MSYS Makefiles" ..' + - > + cmake + -DCMAKE_INSTALL_PREFIX=criterion-%APPVEYOR_REPO_TAG_NAME% + -DCMAKE_PREFIX_PATH="%LOCAL_INSTALL%" + -DCOVERALLS=ON + -DCMAKE_BUILD_TYPE=Debug + -G "MSYS Makefiles" + .. build_script: - 'make' -after_build: +before_deploy: - 'make install' - 'bash -lc "cd $APPVEYOR_BUILD_FOLDER; tar -cvjf criterion-${APPVEYOR_REPO_BRANCH}-windows-${PLATFORM}.tar.bz2 -C build criterion-${APPVEYOR_REPO_TAG_NAME}"' + - ps: Push-AppveyorArtifact "../criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar.bz2" test_script: - 'make test || bash -lc "cat $APPVEYOR_BUILD_FOLDER/build/Testing/Temporary/LastTest.log"' @@ -50,9 +61,6 @@ notifications: to: [franklinmathieu@gmail.com] on_build_status_changed: true -artifacts: - - path: '**\*.tar.bz2' - deploy: provider: GitHub auth_token: From 99385e2f38065cfe929cd0368d935cbe53bc5f72 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 01:22:58 +0200 Subject: [PATCH 25/40] Added msvc builds to appveyor --- appveyor.yml | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index eb11a75..c171866 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -32,25 +32,41 @@ install: - 'git checkout -B %APPVEYOR_REPO_BRANCH%' # Configure project - 'mkdir build && cd build' - - > - cmake - -DCMAKE_INSTALL_PREFIX=criterion-%APPVEYOR_REPO_TAG_NAME% - -DCMAKE_PREFIX_PATH="%LOCAL_INSTALL%" - -DCOVERALLS=ON - -DCMAKE_BUILD_TYPE=Debug - -G "MSYS Makefiles" - .. + - ps: | + if ($env:Compiler -eq "mingw") { + $generator = "MSYS Makefiles" + } else { + $generator = "Visual Studio 14 2015" + } + cmake ` + -DCMAKE_INSTALL_PREFIX=criterion-%APPVEYOR_REPO_TAG_NAME% ` + -DCMAKE_PREFIX_PATH="%LOCAL_INSTALL%" ` + -DCOVERALLS=ON ` + -DCMAKE_BUILD_TYPE=Debug ` + -G "$generator" ` + .. build_script: - - 'make' + - ps: | + if ($env:Compiler -eq "mingw") { + make + } else { + msbuild /m:4 /p:Configuration=Debug:Config Criterion.sln + } before_deploy: - - 'make install' - - 'bash -lc "cd $APPVEYOR_BUILD_FOLDER; tar -cvjf criterion-${APPVEYOR_REPO_BRANCH}-windows-${PLATFORM}.tar.bz2 -C build criterion-${APPVEYOR_REPO_TAG_NAME}"' - - ps: Push-AppveyorArtifact "../criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar.bz2" + - ps: | + if ($env:Compiler -eq "mingw") { + make install + bash -lc "cd $APPVEYOR_BUILD_FOLDER; tar -cvjf criterion-${APPVEYOR_REPO_BRANCH}-windows-${PLATFORM}.tar.bz2 -C build criterion-${APPVEYOR_REPO_TAG_NAME}" + Push-AppveyorArtifact "../criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar.bz2" + } test_script: - - 'make test || bash -lc "cat $APPVEYOR_BUILD_FOLDER/build/Testing/Temporary/LastTest.log"' + - ps: | + if ($env:Compiler -eq "mingw") { + make test || type Testing/Temporary/LastTest.log + } #after_test: # - 'make coveralls' From c8db617e57e90437738ab972c3b000cbe4e2d7b3 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 01:24:25 +0200 Subject: [PATCH 26/40] Disabling Coveralls altogether in appveyor builds --- appveyor.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c171866..c9c3e18 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -41,8 +41,6 @@ install: cmake ` -DCMAKE_INSTALL_PREFIX=criterion-%APPVEYOR_REPO_TAG_NAME% ` -DCMAKE_PREFIX_PATH="%LOCAL_INSTALL%" ` - -DCOVERALLS=ON ` - -DCMAKE_BUILD_TYPE=Debug ` -G "$generator" ` .. From e49120792052966e1075c36a36c5b331b161391f Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 01:28:23 +0200 Subject: [PATCH 27/40] Added -Wno-dev warning remover for CI builds --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index c9c3e18..6d3abfa 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -39,6 +39,7 @@ install: $generator = "Visual Studio 14 2015" } cmake ` + -Wno-dev ` -DCMAKE_INSTALL_PREFIX=criterion-%APPVEYOR_REPO_TAG_NAME% ` -DCMAKE_PREFIX_PATH="%LOCAL_INSTALL%" ` -G "$generator" ` From b3d8ed244ff18e8e336454d5773ba0d5993f51a7 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 01:33:14 +0200 Subject: [PATCH 28/40] Fixed typo in configuration property in appveyor yml --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 6d3abfa..677c1d0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -50,7 +50,7 @@ build_script: if ($env:Compiler -eq "mingw") { make } else { - msbuild /m:4 /p:Configuration=Debug:Config Criterion.sln + msbuild /m:4 /p:Configuration=Debug /p:Platform=Win32 Criterion.sln } before_deploy: From 3f8e179a74813ae8f68e88a81e30ffc0d4a7c4c8 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 01:45:10 +0200 Subject: [PATCH 29/40] Fixed || not being recognised in powershell script --- appveyor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 677c1d0..b77410c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -64,7 +64,8 @@ before_deploy: test_script: - ps: | if ($env:Compiler -eq "mingw") { - make test || type Testing/Temporary/LastTest.log + try { make test } + catch { type Testing/Temporary/LastTest.log } } #after_test: From 19ecd3818eaecd2383f798ca3574c98029472bf5 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 01:54:23 +0200 Subject: [PATCH 30/40] Changed build conditions to use cmake --build --- appveyor.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b77410c..10c77f6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,7 +15,13 @@ environment: GCOV_PREFIX: $(APPVEYOR_BUILD_FOLDER) matrix: - COMPILER: msvc + BUILD_TARGET: all_build + TEST_TARGET: run_tests + INSTALL_TARGET: install - COMPILER: mingw + BUILD_TARGET: all + TEST_TARGET: test + INSTALL_TARGET: install clone_depth: 5 @@ -47,26 +53,20 @@ install: build_script: - ps: | - if ($env:Compiler -eq "mingw") { - make - } else { - msbuild /m:4 /p:Configuration=Debug /p:Platform=Win32 Criterion.sln - } + cmake --build . --target $env:BUILD_TARGET before_deploy: - ps: | if ($env:Compiler -eq "mingw") { - make install + cmake --build . --target $env:INSTALL_TARGET bash -lc "cd $APPVEYOR_BUILD_FOLDER; tar -cvjf criterion-${APPVEYOR_REPO_BRANCH}-windows-${PLATFORM}.tar.bz2 -C build criterion-${APPVEYOR_REPO_TAG_NAME}" Push-AppveyorArtifact "../criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar.bz2" } test_script: - ps: | - if ($env:Compiler -eq "mingw") { - try { make test } - catch { type Testing/Temporary/LastTest.log } - } + try { cmake --build . --target $env:TEST_TARGET } + catch { type Testing/Temporary/LastTest.log } #after_test: # - 'make coveralls' From 507c3183e653f1ac024f3eaee5f72386539f5ccc Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 02:04:06 +0200 Subject: [PATCH 31/40] Run MinGW build before MSVC --- appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 10c77f6..cd7057b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,14 +14,14 @@ environment: LOCAL_INSTALL: $(APPVEYOR_BUILD_FOLDER) GCOV_PREFIX: $(APPVEYOR_BUILD_FOLDER) matrix: - - COMPILER: msvc - BUILD_TARGET: all_build - TEST_TARGET: run_tests - INSTALL_TARGET: install - COMPILER: mingw BUILD_TARGET: all TEST_TARGET: test INSTALL_TARGET: install + - COMPILER: msvc + BUILD_TARGET: all_build + TEST_TARGET: run_tests + INSTALL_TARGET: install clone_depth: 5 From 745d6be22982c2f359d4734cda10562b7d63973a Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 02:08:34 +0200 Subject: [PATCH 32/40] Use cmd for build command --- appveyor.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index cd7057b..b2e4b57 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -52,8 +52,7 @@ install: .. build_script: - - ps: | - cmake --build . --target $env:BUILD_TARGET + - cmake --build . --target %BUILD_TARGET% before_deploy: - ps: | From 44452bc466beff238c01a3a4e34f87fef0cba806 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 02:18:12 +0200 Subject: [PATCH 33/40] Use 7z rather than tar to package the artifacts --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index b2e4b57..12a2502 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -58,7 +58,7 @@ before_deploy: - ps: | if ($env:Compiler -eq "mingw") { cmake --build . --target $env:INSTALL_TARGET - bash -lc "cd $APPVEYOR_BUILD_FOLDER; tar -cvjf criterion-${APPVEYOR_REPO_BRANCH}-windows-${PLATFORM}.tar.bz2 -C build criterion-${APPVEYOR_REPO_TAG_NAME}" + 7z a "../criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar.bz2" "criterion-$env:APPVEYOR_REPO_TAG_NAME" Push-AppveyorArtifact "../criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar.bz2" } From c0c80d588875d485d588bf0c0dcb8d080a23e8e6 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 02:22:23 +0200 Subject: [PATCH 34/40] Fixed environment variables not being expanded in ps script in appveyor config --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 12a2502..3553559 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -46,8 +46,8 @@ install: } cmake ` -Wno-dev ` - -DCMAKE_INSTALL_PREFIX=criterion-%APPVEYOR_REPO_TAG_NAME% ` - -DCMAKE_PREFIX_PATH="%LOCAL_INSTALL%" ` + "-DCMAKE_INSTALL_PREFIX=criterion-$env:APPVEYOR_REPO_TAG_NAME" ` + "-DCMAKE_PREFIX_PATH=$env:LOCAL_INSTALL" ` -G "$generator" ` .. From d65b1c951dad786e033251db77275f44bd1471b7 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 02:42:38 +0200 Subject: [PATCH 35/40] Copy the missing criterion.dll into the samples & test build directories --- appveyor.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 3553559..d4e5274 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -53,6 +53,12 @@ install: build_script: - cmake --build . --target %BUILD_TARGET% + - ps: | + # HACK: We need to copy criterion.dll into the binary directory + if ($env:Compiler -eq "msvc") { + Copy-Item Debug/criterion.dll samples/Debug/ + Copy-Item Debug/criterion.dll test/Debug/ + } before_deploy: - ps: | From af45e407bb0c1370d6bf12eebd9c159f53001c45 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 02:45:58 +0200 Subject: [PATCH 36/40] Removed script-based tests when building with visual studio --- samples/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 5bdb842..5934663 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -48,6 +48,8 @@ foreach(sample ${SAMPLES}) ) endforeach() +if (NOT MSVC) # we disable the scripted tests when building with MSVC + foreach(script ${SCRIPTS}) add_test(${script} sh ${CMAKE_CURRENT_LIST_DIR}/tests/${script}.sh) set_property(TEST ${script} PROPERTY @@ -61,3 +63,5 @@ foreach(script ${SCRIPTS}) ENVIRONMENT "CRITERION_SHORT_FILENAME=1" ) endforeach() + +endif() From e42c57fdacb439dda054f9d3b866e983a3c8cac2 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 02:52:13 +0200 Subject: [PATCH 37/40] Cleaned up appveyor config --- appveyor.yml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d4e5274..0d8f165 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,10 +18,12 @@ environment: BUILD_TARGET: all TEST_TARGET: test INSTALL_TARGET: install + GENERATOR: "MSYS Makefiles" - COMPILER: msvc BUILD_TARGET: all_build TEST_TARGET: run_tests INSTALL_TARGET: install + GENERATOR: "Visual Studio 14 2015" clone_depth: 5 @@ -38,18 +40,13 @@ install: - 'git checkout -B %APPVEYOR_REPO_BRANCH%' # Configure project - 'mkdir build && cd build' - - ps: | - if ($env:Compiler -eq "mingw") { - $generator = "MSYS Makefiles" - } else { - $generator = "Visual Studio 14 2015" - } - cmake ` - -Wno-dev ` - "-DCMAKE_INSTALL_PREFIX=criterion-$env:APPVEYOR_REPO_TAG_NAME" ` - "-DCMAKE_PREFIX_PATH=$env:LOCAL_INSTALL" ` - -G "$generator" ` - .. + - > + cmake + -Wno-dev + -DCMAKE_INSTALL_PREFIX="criterion-%APPVEYOR_REPO_TAG_NAME%" + -DCMAKE_PREFIX_PATH="%LOCAL_INSTALL%" + -G "%GENERATOR%" + .. build_script: - cmake --build . --target %BUILD_TARGET% From 2e1ac26f5a349cc59fbfaf0c850e07302c1dc0af Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 03:04:18 +0200 Subject: [PATCH 38/40] Trying to fix the 7z command --- appveyor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 0d8f165..f6258b9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -61,7 +61,8 @@ before_deploy: - ps: | if ($env:Compiler -eq "mingw") { cmake --build . --target $env:INSTALL_TARGET - 7z a "../criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar.bz2" "criterion-$env:APPVEYOR_REPO_TAG_NAME" + 7z a -ttar "criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar" "criterion-$env:APPVEYOR_REPO_TAG_NAME" + 7z a -tbzip2 "../criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar.bz2" "criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar" Push-AppveyorArtifact "../criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar.bz2" } From 6b91180c9ac9963cbf4b5f25716580a2da928bc0 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 03:29:41 +0200 Subject: [PATCH 39/40] Disabled comparison tests for MSVC builds --- samples/CMakeLists.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 5934663..d8e1d14 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -40,12 +40,14 @@ foreach(sample ${SAMPLES}) ENVIRONMENT "CRITERION_ALWAYS_SUCCEED=1" ) - add_test(${sample}_compare sh ${CMAKE_CURRENT_LIST_DIR}/tests/run_test.sh "${CMAKE_CURRENT_LIST_DIR}" . . ${sample}) - set_property(TEST ${sample}_compare PROPERTY - ENVIRONMENT "LC_ALL=en_US.utf8" - ENVIRONMENT "CRITERION_ALWAYS_SUCCEED=1" - ENVIRONMENT "CRITERION_SHORT_FILENAME=1" - ) + if (NOT MSVC) # we disable the scripted tests when building with MSVC + add_test(${sample}_compare sh ${CMAKE_CURRENT_LIST_DIR}/tests/run_test.sh "${CMAKE_CURRENT_LIST_DIR}" . . ${sample}) + set_property(TEST ${sample}_compare PROPERTY + ENVIRONMENT "LC_ALL=en_US.utf8" + ENVIRONMENT "CRITERION_ALWAYS_SUCCEED=1" + ENVIRONMENT "CRITERION_SHORT_FILENAME=1" + ) + endif () endforeach() if (NOT MSVC) # we disable the scripted tests when building with MSVC From 04523d303f49bd0a3d43c20a9513d3f212e9d08d Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 6 Sep 2015 03:35:48 +0200 Subject: [PATCH 40/40] Fixed artifacts being pushed when there is no git tag --- appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index f6258b9..ca061d3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -59,11 +59,11 @@ build_script: before_deploy: - ps: | - if ($env:Compiler -eq "mingw") { + if ($env:Compiler -eq "mingw" -and !$env:APPVEYOR_REPO_TAG_NAME) { cmake --build . --target $env:INSTALL_TARGET 7z a -ttar "criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar" "criterion-$env:APPVEYOR_REPO_TAG_NAME" - 7z a -tbzip2 "../criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar.bz2" "criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar" - Push-AppveyorArtifact "../criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar.bz2" + 7z a -tbzip2 "../criterion-$env:APPVEYOR_REPO_TAG_NAME-windows-$env:PLATFORM.tar.bz2" "criterion-$env:APPVEYOR_REPO_TAG_NAME-windows-$env:PLATFORM.tar" + Push-AppveyorArtifact "../criterion-$env:APPVEYOR_REPO_TAG_NAME-windows-$env:PLATFORM.tar.bz2" } test_script: