mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-29 04:35:29 +03:00
Merge pull request #26 from pjohnmeyer/fixUnitTestTimeConstraintExemptForFixtures
Fix unit test time constraint exempt for fixtures; closes #9.
This commit is contained in:
commit
8faa479e4b
8 changed files with 50 additions and 19 deletions
|
|
@ -21,7 +21,6 @@ TestList& Test::GetTestList()
|
|||
Test::Test(char const* testName, char const* suiteName, char const* filename, int lineNumber)
|
||||
: m_details(testName, suiteName, filename, lineNumber)
|
||||
, m_nextTest(0)
|
||||
, m_timeConstraintExempt(false)
|
||||
, m_isMockTest(false)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public:
|
|||
|
||||
TestDetails const m_details;
|
||||
Test* m_nextTest;
|
||||
mutable bool m_timeConstraintExempt;
|
||||
|
||||
mutable bool m_isMockTest;
|
||||
|
||||
static TestList& GetTestList();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ TestDetails::TestDetails(char const* testName_, char const* suiteName_, char con
|
|||
, testName(testName_)
|
||||
, filename(filename_)
|
||||
, lineNumber(lineNumber_)
|
||||
, timeConstraintExempt(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -15,6 +16,7 @@ TestDetails::TestDetails(const TestDetails& details, int lineNumber_)
|
|||
, testName(details.testName)
|
||||
, filename(details.filename)
|
||||
, lineNumber(lineNumber_)
|
||||
, timeConstraintExempt(details.timeConstraintExempt)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public:
|
|||
char const* const testName;
|
||||
char const* const filename;
|
||||
int const lineNumber;
|
||||
mutable bool timeConstraintExempt;
|
||||
|
||||
TestDetails(TestDetails const&); // Why is it public? --> http://gcc.gnu.org/bugs.html#cxx_rvalbind
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ void TestRunner::RunTest(TestResults* const result, Test* const curTest, int con
|
|||
curTest->Run();
|
||||
|
||||
double const testTimeInMs = testTimer.GetTimeInMs();
|
||||
if (maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_timeConstraintExempt)
|
||||
if (maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_details.timeConstraintExempt)
|
||||
{
|
||||
MemoryOutStream stream;
|
||||
stream << "Global time constraint failed. Expected under " << maxTestTimeInMs <<
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ private:
|
|||
|
||||
#define UNITTEST_TIME_CONSTRAINT_EXEMPT() \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
m_timeConstraintExempt = true; \
|
||||
m_details.timeConstraintExempt = true; \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -207,24 +207,30 @@ TEST_FIXTURE(TestRunnerFixture, SlowTestHasCorrectFailureInformation)
|
|||
CHECK(strstr(reporter.lastFailedMessage, "3ms"));
|
||||
}
|
||||
|
||||
TEST_FIXTURE(TestRunnerFixture, SlowTestWithTimeExemptionPasses)
|
||||
|
||||
namespace SlowTestHelper
|
||||
{
|
||||
class SlowExemptedTest : public Test
|
||||
TestRunnerFixture testRunnerFixture;
|
||||
|
||||
TEST_EX(SlowExemptedTest, testRunnerFixture.list)
|
||||
{
|
||||
public:
|
||||
SlowExemptedTest() : Test("slowexempted", "", 0) {}
|
||||
virtual void RunImpl() const
|
||||
{
|
||||
UNITTEST_TIME_CONSTRAINT_EXEMPT();
|
||||
TimeHelpers::SleepMs(20);
|
||||
}
|
||||
};
|
||||
UNITTEST_TIME_CONSTRAINT_EXEMPT();
|
||||
TimeHelpers::SleepMs(20);
|
||||
}
|
||||
|
||||
class Fixture {};
|
||||
|
||||
TEST_FIXTURE_EX(Fixture, SlowExemptedTest, testRunnerFixture.list)
|
||||
{
|
||||
UNITTEST_TIME_CONSTRAINT_EXEMPT();
|
||||
TimeHelpers::SleepMs(20);
|
||||
}
|
||||
}
|
||||
|
||||
SlowExemptedTest test;
|
||||
list.Add(&test);
|
||||
|
||||
runner.RunTestsIf(list, NULL, True(), 3);
|
||||
CHECK_EQUAL(0, reporter.testFailedCount);
|
||||
TEST(SlowTestsWithTimeExemptionPass)
|
||||
{
|
||||
SlowTestHelper::testRunnerFixture.runner.RunTestsIf(SlowTestHelper::testRunnerFixture.list, NULL, True(), 3);
|
||||
CHECK_EQUAL(0, SlowTestHelper::testRunnerFixture.reporter.testFailedCount);
|
||||
}
|
||||
|
||||
struct TestSuiteFixture
|
||||
|
|
|
|||
|
|
@ -62,4 +62,27 @@ TEST(TimeConstraintMacroComparesAgainstPreciseActual)
|
|||
CHECK(strstr(reporter.lastFailedTest, "TimeConstraintMacroComparesAgainstPreciseActual"));
|
||||
}
|
||||
|
||||
struct EmptyFixture {};
|
||||
|
||||
TEST_FIXTURE(EmptyFixture, TimeConstraintMacroWorksInFixtures)
|
||||
{
|
||||
int testLine = 0;
|
||||
RecordingReporter reporter;
|
||||
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
UNITTEST_TIME_CONSTRAINT(10); testLine = __LINE__;
|
||||
UnitTest::TimeHelpers::SleepMs(20);
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
|
||||
CHECK_EQUAL(1, reporter.testFailedCount);
|
||||
CHECK(strstr(reporter.lastFailedFile, __FILE__));
|
||||
CHECK_EQUAL(testLine, reporter.lastFailedLine);
|
||||
CHECK(strstr(reporter.lastFailedTest, "TimeConstraintMacroWorksInFixtures"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue