pybind11/tests/test_embed/catch.cpp

46 lines
1.3 KiB
C++
Raw Permalink Normal View History

// The Catch implementation is compiled here. This is a standalone
// translation unit to avoid recompiling it for every test change.
#include <pybind11/embed.h>
#ifdef _MSC_VER
// Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to
// catch 2.0.1; this should be fixed in the next catch release after 2.0.1).
# pragma warning(disable : 4996)
#endif
tests: update catch to 2.13.5 to fix glibc 2.34 failures (#3679) * Download catch for MinGw * Fix rest of MinGW * fix: update catch to 2.13.5 to fix glibc 2.34 failures Update the downloaded Catch version to 2.13.5, in order to fix build failure on glibc 2.34: ``` In file included from /usr/include/signal.h:328, from /tmp/pybind11/.nox/tests-3-9/tmp/tests/catch/catch.hpp:8030, from /tmp/pybind11/tests/test_embed/catch.cpp:13: /tmp/pybind11/.nox/tests-3-9/tmp/tests/catch/catch.hpp:10818:58: error: call to non-‘constexpr’ function ‘long int sysconf(int)’ 10818 | static constexpr std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ; | ^~~~~~~~~~~ In file included from /usr/include/python3.9/Python.h:36, from /tmp/pybind11/include/pybind11/detail/common.h:215, from /tmp/pybind11/include/pybind11/pytypes.h:12, from /tmp/pybind11/include/pybind11/cast.h:13, from /tmp/pybind11/include/pybind11/attr.h:13, from /tmp/pybind11/include/pybind11/pybind11.h:13, from /tmp/pybind11/include/pybind11/embed.h:12, from /tmp/pybind11/tests/test_embed/catch.cpp:4: /usr/include/unistd.h:640:17: note: ‘long int sysconf(int)’ declared here 640 | extern long int sysconf (int __name) __THROW; | ^~~~~~~ In file included from /tmp/pybind11/tests/test_embed/catch.cpp:13: /tmp/pybind11/.nox/tests-3-9/tmp/tests/catch/catch.hpp:10877:45: error: size of array ‘altStackMem’ is not an integral constant-expression 10877 | char FatalConditionHandler::altStackMem[sigStackSize] = {}; | ^~~~~~~~~~~~ ``` The newest Catch version cannot be used yet because of regression: https://github.com/catchorg/Catch2/pull/2364 * fix: add option for _ check, only define on pybind11 * Revert "fix: add option for _ check, only define on pybind11" This reverts commit 86817db488c547816e21e20d678db318bb286384. * fix: only undef _ for catch cpp creation. Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
2022-02-06 04:53:02 +00:00
// Catch uses _ internally, which breaks gettext style defines
#ifdef _
# undef _
tests: update catch to 2.13.5 to fix glibc 2.34 failures (#3679) * Download catch for MinGw * Fix rest of MinGW * fix: update catch to 2.13.5 to fix glibc 2.34 failures Update the downloaded Catch version to 2.13.5, in order to fix build failure on glibc 2.34: ``` In file included from /usr/include/signal.h:328, from /tmp/pybind11/.nox/tests-3-9/tmp/tests/catch/catch.hpp:8030, from /tmp/pybind11/tests/test_embed/catch.cpp:13: /tmp/pybind11/.nox/tests-3-9/tmp/tests/catch/catch.hpp:10818:58: error: call to non-‘constexpr’ function ‘long int sysconf(int)’ 10818 | static constexpr std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ; | ^~~~~~~~~~~ In file included from /usr/include/python3.9/Python.h:36, from /tmp/pybind11/include/pybind11/detail/common.h:215, from /tmp/pybind11/include/pybind11/pytypes.h:12, from /tmp/pybind11/include/pybind11/cast.h:13, from /tmp/pybind11/include/pybind11/attr.h:13, from /tmp/pybind11/include/pybind11/pybind11.h:13, from /tmp/pybind11/include/pybind11/embed.h:12, from /tmp/pybind11/tests/test_embed/catch.cpp:4: /usr/include/unistd.h:640:17: note: ‘long int sysconf(int)’ declared here 640 | extern long int sysconf (int __name) __THROW; | ^~~~~~~ In file included from /tmp/pybind11/tests/test_embed/catch.cpp:13: /tmp/pybind11/.nox/tests-3-9/tmp/tests/catch/catch.hpp:10877:45: error: size of array ‘altStackMem’ is not an integral constant-expression 10877 | char FatalConditionHandler::altStackMem[sigStackSize] = {}; | ^~~~~~~~~~~~ ``` The newest Catch version cannot be used yet because of regression: https://github.com/catchorg/Catch2/pull/2364 * fix: add option for _ check, only define on pybind11 * Revert "fix: add option for _ check, only define on pybind11" This reverts commit 86817db488c547816e21e20d678db318bb286384. * fix: only undef _ for catch cpp creation. Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
2022-02-06 04:53:02 +00:00
#endif
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
namespace py = pybind11;
int main(int argc, char *argv[]) {
// Setup for TEST_CASE in test_interpreter.cpp, tagging on a large random number:
std::string updated_pythonpath("pybind11_test_embed_PYTHONPATH_2099743835476552");
const char *preexisting_pythonpath = getenv("PYTHONPATH");
if (preexisting_pythonpath != nullptr) {
#if defined(_WIN32)
updated_pythonpath += ';';
#else
updated_pythonpath += ':';
#endif
updated_pythonpath += preexisting_pythonpath;
}
#if defined(_WIN32)
_putenv_s("PYTHONPATH", updated_pythonpath.c_str());
#else
setenv("PYTHONPATH", updated_pythonpath.c_str(), /*replace=*/1);
#endif
py::scoped_interpreter guard{};
auto result = Catch::Session().run(argc, argv);
return result < 0xff ? result : 0xff;
}