From aaff2c0d54d9b095778a2bef627574a959aec759 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 20 Oct 2025 18:57:38 +0300 Subject: [PATCH] Add tests for BOOST_CORE_STATIC_ASSERT --- test/Jamfile.v2 | 9 +++++++++ test/static_assert_fail.cpp | 11 +++++++++++ test/static_assert_fail2.cpp | 14 ++++++++++++++ test/static_assert_fail3.cpp | 10 ++++++++++ test/static_assert_fail4.cpp | 16 ++++++++++++++++ test/static_assert_test.cpp | 17 +++++++++++++++++ test/static_assert_test2.cpp | 25 +++++++++++++++++++++++++ test/static_assert_test3.cpp | 16 ++++++++++++++++ 8 files changed, 118 insertions(+) create mode 100644 test/static_assert_fail.cpp create mode 100644 test/static_assert_fail2.cpp create mode 100644 test/static_assert_fail3.cpp create mode 100644 test/static_assert_fail4.cpp create mode 100644 test/static_assert_test.cpp create mode 100644 test/static_assert_test2.cpp create mode 100644 test/static_assert_test3.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index bf2e841..898eff7 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -469,3 +469,12 @@ run minstd_rand_test.cpp use-project /boost/core/swap : ./swap ; build-project ./swap ; + +compile static_assert_test.cpp ; +compile static_assert_test2.cpp ; +compile static_assert_test3.cpp ; + +compile-fail static_assert_fail.cpp ; +compile-fail static_assert_fail2.cpp ; +compile-fail static_assert_fail3.cpp ; +compile-fail static_assert_fail4.cpp ; diff --git a/test/static_assert_fail.cpp b/test/static_assert_fail.cpp new file mode 100644 index 0000000..6145cbc --- /dev/null +++ b/test/static_assert_fail.cpp @@ -0,0 +1,11 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +BOOST_CORE_STATIC_ASSERT( sizeof(char[1]) != 1 ); + +int main() +{ +} diff --git a/test/static_assert_fail2.cpp b/test/static_assert_fail2.cpp new file mode 100644 index 0000000..9f7f4d7 --- /dev/null +++ b/test/static_assert_fail2.cpp @@ -0,0 +1,14 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +struct X +{ + BOOST_CORE_STATIC_ASSERT( sizeof(char[2]) != 2 ); +}; + +int main() +{ +} diff --git a/test/static_assert_fail3.cpp b/test/static_assert_fail3.cpp new file mode 100644 index 0000000..09fb4a4 --- /dev/null +++ b/test/static_assert_fail3.cpp @@ -0,0 +1,10 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +int main() +{ + BOOST_CORE_STATIC_ASSERT( sizeof(char[3]) != 3 ); +} diff --git a/test/static_assert_fail4.cpp b/test/static_assert_fail4.cpp new file mode 100644 index 0000000..f381490 --- /dev/null +++ b/test/static_assert_fail4.cpp @@ -0,0 +1,16 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +template struct X +{ + BOOST_CORE_STATIC_ASSERT( C >= 0 ); +}; + +int main() +{ + X< -4 > x; + (void)x; +} diff --git a/test/static_assert_test.cpp b/test/static_assert_test.cpp new file mode 100644 index 0000000..6241d75 --- /dev/null +++ b/test/static_assert_test.cpp @@ -0,0 +1,17 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +BOOST_CORE_STATIC_ASSERT( sizeof(char[1]) == 1 ); + +struct X +{ + BOOST_CORE_STATIC_ASSERT( sizeof(char[2]) == 2 ); +}; + +int main() +{ + BOOST_CORE_STATIC_ASSERT( sizeof(char[3]) == 3 ); +} diff --git a/test/static_assert_test2.cpp b/test/static_assert_test2.cpp new file mode 100644 index 0000000..b6e7de3 --- /dev/null +++ b/test/static_assert_test2.cpp @@ -0,0 +1,25 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +template struct plus +{ + static const int value = A + B; +}; + +BOOST_CORE_STATIC_ASSERT((plus<1, 2>::value == 3)); + +template struct X +{ + BOOST_CORE_STATIC_ASSERT((plus::value == C + 1)); +}; + +int main() +{ + BOOST_CORE_STATIC_ASSERT((plus<3, 4>::value == 7)); + + X<4> x; + (void)x; +} diff --git a/test/static_assert_test3.cpp b/test/static_assert_test3.cpp new file mode 100644 index 0000000..177b6b4 --- /dev/null +++ b/test/static_assert_test3.cpp @@ -0,0 +1,16 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +template struct X +{ + BOOST_CORE_STATIC_ASSERT( C >= 0 ); +}; + +int main() +{ + X<4> x; + (void)x; +}