From 05235322380aaf1689ef67e57339c3470f781e7c Mon Sep 17 00:00:00 2001 From: arhag Date: Tue, 27 Aug 2019 20:24:23 -0400 Subject: [PATCH 1/4] fix bugs in native tester macros --- libraries/native/crt.cpp | 17 +++++----- libraries/native/native/eosio/tester.hpp | 40 +++++++++++++++--------- libraries/native/tester.hpp | 40 +++++++++++++++--------- 3 files changed, 60 insertions(+), 37 deletions(-) diff --git a/libraries/native/crt.cpp b/libraries/native/crt.cpp index d1392f63d3..112820eda0 100644 --- a/libraries/native/crt.cpp +++ b/libraries/native/crt.cpp @@ -13,7 +13,7 @@ eosio::cdt::output_stream std_err; extern "C" { int main(int, char**); char* _mmap(); - + static jmp_buf env; static jmp_buf test_env; static volatile int jmp_ret; @@ -25,7 +25,8 @@ extern "C" { void ___putc(char c); bool ___disable_output; bool ___has_failed; - + bool ___earlier_unit_test_has_failed; + void* __get_heap_base() { return ___heap_base_ptr; } @@ -79,6 +80,8 @@ extern "C" { ___pages = 1; ___disable_output = false; ___has_failed = false; + ___earlier_unit_test_has_failed = false; + // preset the print functions intrinsics::set_intrinsic([](const char* cs, uint32_t l) { _prints_l(cs, l, eosio::cdt::output_stream_kind::std_out); @@ -106,9 +109,9 @@ extern "C" { memcpy(buff, ret.c_str(), ret.size()); v -= (int)v; buff[ret.size()] = '.'; - size_t size = ret.size(); + size_t size = ret.size(); for (size_t i=size+1; i < size+10; i++) { - v *= 10; + v *= 10; buff[i] = ((int)v)+'0'; v -= (int)v; } @@ -120,9 +123,9 @@ extern "C" { memcpy(buff, ret.c_str(), ret.size()); v -= (long)v; buff[ret.size()] = '.'; - size_t size = ret.size(); + size_t size = ret.size(); for (size_t i=size+1; i < size+10; i++) { - v *= 10; + v *= 10; buff[i] = ((int)v)+'0'; v -= (int)v; } @@ -167,7 +170,7 @@ extern "C" { } return ret_val; } - + extern "C" void* memset(void*, int, size_t); extern "C" void __bzero(void* to, size_t cnt) { char* cp{static_cast(to)}; diff --git a/libraries/native/native/eosio/tester.hpp b/libraries/native/native/eosio/tester.hpp index 4f6f8defb4..1a232e56b5 100644 --- a/libraries/native/native/eosio/tester.hpp +++ b/libraries/native/native/eosio/tester.hpp @@ -7,6 +7,7 @@ extern "C" bool ___disable_output; extern "C" bool ___has_failed; +extern "C" bool ___earlier_unit_test_has_failed; inline void silence_output(bool t) { ___disable_output = t; @@ -32,7 +33,7 @@ inline bool expect_assert(bool check, const std::string& li, Pred&& pred, F&& fu eosio::print("error : expect_assert, no assert {"+li+"}\n"); silence_output(disable_out); return false; - } + } __reset_env(); bool passed = pred(std_err.get()); std_err.clear(); @@ -43,13 +44,13 @@ inline bool expect_assert(bool check, const std::string& li, Pred&& pred, F&& fu eosio::print("error : expect_assert, wrong assert {"+li+"}\n"); silence_output(disable_out); - return passed; + return passed; } template inline bool expect_assert(bool check, const std::string& li, const char (&expected)[N], F&& func, Args... args) { - return expect_assert(check, li, - [&](const std::string& s) { + return expect_assert(check, li, + [&](const std::string& s) { return std_err.index == N-1 && memcmp(expected, s.c_str(), N-1) == 0; }, func, args...); } @@ -72,51 +73,60 @@ inline bool expect_print(bool check, const std::string& li, Pred&& pred, F&& fun template inline bool expect_print(bool check, const std::string& li, const char (&expected)[N], F&& func, Args... args) { - return expect_print(check, li, - [&](const std::string& s) { + return expect_print(check, li, + [&](const std::string& s) { return std_out.index == N-1 && memcmp(expected, s.c_str(), N-1) == 0; }, func, args...); } #define CHECK_ASSERT(...) \ - ___has_failed &= expect_assert(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); + ___has_failed |= expect_assert(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); #define REQUIRE_ASSERT(...) \ expect_assert(false, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); #define CHECK_PRINT(...) \ - ___has_failed &= expect_print(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); + ___has_failed |= expect_print(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); #define REQUIRE_PRINT(...) \ expect_print(false, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); #define CHECK_EQUAL(X, Y) \ - if (X != Y) { \ + if (!(X == Y)) { \ ___has_failed = true; \ eosio::print(std::string("CHECK_EQUAL failed (")+#X+" != "+#Y+") {"+__FILE__+":"+std::to_string(__LINE__)+"}\n"); \ } #define REQUIRE_EQUAL(X, Y) \ eosio::check(X == Y, std::string(std::string("REQUIRE_EQUAL failed (")+#X+" != "+#Y+") {"+__FILE__+":"+std::to_string(__LINE__)+"}").c_str()); - + #define EOSIO_TEST(X) \ int X ## _ret = setjmp(*___env_ptr); \ if ( X ## _ret == 0 ) \ X(); \ else { \ + bool ___original_disable_output = ___disable_output; \ silence_output(false); \ - eosio::print("\033[1;37m", #X, " \033[0;37munit test \033[1;31mfailed\033[0m\n"); \ + eosio::print("\033[1;37m", #X, " \033[0;37munit test \033[1;31mfailed\033[0m (aborted)\n"); \ ___has_failed = true; \ - silence_output(___disable_output); \ + silence_output(___original_disable_output); \ } #define EOSIO_TEST_BEGIN(X) \ void X() { \ - static constexpr const char* __test_name = #X; + static constexpr const char* __test_name = #X; \ + ___earlier_unit_test_has_failed = ___has_failed; \ + ___has_failed = false; #define EOSIO_TEST_END \ + bool ___original_disable_output = ___disable_output; \ silence_output(false); \ - eosio::print("\033[1;37m",__test_name," \033[0;37munit test \033[1;32mpassed\033[0m\n"); \ - silence_output(___disable_output); \ + if (___has_failed) \ + eosio::print("\033[1;37m", __test_name, " \033[0;37munit test \033[1;31mfailed\033[0m\n"); \ + else \ + eosio::print("\033[1;37m", __test_name, " \033[0;37munit test \033[1;32mpassed\033[0m\n"); \ + silence_output(___original_disable_output); \ + ___has_failed |= ___earlier_unit_test_has_failed; \ + ___earlier_unit_test_has_failed = ___has_failed; \ } diff --git a/libraries/native/tester.hpp b/libraries/native/tester.hpp index 981e450a9e..17a3840201 100644 --- a/libraries/native/tester.hpp +++ b/libraries/native/tester.hpp @@ -9,6 +9,7 @@ extern "C" bool ___disable_output; extern "C" bool ___has_failed; +extern "C" bool ___earlier_unit_test_has_failed; inline void silence_output(bool t) { ___disable_output = t; @@ -34,7 +35,7 @@ inline bool expect_assert(bool check, const std::string& li, Pred&& pred, F&& fu eosio::print("error : expect_assert, no assert {"+li+"}\n"); silence_output(disable_out); return false; - } + } __reset_env(); bool passed = pred(std_err.get()); std_err.clear(); @@ -45,13 +46,13 @@ inline bool expect_assert(bool check, const std::string& li, Pred&& pred, F&& fu eosio::print("error : expect_assert, wrong assert {"+li+"}\n"); silence_output(disable_out); - return passed; + return passed; } template inline bool expect_assert(bool check, const std::string& li, const char (&expected)[N], F&& func, Args... args) { - return expect_assert(check, li, - [&](const std::string& s) { + return expect_assert(check, li, + [&](const std::string& s) { return std_err.index == N-1 && memcmp(expected, s.c_str(), N-1) == 0; }, func, args...); } @@ -74,51 +75,60 @@ inline bool expect_print(bool check, const std::string& li, Pred&& pred, F&& fun template inline bool expect_print(bool check, const std::string& li, const char (&expected)[N], F&& func, Args... args) { - return expect_print(check, li, - [&](const std::string& s) { + return expect_print(check, li, + [&](const std::string& s) { return std_out.index == N-1 && memcmp(expected, s.c_str(), N-1) == 0; }, func, args...); } #define CHECK_ASSERT(...) \ - ___has_failed &= expect_assert(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); + ___has_failed |= expect_assert(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); #define REQUIRE_ASSERT(...) \ expect_assert(false, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); #define CHECK_PRINT(...) \ - ___has_failed &= expect_print(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); + ___has_failed |= expect_print(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); #define REQUIRE_PRINT(...) \ expect_print(false, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); #define CHECK_EQUAL(X, Y) \ - if (X != Y) { \ + if (!(X == Y)) { \ ___has_failed = true; \ eosio::print(std::string("CHECK_EQUAL failed (")+#X+" != "+#Y+") {"+__FILE__+":"+std::to_string(__LINE__)+"}\n"); \ } #define REQUIRE_EQUAL(X, Y) \ eosio_assert(X == Y, std::string(std::string("REQUIRE_EQUAL failed (")+#X+" != "+#Y+") {"+__FILE__+":"+std::to_string(__LINE__)+"}").c_str()); - + #define EOSIO_TEST(X) \ int X ## _ret = setjmp(*___env_ptr); \ if ( X ## _ret == 0 ) \ X(); \ else { \ + bool ___original_disable_output = ___disable_output; \ silence_output(false); \ - eosio::print("\033[1;37m", #X, " \033[0;37munit test \033[1;31mfailed\033[0m\n"); \ + eosio::print("\033[1;37m", #X, " \033[0;37munit test \033[1;31mfailed\033[0m (aborted)\n"); \ ___has_failed = true; \ - silence_output(___disable_output); \ + silence_output(___original_disable_output); \ } #define EOSIO_TEST_BEGIN(X) \ void X() { \ - static constexpr const char* __test_name = #X; + static constexpr const char* __test_name = #X; \ + ___earlier_unit_test_has_failed = ___has_failed; \ + ___has_failed = false; #define EOSIO_TEST_END \ + bool ___original_disable_output = ___disable_output; \ silence_output(false); \ - eosio::print("\033[1;37m",__test_name," \033[0;37munit test \033[1;32mpassed\033[0m\n"); \ - silence_output(___disable_output); \ + if (___has_failed) \ + eosio::print("\033[1;37m", __test_name, " \033[0;37munit test \033[1;31mfailed\033[0m\n"); \ + else \ + eosio::print("\033[1;37m", __test_name, " \033[0;37munit test \033[1;32mpassed\033[0m\n"); \ + silence_output(___original_disable_output); \ + ___has_failed |= ___earlier_unit_test_has_failed; \ + ___earlier_unit_test_has_failed = ___has_failed; \ } From 3e403ab30397acac0e1d3b48824351d6ac66b4f3 Mon Sep 17 00:00:00 2001 From: arhag Date: Tue, 27 Aug 2019 20:32:23 -0400 Subject: [PATCH 2/4] remove deprecated libnative header files --- libraries/native/crt.hpp | 31 ----- libraries/native/intrinsics.hpp | 45 ------- libraries/native/intrinsics_def.hpp | 178 ---------------------------- libraries/native/tester.hpp | 134 --------------------- 4 files changed, 388 deletions(-) delete mode 100644 libraries/native/crt.hpp delete mode 100644 libraries/native/intrinsics.hpp delete mode 100644 libraries/native/intrinsics_def.hpp delete mode 100644 libraries/native/tester.hpp diff --git a/libraries/native/crt.hpp b/libraries/native/crt.hpp deleted file mode 100644 index a6f43201f3..0000000000 --- a/libraries/native/crt.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include - -#warning " is deprecated use " -namespace eosio { namespace cdt { - enum output_stream_kind { - std_out, - std_err, - none - }; - struct output_stream { - char output[1024*2]; - size_t index = 0; - std::string to_string()const { return std::string((const char*)output, index); } - const char* get()const { return output; } - void push(char c) { output[index++] = c; } - void clear() { index = 0; } - }; -}} //ns eosio::cdt - -extern eosio::cdt::output_stream std_out; -extern eosio::cdt::output_stream std_err; -extern "C" jmp_buf* ___env_ptr; -extern "C" char* ___heap_ptr; - -extern "C" { - void __set_env_test(); - void __reset_env(); - void _prints_l(const char* cstr, uint32_t len, uint8_t which); - void _prints(const char* cstr, uint8_t which); -} diff --git a/libraries/native/intrinsics.hpp b/libraries/native/intrinsics.hpp deleted file mode 100644 index b6f1db0aab..0000000000 --- a/libraries/native/intrinsics.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include "intrinsics_def.hpp" - -#pragma once - -#warning " is deprecated use " -namespace eosio { namespace native { - - class intrinsics { - public: - static intrinsics& get() { - static intrinsics inst; - return inst; - } - - enum intrinsic_name { - INTRINSICS(CREATE_ENUM) - INTRINSICS_SIZE - }; - - INTRINSICS(GENERATE_TYPE_MAPPING) - std::tuple< INTRINSICS(GET_TYPE) std::function > funcs { - INTRINSICS(REGISTER_INTRINSIC) - std::function{[](){}} - }; - - template - auto call(Args... args) -> decltype(std::get(intrinsics::get().funcs)(args...)) { - return std::get(intrinsics::get().funcs)(args...); - } - - template - static void set_intrinsic(F&& func) { - auto& f = std::get(intrinsics::get().funcs); - std::get(intrinsics::get().funcs) = typename std::remove_reference::type {func}; - } - - template - static auto get_intrinsic() - -> typename std::remove_reference(intrinsics::get().funcs))>::type { - return std::get(intrinsics::get().funcs); - } - }; - -}} //ns eosio::native diff --git a/libraries/native/intrinsics_def.hpp b/libraries/native/intrinsics_def.hpp deleted file mode 100644 index 5aae45c4ca..0000000000 --- a/libraries/native/intrinsics_def.hpp +++ /dev/null @@ -1,178 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#warning " is deprecated use " -namespace eosio { namespace native { - template - auto get_args_full(std::index_sequence) { - std::tuple...> tup; - return std::tuple{std::get(tup)...}; - } - - template - auto get_args_full(R(Args...)) { - return get_args_full(std::index_sequence_for{}); - } - - template - auto get_args(R(Args...)) { - return std::tuple...>{}; - } - - template - auto create_function(std::index_sequence) { - return std::function::type ...)>{ - [](typename std::tuple_element::type ...) { - eosio_assert(false, "unsupported intrinsic"); return (R)0; - } - }; - } - -#define INTRINSICS(intrinsic_macro) \ -intrinsic_macro(get_resource_limits) \ -intrinsic_macro(set_resource_limits) \ -intrinsic_macro(set_proposed_producers) \ -intrinsic_macro(get_blockchain_parameters_packed) \ -intrinsic_macro(set_blockchain_parameters_packed) \ -intrinsic_macro(is_privileged) \ -intrinsic_macro(set_privileged) \ -intrinsic_macro(get_active_producers) \ -intrinsic_macro(db_idx64_store) \ -intrinsic_macro(db_idx64_remove) \ -intrinsic_macro(db_idx64_update) \ -intrinsic_macro(db_idx64_find_primary) \ -intrinsic_macro(db_idx64_find_secondary) \ -intrinsic_macro(db_idx64_lowerbound) \ -intrinsic_macro(db_idx64_upperbound) \ -intrinsic_macro(db_idx64_end) \ -intrinsic_macro(db_idx64_next) \ -intrinsic_macro(db_idx64_previous) \ -intrinsic_macro(db_idx128_store) \ -intrinsic_macro(db_idx128_remove) \ -intrinsic_macro(db_idx128_update) \ -intrinsic_macro(db_idx128_find_primary) \ -intrinsic_macro(db_idx128_find_secondary) \ -intrinsic_macro(db_idx128_lowerbound) \ -intrinsic_macro(db_idx128_upperbound) \ -intrinsic_macro(db_idx128_end) \ -intrinsic_macro(db_idx128_next) \ -intrinsic_macro(db_idx128_previous) \ -intrinsic_macro(db_idx256_store) \ -intrinsic_macro(db_idx256_remove) \ -intrinsic_macro(db_idx256_update) \ -intrinsic_macro(db_idx256_find_primary) \ -intrinsic_macro(db_idx256_find_secondary) \ -intrinsic_macro(db_idx256_lowerbound) \ -intrinsic_macro(db_idx256_upperbound) \ -intrinsic_macro(db_idx256_end) \ -intrinsic_macro(db_idx256_next) \ -intrinsic_macro(db_idx256_previous) \ -intrinsic_macro(db_idx_double_store) \ -intrinsic_macro(db_idx_double_remove) \ -intrinsic_macro(db_idx_double_update) \ -intrinsic_macro(db_idx_double_find_primary) \ -intrinsic_macro(db_idx_double_find_secondary) \ -intrinsic_macro(db_idx_double_lowerbound) \ -intrinsic_macro(db_idx_double_upperbound) \ -intrinsic_macro(db_idx_double_end) \ -intrinsic_macro(db_idx_double_next) \ -intrinsic_macro(db_idx_double_previous) \ -intrinsic_macro(db_idx_long_double_store) \ -intrinsic_macro(db_idx_long_double_remove) \ -intrinsic_macro(db_idx_long_double_update) \ -intrinsic_macro(db_idx_long_double_find_primary) \ -intrinsic_macro(db_idx_long_double_find_secondary) \ -intrinsic_macro(db_idx_long_double_lowerbound) \ -intrinsic_macro(db_idx_long_double_upperbound) \ -intrinsic_macro(db_idx_long_double_end) \ -intrinsic_macro(db_idx_long_double_next) \ -intrinsic_macro(db_idx_long_double_previous) \ -intrinsic_macro(db_store_i64) \ -intrinsic_macro(db_update_i64) \ -intrinsic_macro(db_remove_i64) \ -intrinsic_macro(db_get_i64) \ -intrinsic_macro(db_next_i64) \ -intrinsic_macro(db_previous_i64) \ -intrinsic_macro(db_find_i64) \ -intrinsic_macro(db_lowerbound_i64) \ -intrinsic_macro(db_upperbound_i64) \ -intrinsic_macro(db_end_i64) \ -intrinsic_macro(assert_recover_key) \ -intrinsic_macro(recover_key) \ -intrinsic_macro(assert_sha256) \ -intrinsic_macro(assert_sha1) \ -intrinsic_macro(assert_sha512) \ -intrinsic_macro(assert_ripemd160) \ -intrinsic_macro(sha1) \ -intrinsic_macro(sha256) \ -intrinsic_macro(sha512) \ -intrinsic_macro(ripemd160) \ -intrinsic_macro(check_transaction_authorization) \ -intrinsic_macro(check_permission_authorization) \ -intrinsic_macro(get_permission_last_used) \ -intrinsic_macro(get_account_creation_time) \ -intrinsic_macro(current_time) \ -intrinsic_macro(publication_time) \ -intrinsic_macro(read_action_data) \ -intrinsic_macro(action_data_size) \ -intrinsic_macro(current_receiver) \ -intrinsic_macro(require_recipient) \ -intrinsic_macro(require_auth) \ -intrinsic_macro(require_auth2) \ -intrinsic_macro(has_auth) \ -intrinsic_macro(is_account) \ -intrinsic_macro(prints) \ -intrinsic_macro(prints_l) \ -intrinsic_macro(printi) \ -intrinsic_macro(printui) \ -intrinsic_macro(printi128) \ -intrinsic_macro(printui128) \ -intrinsic_macro(printsf) \ -intrinsic_macro(printdf) \ -intrinsic_macro(printqf) \ -intrinsic_macro(printn) \ -intrinsic_macro(printhex) \ -intrinsic_macro(read_transaction) \ -intrinsic_macro(transaction_size) \ -intrinsic_macro(expiration) \ -intrinsic_macro(tapos_block_prefix) \ -intrinsic_macro(tapos_block_num) \ -intrinsic_macro(get_action) \ -intrinsic_macro(send_inline) \ -intrinsic_macro(send_context_free_inline) \ -intrinsic_macro(send_deferred) \ -intrinsic_macro(cancel_deferred) \ -intrinsic_macro(get_context_free_data) - -#define CREATE_ENUM(name) \ - name, - -#define GENERATE_TYPE_MAPPING(name) \ - struct __ ## name ## _types { \ - using deduced_full_ts = decltype(eosio::native::get_args_full(::name)); \ - using deduced_ts = decltype(eosio::native::get_args(::name)); \ - using res_t = decltype(std::apply(::name, deduced_ts{})); \ - static constexpr auto is = std::make_index_sequence::value>(); \ - }; - -#define GET_TYPE(name) \ - decltype(create_function(eosio::native::intrinsics::__ ## name ## _types::is)), - -#define REGISTER_INTRINSIC(name) \ - create_function(eosio::native::intrinsics::__ ## name ## _types::is), - -}} //ns eosio::native diff --git a/libraries/native/tester.hpp b/libraries/native/tester.hpp deleted file mode 100644 index 17a3840201..0000000000 --- a/libraries/native/tester.hpp +++ /dev/null @@ -1,134 +0,0 @@ -#pragma once -#include -#include "crt.hpp" -#include "intrinsics.hpp" -#include -#include - -#warning " is deprecated use " - -extern "C" bool ___disable_output; -extern "C" bool ___has_failed; -extern "C" bool ___earlier_unit_test_has_failed; - -inline void silence_output(bool t) { - ___disable_output = t; -} -inline bool has_failed() { - return ___has_failed; -} - -extern "C" void apply(uint64_t, uint64_t, uint64_t); - -template -inline bool expect_assert(bool check, const std::string& li, Pred&& pred, F&& func, Args... args) { - std_err.clear(); - __set_env_test(); - int ret = setjmp(*___env_ptr); - bool disable_out = ___disable_output; - if (ret == 0) { - func(args...); - __reset_env(); - silence_output(false); - if (!check) - eosio_assert(false, std::string("error : expect_assert, no assert {"+li+"}").c_str()); - eosio::print("error : expect_assert, no assert {"+li+"}\n"); - silence_output(disable_out); - return false; - } - __reset_env(); - bool passed = pred(std_err.get()); - std_err.clear(); - silence_output(false); - if (!check) - eosio_assert(passed, std::string("error : expect_assert, wrong assert {"+li+"}").c_str()); - if (!passed) - eosio::print("error : expect_assert, wrong assert {"+li+"}\n"); - silence_output(disable_out); - - return passed; -} - -template -inline bool expect_assert(bool check, const std::string& li, const char (&expected)[N], F&& func, Args... args) { - return expect_assert(check, li, - [&](const std::string& s) { - return std_err.index == N-1 && - memcmp(expected, s.c_str(), N-1) == 0; }, func, args...); -} - -template -inline bool expect_print(bool check, const std::string& li, Pred&& pred, F&& func, Args... args) { - std_out.clear(); - func(args...); - bool passed = pred(std_out.get()); - std_out.clear(); - bool disable_out = ___disable_output; - silence_output(false); - if (!check) - eosio_assert(passed, std::string("error : wrong print message {"+li+"}").c_str()); - if (!passed) - eosio::print("error : wrong print message9 {"+li+"}\n"); - silence_output(disable_out); - return passed; -} - -template -inline bool expect_print(bool check, const std::string& li, const char (&expected)[N], F&& func, Args... args) { - return expect_print(check, li, - [&](const std::string& s) { - return std_out.index == N-1 && - memcmp(expected, s.c_str(), N-1) == 0; }, func, args...); - -} - -#define CHECK_ASSERT(...) \ - ___has_failed |= expect_assert(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); - -#define REQUIRE_ASSERT(...) \ - expect_assert(false, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); - -#define CHECK_PRINT(...) \ - ___has_failed |= expect_print(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); - -#define REQUIRE_PRINT(...) \ - expect_print(false, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); - -#define CHECK_EQUAL(X, Y) \ - if (!(X == Y)) { \ - ___has_failed = true; \ - eosio::print(std::string("CHECK_EQUAL failed (")+#X+" != "+#Y+") {"+__FILE__+":"+std::to_string(__LINE__)+"}\n"); \ - } - -#define REQUIRE_EQUAL(X, Y) \ - eosio_assert(X == Y, std::string(std::string("REQUIRE_EQUAL failed (")+#X+" != "+#Y+") {"+__FILE__+":"+std::to_string(__LINE__)+"}").c_str()); - -#define EOSIO_TEST(X) \ - int X ## _ret = setjmp(*___env_ptr); \ - if ( X ## _ret == 0 ) \ - X(); \ - else { \ - bool ___original_disable_output = ___disable_output; \ - silence_output(false); \ - eosio::print("\033[1;37m", #X, " \033[0;37munit test \033[1;31mfailed\033[0m (aborted)\n"); \ - ___has_failed = true; \ - silence_output(___original_disable_output); \ - } - -#define EOSIO_TEST_BEGIN(X) \ - void X() { \ - static constexpr const char* __test_name = #X; \ - ___earlier_unit_test_has_failed = ___has_failed; \ - ___has_failed = false; - -#define EOSIO_TEST_END \ - bool ___original_disable_output = ___disable_output; \ - silence_output(false); \ - if (___has_failed) \ - eosio::print("\033[1;37m", __test_name, " \033[0;37munit test \033[1;31mfailed\033[0m\n"); \ - else \ - eosio::print("\033[1;37m", __test_name, " \033[0;37munit test \033[1;32mpassed\033[0m\n"); \ - silence_output(___original_disable_output); \ - ___has_failed |= ___earlier_unit_test_has_failed; \ - ___earlier_unit_test_has_failed = ___has_failed; \ - } From fdca6225589d42783d8baa4091ea4ec5ed666048 Mon Sep 17 00:00:00 2001 From: arhag Date: Wed, 28 Aug 2019 15:19:31 -0400 Subject: [PATCH 3/4] support verbose output in unit tests --- tests/unit/asset_tests.cpp | 38 ++++++++++++------------ tests/unit/binary_extension_tests.cpp | 12 ++++---- tests/unit/crypto_tests.cpp | 14 ++++----- tests/unit/datastream_tests.cpp | 42 ++++++++++----------------- tests/unit/fixed_bytes_tests.cpp | 10 ++++--- tests/unit/name_tests.cpp | 34 ++++++++++++---------- tests/unit/print_tests.cpp | 8 +++-- tests/unit/rope_tests.cpp | 25 +++++++++------- tests/unit/serialize_tests.cpp | 14 +++++---- tests/unit/symbol_tests.cpp | 24 ++++++--------- tests/unit/system_tests.cpp | 10 ++++--- tests/unit/time_tests.cpp | 36 +++++++++-------------- tests/unit/varint_tests.cpp | 18 +++++------- 13 files changed, 135 insertions(+), 150 deletions(-) diff --git a/tests/unit/asset_tests.cpp b/tests/unit/asset_tests.cpp index 386f888175..747e4f37d8 100644 --- a/tests/unit/asset_tests.cpp +++ b/tests/unit/asset_tests.cpp @@ -22,8 +22,6 @@ static constexpr int64_t asset_max{ asset_mask}; // 4611686018427387903 // Definitions in `eosio.cdt/libraries/eosio/asset.hpp` EOSIO_TEST_BEGIN(asset_type_test) - silence_output(true); - static constexpr symbol s0{"A", 0}; static constexpr symbol s1{"Z", 0}; static constexpr symbol s2{"AAAAAAA", 0}; @@ -34,7 +32,7 @@ EOSIO_TEST_BEGIN(asset_type_test) //// constexpr asset() CHECK_EQUAL( asset{}.amount, 0ULL ) CHECK_EQUAL( asset{}.symbol.raw(), 0ULL ) - + //// constexpr asset(int64_t, symbol) CHECK_EQUAL( (asset{0LL, s0}.amount), 0LL ) CHECK_EQUAL( (asset{asset_min, s0}.amount), asset_min ) @@ -44,12 +42,12 @@ EOSIO_TEST_BEGIN(asset_type_test) CHECK_EQUAL( (asset{0LL, s1}.symbol.raw()), 23040ULL ) // "Z", precision: 0 CHECK_EQUAL( (asset{0LL, s2}.symbol.raw()), 4702111234474983680ULL ) // "AAAAAAA", precision: 0 CHECK_EQUAL( (asset{0LL, s3}.symbol.raw()), 6510615555426900480ULL ) // "ZZZZZZZ", precision: 0 - + // Note: there is an invariant established for `asset` that is not enforced for `symbol` // For example: // `symbol{};` // valid code // `asset{{}, symbol{}};` // throws "invalid symbol name" - + CHECK_ASSERT( "invalid symbol name", ([]() {asset{0LL, symbol{0LL}};}) ) CHECK_ASSERT( "invalid symbol name", ([]() {asset{0LL, symbol{1LL}};}) ) CHECK_ASSERT( "invalid symbol name", ([]() {asset{0LL, symbol{16639ULL}};}) ) @@ -95,7 +93,7 @@ EOSIO_TEST_BEGIN(asset_type_test) CHECK_EQUAL( (asset_set_amount.set_amount(1LL), asset_set_amount.amount), 1LL ) CHECK_EQUAL( (asset_set_amount.set_amount(asset_min), asset_set_amount.amount), asset_min ) CHECK_EQUAL( (asset_set_amount.set_amount(asset_max), asset_set_amount.amount), asset_max ) - + CHECK_ASSERT( "magnitude of asset amount must be less than 2^62", ( [&]() { asset_set_amount.set_amount(asset_min - 1); @@ -114,7 +112,7 @@ EOSIO_TEST_BEGIN(asset_type_test) // Printing an `asset` is limited to a precision of 63 // This will trigger an error: // `asset{int64_t{1LL}, symbol{"SYMBOLL", 64}}.print();` // output: "Floating point exception: ..." - + CHECK_EQUAL( (asset{ 0LL, sym_no_prec}.to_string()), "0 SYMBOLL" ) CHECK_EQUAL( (asset{-0LL, sym_no_prec}.to_string()), "0 SYMBOLL" ) CHECK_EQUAL( (asset{ 0LL, sym_prec}.to_string()), @@ -128,7 +126,7 @@ EOSIO_TEST_BEGIN(asset_type_test) "0.000000000000000000000000000000000000000000000000000000000000001 SYMBOLL" ) CHECK_EQUAL( (asset{-1LL, sym_prec}.to_string()), "-0.000000000000000000000000000000000000000000000000000000000000001 SYMBOLL" ) - + CHECK_EQUAL( (asset{asset_min, sym_no_prec}.to_string()), "-4611686018427387903 SYMBOLL" ) CHECK_EQUAL( (asset{asset_max, sym_no_prec}.to_string()), "4611686018427387903 SYMBOLL" ) CHECK_EQUAL( (asset{asset_min, sym_prec}.to_string()), @@ -222,7 +220,7 @@ EOSIO_TEST_BEGIN(asset_type_test) asset{asset_max, sym_no_prec} += asset{1LL, sym_no_prec}; }) ) - + // ------------------------------------------------------------------------------------------ // inline friend asset& operator-(const asset&, const asset&)/asset& operator-=(const asset&) CHECK_EQUAL( (asset{0LL, sym_no_prec} -= asset{0LL, sym_no_prec} ), (asset{0LL, sym_no_prec}) ) @@ -342,14 +340,10 @@ EOSIO_TEST_BEGIN(asset_type_test) // friend bool operator>=( const asset&, const asset&) CHECK_EQUAL( ( asset{1LL, sym_no_prec} >= asset{0LL, sym_no_prec} ), true ) CHECK_EQUAL( ( asset{1LL, sym_no_prec} >= asset{1LL, sym_no_prec} ), true ) - - silence_output(false); EOSIO_TEST_END // Definitions in `eosio.cdt/libraries/eosio/asset.hpp` EOSIO_TEST_BEGIN(extended_asset_type_test) - silence_output(true); - static constexpr symbol sym_no_prec{"SYMBOLL",0}; static constexpr symbol sym_prec{"SYMBOLL",63}; @@ -382,12 +376,12 @@ EOSIO_TEST_BEGIN(extended_asset_type_test) CHECK_PRINT( "0 A@5", [](){extended_asset{asset{int64_t{0}, symbol{"A", 0}}, name{"5"}}.print();} ) CHECK_PRINT( "0 Z@a", [](){extended_asset{asset{int64_t{0}, symbol{"Z", 0}}, name{"a"}}.print();} ) CHECK_PRINT( "0 Z@z", [](){extended_asset{asset{int64_t{0}, symbol{"Z", 0}}, name{"z"}}.print();} ) - + CHECK_PRINT( "1.1 A@1", [](){extended_asset{asset{int64_t{11}, symbol{"A", 1}}, name{"1"}}.print();} ) CHECK_PRINT( "1.1 A@5", [](){extended_asset{asset{int64_t{11}, symbol{"A", 1}}, name{"5"}}.print();} ) CHECK_PRINT( "1.1 Z@a", [](){extended_asset{asset{int64_t{11}, symbol{"Z", 1}}, name{"a"}}.print();} ) CHECK_PRINT( "1.1 Z@z", [](){extended_asset{asset{int64_t{11}, symbol{"Z", 1}}, name{"z"}}.print();} ) - + CHECK_PRINT( "0.000000000000000000000000000000000000000000000000000000000000011 A@1", [](){extended_asset{asset{int64_t{11}, symbol{"A", 63}}, name{"1"}}.print();} ) CHECK_PRINT( "0.000000000000000000000000000000000000000000000000000000000000011 A@5", @@ -401,12 +395,12 @@ EOSIO_TEST_BEGIN(extended_asset_type_test) CHECK_PRINT( "0 AAAAAAA@555555555555j", [](){extended_asset{asset{int64_t{0}, symbol{"AAAAAAA", 0}}, name{"555555555555j"}}.print();} ) CHECK_PRINT( "0 ZZZZZZZ@aaaaaaaaaaaaj", [](){extended_asset{asset{int64_t{0}, symbol{"ZZZZZZZ", 0}}, name{"aaaaaaaaaaaaj"}}.print();} ) CHECK_PRINT( "0 ZZZZZZZ@zzzzzzzzzzzzj", [](){extended_asset{asset{int64_t{0}, symbol{"ZZZZZZZ", 0}}, name{"zzzzzzzzzzzzj"}}.print();} ) - + CHECK_PRINT( "11 AAAAAAA@111111111111j", [](){extended_asset{asset{int64_t{11}, symbol{"AAAAAAA", 0}}, name{"111111111111j"}}.print();} ) CHECK_PRINT( "11 AAAAAAA@555555555555j", [](){extended_asset{asset{int64_t{11}, symbol{"AAAAAAA", 0}}, name{"555555555555j"}}.print();} ) CHECK_PRINT( "11 ZZZZZZZ@aaaaaaaaaaaaj", [](){extended_asset{asset{int64_t{11}, symbol{"ZZZZZZZ", 0}}, name{"aaaaaaaaaaaaj"}}.print();} ) CHECK_PRINT( "11 ZZZZZZZ@zzzzzzzzzzzzj", [](){extended_asset{asset{int64_t{11}, symbol{"ZZZZZZZ", 0}}, name{"zzzzzzzzzzzzj"}}.print();} ) - + CHECK_PRINT( "0.000000000000000000000000000000000000000000000000000000000000011 AAAAAAA@111111111111j", [](){extended_asset{asset{int64_t{11}, symbol{"AAAAAAA", 63}}, name{"111111111111j"}}.print();} ) CHECK_PRINT( "0.000000000000000000000000000000000000000000000000000000000000011 AAAAAAA@555555555555j", @@ -415,7 +409,7 @@ EOSIO_TEST_BEGIN(extended_asset_type_test) [](){extended_asset{asset{int64_t{11}, symbol{"ZZZZZZZ", 63}}, name{"aaaaaaaaaaaaj"}}.print();} ) CHECK_PRINT( "0.000000000000000000000000000000000000000000000000000000000000011 ZZZZZZZ@zzzzzzzzzzzzj", [](){extended_asset{asset{int64_t{11}, symbol{"ZZZZZZZ", 63}}, name{"zzzzzzzzzzzzj"}}.print();} ) - + // ------------------------------- // extended_asset operator-()const CHECK_EQUAL( (-extended_asset{asset{ 0, sym_no_prec}, {}}.quantity), (extended_asset{asset_no_prec, {}}.quantity) ) @@ -523,11 +517,15 @@ EOSIO_TEST_BEGIN(extended_asset_type_test) return b; }) ) - - silence_output(false); EOSIO_TEST_END int main(int argc, char* argv[]) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(asset_type_test); EOSIO_TEST(extended_asset_type_test); return has_failed(); diff --git a/tests/unit/binary_extension_tests.cpp b/tests/unit/binary_extension_tests.cpp index 057c8c3b23..9d4ffc0a30 100644 --- a/tests/unit/binary_extension_tests.cpp +++ b/tests/unit/binary_extension_tests.cpp @@ -13,8 +13,6 @@ using eosio::binary_extension; // Definitions in `eosio.cdt/libraries/eosio/binary_extension.hpp` EOSIO_TEST_BEGIN(binary_extension_test) - silence_output(true); - //// constexpr binary_extension() // constexpr bool has_value()const CHECK_EQUAL( (binary_extension{}.has_value()), false ) @@ -208,7 +206,7 @@ EOSIO_TEST_BEGIN(binary_extension_test) binary_extension be_str_emplace{"abcd"}; be_str_emplace.emplace(move("efgh")); CHECK_EQUAL( be_str_emplace.value() == "efgh", true ) - CHECK_EQUAL( be_str_emplace.value() != "abcd", true ) + CHECK_EQUAL( be_str_emplace.value() != "abcd", true ) // ------------ // void reset() @@ -221,11 +219,15 @@ EOSIO_TEST_BEGIN(binary_extension_test) CHECK_EQUAL( be_str_reset.has_value(), true ) be_str_reset.reset(); CHECK_EQUAL( be_str_reset.has_value(), false ) - - silence_output(false); EOSIO_TEST_END int main(int argc, char* argv[]) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(binary_extension_test); return has_failed(); } diff --git a/tests/unit/crypto_tests.cpp b/tests/unit/crypto_tests.cpp index 8f24f40835..697e3228b2 100644 --- a/tests/unit/crypto_tests.cpp +++ b/tests/unit/crypto_tests.cpp @@ -11,8 +11,6 @@ using eosio::signature; // Definitions in `eosio.cdt/libraries/eosio/crypto.hpp` EOSIO_TEST_BEGIN(public_key_type_test) - silence_output(true); - // ----------------------------------------------------- // bool operator==(const public_key&, const public_key&) CHECK_EQUAL( (public_key{0, std::array{}} == public_key{0, std::array{}}), true ) @@ -22,14 +20,10 @@ EOSIO_TEST_BEGIN(public_key_type_test) // bool operator!=(const public_key&, const public_key&) CHECK_EQUAL( (public_key{0, std::array{}} != public_key{0, std::array{}}), false ) CHECK_EQUAL( (public_key{0, std::array{1}} != public_key{0, std::array{}}), true ) - - silence_output(false); EOSIO_TEST_END // Definitions in `eosio.cdt/libraries/eosio/crypto.hpp` EOSIO_TEST_BEGIN(signature_type_test) - silence_output(true); - // --------------------------------------------------- // bool operator==(const signature&, const signature&) CHECK_EQUAL( (signature{0, std::array{}} == signature{0, std::array{}}), true ) @@ -39,11 +33,15 @@ EOSIO_TEST_BEGIN(signature_type_test) // bool operator!=(const signature&, const signature&) CHECK_EQUAL( (signature{0, std::array{1}} != signature{0, std::array{}}), true ) CHECK_EQUAL( (signature{0, std::array{}} != signature{0, std::array{}}), false ) - - silence_output(false); EOSIO_TEST_END int main(int argc, char* argv[]) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(public_key_type_test) EOSIO_TEST(signature_type_test) return has_failed(); diff --git a/tests/unit/datastream_tests.cpp b/tests/unit/datastream_tests.cpp index cdb2fc6c31..cf102ec1b0 100644 --- a/tests/unit/datastream_tests.cpp +++ b/tests/unit/datastream_tests.cpp @@ -56,8 +56,6 @@ struct be_test { // Definitions in `eosio.cdt/libraries/eosio/datastream.hpp` EOSIO_TEST_BEGIN(datastream_test) - silence_output(true); - static constexpr uint16_t buffer_size{256}; char datastream_buffer[buffer_size]{}; // Buffer for the datastream to point to char buffer[buffer_size]; // Buffer to compare `datastream_buffer` with @@ -74,7 +72,7 @@ EOSIO_TEST_BEGIN(datastream_test) CHECK_EQUAL( ds.pos(), datastream_buffer+1 ) ds.skip(-1); CHECK_EQUAL( ds.pos(), datastream_buffer ) - + // inline bool read(char*, size_t) CHECK_EQUAL( ds.read(buffer, 256), true ) CHECK_EQUAL( memcmp(buffer, datastream_buffer, 256), 0) @@ -104,7 +102,7 @@ EOSIO_TEST_BEGIN(datastream_test) ds.seekp(256); CHECK_ASSERT( "put", ([&]() {ds.put('c');}) ) - + // inline bool get(unsigned char&) unsigned char uch{}; @@ -141,14 +139,10 @@ EOSIO_TEST_BEGIN(datastream_test) CHECK_EQUAL( ds.remaining(), 0 ) ds.seekp(257); CHECK_EQUAL( ds.remaining(), -1) - - silence_output(false); EOSIO_TEST_END // Definitions in `eosio.cdt/libraries/eosio/datastream.hpp` EOSIO_TEST_BEGIN(datastream_specialization_test) - silence_output(true); - static constexpr uint16_t buffer_size{256}; char datastream_buffer[buffer_size]{}; // Buffer for the datastream to point to char buffer[buffer_size]; // Buffer to compare `datastream_buffer` with @@ -164,16 +158,16 @@ EOSIO_TEST_BEGIN(datastream_specialization_test) // inline size_t tellp()const CHECK_EQUAL( ds.skip(0), true) CHECK_EQUAL( ds.tellp(), 256) - + CHECK_EQUAL( ds.skip(1), true) CHECK_EQUAL( ds.tellp(), 257) - + CHECK_EQUAL( ds.skip(255), true) CHECK_EQUAL( ds.tellp(), 512) - + CHECK_EQUAL( ds.skip(1028), true) CHECK_EQUAL( ds.tellp(), 1540) - + // inline bool seekp(size_t) ds.seekp(0); CHECK_EQUAL( ds.tellp(), 0) @@ -187,7 +181,7 @@ EOSIO_TEST_BEGIN(datastream_specialization_test) // inline bool put(char) char ch{'c'}; - + ds.seekp(0); CHECK_EQUAL( ds.put(ch), true ) CHECK_EQUAL( ds.tellp(), 1 ) @@ -217,14 +211,10 @@ EOSIO_TEST_BEGIN(datastream_specialization_test) ds.seekp(257); CHECK_EQUAL( ds.remaining(), 0 ) - - silence_output(false); EOSIO_TEST_END // Definitions in `eosio.cdt/libraries/eosio/datastream.hpp` EOSIO_TEST_BEGIN(datastream_stream_test) - silence_output(true); - static constexpr uint16_t buffer_size{256}; char datastream_buffer[buffer_size]; // Buffer for the datastream to point to @@ -315,7 +305,7 @@ EOSIO_TEST_BEGIN(datastream_stream_test) ds.seekp(0); ds >> arr; CHECK_EQUAL( carr, arr ) - + // ---------- // std::deque ds.seekp(0); @@ -414,7 +404,7 @@ EOSIO_TEST_BEGIN(datastream_stream_test) ds.seekp(0); ds >> v; CHECK_EQUAL( cv, v ) - + // ----------- // std::vector struct vec_test { @@ -553,7 +543,7 @@ EOSIO_TEST_BEGIN(datastream_stream_test) ds.seekp(0); ds >> sym; CHECK_EQUAL( csym_prec, sym ) - + // ------------------ // eosio::symbol_code ds.seekp(0); @@ -564,14 +554,10 @@ EOSIO_TEST_BEGIN(datastream_stream_test) ds.seekp(0); ds >> sc; CHECK_EQUAL( csc, sc ) - - silence_output(false); EOSIO_TEST_END // Definitions in `eosio.cdt/libraries/eosio/datastream.hpp` EOSIO_TEST_BEGIN(misc_datastream_test) - silence_output(true); - // --------------------------- // vector pack(const T&) static const string pack_str{"abcdefghi"}; @@ -604,11 +590,15 @@ EOSIO_TEST_BEGIN(misc_datastream_test) unpack_ch = unpack(unpack_source_buffer+i, 9); CHECK_EQUAL( unpack_source_buffer[i], unpack_ch ) } - - silence_output(false); EOSIO_TEST_END int main(int argc, char* argv[]) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(datastream_test); EOSIO_TEST(datastream_specialization_test); EOSIO_TEST(datastream_stream_test); diff --git a/tests/unit/fixed_bytes_tests.cpp b/tests/unit/fixed_bytes_tests.cpp index 965ed86362..d786aa3c26 100644 --- a/tests/unit/fixed_bytes_tests.cpp +++ b/tests/unit/fixed_bytes_tests.cpp @@ -14,8 +14,6 @@ using eosio::fixed_bytes; // Definitions in `eosio.cdt/libraries/eosio/fixed_bytes.hpp` EOSIO_TEST_BEGIN(fixed_bytes_test) - silence_output(true); - //// constexpr fixed_bytes() // static constexpr size_t padded_bytes() CHECK_EQUAL( fixed_bytes<20>{}.padded_bytes(), 12 ) @@ -175,11 +173,15 @@ EOSIO_TEST_BEGIN(fixed_bytes_test) // friend bool operator>= <>(const fixed_bytes, const fixed_bytes) CHECK_EQUAL( fb_cmp1 >= fb_cmp1, true ) CHECK_EQUAL( fb_cmp1 >= fb_cmp2, false ) - - silence_output(false); EOSIO_TEST_END int main(int argc, char* argv[]) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(fixed_bytes_test); return has_failed(); } diff --git a/tests/unit/name_tests.cpp b/tests/unit/name_tests.cpp index d26a1e29e5..f5425b56ca 100644 --- a/tests/unit/name_tests.cpp +++ b/tests/unit/name_tests.cpp @@ -19,8 +19,6 @@ static constexpr uint64_t u64max = numeric_limits::max(); // 184467440 // Definitions in `eosio.cdt/libraries/eosio/name.hpp` EOSIO_TEST_BEGIN(name_type_test) - silence_output(true); - //// constexpr name() CHECK_EQUAL( name{}.value, 0ULL ) @@ -50,7 +48,7 @@ EOSIO_TEST_BEGIN(name_type_test) CHECK_EQUAL( name{"123."}.value, 614178399182651392ULL ) CHECK_EQUAL( name{"123........."}.value, 614178399182651392ULL ) CHECK_EQUAL( name{".a.b.c.1.2.3."}.value, 108209673814966320ULL ) - + CHECK_EQUAL( name{"abc.123"}.value, 3589369488740450304ULL ) CHECK_EQUAL( name{"123.abc"}.value, 614181822271586304ULL ) @@ -86,14 +84,14 @@ EOSIO_TEST_BEGIN(name_type_test) CHECK_EQUAL( name::char_to_value(c), expected_value ) ++expected_value; } - + CHECK_ASSERT( "character is not in allowed character set for names", ([]() {name::char_to_value(char{'-'});}) ) CHECK_ASSERT( "character is not in allowed character set for names", ([]() {name::char_to_value(char{'/'});}) ) CHECK_ASSERT( "character is not in allowed character set for names", ([]() {name::char_to_value(char{'6'});}) ) CHECK_ASSERT( "character is not in allowed character set for names", ([]() {name::char_to_value(char{'A'});}) ) CHECK_ASSERT( "character is not in allowed character set for names", ([]() {name::char_to_value(char{'Z'});}) ) CHECK_ASSERT( "character is not in allowed character set for names", ([]() {name::char_to_value(char{'`'});}) ) - CHECK_ASSERT( "character is not in allowed character set for names", ([]() {name::char_to_value(char{'{'});}) ); + CHECK_ASSERT( "character is not in allowed character set for names", ([]() {name::char_to_value(char{'{'});}) ); // ------------------------------- // constexpr uint8_t length()cosnt @@ -113,7 +111,7 @@ EOSIO_TEST_BEGIN(name_type_test) CHECK_EQUAL( name{"eosioaccountj"}.length(), 13 ) CHECK_ASSERT( "string is too long to be a valid name", ([]() {name{"12345abcdefghj"}.length();}) ) - + // ---------------------------- // constexpr name suffix()const CHECK_EQUAL( name{".eosioaccounj"}.suffix(), name{"eosioaccounj"} ) @@ -159,7 +157,7 @@ EOSIO_TEST_BEGIN(name_type_test) CHECK_EQUAL( name{"555555555555j"}.operator name::raw(), static_cast(2975281302211218015ULL) ) CHECK_EQUAL( name{"aaaaaaaaaaaaj"}.operator name::raw(), static_cast(3570337562653461615ULL) ) CHECK_EQUAL( name{"zzzzzzzzzzzzj"}.operator name::raw(), static_cast(u64max) ) - + // --------------------------------------- // constexpr explicit operator bool()const // Note that I must be explicit about calling the operator because it is defined as `explicit` @@ -177,7 +175,7 @@ EOSIO_TEST_BEGIN(name_type_test) // char* write_as_string(char*, char*)const static constexpr uint8_t buffer_size{32}; char buffer[buffer_size]{}; - + string str{"1"}; name{str}.write_as_string( buffer, buffer + sizeof(buffer) ); CHECK_EQUAL( memcmp(str.c_str(), buffer, strlen(str.c_str())), 0 ) @@ -242,7 +240,7 @@ EOSIO_TEST_BEGIN(name_type_test) CHECK_EQUAL( name{"123."}.to_string(), "123" ) CHECK_EQUAL( name{"123........."}.to_string(), "123" ) CHECK_EQUAL( name{".a.b.c.1.2.3."}.to_string(), ".a.b.c.1.2.3" ) - + CHECK_EQUAL( name{"abc.123"}.to_string(), "abc.123" ) CHECK_EQUAL( name{"123.abc"}.to_string(), "123.abc" ) @@ -270,7 +268,7 @@ EOSIO_TEST_BEGIN(name_type_test) CHECK_EQUAL( name{"123."} == name{"123"}, true ) CHECK_EQUAL( name{"123........."} == name{"123"}, true ) CHECK_EQUAL( name{".a.b.c.1.2.3."} == name{".a.b.c.1.2.3"}, true ) - + CHECK_EQUAL( name{"abc.123"} == name{"abc.123"}, true ) CHECK_EQUAL( name{"123.abc"} == name{"123.abc"}, true ) @@ -298,7 +296,7 @@ EOSIO_TEST_BEGIN(name_type_test) CHECK_EQUAL( name{"123."} != name{}, true ) CHECK_EQUAL( name{"123........."} != name{}, true ) CHECK_EQUAL( name{".a.b.c.1.2.3."} != name{}, true ) - + CHECK_EQUAL( name{"abc.123"} != name{}, true ) CHECK_EQUAL( name{"123.abc"} != name{}, true ) @@ -326,7 +324,7 @@ EOSIO_TEST_BEGIN(name_type_test) CHECK_EQUAL( name{} < name{"123."}, true ) CHECK_EQUAL( name{} < name{"123........."}, true ) CHECK_EQUAL( name{} < name{".a.b.c.1.2.3."}, true ) - + CHECK_EQUAL( name{} < name{"abc.123"}, true ) CHECK_EQUAL( name{} < name{"123.abc"}, true ) @@ -342,7 +340,7 @@ EOSIO_TEST_BEGIN(name_type_test) // ------------------------------------ // inline constexpr name operator""_n() CHECK_EQUAL( name{}, ""_n ) - + CHECK_EQUAL( name{"1"}, "1"_n ) CHECK_EQUAL( name{"5"}, "5"_n ) CHECK_EQUAL( name{"a"}, "a"_n ) @@ -356,7 +354,7 @@ EOSIO_TEST_BEGIN(name_type_test) CHECK_EQUAL( name{"123."}, "123."_n ) CHECK_EQUAL( name{"123........."}, "123........."_n ) CHECK_EQUAL( name{".a.b.c.1.2.3."}, ".a.b.c.1.2.3."_n ) - + CHECK_EQUAL( name{"abc.123"}, "abc.123"_n ) CHECK_EQUAL( name{"123.abc"}, "123.abc"_n ) @@ -368,11 +366,15 @@ EOSIO_TEST_BEGIN(name_type_test) CHECK_EQUAL( name{"555555555555j"}, "555555555555j"_n ) CHECK_EQUAL( name{"aaaaaaaaaaaaj"}, "aaaaaaaaaaaaj"_n ) CHECK_EQUAL( name{"zzzzzzzzzzzzj"}, "zzzzzzzzzzzzj"_n ) - - silence_output(false); EOSIO_TEST_END int main(int argc, char* argv[]) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(name_type_test); return has_failed(); } diff --git a/tests/unit/print_tests.cpp b/tests/unit/print_tests.cpp index ccaf61a44b..2486f5f867 100644 --- a/tests/unit/print_tests.cpp +++ b/tests/unit/print_tests.cpp @@ -4,7 +4,6 @@ using namespace eosio::native; EOSIO_TEST_BEGIN(print_test) - silence_output(false); CHECK_PRINT("27", [](){ eosio::print((uint8_t)27); }); CHECK_PRINT("34", [](){ eosio::print((int)34); }); CHECK_PRINT([](std::string s){return s[0] == 'a';}, [](){ eosio::print((char)'a'); }); @@ -21,10 +20,15 @@ EOSIO_TEST_BEGIN(print_test) CHECK_PRINT("-404000000", [](){ eosio::print((int64_t)-404000000); }); CHECK_PRINT("0x0066000000000000", [](){ eosio::print((uint128_t)102); }); CHECK_PRINT("0xffffff9affffffffffffffffffffffff", [](){ eosio::print((int128_t)-102); }); - silence_output(false); EOSIO_TEST_END int main(int argc, char** argv) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(print_test); return has_failed(); } diff --git a/tests/unit/rope_tests.cpp b/tests/unit/rope_tests.cpp index b6ef61814d..c9ddd185d0 100644 --- a/tests/unit/rope_tests.cpp +++ b/tests/unit/rope_tests.cpp @@ -11,7 +11,6 @@ using namespace eosio::native; EOSIO_TEST_BEGIN(rope_test) - silence_output(false); eosio::rope r("test string 0"); r += ", test string 1"; r += ", test string 2"; @@ -20,7 +19,7 @@ EOSIO_TEST_BEGIN(rope_test) r += ", test string 5"; r += ", test string 6"; r += ", test string 7"; - + std::string s("test string 0"); s += ", test string 1"; s += ", test string 2"; @@ -36,23 +35,23 @@ EOSIO_TEST_BEGIN(rope_test) r2 += eosio::rope("rvalue +="); s2 += std::string("rvalue +="); - r2 = r2 + r2; + r2 = r2 + r2; s2 = s2 + s2; r2 += "the end"; s2 += "the end"; - + eosio::rope r3(r2); std::string s3(s2); REQUIRE_EQUAL(s.compare(std::string(r.c_str())), 0); REQUIRE_EQUAL(s2.compare(std::string(r2.c_str())), 0); REQUIRE_EQUAL(s3.compare(std::string(r3.c_str())), 0); - - REQUIRE_EQUAL(s.length(), r.length()); - REQUIRE_EQUAL(s2.length(), r2.length()); - REQUIRE_EQUAL(s3.length(), r3.length()); - + + REQUIRE_EQUAL(s.length(), r.length()); + REQUIRE_EQUAL(s2.length(), r2.length()); + REQUIRE_EQUAL(s3.length(), r3.length()); + for (int i=0; i < s.length(); i++) { REQUIRE_EQUAL(s[i], r[i]); } @@ -64,11 +63,15 @@ EOSIO_TEST_BEGIN(rope_test) for (int i=0; i < s3.length(); i++) { REQUIRE_EQUAL(s3[i], r3[i]); } - - silence_output(false); EOSIO_TEST_END int main(int argc, char** argv) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(rope_test); return has_failed(); } diff --git a/tests/unit/serialize_tests.cpp b/tests/unit/serialize_tests.cpp index 4792038673..940cf9a7c4 100644 --- a/tests/unit/serialize_tests.cpp +++ b/tests/unit/serialize_tests.cpp @@ -52,8 +52,6 @@ struct D2 : public D1 { // Definitions in `eosio.cdt/libraries/eosio/serialize.hpp` EOSIO_TEST_BEGIN(serialize_test) - silence_output(true); - static constexpr uint16_t buffer_size{256}; char ds_buffer[buffer_size]{}; // Buffer for the datastream to point to char ds_expected_buffer[buffer_size]{}; // Buffer to compare `ds_buffer` with @@ -81,7 +79,7 @@ EOSIO_TEST_BEGIN(serialize_test) ds_expected << d1.c << d1.i; ds << d1; REQUIRE_EQUAL( memcmp( ds_buffer, ds_expected_buffer, 256), 0 ) - + ds.seekp(0); ds >> dd1; REQUIRE_EQUAL( d1, dd1 ) @@ -97,15 +95,19 @@ EOSIO_TEST_BEGIN(serialize_test) ds_expected << d2.c << d2.i << d2.v; ds << d2; REQUIRE_EQUAL( memcmp( ds_buffer, ds_expected_buffer, 256), 0 ) - + ds.seekp(0); ds >> dd2; REQUIRE_EQUAL( d2, dd2 ) - - silence_output(false); EOSIO_TEST_END int main(int argc, char* argv[]) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(serialize_test) return has_failed(); } diff --git a/tests/unit/symbol_tests.cpp b/tests/unit/symbol_tests.cpp index 0d0bde5a54..1b564da0f7 100644 --- a/tests/unit/symbol_tests.cpp +++ b/tests/unit/symbol_tests.cpp @@ -22,8 +22,6 @@ static constexpr uint64_t u64max = numeric_limits::max(); // 184467440 // Definitions in `eosio.cdt/libraries/eosio/symbol.hpp` EOSIO_TEST_BEGIN(symbol_code_type_test) - silence_output(true); - //// constexpr symbol_code() // constexpr uint64_t raw()const CHECK_EQUAL( symbol_code{}.raw(), 0ULL ) @@ -119,14 +117,10 @@ EOSIO_TEST_BEGIN(symbol_code_type_test) CHECK_EQUAL( symbol_code{} < symbol_code{"Z"}, true ) CHECK_EQUAL( symbol_code{} < symbol_code{"AAAAAAA"}, true ) CHECK_EQUAL( symbol_code{} < symbol_code{"ZZZZZZZ"}, true ) - - silence_output(false); EOSIO_TEST_END // Definitions in `eosio.cdt/libraries/eosio/symbol.hpp` EOSIO_TEST_BEGIN(symbol_type_test) - silence_output(true); - static constexpr symbol_code sc0{"A"}; static constexpr symbol_code sc1{"Z"}; static constexpr symbol_code sc2{"AAAAAAA"}; @@ -195,7 +189,7 @@ EOSIO_TEST_BEGIN(symbol_type_test) CHECK_EQUAL( (symbol{"SYMBOLL", 0}.operator bool()), true ) CHECK_EQUAL( (!symbol{"", 0}.operator bool()), true ) CHECK_EQUAL( (!symbol{"SYMBOLL", 0}.operator bool()), false ) - + // --------------------- // void print(bool)const // Note: @@ -225,14 +219,10 @@ EOSIO_TEST_BEGIN(symbol_type_test) CHECK_EQUAL( (symbol{} < symbol{sc1, 0}), true ) CHECK_EQUAL( (symbol{} < symbol{sc2, 0}), true ) CHECK_EQUAL( (symbol{} < symbol{sc3, 0}), true ) - - silence_output(false); EOSIO_TEST_END // Definitions in `eosio.cdt/libraries/eosio/symbol.hpp` EOSIO_TEST_BEGIN(extended_symbol_type_test) - silence_output(true); - static constexpr name n0{"1"}; static constexpr name n1{"5"}; static constexpr name n2{"a"}; @@ -252,7 +242,7 @@ EOSIO_TEST_BEGIN(extended_symbol_type_test) // constexpr name get_contract() CHECK_EQUAL( (extended_symbol{{}, {}}.get_symbol().raw()), 0ULL ) CHECK_EQUAL( (extended_symbol{{}, {}}.get_contract().value), 0ULL ) - + //// constexpr extended_symbol(symbol, name) CHECK_EQUAL( (extended_symbol{s0, n0}.get_symbol().raw()), 16640ULL ) CHECK_EQUAL( (extended_symbol{s0, n1}.get_symbol().code().raw()), 65ULL ) @@ -270,7 +260,7 @@ EOSIO_TEST_BEGIN(extended_symbol_type_test) CHECK_EQUAL( (extended_symbol{s2, n5}.get_contract().value), 2975281302211218015ULL ) CHECK_EQUAL( (extended_symbol{s3, n6}.get_contract().value), 3570337562653461615ULL ) CHECK_EQUAL( (extended_symbol{s3, n7}.get_contract().value), u64max ) - + // --------------------- // void print(bool)const // Note: @@ -304,11 +294,15 @@ EOSIO_TEST_BEGIN(extended_symbol_type_test) CHECK_EQUAL( (extended_symbol{} < extended_symbol{s1, {}}), true ) CHECK_EQUAL( (extended_symbol{} < extended_symbol{s2, {}}), true ) CHECK_EQUAL( (extended_symbol{} < extended_symbol{s3, {}}), true ) - - silence_output(false); EOSIO_TEST_END int main(int argc, char* argv[]) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(symbol_code_type_test); EOSIO_TEST(symbol_type_test); EOSIO_TEST(extended_symbol_type_test); diff --git a/tests/unit/system_tests.cpp b/tests/unit/system_tests.cpp index 016fd0d3ca..3fa9ce7a45 100644 --- a/tests/unit/system_tests.cpp +++ b/tests/unit/system_tests.cpp @@ -15,8 +15,6 @@ using eosio::check; // Definitions in `eosio.cdt/libraries/eosiolib/system.hpp` EOSIO_TEST_BEGIN(system_test) - silence_output(true); - // ------------------------------------ // inline void check(bool, const char*) CHECK_ASSERT( "asserted", []() { const char* str{"asserted"}; check(false, str);} ); @@ -43,11 +41,15 @@ EOSIO_TEST_BEGIN(system_test) CHECK_ASSERT("100", []() { check(false, 100);} ); CHECK_ASSERT("18446744073709551615", []() { check(false, 18446744073709551615ULL);} ); CHECK_ASSERT("18446744073709551615", []() { check(false, -1ULL);} ); - - silence_output(false); EOSIO_TEST_END int main(int argc, char* argv[]) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(system_test); return has_failed(); } diff --git a/tests/unit/time_tests.cpp b/tests/unit/time_tests.cpp index 6eb8265924..d5d46ff2b0 100644 --- a/tests/unit/time_tests.cpp +++ b/tests/unit/time_tests.cpp @@ -26,8 +26,6 @@ static constexpr uint32_t u32max = numeric_limits::max(); // 429496729 // Definitions in `eosio.cdt/libraries/eosio/time.hpp` EOSIO_TEST_BEGIN(microseconds_type_test) -silence_output(true); - //// explicit microseconds(uint64_t)/int64_t count() CHECK_EQUAL( microseconds{}._count, 0ULL ) CHECK_EQUAL( microseconds{i64max}._count, i64max ) @@ -120,20 +118,16 @@ silence_output(true); CHECK_EQUAL( days(0LL), microseconds{0LL} ) CHECK_EQUAL( days(1LL), microseconds{24LL*60LL*60LL*1000000LL} ) CHECK_EQUAL( days(60LL), microseconds{24LL*60LL*60LL*60LL*1000000LL} ) - - silence_output(false); EOSIO_TEST_END // Definitions in `eosio.cdt/libraries/eosio/time.hpp` EOSIO_TEST_BEGIN(time_point_type_test) - silence_output(true); - static const microseconds ms0 { 0LL}; static const microseconds ms1 { 1LL}; static const microseconds msn1{-1LL}; static const microseconds ms_min{i64min}; static const microseconds ms_max{i64max}; - + //// explicit time_point(microseconds) // microseconds& time_since_epoch() CHECK_EQUAL( time_point{ms0}.time_since_epoch(), ms0 ) @@ -172,7 +166,7 @@ EOSIO_TEST_BEGIN(time_point_type_test) // time_point& operator+=(const microseconds&) CHECK_EQUAL( (time_point{ms0} += ms1), time_point{ms1} ) CHECK_EQUAL( (time_point{msn1} += ms1), time_point{ms0} ) - + // ------------------------------------------- // time_point& operator-=(const microseconds&) CHECK_EQUAL( (time_point{ms0} -= ms1), time_point{msn1} ) @@ -207,14 +201,10 @@ EOSIO_TEST_BEGIN(time_point_type_test) // bool operator>=(const time_point&) CHECK_EQUAL( (time_point{ms1} >= time_point{ms1}), true ) CHECK_EQUAL( (time_point{ms0} >= time_point{ms1}), false ) - - silence_output(false); EOSIO_TEST_END // Definitions in `eosio.cdt/libraries/eosio/time.hpp` EOSIO_TEST_BEGIN(time_point_sec_type_test) - silence_output(true); - static const microseconds ms0 { 0LL}; static const microseconds ms1 { 1LL}; static const microseconds msn1{-1LL}; @@ -255,7 +245,7 @@ EOSIO_TEST_BEGIN(time_point_sec_type_test) // operator time_point()const CHECK_EQUAL( time_point_sec{u32min}.operator time_point(), time_point{microseconds{static_cast(u32min)*1000000}} ) CHECK_EQUAL( time_point_sec{u32max}.operator time_point(), time_point{microseconds{static_cast(u32max)*1000000}} ) - + // ------------------------------------------- // time_point_sec operator=(const time_point&) CHECK_EQUAL( (time_point_sec{} = tp0), time_point_sec{} ) @@ -280,14 +270,14 @@ EOSIO_TEST_BEGIN(time_point_sec_type_test) CHECK_EQUAL( (time_point_sec{0} - microseconds{-1000000LL}), time_point{microseconds{ 1000000LL}} ) CHECK_EQUAL( (time_point_sec{1} - microseconds{ 1000000LL}), time_point{microseconds{ 0LL}} ) CHECK_EQUAL( (time_point_sec{1} - microseconds{-1000000LL}), time_point{microseconds{ 2000000LL}} ) - + // --------------------------------------------------------------------------- // friend microseconds operator-(const time_point_sec&, const time_point_sec&) CHECK_EQUAL( (time_point_sec{0} - time_point_sec{0}), microseconds{ 0LL} ) CHECK_EQUAL( (time_point_sec{0} - time_point_sec{1}), microseconds{-1000000LL} ) CHECK_EQUAL( (time_point_sec{1} - time_point_sec{0}), microseconds{ 1000000LL} ) CHECK_EQUAL( (time_point_sec{1} - time_point_sec{1}), microseconds{ 0LL} ) - + // ----------------------------------------------------------------------- // friend microseconds operator-(const time_point&, const time_point_sec&) CHECK_EQUAL( (time_point{microseconds{0}} - time_point_sec{0}), microseconds{ 0LL} ) @@ -374,14 +364,10 @@ EOSIO_TEST_BEGIN(time_point_sec_type_test) // friend bool operator>=(const time_point_sec&, const time_point_sec&) CHECK_EQUAL( (time_point_sec{1} >= time_point_sec{1}), true ) CHECK_EQUAL( (time_point_sec{1} >= time_point_sec{2}), false ) - - silence_output(false); EOSIO_TEST_END // Definitions in `eosio.cdt/libraries/eosio/time.hpp` EOSIO_TEST_BEGIN(block_timestamp_type_test) - silence_output(true); - static const int64_t bt_epoch{946684800000LL}; static const microseconds ms0{bt_epoch*1000}; @@ -402,7 +388,7 @@ EOSIO_TEST_BEGIN(block_timestamp_type_test) CHECK_EQUAL( block_timestamp{}.slot, 0 ) CHECK_EQUAL( block_timestamp{u32min}.slot, u32min ) CHECK_EQUAL( block_timestamp{u32max}.slot, u32max ) - + //// block_timestamp(const time_point&) // void set_time_point(const time_point&) CHECK_EQUAL( block_timestamp{tp0}.slot, 0 ) @@ -436,7 +422,7 @@ EOSIO_TEST_BEGIN(block_timestamp_type_test) CHECK_EQUAL( block_timestamp{1}.to_time_point(), time_point{microseconds{(1*500+bt_epoch)*1000}} ) CHECK_EQUAL( block_timestamp{2}.to_time_point(), time_point{microseconds{(2*500+bt_epoch)*1000}} ) CHECK_EQUAL( block_timestamp{3}.to_time_point(), time_point{microseconds{(3*500+bt_epoch)*1000}} ) - + // -------------------------- // operator time_point()const CHECK_EQUAL( block_timestamp{1}.operator time_point(), time_point{microseconds{(1*500+bt_epoch)*1000}} ) @@ -482,11 +468,15 @@ EOSIO_TEST_BEGIN(block_timestamp_type_test) // bool operator>=(const block_timestamp&) CHECK_EQUAL( block_timestamp{1} >= block_timestamp{1}, true ) CHECK_EQUAL( block_timestamp{1} >= block_timestamp{2}, false ) - - silence_output(false); EOSIO_TEST_END int main(int argc, char* argv[]) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(microseconds_type_test); EOSIO_TEST(time_point_type_test); EOSIO_TEST(time_point_sec_type_test); diff --git a/tests/unit/varint_tests.cpp b/tests/unit/varint_tests.cpp index 0eceda3122..f79313ddf0 100644 --- a/tests/unit/varint_tests.cpp +++ b/tests/unit/varint_tests.cpp @@ -23,13 +23,11 @@ static constexpr int32_t i32max = numeric_limits::max(); // 2147483647 // Defined in `eosio.cdt/libraries/eosio/varint.hpp` EOSIO_TEST_BEGIN(unsigned_int_type_test) - silence_output(false); - //// unsigned_int(uint32_t) CHECK_EQUAL( unsigned_int{}.value, 0 ) CHECK_EQUAL( unsigned_int{u32min}.value, 0 ) CHECK_EQUAL( unsigned_int{u32max}.value, 4294967295 ) - + //// unsigned_int(T) CHECK_EQUAL( unsigned_int{uint8_t{0}}.value, 0 ) CHECK_EQUAL( unsigned_int{uint16_t{1}}.value, 1 ) @@ -116,21 +114,17 @@ EOSIO_TEST_BEGIN(unsigned_int_type_test) char datastream_buffer[buffer_size]; // Buffer for the datastream to point to datastream ds{datastream_buffer, buffer_size}; - + static const unsigned_int cui{42}; unsigned_int ui{}; ds << cui; ds.seekp(0); ds >> ui; CHECK_EQUAL( cui, ui) - - silence_output(false); EOSIO_TEST_END // Defined in `eosio.cdt/libraries/eosio/varint.hpp` EOSIO_TEST_BEGIN(signed_int_type_test) - silence_output(false); - //// signed_int(uint32_t) CHECK_EQUAL( signed_int{}.value, 0 ) CHECK_EQUAL( signed_int{i32min}.value, -2147483648 ) @@ -256,11 +250,15 @@ EOSIO_TEST_BEGIN(signed_int_type_test) CHECK_EQUAL( b, bb ) CHECK_EQUAL( c, cc ) CHECK_EQUAL( d, dd ) - - silence_output(false); EOSIO_TEST_END int main(int argc, char* argv[]) { + bool verbose = false; + if( argc >= 2 && std::strcmp( argv[1], "-v" ) == 0 ) { + verbose = true; + } + silence_output(!verbose); + EOSIO_TEST(unsigned_int_type_test) EOSIO_TEST(signed_int_type_test); return has_failed(); From 8b63a0b2f3155927106ddd7185c02e1643ee3497 Mon Sep 17 00:00:00 2001 From: arhag Date: Wed, 28 Aug 2019 15:57:45 -0400 Subject: [PATCH 4/4] revert changes to CHECK_ASSERT and CHECK_PRINT --- libraries/native/native/eosio/tester.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/native/native/eosio/tester.hpp b/libraries/native/native/eosio/tester.hpp index 1a232e56b5..93a5e9e432 100644 --- a/libraries/native/native/eosio/tester.hpp +++ b/libraries/native/native/eosio/tester.hpp @@ -81,13 +81,13 @@ inline bool expect_print(bool check, const std::string& li, const char (&expecte } #define CHECK_ASSERT(...) \ - ___has_failed |= expect_assert(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); + ___has_failed &= expect_assert(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); #define REQUIRE_ASSERT(...) \ expect_assert(false, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); #define CHECK_PRINT(...) \ - ___has_failed |= expect_print(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); + ___has_failed &= expect_print(true, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__); #define REQUIRE_PRINT(...) \ expect_print(false, std::string(__FILE__)+":"+__func__+":"+(std::to_string(__LINE__)), __VA_ARGS__);