<commit_before>﻿/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2013
<NAME>

This file is part of Application-Building Components (henceforth referred to as ABC).

ABC is free software: you can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.

ABC 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 General Public
License for more details.

You should have received a copy of the GNU General Public License along with ABC. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#include <abc/testing/core.hxx>
#include <abc/testing/test_case.hxx>
#include <abc/trace.hxx>



////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::testing::test_case


namespace abc {

namespace testing {

test_case::test_case() {
}


/*virtual*/ test_case::~test_case() {
}


void test_case::init(runner * prunner) {
   ABC_TRACE_FN((this, prunner));

   m_prunner = prunner;
}


void test_case::assert_does_not_throw(
   source_location const & srcloc, std::function<void ()> fnExpr, istr const & sExpr
) {
   ABC_TRACE_FN((this, srcloc, /*fnExpr, */sExpr));

   istr sCaughtWhat;
   try {
      fnExpr();
   } catch (::std::exception const & x) {
      sCaughtWhat = istr(SL("throws {}")).format(x.what());
   } catch (...) {
      sCaughtWhat = SL("unknown type");
   }
   m_prunner->log_assertion(srcloc, !sCaughtWhat, sExpr, istr(), SL("does not throw"), sCaughtWhat);
}


void test_case::assert_false(source_location const & srcloc, bool bActual, istr const & sExpr) {
   ABC_TRACE_FN((this, srcloc, bActual, sExpr));

   m_prunner->log_assertion(
      srcloc, !bActual, sExpr, istr(), !bActual ? istr() : SL("false"), SL("true")
   );
}


void test_case::assert_true(source_location const & srcloc, bool bActual, istr const & sExpr) {
   ABC_TRACE_FN((this, srcloc, bActual, sExpr));

   m_prunner->log_assertion(
      srcloc, bActual, sExpr, istr(), bActual ? istr() : SL("true"), SL("false")
   );
}


void test_case::assert_throws(
   source_location const & srcloc, std::function<void ()> fnExpr, istr const & sExpr,
   std::function<bool (std::exception const &)> fnMatchType, char const * pszExpectedWhat
) {
   bool bPass(false);
   istr sCaughtWhat;
   try {
      fnExpr();
      sCaughtWhat = SL("does not throw");
   } catch (::std::exception const & x) {
      if (fnMatchType(x)) {
         bPass = true;
      } else {
         sCaughtWhat = istr(SL("throws {}")).format(x.what());
      }
   } catch (...) {
      sCaughtWhat = SL("unknown type");
   }
   this->m_prunner->log_assertion(
      srcloc, bPass, sExpr, istr(), istr(SL("throws {}")).format(pszExpectedWhat), sCaughtWhat
   );
}

} //namespace testing

} //namespace abc


////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::testing::test_case_factory_impl


namespace abc {

namespace testing {

/*static*/ test_case_factory_impl::list_item * test_case_factory_impl::sm_pliHead(nullptr);
// MSC16 BUG: for some reason, this will be parsed as a function declaration if written as a
// constructor call.
/*static*/ test_case_factory_impl::list_item ** test_case_factory_impl::sm_ppliTailNext = nullptr;


test_case_factory_impl::test_case_factory_impl(list_item * pli) {
   if (sm_pliHead) {
      // We have a head and therefore a tail as well: add *pli as the new tail.
      *sm_ppliTailNext = pli;
   } else {
      // We don’t have a head yet: set it up now.
      sm_pliHead = pli;
   }
   // Save the “next” pointer of *pli for the next call.
   sm_ppliTailNext = &pli->pliNext;
}

} //namespace testing

} //namespace abc


////////////////////////////////////////////////////////////////////////////////////////////////////

<commit_msg>Add missing ABC_TRACE_FN<commit_after>﻿/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2013
<NAME>

This file is part of Application-Building Components (henceforth referred to as ABC).

ABC is free software: you can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.

ABC 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 General Public
License for more details.

You should have received a copy of the GNU General Public License along with ABC. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#include <abc/testing/core.hxx>
#include <abc/testing/test_case.hxx>
#include <abc/trace.hxx>



////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::testing::test_case


namespace abc {

namespace testing {

test_case::test_case() {
}


/*virtual*/ test_case::~test_case() {
}


void test_case::init(runner * prunner) {
   ABC_TRACE_FN((this, prunner));

   m_prunner = prunner;
}


void test_case::assert_does_not_throw(
   source_location const & srcloc, std::function<void ()> fnExpr, istr const & sExpr
) {
   ABC_TRACE_FN((this, srcloc, /*fnExpr, */sExpr));

   istr sCaughtWhat;
   try {
      fnExpr();
   } catch (::std::exception const & x) {
      sCaughtWhat = istr(SL("throws {}")).format(x.what());
   } catch (...) {
      sCaughtWhat = SL("unknown type");
   }
   m_prunner->log_assertion(srcloc, !sCaughtWhat, sExpr, istr(), SL("does not throw"), sCaughtWhat);
}


void test_case::assert_false(source_location const & srcloc, bool bActual, istr const & sExpr) {
   ABC_TRACE_FN((this, srcloc, bActual, sExpr));

   m_prunner->log_assertion(
      srcloc, !bActual, sExpr, istr(), !bActual ? istr() : SL("false"), SL("true")
   );
}


void test_case::assert_true(source_location const & srcloc, bool bActual, istr const & sExpr) {
   ABC_TRACE_FN((this, srcloc, bActual, sExpr));

   m_prunner->log_assertion(
      srcloc, bActual, sExpr, istr(), bActual ? istr() : SL("true"), SL("false")
   );
}


void test_case::assert_throws(
   source_location const & srcloc, std::function<void ()> fnExpr, istr const & sExpr,
   std::function<bool (std::exception const &)> fnMatchType, char const * pszExpectedWhat
) {
   ABC_TRACE_FN((this, srcloc, /*fnExpr, */sExpr, /*fnMatchType, */pszExpectedWhat));

   bool bPass(false);
   istr sCaughtWhat;
   try {
      fnExpr();
      sCaughtWhat = SL("does not throw");
   } catch (::std::exception const & x) {
      if (fnMatchType(x)) {
         bPass = true;
      } else {
         sCaughtWhat = istr(SL("throws {}")).format(x.what());
      }
   } catch (...) {
      sCaughtWhat = SL("unknown type");
   }
   this->m_prunner->log_assertion(
      srcloc, bPass, sExpr, istr(), istr(SL("throws {}")).format(pszExpectedWhat), sCaughtWhat
   );
}

} //namespace testing

} //namespace abc


////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::testing::test_case_factory_impl


namespace abc {

namespace testing {

/*static*/ test_case_factory_impl::list_item * test_case_factory_impl::sm_pliHead(nullptr);
// MSC16 BUG: for some reason, this will be parsed as a function declaration if written as a
// constructor call.
/*static*/ test_case_factory_impl::list_item ** test_case_factory_impl::sm_ppliTailNext = nullptr;


test_case_factory_impl::test_case_factory_impl(list_item * pli) {
   if (sm_pliHead) {
      // We have a head and therefore a tail as well: add *pli as the new tail.
      *sm_ppliTailNext = pli;
   } else {
      // We don’t have a head yet: set it up now.
      sm_pliHead = pli;
   }
   // Save the “next” pointer of *pli for the next call.
   sm_ppliTailNext = &pli->pliNext;
}

} //namespace testing

} //namespace abc


////////////////////////////////////////////////////////////////////////////////////////////////////


{'fraction_non_alphanumeric': 0.21544715447154472, 'fraction_numerical': 0.002152080344332855, 'mean_word_length': 2.4956122022565816, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '218316', 'n_tokens_mistral': 2669, 'n_tokens_neox': 2596, 'n_words': 726}