Skip to content

Commit

Permalink
Merge pull request #434 from ValeevGroup/evaleev/cmake/disable-throw-…
Browse files Browse the repository at this point in the history
…tests-unless-assert-policy-throws

disable throw tests unless assert policy throws
  • Loading branch information
evaleev authored Nov 19, 2023
2 parents 498561d + 1ba4fbb commit f0115e9
Show file tree
Hide file tree
Showing 19 changed files with 175 additions and 154 deletions.
23 changes: 13 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ include(LoadFetchContent)
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(FeatureSummary)
include(CTest) # testing, defined BUILD_TESTING

set(MPI_CXX_SKIP_MPICXX TRUE CACHE BOOL "MPI_CXX_SKIP_MPICXX")

Expand Down Expand Up @@ -284,13 +285,6 @@ set_property(
CACHE TA_ASSERT_POLICY PROPERTY
STRINGS TA_ASSERT_THROW TA_ASSERT_ABORT TA_ASSERT_IGNORE)

# if building unit tests default to throw to be able to test TA_ASSERT statements
if (NOT (TA_ASSERT_POLICY STREQUAL TA_ASSERT_THROW))
if (BUILD_TESTING)
message(FATAL_ERROR "TA_ASSERT_POLICY=${TA_ASSERT_POLICY} requires BUILD_TESTING=OFF")
endif(BUILD_TESTING)
endif()

##########################
# Include source dirctories
##########################
Expand Down Expand Up @@ -368,14 +362,20 @@ add_subdirectory(doc)
##########################
# checking/testing
##########################
include(CTest)
# N.B. CTest was included above
if (BUILD_TESTING)
set(_ctest_args -V -R "tiledarray/unit/run-np.*")
set(_ctest_args_serial -V -R "tiledarray/unit/run-np-1")
if (DEFINED TA_UT_CTEST_TIMEOUT)
list(APPEND _ctest_args --timeout ${TA_UT_CTEST_TIMEOUT})
list(APPEND _ctest_args_serial --timeout ${TA_UT_CTEST_TIMEOUT})
endif(DEFINED TA_UT_CTEST_TIMEOUT)

# if building unit tests need to configure with TA_ASSERT_POLICY=TA_ASSERT_THROW to be able to test TA_ASSERT statements
if (NOT (TA_ASSERT_POLICY STREQUAL TA_ASSERT_THROW))
message(WARNING "BUILD_TESTING=ON requires configuring with TA_ASSERT_POLICY=TA_ASSERT_THROW to engage REQUIRE_THROWS() tests; will skip these tests")
endif()

add_custom_target_subproject(tiledarray check USES_TERMINAL COMMAND ${CMAKE_CTEST_COMMAND} ${_ctest_args})
add_custom_target_subproject(tiledarray check_serial USES_TERMINAL COMMAND ${CMAKE_CTEST_COMMAND} ${_ctest_args_serial})
add_subdirectory(tests)
Expand Down Expand Up @@ -479,8 +479,11 @@ ADD_CUSTOM_TARGET(release
COMMENT "Switch CMAKE_BUILD_TYPE to Release"
)

feature_summary(WHAT ALL
DESCRIPTION "=== TiledArray Package/Feature Info ===")
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
feature_summary(WHAT ALL
DESCRIPTION "=== TiledArray Package/Feature Info ===")
feature_summary(FILENAME ${CMAKE_CURRENT_BINARY_DIR}/features.log WHAT ALL)
endif()

option(TA_PYTHON "Build TA python module" OFF)
if (TA_PYTHON)
Expand Down
2 changes: 1 addition & 1 deletion tests/annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ BOOST_AUTO_TEST_SUITE(split_index_fxn)

BOOST_AUTO_TEST_CASE(invalid_idx) {
if (TiledArray::get_default_world().nproc() == 1)
BOOST_CHECK_THROW(split_index("i,"), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(split_index("i,"), TiledArray::Exception);
}

BOOST_AUTO_TEST_CASE(non_tot) {
Expand Down
22 changes: 11 additions & 11 deletions tests/bipartite_index_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ BOOST_AUTO_TEST_CASE(default_ctor) {
*/
BOOST_AUTO_TEST_CASE(string_ctor) {
if (world.nproc() == 1) {
BOOST_CHECK_THROW(BipartiteIndexList("i,"), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(BipartiteIndexList("i,"), TiledArray::Exception);
}

for (auto&& [str, idx] : idxs) {
Expand Down Expand Up @@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(copy_assignment) {
BOOST_AUTO_TEST_CASE(string_assignment) {
if (world.nproc() == 1) {
BipartiteIndexList v1;
BOOST_CHECK_THROW(v1.operator=("i,"), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(v1.operator=("i,"), TiledArray::Exception);
}

for (auto&& [str, idx] : idxs) {
Expand Down Expand Up @@ -282,7 +282,7 @@ BOOST_AUTO_TEST_CASE(permute_in_place) {
if (world.nproc() == 1) {
BipartiteIndexList v0;
Permutation p{0, 1};
BOOST_CHECK_THROW(v0 *= p, TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(v0 *= p, TiledArray::Exception);
}

Permutation p({1, 2, 3, 0});
Expand Down Expand Up @@ -335,13 +335,13 @@ BOOST_AUTO_TEST_CASE(end_itr) {
BOOST_AUTO_TEST_CASE(at_member) {
for (auto&& [str, idx] : idxs) {
if (world.nproc() == 1) {
BOOST_CHECK_THROW(idx.at(idx.size()),
BOOST_CHECK_TA_ASSERT(idx.at(idx.size()),
#ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS
std::out_of_range
std::out_of_range
#else
boost::container::out_of_range
boost::container::out_of_range
#endif
);
);
}
auto [outer, inner] = detail::split_index(str);
for (size_type i = 0; i < outer.size(); ++i)
Expand Down Expand Up @@ -498,23 +498,23 @@ BOOST_AUTO_TEST_CASE(permutation_fxn) {

{ // not both ToT
BipartiteIndexList v1("i;j");
BOOST_CHECK_THROW(v1.permutation(v0), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(v1.permutation(v0), TiledArray::Exception);
}

{ // wrong size
BipartiteIndexList v1("i");
BOOST_CHECK_THROW(v1.permutation(v0), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(v1.permutation(v0), TiledArray::Exception);
}

{ // not a permutation
BipartiteIndexList v1("i, a");
BOOST_CHECK_THROW(v1.permutation(v0), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(v1.permutation(v0), TiledArray::Exception);
}

{ // ToTs mix outer and inner
BipartiteIndexList v1("i,j;k,l");
BipartiteIndexList v2("i,k;j,l");
BOOST_CHECK_THROW(v1.permutation(v2), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(v1.permutation(v2), TiledArray::Exception);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/bitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ BOOST_AUTO_TEST_CASE(accessor) {

// Check that exceptions are thrown when accessing an element that is out of
// range.
BOOST_CHECK_THROW(set[set.size()], Exception);
BOOST_CHECK_THROW(set[set.size() + 1], Exception);
BOOST_CHECK_TA_ASSERT(set[set.size()], Exception);
BOOST_CHECK_TA_ASSERT(set[set.size() + 1], Exception);
}

BOOST_AUTO_TEST_CASE(set_bit) {
Expand Down
12 changes: 6 additions & 6 deletions tests/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,12 @@ BOOST_AUTO_TEST_CASE(concat) {
}
}
// ranges of non-concatted dims must match
BOOST_CHECK_THROW((TiledArray::concat<Tensor, Policy>(
{a, b_t}, std::vector<bool>{false, true})),
TiledArray::Exception);
BOOST_CHECK_THROW((TiledArray::concat<Tensor, Policy>(
{a, b_t}, std::vector<bool>{true, false})),
TiledArray::Exception);
BOOST_CHECK_TA_ASSERT((TiledArray::concat<Tensor, Policy>(
{a, b_t}, std::vector<bool>{false, true})),
TiledArray::Exception);
BOOST_CHECK_TA_ASSERT((TiledArray::concat<Tensor, Policy>(
{a, b_t}, std::vector<bool>{true, false})),
TiledArray::Exception);
};

do_test(static_cast<TArrayI*>(nullptr));
Expand Down
42 changes: 21 additions & 21 deletions tests/cyclic_pmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,28 @@ BOOST_AUTO_TEST_CASE(constructor) {

ProcessID size = GlobalFixture::world->size();

BOOST_CHECK_THROW(TiledArray::detail::CyclicPmap pmap(*GlobalFixture::world,
0ul, 10ul, 1, 1),
TiledArray::Exception);
BOOST_CHECK_THROW(TiledArray::detail::CyclicPmap pmap(*GlobalFixture::world,
10ul, 0ul, 1, 1),
TiledArray::Exception);
BOOST_CHECK_THROW(TiledArray::detail::CyclicPmap pmap(*GlobalFixture::world,
10ul, 10ul, 0, 1),
TiledArray::Exception);
BOOST_CHECK_THROW(TiledArray::detail::CyclicPmap pmap(*GlobalFixture::world,
10ul, 10ul, 1, 0),
TiledArray::Exception);
BOOST_CHECK_THROW(TiledArray::detail::CyclicPmap pmap(
*GlobalFixture::world, 10ul, 10ul, size * 2, 1),
TiledArray::Exception);
BOOST_CHECK_THROW(TiledArray::detail::CyclicPmap pmap(
*GlobalFixture::world, 10ul, 10ul, 1, size * 2),
TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(TiledArray::detail::CyclicPmap pmap(
*GlobalFixture::world, 0ul, 10ul, 1, 1),
TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(TiledArray::detail::CyclicPmap pmap(
*GlobalFixture::world, 10ul, 0ul, 1, 1),
TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(TiledArray::detail::CyclicPmap pmap(
*GlobalFixture::world, 10ul, 10ul, 0, 1),
TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(TiledArray::detail::CyclicPmap pmap(
*GlobalFixture::world, 10ul, 10ul, 1, 0),
TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(TiledArray::detail::CyclicPmap pmap(
*GlobalFixture::world, 10ul, 10ul, size * 2, 1),
TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(TiledArray::detail::CyclicPmap pmap(
*GlobalFixture::world, 10ul, 10ul, 1, size * 2),
TiledArray::Exception);
if (size > 1) {
BOOST_CHECK_THROW(TiledArray::detail::CyclicPmap pmap(
*GlobalFixture::world, 10ul, 10ul, size, size),
TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(TiledArray::detail::CyclicPmap pmap(
*GlobalFixture::world, 10ul, 10ul, size, size),
TiledArray::Exception);
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/dist_op_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ BOOST_AUTO_TEST_CASE(constructor_empty) {

#if defined(MADNESS_ASSERTIONS_THROW)
// Check that accessing group data throws exceptions for an empty group.
BOOST_CHECK_THROW(empty_group.id(), madness::MadnessException);
BOOST_CHECK_THROW(empty_group.get_world(), madness::MadnessException);
BOOST_CHECK_THROW(empty_group.rank(), madness::MadnessException);
BOOST_CHECK_THROW(empty_group.rank(0), madness::MadnessException);
BOOST_CHECK_THROW(empty_group.world_rank(0), madness::MadnessException);
BOOST_CHECK_TA_ASSERT(empty_group.id(), madness::MadnessException);
BOOST_CHECK_TA_ASSERT(empty_group.get_world(), madness::MadnessException);
BOOST_CHECK_TA_ASSERT(empty_group.rank(), madness::MadnessException);
BOOST_CHECK_TA_ASSERT(empty_group.rank(0), madness::MadnessException);
BOOST_CHECK_TA_ASSERT(empty_group.world_rank(0), madness::MadnessException);
ProcessID parent, child1, child2;
BOOST_CHECK_THROW(empty_group.make_tree(0, parent, child1, child2),
madness::MadnessException);
BOOST_CHECK_TA_ASSERT(empty_group.make_tree(0, parent, child1, child2),
madness::MadnessException);
#endif // MADNESS_ASSERTIONS_THROW
}

Expand Down
6 changes: 3 additions & 3 deletions tests/distributed_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ BOOST_AUTO_TEST_CASE(set_value) {
BOOST_CHECK_EQUAL(n, t.max_size());

// Check throw for an out-of-range set.
BOOST_CHECK_THROW(t.set(t.max_size(), 1), TiledArray::Exception);
BOOST_CHECK_THROW(t.set(t.max_size() + 2, 1), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(t.set(t.max_size(), 1), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(t.set(t.max_size() + 2, 1), TiledArray::Exception);
}

BOOST_AUTO_TEST_CASE(array_operator) {
Expand All @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(array_operator) {
BOOST_CHECK_EQUAL(n, t.max_size());

// Check throw for an out-of-range set.
BOOST_CHECK_THROW(t.get(t.max_size()), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(t.get(t.max_size()), TiledArray::Exception);
BOOST_CHECK_THROW(t.get(t.max_size() + 2), TiledArray::Exception);
}

Expand Down
18 changes: 9 additions & 9 deletions tests/index_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ BOOST_AUTO_TEST_CASE(accessors) {
BOOST_CHECK_EQUAL(v.at(3), "d"); // check last variable access
BOOST_CHECK_EQUAL(v[0], "a"); // check 1st variable access
BOOST_CHECK_EQUAL(v[3], "d"); // check last variable access
BOOST_CHECK_THROW(v.at(4),
BOOST_CHECK_TA_ASSERT(v.at(4),
#ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS
std::out_of_range
std::out_of_range
#else
boost::container::out_of_range
boost::container::out_of_range
#endif
); // check for out of range throw.
}
Expand Down Expand Up @@ -175,11 +175,11 @@ BOOST_AUTO_TEST_CASE(constructor) {
BOOST_CHECK_EQUAL(v10.at(2), "c");
BOOST_CHECK_EQUAL(v10.at(3), "d");

BOOST_CHECK_THROW(IndexList v3(",a,b,c"),
Exception); // check invalid input
BOOST_CHECK_THROW(IndexList v4("a,,b,c"), Exception);
BOOST_CHECK_THROW(IndexList v5(" ,a,b"), Exception);
BOOST_CHECK_THROW(IndexList v6("a, b, , c"), Exception);
BOOST_CHECK_TA_ASSERT(IndexList v3(",a,b,c"),
Exception); // check invalid input
BOOST_CHECK_TA_ASSERT(IndexList v4("a,,b,c"), Exception);
BOOST_CHECK_TA_ASSERT(IndexList v5(" ,a,b"), Exception);
BOOST_CHECK_TA_ASSERT(IndexList v6("a, b, , c"), Exception);

IndexList v7(" a , b, c, d , e e ,f f, g10,h, i "); // check input with
// various spacings.
Expand All @@ -193,7 +193,7 @@ BOOST_AUTO_TEST_CASE(constructor) {
BOOST_CHECK_EQUAL(v7.at(7), "h");
BOOST_CHECK_EQUAL(v7.at(8), "i");

BOOST_REQUIRE_THROW(
BOOST_REQUIRE_TA_ASSERT(
IndexList v11(""),
TiledArray::Exception); // Empty string is not permitted constructor
}
Expand Down
2 changes: 1 addition & 1 deletion tests/initializer_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE(scalar) {
BOOST_AUTO_TEST_CASE(empty_vector) {
vector_il<double> il{};
if (world.rank() == 0) // only rank 0 does the work
BOOST_CHECK_THROW(tiled_range_from_il(il), Exception);
BOOST_CHECK_TA_ASSERT(tiled_range_from_il(il), Exception);
}

BOOST_AUTO_TEST_CASE(vector) {
Expand Down
5 changes: 2 additions & 3 deletions tests/perm_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ const std::array<std::size_t, 4> PermIndexFixture::start = {
const std::array<std::size_t, 4> PermIndexFixture::finish = {
{3ul, 5ul, 7ul, 11ul}};

BOOST_FIXTURE_TEST_SUITE(perm_index_suite, PermIndexFixture,
TA_UT_LABEL_SERIAL)
BOOST_FIXTURE_TEST_SUITE(perm_index_suite, PermIndexFixture, TA_UT_LABEL_SERIAL)

BOOST_AUTO_TEST_CASE(default_constructor) {
BOOST_CHECK_NO_THROW(PermIndex x;);
Expand All @@ -61,7 +60,7 @@ BOOST_AUTO_TEST_CASE(default_constructor) {
BOOST_CHECK(!x.data());

// Check that an exception is thrown when using a default constructed object
BOOST_CHECK_THROW(x(0), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(x(0), TiledArray::Exception);
}

BOOST_AUTO_TEST_CASE(constructor) {
Expand Down
4 changes: 2 additions & 2 deletions tests/range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ BOOST_AUTO_TEST_CASE(constructors) {
BOOST_CHECK_EQUAL(r2.volume(), 48);
}
#else // TA_SIGNED_1INDEX_TYPE
BOOST_REQUIRE_THROW(Range r2({{-1, 1}, {-2, 2}, {0, 6}}),
TiledArray::Exception);
BOOST_REQUIRE_TA_ASSERT(Range r2({{-1, 1}, {-2, 2}, {0, 6}}),
TiledArray::Exception);
#endif // TA_SIGNED_1INDEX_TYPE

// Copy Constructor
Expand Down
Loading

0 comments on commit f0115e9

Please sign in to comment.