<commit_before>// This file is part of Poseidon.
// Copyleft 2022, LH_Mouse. All wrongs reserved.

#ifndef POSEIDON_TEST_UTILS_
#define POSEIDON_TEST_UTILS_

#include "../src/fwd.hpp"
#include "../src/utils.hpp"
#include <unistd.h>   // ::alarm()

#define POSEIDON_TEST_CHECK(expr)  \
    do  \
      try {  \
        if(static_cast<bool>(expr) == false) {  \
          /* failed */  \
          ::asteria::write_log_to_stderr(__FILE__, __LINE__, __func__,  \
              ::rocket::sref("POSEIDON_TEST_CHECK FAIL: " #expr));  \
          \
          ::abort();  \
        }  \
        \
        /* successful */  \
        ::asteria::write_log_to_stderr(__FILE__, __LINE__, __func__,  \
            ::rocket::sref("POSEIDON_TEST_CHECK PASS: " #expr));  \
      }  \
      catch(exception& stdex) {  \
        /* failed */  \
        ::asteria::write_log_to_stderr(__FILE__, __LINE__, __func__,  \
            ::rocket::cow_string("POSEIDON_TEST_CHECK EXCEPTION: " #expr)  \
              + "\n" + stdex.what());  \
        \
        ::abort();  \
      }  \
    while(false)

#define POSEIDON_TEST_CHECK_CATCH(expr)  \
    do  \
      try {  \
        (void) (expr);  \
        \
        /* failed */  \
        ::asteria::write_log_to_stderr(__FILE__, __LINE__, __func__,  \
            ::rocket::sref("POSEIDON_TEST_CHECK XPASS: " #expr));  \
        \
        ::abort();  \
      }  \
      catch(::std::exception& stdex) {  \
        /* successful */  \
        ::asteria::write_log_to_stderr(__FILE__, __LINE__, __func__,  \
            ::rocket::cow_string("POSEIDON_TEST_CHECK XFAIL: " #expr)  \
              + "\n" + stdex.what());  \
      }  \
    while(false)

// Set terminate handler.
static const auto poseidon_test_terminate = ::std::set_terminate(
    [] {
      auto eptr = ::std::current_exception();
      if(eptr) {
        try {
          ::std::rethrow_exception(eptr);
        }
        catch(::std::exception& stdex) {
          ::fprintf(stderr,
              "`::std::terminate()` called after `::std::exception`:\n%s\n",
              stdex.what());
        }
        catch(...) {
          ::fprintf(stderr,
              "`::std::terminate()` called after an unknown exception\n");
        }
      }
      else
        ::fprintf(stderr,
            "`::std::terminate()` called without an exception\n");

      ::fflush(nullptr);
      ::_Exit(1);
    });

// Set kill timer.
static const auto poseidon_test_alarm = ::alarm(30);

#endif
<commit_msg>test: Use qualified names for `::std::exception`<commit_after>// This file is part of Poseidon.
// Copyleft 2022, LH_Mouse. All wrongs reserved.

#ifndef POSEIDON_TEST_UTILS_
#define POSEIDON_TEST_UTILS_

#include "../src/fwd.hpp"
#include "../src/utils.hpp"
#include <unistd.h>   // ::alarm()

#define POSEIDON_TEST_CHECK(expr)  \
    do  \
      try {  \
        if(static_cast<bool>(expr) == false) {  \
          /* failed */  \
          ::asteria::write_log_to_stderr(__FILE__, __LINE__, __func__,  \
              ::rocket::sref("POSEIDON_TEST_CHECK FAIL: " #expr));  \
          \
          ::abort();  \
        }  \
        \
        /* successful */  \
        ::asteria::write_log_to_stderr(__FILE__, __LINE__, __func__,  \
            ::rocket::sref("POSEIDON_TEST_CHECK PASS: " #expr));  \
      }  \
      catch(::std::exception& stdex) {  \
        /* failed */  \
        ::asteria::write_log_to_stderr(__FILE__, __LINE__, __func__,  \
            ::rocket::cow_string("POSEIDON_TEST_CHECK EXCEPTION: " #expr)  \
              + "\n" + stdex.what());  \
        \
        ::abort();  \
      }  \
    while(false)

#define POSEIDON_TEST_CHECK_CATCH(expr)  \
    do  \
      try {  \
        (void) (expr);  \
        \
        /* failed */  \
        ::asteria::write_log_to_stderr(__FILE__, __LINE__, __func__,  \
            ::rocket::sref("POSEIDON_TEST_CHECK XPASS: " #expr));  \
        \
        ::abort();  \
      }  \
      catch(::std::exception& stdex) {  \
        /* successful */  \
        ::asteria::write_log_to_stderr(__FILE__, __LINE__, __func__,  \
            ::rocket::cow_string("POSEIDON_TEST_CHECK XFAIL: " #expr)  \
              + "\n" + stdex.what());  \
      }  \
    while(false)

// Set terminate handler.
static const auto poseidon_test_terminate = ::std::set_terminate(
    [] {
      auto eptr = ::std::current_exception();
      if(eptr) {
        try {
          ::std::rethrow_exception(eptr);
        }
        catch(::std::exception& stdex) {
          ::fprintf(stderr,
              "`::std::terminate()` called after `::std::exception`:\n%s\n",
              stdex.what());
        }
        catch(...) {
          ::fprintf(stderr,
              "`::std::terminate()` called after an unknown exception\n");
        }
      }
      else
        ::fprintf(stderr,
            "`::std::terminate()` called without an exception\n");

      ::fflush(nullptr);
      ::_Exit(1);
    });

// Set kill timer.
static const auto poseidon_test_alarm = ::alarm(30);

#endif

{'fraction_non_alphanumeric': 0.16566746602717825, 'fraction_numerical': 0.002797761790567546, 'mean_word_length': 1.8764367816091954, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2704651', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1710, 'n_words': 269}