diff --git a/Base/CMakeLists.txt b/Base/CMakeLists.txt index 4e457b2fb02477c14e704f33a4d45f833aa98f7d..9da6206c01dd3fb78b6223de89c3fb60d7836e05 100644 --- a/Base/CMakeLists.txt +++ b/Base/CMakeLists.txt @@ -26,11 +26,6 @@ target_include_directories(${lib} ) target_link_libraries(${lib} ${GSL_LIBRARIES} ${FFTW3_LIBRARIES} ${Boost_LIBRARIES}) -if(BORNAGAIN_GUI) - target_include_directories(${lib} PUBLIC ${Qt5Core_INCLUDE_DIRS}) - target_link_libraries(${lib} ${Qt5Core_LIBRARIES}) -endif() - if(BORNAGAIN_MPI) add_definitions(-DBORNAGAIN_MPI) include_directories(${MPI_INCLUDE_PATH}) diff --git a/Base/Utils/Assert.h b/Base/Utils/Assert.h index db398824f74b03f387df59301b98c8b6a6d6d9dc..3a28667e87fdd92b0a8e3539114e5854a7c78fc8 100644 --- a/Base/Utils/Assert.h +++ b/Base/Utils/Assert.h @@ -18,18 +18,14 @@ // ASSERT must be declared as a macro, not a function, in order for the error // message to correctly report the source line where the assertion failed. -#ifdef HAVE_QT +// For an alternative implementation that calls qFatal, see Base/Utils/Assert.h < 29oct20. -#include <QtGlobal> -#define ASSERT(condition) \ - if (!(condition)) \ - qFatal("Assertion %s failed in %s, line %d", (#condition), __FILE__, __LINE__) +#include <stdexcept> +#include <sstream> -#else // HAVE_QT undefined - -#include <cassert> -#define ASSERT(condition) assert(condition) - -#endif // HAVE_QT +#define ASSERT(condition) if (!(condition)) { \ + std::stringstream msg; \ + msg << "Assertion " << (#condition) << " failed in " << __FILE__ << ", line " << __LINE__; \ + throw std::runtime_error(msg.str()); } #endif // BORNAGAIN_BASE_UTILS_ASSERT_H diff --git a/Tests/UnitTests/Core/Basics/TestAssert.cpp b/Tests/UnitTests/Core/Basics/TestAssert.cpp deleted file mode 100644 index 4962e005770b45450dc96fe4c025797308f49ac9..0000000000000000000000000000000000000000 --- a/Tests/UnitTests/Core/Basics/TestAssert.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "Base/Utils/Assert.h" -#include "Tests/GTestWrapper/google_test.h" - -class TestAssert : public ::testing::Test -{ -}; - -TEST_F(TestAssert, Assert) -{ - EXPECT_NO_THROW(ASSERT(1)); -#ifndef WIN32 // Win currently dies with msg '' -- TODO verify, repair, restore test - EXPECT_DEATH(ASSERT(0), "Assertion .* failed .*"); -#endif -} diff --git a/Tests/UnitTests/Core/Other/SampleBuilderNodeTest.cpp b/Tests/UnitTests/Core/Other/SampleBuilderNodeTest.cpp index 5a3ad8b104c89d71dfd93271a2ca6f70d328683d..4e0f905692ef7d017cc6990474ac1027e193bdf7 100644 --- a/Tests/UnitTests/Core/Other/SampleBuilderNodeTest.cpp +++ b/Tests/UnitTests/Core/Other/SampleBuilderNodeTest.cpp @@ -7,6 +7,8 @@ #include <memory> #include <stdexcept> +#define EXPECT_ASSERT_TRIGGERED(condition) EXPECT_THROW((condition), std::runtime_error) + class SampleBuilderNodeTest : public ::testing::Test { public: @@ -66,7 +68,7 @@ TEST_F(SampleBuilderNodeTest, builderParameters) builderNode.reset(); EXPECT_EQ(builder.use_count(), 1); EXPECT_EQ(builderNode.parameterPool()->size(), 0u); - EXPECT_DEATH(builderNode.createMultiLayer(), ".*"); + EXPECT_ASSERT_TRIGGERED(builderNode.createMultiLayer()); } //! Checks assignment operator. diff --git a/Tests/UnitTests/GUI/TestSessionItem.cpp b/Tests/UnitTests/GUI/TestSessionItem.cpp index a8879d30d84515f12f4ad1e9e0abdbd0862ba059..f599460b1c7b4b5d9fa56394191bb79421811c9a 100644 --- a/Tests/UnitTests/GUI/TestSessionItem.cpp +++ b/Tests/UnitTests/GUI/TestSessionItem.cpp @@ -2,6 +2,8 @@ #include "GUI/coregui/utils/GUIHelpers.h" #include "Tests/GTestWrapper/google_test.h" +#define EXPECT_ASSERT_TRIGGERED(condition) EXPECT_THROW((condition), std::runtime_error) + class TestSessionItem : public ::testing::Test { }; @@ -25,7 +27,7 @@ TEST_F(TestSessionItem, defaultTag) // insertion without tag is forbidden SessionItem* child = new SessionItem(modelType); - EXPECT_DEATH(item->insertItem(0, child), ".*"); + EXPECT_ASSERT_TRIGGERED(item->insertItem(0, child)); delete child; EXPECT_EQ(item->numberOfChildren(), 0); } @@ -55,7 +57,7 @@ TEST_F(TestSessionItem, singleTagAndItems) SessionItem* child = new SessionItem(modelType); EXPECT_TRUE(item->insertItem(0, child, tag1)); // double insertion is forbidden - EXPECT_DEATH(item->insertItem(0, child, tag1), ".*"); + EXPECT_ASSERT_TRIGGERED(item->insertItem(0, child, tag1)); EXPECT_TRUE(child->parent() == item.get()); EXPECT_EQ(item->numberOfChildren(), 1); @@ -135,7 +137,7 @@ TEST_F(TestSessionItem, tagWithLimits) EXPECT_TRUE(item->insertItem(-1, child, tag1)); } auto extra = new SessionItem(modelType); - EXPECT_DEATH(item->insertItem(-1, extra, tag1), ".*"); + EXPECT_ASSERT_TRIGGERED(item->insertItem(-1, extra, tag1)); } TEST_F(TestSessionItem, tagsAndModelTypes) @@ -250,25 +252,25 @@ TEST_F(TestSessionItem, modelTypes) EXPECT_TRUE(item->insertItem(0, new SessionItem(model2), "Tag1")); auto child = new SessionItem(model3); - EXPECT_DEATH(item->insertItem(0, child, "Tag1"), ".*"); + EXPECT_ASSERT_TRIGGERED(item->insertItem(0, child, "Tag1")); delete child; child = new SessionItem(model4); - EXPECT_DEATH(item->insertItem(0, child, "Tag1"), ".*"); + EXPECT_ASSERT_TRIGGERED(item->insertItem(0, child, "Tag1")); delete child; child = new SessionItem(model5); - EXPECT_DEATH(item->insertItem(0, child, "Tag1"), ".*"); + EXPECT_ASSERT_TRIGGERED(item->insertItem(0, child, "Tag1")); delete child; EXPECT_TRUE(item->registerTag("Tag2", 0, -1, QStringList() << model3 << model4 << model5)); child = new SessionItem(model1); - EXPECT_DEATH(item->insertItem(0, child, "Tag2"), ".*"); + EXPECT_ASSERT_TRIGGERED(item->insertItem(0, child, "Tag2")); delete child; child = new SessionItem(model2); - EXPECT_DEATH(item->insertItem(0, child, "Tag2"), ".*"); + EXPECT_ASSERT_TRIGGERED(item->insertItem(0, child, "Tag2")); delete child; EXPECT_TRUE(item->insertItem(0, new SessionItem(model3), "Tag2")); diff --git a/cmake/configurables/FixAppleBundle.cmake.in b/cmake/configurables/FixAppleBundle.cmake.in index 87e9d1a6eb7c95889ddbad7cdcdfd1b8290facef..f6bc7be09f30997a4dd3c8d455cbb554b451e0f5 100644 --- a/cmake/configurables/FixAppleBundle.cmake.in +++ b/cmake/configurables/FixAppleBundle.cmake.in @@ -1,6 +1,8 @@ ############################################################################### -# Runs Python script to fix dependencies in Apple bundle +# Runs Python script to fix dependencies in Apple bundle. +# Configured and run from GUI/main/CMakeLists.txt. ############################################################################### set(bundle ${CMAKE_INSTALL_PREFIX}/BornAgain.app ) -execute_process(COMMAND @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/cmake/bornagain/scripts/fix_apple_bundle.py ${bundle}) +execute_process(COMMAND @Python3_EXECUTABLE@ + @CMAKE_SOURCE_DIR@/cmake/pack/fix_apple_bundle.py ${bundle}) diff --git a/cmake/configurables/fix_apple_bundle.py b/cmake/pack/fix_apple_bundle.py similarity index 98% rename from cmake/configurables/fix_apple_bundle.py rename to cmake/pack/fix_apple_bundle.py index fae2dd3c9bba4ce5705124746cdd2dc4169050fc..f40cc3e32f118d9f77396a3064f069e22e94591c 100644 --- a/cmake/configurables/fix_apple_bundle.py +++ b/cmake/pack/fix_apple_bundle.py @@ -1,5 +1,7 @@ """ -Script to fix all dependencies in OS X bundle. Runs automatically when -DBORNAGAIN_APPLE_BUNDLE +Script to fix all dependencies in OS X bundle. +Runs automatically when -DBORNAGAIN_APPLE_BUNDLE. +Called via cmake/configurables/FixAppleBundle.cmake.in. """ from __future__ import print_function import os @@ -425,7 +427,7 @@ def fix_apple_bundle(): if __name__ == '__main__': if not platform.system() == 'Darwin': - exit("This script is intended for MacOs systems. Exiting...") + exit("This script is intended for MacOS. Exiting...") if len(sys.argv) != 2: exit("Please specify bundle location")