<commit_before>/* Check-Plus: An EDSL for declaring unit tests using Check
 * Copyright (C) 2010 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <check.h>

#define __used __attribute__((used))

Suite *gc_suite();
Suite *vm_suite();

typedef void (*test_func)(int);
typedef void (*test_hook)(void);

struct test_case {
    test_func  *funcs, *end_funcs;
    const char *test_name;
    test_hook *setup_hooks, *end_setup_hooks;
    test_hook *teardown_hooks, *end_teardown_hooks;
};

struct test_suite {
    struct test_case *cases, *end_cases;
    const char *suite_name;
};

#define BEGIN_SUITE(name) _BEGIN_SUITE(SUITE_NAME, name)
#define _BEGIN_SUITE(sym, name) __BEGIN_SUITE(sym, name)
#define __BEGIN_SUITE(sym, name)                                        \
    extern struct test_case _begin_ ## sym ## _cases[];                 \
    extern struct test_case _end_ ## sym ## _cases[];                   \
    struct test_suite _suite_ ## sym = {                                \
        .cases       = (struct test_case*)_begin_ ## sym ## _cases,     \
        .end_cases   = (struct test_case*)_end_ ## sym ## _cases,       \
        .suite_name  = name,                                            \
    };                                                                  \
    struct test_case _begin_ ## sym ## _cases[0]                        \
    __attribute__((section(".data." #sym ".cases")))                    \

#define BEGIN_TEST_CASE(name) _BEGIN_TEST_CASE(SUITE_NAME, TEST_CASE, name)
#define _BEGIN_TEST_CASE(sym, test, name) __BEGIN_TEST_CASE(sym, test, name)

#define __BEGIN_TEST_CASE(suite, test, name)                    \
    _BEGIN_TEST_CASE_IMPL(suite, suite ## _ ## test,            \
                ".data." #suite "." #test, name)

#define _BEGIN_TEST_CASE_IMPL(suite, sym, sec, name)            \
    extern test_func _begin_ ## sym ## _funcs[];                \
    extern test_hook _begin_ ## sym ## _setup[];                \
    extern test_hook _begin_ ## sym ## _teardown[];             \
    extern test_func _end_ ## sym ## _funcs[];                  \
    extern test_hook _end_ ## sym ## _setup[];                  \
    extern test_hook _end_ ## sym ## _teardown[];               \
    struct test_case _test_ ## sym                              \
    __attribute__((section(".data." #suite ".cases"),           \
                   aligned(__alignof__(struct test_case)))) = { \
        .test_name = name,                                      \
        .funcs = _begin_ ## sym ## _funcs,                      \
        .end_funcs = _end_ ## sym ## _funcs,                    \<commit_msg>Kill `extern' for forward-declarations in the same compilation unit.<commit_after>/* Check-Plus: An EDSL for declaring unit tests using Check
 * Copyright (C) 2010 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <check.h>

#define __used __attribute__((used))

Suite *gc_suite();
Suite *vm_suite();

typedef void (*test_func)(int);
typedef void (*test_hook)(void);

struct test_case {
    test_func  *funcs, *end_funcs;
    const char *test_name;
    test_hook *setup_hooks, *end_setup_hooks;
    test_hook *teardown_hooks, *end_teardown_hooks;
};

struct test_suite {
    struct test_case *cases, *end_cases;
    const char *suite_name;
};

#define BEGIN_SUITE(name) _BEGIN_SUITE(SUITE_NAME, name)
#define _BEGIN_SUITE(sym, name) __BEGIN_SUITE(sym, name)
#define __BEGIN_SUITE(sym, name)                                        \
    struct test_case _begin_ ## sym ## _cases[];                        \
    struct test_case _end_ ## sym ## _cases[];                          \
    struct test_suite _suite_ ## sym = {                                \
        .cases       = (struct test_case*)_begin_ ## sym ## _cases,     \
        .end_cases   = (struct test_case*)_end_ ## sym ## _cases,       \
        .suite_name  = name,                                            \
    };                                                                  \
    struct test_case _begin_ ## sym ## _cases[0]                        \
    __attribute__((section(".data." #sym ".cases")))                    \

#define BEGIN_TEST_CASE(name) _BEGIN_TEST_CASE(SUITE_NAME, TEST_CASE, name)
#define _BEGIN_TEST_CASE(sym, test, name) __BEGIN_TEST_CASE(sym, test, name)

#define __BEGIN_TEST_CASE(suite, test, name)                    \
    _BEGIN_TEST_CASE_IMPL(suite, suite ## _ ## test,            \
                ".data." #suite "." #test, name)

#define _BEGIN_TEST_CASE_IMPL(suite, sym, sec, name)            \
    test_func _begin_ ## sym ## _funcs[];                       \
    test_hook _begin_ ## sym ## _setup[];                       \
    test_hook _begin_ ## sym ## _teardown[];                    \
    test_func _end_ ## sym ## _funcs[];                         \
    test_hook _end_ ## sym ## _setup[];                         \
    test_hook _end_ ## sym ## _teardown[];                      \
    struct test_case _test_ ## sym                              \
    __attribute__((section(".data." #suite ".cases"),           \
                   aligned(__alignof__(struct test_case)))) = { \
        .test_name = name,                                      \
        .funcs = _begin_ ## sym ## _funcs,                      \
        .end_funcs = _end_ ## sym ## _funcs,                    \
{'fraction_non_alphanumeric': 0.10001479508803078, 'fraction_numerical': 0.005326231691078562, 'mean_word_length': 1.870488322717622, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6664050', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1876, 'n_words': 586}