<commit_before>#include "../include/luawrapp.h"

#include <utility>

#include <stdio.h>
#include <vector>
#include <type_traits>

#include <Windows.h>

struct test_context {
    HANDLE con;
    unsigned started { 0 };
    unsigned failed { 0 };
    unsigned passed { 0 };
    test_context() {
        con = GetStdHandle( STD_OUTPUT_HANDLE );
    }
    void begin_test( const char* name_ ) {
        SetConsoleTextAttribute( con, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED );
        printf( "test %s ...", name_ );
        ++started;
    }

    void test_ok() {
        SetConsoleTextAttribute( con, FOREGROUND_GREEN );
        printf( "%s\r\n", "ok" );
        ++passed;
    }

    void test_failed() {
        SetConsoleTextAttribute( con, FOREGROUND_RED );
        printf( "%s\r\n", "failed" );
        ++failed;
    }

    void test_failed( const char* msg_ ) {
        SetConsoleTextAttribute( con, FOREGROUND_RED );
        printf( "%s\r\n", "failed" );
        SetConsoleTextAttribute( con, FOREGROUND_RED );
        printf( "%s\r\n", msg_ );
        ++failed;
    }

    ~test_context() {
        SetConsoleTextAttribute( con, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED );
        printf( "=============\r\nTests run: %d\r\n", started );
        SetConsoleTextAttribute( con, FOREGROUND_GREEN );
        printf( "Tests passed: %d\r\n", passed );
        SetConsoleTextAttribute( con, FOREGROUND_RED );
        printf( "Tests failed: %d\r\n", failed );
        SetConsoleTextAttribute( con, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED );
        printf( "%s", "press a key to exit" );
        getchar();
    }
};
#define DefTest(name_, code_) struct name_ { name_(test_context& ctx_ ) { ctx_.begin_test(#name_); code_ ctx_.test_ok(); } };
DefTest( unique_context, {
    lua::unique_context ctx;
    ctx.open( {} );
} )
DefTest( shared_context, {
    lua::shared_context ctx;
    ctx.open( {} );

    auto copy = ctx;
    ctx.close();
} )

template<typename... Tests>
struct test_set {

    template<typename First>
    void do_tests( test_context& ctx_ ) {
        try {
            First f { ctx_ };
        } catch ( const std::exception& e_ ) {
            ctx_.test_failed( e_.what() );
        } catch ( ... ) {
            ctx_.test_failed();
        }
    }
    template<typename First, typename... Others>
    typename std::enable_if<sizeof...( Others ) != 0>::type do_tests( test_context & ctx_ ) {
        try {
            First f { ctx_ };
        } catch ( ... ) {
            ctx_.test_failed();
        }
        do_tests<Others...>(ctx_);
    }

    test_set() {
        test_context ctx;
        do_tests<Tests...>(ctx);
    }

}; 

void main() {
    test_set<unique_context, shared_context> test {};
}<commit_msg>updated test stuff<commit_after>#include "../include/luawrapp.h"

#include <utility>

#include <stdio.h>
#include <vector>
#include <type_traits>

#include <Windows.h>

struct test_context {
    HANDLE con;
    unsigned started { 0 };
    unsigned failed { 0 };
    unsigned passed { 0 };
    test_context() {
        con = GetStdHandle( STD_OUTPUT_HANDLE );
    }
    void begin_test( const char* name_ ) {
        SetConsoleTextAttribute( con, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED );
        printf( "test %s ...", name_ );
        ++started;
    }

    void test_ok() {
        SetConsoleTextAttribute( con, FOREGROUND_GREEN );
        printf( "%s\r\n", "ok" );
        ++passed;
    }

    void test_failed() {
        SetConsoleTextAttribute( con, FOREGROUND_RED );
        printf( "%s\r\n", "failed" );
        ++failed;
    }

    void test_failed( const char* msg_ ) {
        SetConsoleTextAttribute( con, FOREGROUND_RED );
        printf( "%s\r\n", "failed" );
        SetConsoleTextAttribute( con, FOREGROUND_RED );
        printf( "%s\r\n", msg_ );
        ++failed;
    }

    ~test_context() {
        SetConsoleTextAttribute( con, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED );
        printf( "=============\r\nTests run: %d\r\n", started );
        SetConsoleTextAttribute( con, FOREGROUND_GREEN );
        printf( "Tests passed: %d\r\n", passed );
        SetConsoleTextAttribute( con, FOREGROUND_RED );
        printf( "Tests failed: %d\r\n", failed );
        SetConsoleTextAttribute( con, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED );
        printf( "%s", "press a key to exit" );
        getchar();
    }
};

struct test_token {
    virtual ~test_token() = default;
    virtual void run( test_context& __tctx__ ) = 0;
};

template<typename Test>
struct test_instance : test_token {
    Test _instance;
    virtual void run( test_context& __tctx__ ) override {
        __tctx__.begin_test( _instance.name() );
        try {
            _instance.run_test( __tctx__ );
            __tctx__.test_ok();
        } catch ( const std::exception& e_ ) {
            __tctx__.test_failed( e_.what() );
        } catch ( ... ) {
            __tctx__.test_failed();
        }
    }
};

std::vector<std::unique_ptr<test_token>> _test_set;

void do_all_tests() {
    test_context ctx {};
    for ( auto& test : _test_set ) {
        test->run(ctx);
    }
}

template<typename RegTest>
test_token* reg_test() {
    auto ptr = new test_instance<RegTest> {};
    _test_set.emplace_back( ptr );
    return ptr;
}

#define TestClassName(case_,name_) case_##name_##_test
#define Test(case_,name_) \
struct TestClassName( case_, name_ ) {\
    const char* name() { return #case_": "#name_; }\
    void run_test(test_context& __tctx__);\
    static test_token* _tok;\
};\
    test_token* TestClassName( case_, name_ )::_tok = reg_test<TestClassName( case_, name_ )>();\
    void TestClassName( case_, name_ )::run_test(test_context& __tctx__)

Test( context, unique ) {
        lua::unique_context ctx;
        ctx.open( {} );
}

Test( context, shared ) {
    lua::shared_context ctx;
    ctx.open( {} );

    auto copy = ctx;

    ctx.close();
}
void main() {
    do_all_tests();
}
{'fraction_non_alphanumeric': 0.14364548494983279, 'fraction_numerical': 0.0013377926421404682, 'mean_word_length': 2.5474495848161327, 'pattern_counts': {'":': 1, '<': 26, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '293122', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1940, 'n_words': 430}