<commit_before>#include "../UnitTest++.h"
#include "../TestMacros.h"
#include "../TestList.h"
#include "../TestResults.h"
#include "../TestReporter.h"
#include "../ReportAssert.h"
#include "RecordingReporter.h"

using namespace UnitTest;

namespace {

TestList list1;
TEST_EX(DummyTest, list1)
{
    (void)testResults_;
}

TEST (TestsAreAddedToTheListThroughMacro)
{
    CHECK (list1.GetHead() != 0);
    CHECK (list1.GetHead()->next == 0);
}

struct ThrowingThingie
{
    ThrowingThingie() : dummy(false)
    {
        if (!dummy)
            throw "Oops";
    } 
    bool dummy;
};

TestList list2;
TEST_FIXTURE_EX(ThrowingThingie,DummyTestName,list2)
{
    (void)testResults_;
}

TEST (ExceptionsInFixtureAreReportedAsHappeningInTheFixture)
{
    RecordingReporter reporter;
    TestResults result(&reporter);
    list2.GetHead()->Run(result);

    CHECK (strstr(reporter.lastFailedMessage, "xception"));
    CHECK (strstr(reporter.lastFailedMessage, "fixture"));
    CHECK (strstr(reporter.lastFailedMessage, "ThrowingThingie"));
}

struct DummyFixture
{
    int x;
};

// We're really testing the macros so we just want them to compile and link
SUITE(TestSuite1)
{

	TEST(SimilarlyNamedTestsInDifferentSuitesWork)
	{
		(void)testResults_;
	}

	TEST_FIXTURE(DummyFixture,SimilarlyNamedFixtureTestsInDifferentSuitesWork)
	{
	    (void)testResults_;
	}

}

SUITE(TestSuite2)
{

	TEST(SimilarlyNamedTestsInDifferentSuitesWork)
	{
	    (void)testResults_;
	}

	TEST_FIXTURE(DummyFixture,SimilarlyNamedFixtureTestsInDifferentSuitesWork)
	{
	    (void)testResults_;
	}

}

TestList macroTestList1;
TEST_EX(MacroTestHelper1,macroTestList1)
{
    (void)testResults_;
}

TEST(TestAddedWithTEST_EXMacroGetsDefaultSuite)
{
    CHECK(macroTestList1.GetHead() != NULL);
    CHECK_EQUAL ("MacroTestHelper1", macroTestList1.GetHead()->m_details.testName);
    CHECK_EQUAL ("DefaultSuite", macroTestList1.GetHead()->m_details.suiteName);
}

TestList macroTestList2;
TEST_FIXTURE_EX(DummyFixture,MacroTestHelper2,macroTestList2)
{
    (void)testResults_;
}

TEST(TestAddedWithTEST_FIXTURE_EXMacroGetsDefaultSuite)
{
    CHECK(macroTestList2.GetHead() != NULL);
    CHECK_EQUAL ("MacroTestHelper2", macroTestList2.GetHead()->m_details.testName);
    CHECK_EQUAL ("DefaultSuite", macroTestList2.GetHead()->m_details.suiteName);
}

struct FixtureCtorThrows
{
	FixtureCtorThrows()	{ throw "exception"; }
};

TestList throwingFixtureTestList1;
TEST_FIXTURE_EX(FixtureCtorThrows, FixtureCtorThrowsTestName, throwingFixtureTestList1)
{
	(void)testResults_;
}

TEST(FixturesWithThrowingCtorsAreFailures)
{
	CHECK(throwingFixtureTestList1.GetHead() != NULL);
	RecordingReporter reporter;
	TestResults result(&reporter);
	throwingFixtureTestList1.GetHead()->Run(result);

	int const failureCount = result.GetFailedTestCount();
	CHECK_EQUAL(1, failureCount);
	CHECK(strstr(reporter.lastFailedMessage, "while constructing fixture"));
}

struct FixtureDtorThrows
{
	~FixtureDtorThrows() { throw "exception"; }
};

TestList throwingFixtureTestList2;
TEST_FIXTURE_EX(FixtureDtorThrows, FixtureDtorThrowsTestName, throwingFixtureTestList2)
{
	(void)testResults_;
}

TEST(FixturesWithThrowingDtorsAreFailures)
{
	CHECK(throwingFixtureTestList2.GetHead() != NULL);
	RecordingReporter reporter;
	TestResults result(&reporter);
	throwingFixtureTestList2.GetHead()->Run(result);

	int const failureCount = result.GetFailedTestCount();
	CHECK_EQUAL(1, failureCount);
	CHECK(strstr(reporter.lastFailedMessage, "while destroying fixture"));
}

struct FixtureCtorAsserts
{
	enum { FailingLine = 123 };
	FixtureCtorAsserts()
	{
		UnitTest::ReportAssert("assert failure", "file", FailingLine);
	}
};

TestList ctorAssertFixtureTestList;
TEST_FIXTURE_EX(FixtureCtorAsserts, CorrectlyReportsAssertFailureInCtor, ctorAssertFixtureTestList)
{
	(void)testResults_;
}

TEST(CorrectlyReportsFixturesWithCtorsThatAssert)
{
	RecordingReporter reporter;
	TestResults result(&reporter);
	ctorAssertFixtureTestList.GetHead()->Run(result);

	const int failureCount = result.GetFailedTestCount();
	CHECK_EQUAL(1, failureCount);
	CHECK_EQUAL(FixtureCtorAsserts::FailingLine, reporter.lastFailedLine);
	CHECK(strstr(reporter.lastFailedMessage, "assert failure"));
}

}
<commit_msg>Fix gcc build, CheckEqual isn't nice about comparing an int to an integral-enum.<commit_after>#include "../UnitTest++.h"
#include "../TestMacros.h"
#include "../TestList.h"
#include "../TestResults.h"
#include "../TestReporter.h"
#include "../ReportAssert.h"
#include "RecordingReporter.h"

using namespace UnitTest;

namespace {

TestList list1;
TEST_EX(DummyTest, list1)
{
    (void)testResults_;
}

TEST (TestsAreAddedToTheListThroughMacro)
{
    CHECK (list1.GetHead() != 0);
    CHECK (list1.GetHead()->next == 0);
}

struct ThrowingThingie
{
    ThrowingThingie() : dummy(false)
    {
        if (!dummy)
            throw "Oops";
    } 
    bool dummy;
};

TestList list2;
TEST_FIXTURE_EX(ThrowingThingie,DummyTestName,list2)
{
    (void)testResults_;
}

TEST (ExceptionsInFixtureAreReportedAsHappeningInTheFixture)
{
    RecordingReporter reporter;
    TestResults result(&reporter);
    list2.GetHead()->Run(result);

    CHECK (strstr(reporter.lastFailedMessage, "xception"));
    CHECK (strstr(reporter.lastFailedMessage, "fixture"));
    CHECK (strstr(reporter.lastFailedMessage, "ThrowingThingie"));
}

struct DummyFixture
{
    int x;
};

// We're really testing the macros so we just want them to compile and link
SUITE(TestSuite1)
{

	TEST(SimilarlyNamedTestsInDifferentSuitesWork)
	{
		(void)testResults_;
	}

	TEST_FIXTURE(DummyFixture,SimilarlyNamedFixtureTestsInDifferentSuitesWork)
	{
	    (void)testResults_;
	}

}

SUITE(TestSuite2)
{

	TEST(SimilarlyNamedTestsInDifferentSuitesWork)
	{
	    (void)testResults_;
	}

	TEST_FIXTURE(DummyFixture,SimilarlyNamedFixtureTestsInDifferentSuitesWork)
	{
	    (void)testResults_;
	}

}

TestList macroTestList1;
TEST_EX(MacroTestHelper1,macroTestList1)
{
    (void)testResults_;
}

TEST(TestAddedWithTEST_EXMacroGetsDefaultSuite)
{
    CHECK(macroTestList1.GetHead() != NULL);
    CHECK_EQUAL ("MacroTestHelper1", macroTestList1.GetHead()->m_details.testName);
    CHECK_EQUAL ("DefaultSuite", macroTestList1.GetHead()->m_details.suiteName);
}

TestList macroTestList2;
TEST_FIXTURE_EX(DummyFixture,MacroTestHelper2,macroTestList2)
{
    (void)testResults_;
}

TEST(TestAddedWithTEST_FIXTURE_EXMacroGetsDefaultSuite)
{
    CHECK(macroTestList2.GetHead() != NULL);
    CHECK_EQUAL ("MacroTestHelper2", macroTestList2.GetHead()->m_details.testName);
    CHECK_EQUAL ("DefaultSuite", macroTestList2.GetHead()->m_details.suiteName);
}

struct FixtureCtorThrows
{
	FixtureCtorThrows()	{ throw "exception"; }
};

TestList throwingFixtureTestList1;
TEST_FIXTURE_EX(FixtureCtorThrows, FixtureCtorThrowsTestName, throwingFixtureTestList1)
{
	(void)testResults_;
}

TEST(FixturesWithThrowingCtorsAreFailures)
{
	CHECK(throwingFixtureTestList1.GetHead() != NULL);
	RecordingReporter reporter;
	TestResults result(&reporter);
	throwingFixtureTestList1.GetHead()->Run(result);

	int const failureCount = result.GetFailedTestCount();
	CHECK_EQUAL(1, failureCount);
	CHECK(strstr(reporter.lastFailedMessage, "while constructing fixture"));
}

struct FixtureDtorThrows
{
	~FixtureDtorThrows() { throw "exception"; }
};

TestList throwingFixtureTestList2;
TEST_FIXTURE_EX(FixtureDtorThrows, FixtureDtorThrowsTestName, throwingFixtureTestList2)
{
	(void)testResults_;
}

TEST(FixturesWithThrowingDtorsAreFailures)
{
	CHECK(throwingFixtureTestList2.GetHead() != NULL);
	RecordingReporter reporter;
	TestResults result(&reporter);
	throwingFixtureTestList2.GetHead()->Run(result);

	int const failureCount = result.GetFailedTestCount();
	CHECK_EQUAL(1, failureCount);
	CHECK(strstr(reporter.lastFailedMessage, "while destroying fixture"));
}

const int FailingLine = 123;

struct FixtureCtorAsserts
{
	FixtureCtorAsserts()
	{
		UnitTest::ReportAssert("assert failure", "file", FailingLine);
	}
};

TestList ctorAssertFixtureTestList;
TEST_FIXTURE_EX(FixtureCtorAsserts, CorrectlyReportsAssertFailureInCtor, ctorAssertFixtureTestList)
{
	(void)testResults_;
}

TEST(CorrectlyReportsFixturesWithCtorsThatAssert)
{
	RecordingReporter reporter;
	TestResults result(&reporter);
	ctorAssertFixtureTestList.GetHead()->Run(result);

	const int failureCount = result.GetFailedTestCount();
	CHECK_EQUAL(1, failureCount);
	CHECK_EQUAL(FailingLine, reporter.lastFailedLine);
	CHECK(strstr(reporter.lastFailedMessage, "assert failure"));
}

}

{'fraction_non_alphanumeric': 0.11602730054130383, 'fraction_numerical': 0.009178630265944928, 'mean_word_length': 6.601967799642218, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '7193832', 'n_tokens_mistral': 2995, 'n_tokens_neox': 2922, 'n_words': 425}