From edd62ccd71c822ef042e65f1b721b0a1f9d0cbf5 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Mon, 16 Mar 2015 15:12:18 +0100 Subject: [PATCH] Added portable size_t printf format code --- include/criterion/common.h | 6 ++++++ src/report.c | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/criterion/common.h b/include/criterion/common.h index 32d6420..cdeffa9 100644 --- a/include/criterion/common.h +++ b/include/criterion/common.h @@ -57,6 +57,12 @@ # define UNUSED __attribute__((unused)) +# ifdef _WIN32 +# define SIZE_T_FORMAT "%Iu" +# else +# define SIZE_T_FORMAT "%zu" +# endif + # ifdef __GNUC__ # define FORMAT(Archetype, Index, Ftc) __attribute__((format(Archetype, Index, Ftc))) # else diff --git a/src/report.c b/src/report.c index 0a79eb9..fc07f03 100644 --- a/src/report.c +++ b/src/report.c @@ -57,7 +57,7 @@ ReportHook(PRE_INIT)(struct criterion_test *test) { ReportHook(POST_TEST)(struct criterion_test_stats *stats) { if (criterion_options.enable_tap_format) { - criterion_important("%s %lu - %s::%s\n", + criterion_important("%s " SIZE_T_FORMAT " - %s::%s\n", stats->failed ? "not ok" : "ok", tap_test_index++, stats->test->category, @@ -93,13 +93,13 @@ ReportHook(PRE_ALL)(struct criterion_test_set *set) { for (struct criterion_test **test = set->tests; i < set->nb_tests; ++i) if (!(test[i])->data->disabled) ++enabled_count; - criterion_important("1..%lu\n", enabled_count); + criterion_important("1.." SIZE_T_FORMAT "\n", enabled_count); } } ReportHook(POST_ALL)(struct criterion_global_stats *stats) { if (criterion_options.enable_tap_format) return; - criterion_important("Synthesis: %lu tests were run. %lu passed, %lu failed (with %lu crashes)\n", + criterion_important("Synthesis: " SIZE_T_FORMAT " tests were run. " SIZE_T_FORMAT " passed, " SIZE_T_FORMAT " failed (with " SIZE_T_FORMAT " crashes)\n", stats->nb_tests, stats->tests_passed, stats->tests_failed, @@ -119,7 +119,7 @@ ReportHook(ASSERT)(struct criterion_assert_stats *stats) { ReportHook(TEST_CRASH)(struct criterion_test_stats *stats) { if (criterion_options.enable_tap_format) { - criterion_important("not ok %lu - %s::%s unexpected signal after %s:%u\n", + criterion_important("not ok " SIZE_T_FORMAT " - %s::%s unexpected signal after %s:%u\n", tap_test_index++, stats->test->category, stats->test->name,