-
Notifications
You must be signed in to change notification settings - Fork 790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EXPECT_TIMELY
test macro
#3940
Add EXPECT_TIMELY
test macro
#3940
Conversation
Being the last checks makes them the same as ASSERT_TIMELY, doesn't it? |
0229552
to
dacdaab
Compare
nano/test_common/testutil.hpp
Outdated
{ \ | ||
ASSERT_NO_ERROR (system.poll ()); \ | ||
} | ||
#define ASSERT_TIMELY(time, condition) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this is that it checks the condition twice. It should only check it once per loop.
For example, it won't catch this condition:
bool counter_increment_and_equals_ten()
{
static int i = 0;
return (--i) == 10;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, that was not the best solution. I decided to leave ASSERT TIMELY as is
dacdaab
to
a1cddb9
Compare
nano/test_common/testutil.hpp
Outdated
/** Extends gtest with a std::error_code assert that expects an error */ | ||
#define ASSERT_IS_ERROR(condition) \ | ||
GTEST_TEST_ERROR_CODE ((condition.value () > 0), #condition, "An error was expected", "", \ | ||
GTEST_FATAL_FAILURE_) | ||
|
||
/** Extends gtest with a std::error_code assert that expects an error */ | ||
#define EXPECT_IS_ERROR(condition) \ | ||
GTEST_TEST_ERROR_CODE ((condition.value () > 0), #condition, "An error was expected", "", \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
condition.value () != 0
protects against signed vs unsigned problems.
condition.value () > 0
nano/test_common/testutil.hpp
Outdated
#define EXPECT_NO_ERROR(condition) \ | ||
GTEST_TEST_ERROR_CODE (!(condition), #condition, condition.message ().c_str (), "", \ | ||
GTEST_NONFATAL_FAILURE_) | ||
|
||
/** Extends gtest with a std::error_code assert that expects an error */ | ||
#define ASSERT_IS_ERROR(condition) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!= 0
is better than > 0
7b4bc1b
to
15b5330
Compare
It is not always possible to call ASSERT_TIMELY, for example from helper functions or lambdas.