github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/pybind11/tests/test_embed/catch.cpp (about) 1 // The Catch implementation is compiled here. This is a standalone 2 // translation unit to avoid recompiling it for every test change. 3 4 #include <pybind11/embed.h> 5 6 // Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to 7 // catch 2.0.1; this should be fixed in the next catch release after 2.0.1). 8 PYBIND11_WARNING_DISABLE_MSVC(4996) 9 10 // Catch uses _ internally, which breaks gettext style defines 11 #ifdef _ 12 # undef _ 13 #endif 14 15 #define CATCH_CONFIG_RUNNER 16 #include <catch.hpp> 17 18 namespace py = pybind11; 19 20 int main(int argc, char *argv[]) { 21 // Setup for TEST_CASE in test_interpreter.cpp, tagging on a large random number: 22 std::string updated_pythonpath("pybind11_test_embed_PYTHONPATH_2099743835476552"); 23 const char *preexisting_pythonpath = getenv("PYTHONPATH"); 24 if (preexisting_pythonpath != nullptr) { 25 #if defined(_WIN32) 26 updated_pythonpath += ';'; 27 #else 28 updated_pythonpath += ':'; 29 #endif 30 updated_pythonpath += preexisting_pythonpath; 31 } 32 #if defined(_WIN32) 33 _putenv_s("PYTHONPATH", updated_pythonpath.c_str()); 34 #else 35 setenv("PYTHONPATH", updated_pythonpath.c_str(), /*replace=*/1); 36 #endif 37 38 py::scoped_interpreter guard{}; 39 40 auto result = Catch::Session().run(argc, argv); 41 42 return result < 0xff ? result : 0xff; 43 }