Improve test assertion messages.

This commit is contained in:
levlam 2023-03-02 17:35:57 +03:00
parent 672ef60828
commit 2c86bc719b
2 changed files with 10 additions and 9 deletions

View File

@ -84,7 +84,7 @@ class RegressionTesterImpl final : public RegressionTester {
auto wa_path = db_cache_dir_ + "WA";
write_file(wa_path, result).ensure();
return Status::Error(PSLICE() << "Test " << name << " changed: " << tag("expected", old_test_info.result_hash)
<< tag("got", hash));
<< tag("received", hash));
}
auto result_cache_path = db_cache_dir_ + hash;
if (stat(result_cache_path).is_error()) {

View File

@ -176,23 +176,24 @@ void rand_shuffle(MutableSpan<T> v, R &rnd) {
}
template <class T1, class T2>
void assert_eq_impl(const T1 &expected, const T2 &got, const char *file, int line) {
LOG_CHECK(expected == got) << tag("expected", expected) << tag("got", got) << " in " << file << " at line " << line;
void assert_eq_impl(const T1 &expected, const T2 &received, const char *file, int line) {
LOG_CHECK(expected == received) << tag("expected", expected) << tag("received", received) << " in " << file
<< " at line " << line;
}
template <class T>
void assert_true_impl(const T &got, const char *file, int line) {
LOG_CHECK(got) << "Expected true in " << file << " at line " << line;
void assert_true_impl(const T &received, const char *file, int line) {
LOG_CHECK(received) << "Expected true in " << file << " at line " << line;
}
} // namespace td
#define ASSERT_EQ(expected, got) ::td::assert_eq_impl((expected), (got), __FILE__, __LINE__)
#define ASSERT_EQ(expected, received) ::td::assert_eq_impl((expected), (received), __FILE__, __LINE__)
#define ASSERT_TRUE(got) ::td::assert_true_impl((got), __FILE__, __LINE__)
#define ASSERT_TRUE(received) ::td::assert_true_impl((received), __FILE__, __LINE__)
#define ASSERT_STREQ(expected, got) \
::td::assert_eq_impl(::td::Slice((expected)), ::td::Slice((got)), __FILE__, __LINE__)
#define ASSERT_STREQ(expected, received) \
::td::assert_eq_impl(::td::Slice((expected)), ::td::Slice((received)), __FILE__, __LINE__)
#define REGRESSION_VERIFY(data) ::td::TestContext::get()->verify(data).ensure()