From 62bf296a9c0f5be492f0677ed111b3fa217f4c11 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 3 May 2022 08:21:01 -0400 Subject: Make assert handling less error-prone Prevent my future self or other contributors from using assert in tests and then having that assert not do anything because of the NDEBUG macro. --- libtests/arg_parser.cc | 8 ++------ libtests/base64.cc | 3 ++- libtests/buffer.cc | 8 ++------ libtests/concatenate.cc | 8 ++------ libtests/cxx11.cc | 8 ++------ libtests/json.cc | 8 ++------ libtests/json_handler.cc | 8 ++------ libtests/matrix.cc | 8 ++------ libtests/pdf_version.cc | 8 ++------ libtests/predictors.cc | 8 ++------ libtests/qintc.cc | 8 ++------ libtests/qutil.cc | 8 ++------ libtests/rc4.cc | 8 ++------ libtests/sparse_array.cc | 8 ++------ 14 files changed, 28 insertions(+), 79 deletions(-) (limited to 'libtests') diff --git a/libtests/arg_parser.cc b/libtests/arg_parser.cc index 8b4d556a..1480a717 100644 --- a/libtests/arg_parser.cc +++ b/libtests/arg_parser.cc @@ -1,15 +1,11 @@ +#include + #include #include #include #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - class ArgParser { public: diff --git a/libtests/base64.cc b/libtests/base64.cc index 66f2d828..0ce6f9a3 100644 --- a/libtests/base64.cc +++ b/libtests/base64.cc @@ -1,8 +1,9 @@ +#include + #include #include #include -#include #include #include #include diff --git a/libtests/buffer.cc b/libtests/buffer.cc index a24c0f99..a65efb1c 100644 --- a/libtests/buffer.cc +++ b/libtests/buffer.cc @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -7,12 +9,6 @@ #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - static unsigned char* uc(char const* s) { diff --git a/libtests/concatenate.cc b/libtests/concatenate.cc index 10902adf..9bc0fd04 100644 --- a/libtests/concatenate.cc +++ b/libtests/concatenate.cc @@ -1,15 +1,11 @@ +#include + #include #include #include #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - static void pipeStringAndFinish(Pipeline* p, std::string const& str) { diff --git a/libtests/cxx11.cc b/libtests/cxx11.cc index 4c2c2cb6..250e7e2b 100644 --- a/libtests/cxx11.cc +++ b/libtests/cxx11.cc @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -9,12 +11,6 @@ #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - // Functional programming // Function that returns a callable in the form of a lambda diff --git a/libtests/json.cc b/libtests/json.cc index 43f2b3c6..3844222f 100644 --- a/libtests/json.cc +++ b/libtests/json.cc @@ -1,13 +1,9 @@ +#include + #include #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - static void check(JSON const& j, std::string const& exp) { diff --git a/libtests/json_handler.cc b/libtests/json_handler.cc index 567cde86..4e610b08 100644 --- a/libtests/json_handler.cc +++ b/libtests/json_handler.cc @@ -1,14 +1,10 @@ +#include + #include #include #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - static void print_null(std::string const& path) { diff --git a/libtests/matrix.cc b/libtests/matrix.cc index 7dc73390..f69d270c 100644 --- a/libtests/matrix.cc +++ b/libtests/matrix.cc @@ -1,13 +1,9 @@ +#include + #include #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - static void check(QPDFMatrix const& m, std::string const& exp) { diff --git a/libtests/pdf_version.cc b/libtests/pdf_version.cc index e9bfb00b..5db444b3 100644 --- a/libtests/pdf_version.cc +++ b/libtests/pdf_version.cc @@ -1,13 +1,9 @@ +#include + #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - int main() { diff --git a/libtests/predictors.cc b/libtests/predictors.cc index c024cbd6..a8f6c5d9 100644 --- a/libtests/predictors.cc +++ b/libtests/predictors.cc @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -9,12 +11,6 @@ #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - void run(char const* filename, char const* filter, diff --git a/libtests/qintc.cc b/libtests/qintc.cc index d3e19f5b..d5738a4b 100644 --- a/libtests/qintc.cc +++ b/libtests/qintc.cc @@ -1,12 +1,8 @@ +#include + #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - #define try_convert(exp_pass, fn, i) \ try_convert_real(#fn "(" #i ")", exp_pass, fn, i) diff --git a/libtests/qutil.cc b/libtests/qutil.cc index 017f371b..f79f9a3f 100644 --- a/libtests/qutil.cc +++ b/libtests/qutil.cc @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -17,12 +19,6 @@ # include #endif -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - template void test_to_number( diff --git a/libtests/rc4.cc b/libtests/rc4.cc index 7245ef86..1b1a8744 100644 --- a/libtests/rc4.cc +++ b/libtests/rc4.cc @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -8,12 +10,6 @@ #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - static void other_tests() { diff --git a/libtests/sparse_array.cc b/libtests/sparse_array.cc index 8d37bc2f..62410399 100644 --- a/libtests/sparse_array.cc +++ b/libtests/sparse_array.cc @@ -1,12 +1,8 @@ +#include + #include #include -#ifdef NDEBUG -// We need assert even in a release build for test code. -# undef NDEBUG -#endif -#include - int main() { -- cgit v1.2.3-54-g00ecf