mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Improve the testing macros to work across platforms.
Add a note to the documentation about SOL_NO_LUA_HPP being less preferred over the C++ defines, to Fix #1013. Add regression tests (not yet fixed) so I can get to the bottom of VC++ being ass.
This commit is contained in:
parent
5bbc095396
commit
af779f0bed
@ -134,6 +134,7 @@ Linker Config
|
|||||||
|
|
||||||
``SOL_USING_CXX_LUA`` triggers the following changes:
|
``SOL_USING_CXX_LUA`` triggers the following changes:
|
||||||
* Lua includes are no longer wrapped in ``extern "C" {}`` blocks
|
* Lua includes are no longer wrapped in ``extern "C" {}`` blocks
|
||||||
|
* ``SOL_NO_LUA_HPP`` takes less precedence if this is explicitly turned on
|
||||||
* Turns on ``SOL_EXCEPTIONS_SAFE_PROPAGATION`` automatically for you
|
* Turns on ``SOL_EXCEPTIONS_SAFE_PROPAGATION`` automatically for you
|
||||||
* Only use this if you know you've built your LuaJIT with the C++-specific invocations of your compiler (Lua by default builds as C code and is not distributed as a C++ library, but a C one with C symbols)
|
* Only use this if you know you've built your LuaJIT with the C++-specific invocations of your compiler (Lua by default builds as C code and is not distributed as a C++ library, but a C one with C symbols)
|
||||||
|
|
||||||
|
@ -38,11 +38,13 @@
|
|||||||
|
|
||||||
#define SOL_IS_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) != 0)
|
#define SOL_IS_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) != 0)
|
||||||
#define SOL_IS_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3) == 0)
|
#define SOL_IS_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3) == 0)
|
||||||
#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) == 1)
|
#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) > 3)
|
||||||
|
#define SOL_IS_DEFAULT_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3 OP_SYMBOL 3) < 0)
|
||||||
|
|
||||||
#define SOL_ON +
|
#define SOL_ON |
|
||||||
#define SOL_OFF -
|
#define SOL_OFF ^
|
||||||
#define SOL_DEFAULT_ON /
|
#define SOL_DEFAULT_ON +
|
||||||
|
#define SOL_DEFAULT_OFF -
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#define SOL_COMPILER_CLANG_I_ SOL_OFF
|
#define SOL_COMPILER_CLANG_I_ SOL_OFF
|
||||||
@ -473,6 +475,8 @@
|
|||||||
#else
|
#else
|
||||||
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
||||||
#endif
|
#endif
|
||||||
|
#elif defined(SOL_USING_CXX_LUA)
|
||||||
|
#define SOL_USE_LUA_HPP_I_ SOL_OFF
|
||||||
#elif defined(__has_include)
|
#elif defined(__has_include)
|
||||||
#if __has_include(<lua.hpp>)
|
#if __has_include(<lua.hpp>)
|
||||||
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// This file was generated with a script.
|
// This file was generated with a script.
|
||||||
// Generated 2020-08-02 22:15:17.519015 UTC
|
// Generated 2020-08-12 23:04:25.864654 UTC
|
||||||
// This header was generated with sol v3.2.1 (revision 7be51eb)
|
// This header was generated with sol v3.2.1 (revision 5bbc095)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_CONFIG_HPP
|
#ifndef SOL_SINGLE_CONFIG_HPP
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// This file was generated with a script.
|
// This file was generated with a script.
|
||||||
// Generated 2020-08-02 22:15:17.497014 UTC
|
// Generated 2020-08-12 23:04:25.839654 UTC
|
||||||
// This header was generated with sol v3.2.1 (revision 7be51eb)
|
// This header was generated with sol v3.2.1 (revision 5bbc095)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||||
@ -46,11 +46,13 @@
|
|||||||
|
|
||||||
#define SOL_IS_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) != 0)
|
#define SOL_IS_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) != 0)
|
||||||
#define SOL_IS_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3) == 0)
|
#define SOL_IS_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3) == 0)
|
||||||
#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) == 1)
|
#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) > 3)
|
||||||
|
#define SOL_IS_DEFAULT_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3 OP_SYMBOL 3) < 0)
|
||||||
|
|
||||||
#define SOL_ON +
|
#define SOL_ON |
|
||||||
#define SOL_OFF -
|
#define SOL_OFF ^
|
||||||
#define SOL_DEFAULT_ON /
|
#define SOL_DEFAULT_ON +
|
||||||
|
#define SOL_DEFAULT_OFF -
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#define SOL_COMPILER_CLANG_I_ SOL_OFF
|
#define SOL_COMPILER_CLANG_I_ SOL_OFF
|
||||||
@ -479,6 +481,8 @@
|
|||||||
#else
|
#else
|
||||||
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
||||||
#endif
|
#endif
|
||||||
|
#elif defined(SOL_USING_CXX_LUA)
|
||||||
|
#define SOL_USE_LUA_HPP_I_ SOL_OFF
|
||||||
#elif defined(__has_include)
|
#elif defined(__has_include)
|
||||||
#if __has_include(<lua.hpp>)
|
#if __has_include(<lua.hpp>)
|
||||||
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// This file was generated with a script.
|
// This file was generated with a script.
|
||||||
// Generated 2020-08-02 22:15:16.995707 UTC
|
// Generated 2020-08-12 23:04:25.317593 UTC
|
||||||
// This header was generated with sol v3.2.1 (revision 7be51eb)
|
// This header was generated with sol v3.2.1 (revision 5bbc095)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||||
@ -72,11 +72,13 @@
|
|||||||
|
|
||||||
#define SOL_IS_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) != 0)
|
#define SOL_IS_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) != 0)
|
||||||
#define SOL_IS_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3) == 0)
|
#define SOL_IS_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3) == 0)
|
||||||
#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) == 1)
|
#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) > 3)
|
||||||
|
#define SOL_IS_DEFAULT_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3 OP_SYMBOL 3) < 0)
|
||||||
|
|
||||||
#define SOL_ON +
|
#define SOL_ON |
|
||||||
#define SOL_OFF -
|
#define SOL_OFF ^
|
||||||
#define SOL_DEFAULT_ON /
|
#define SOL_DEFAULT_ON +
|
||||||
|
#define SOL_DEFAULT_OFF -
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#define SOL_COMPILER_CLANG_I_ SOL_OFF
|
#define SOL_COMPILER_CLANG_I_ SOL_OFF
|
||||||
@ -505,6 +507,8 @@
|
|||||||
#else
|
#else
|
||||||
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
||||||
#endif
|
#endif
|
||||||
|
#elif defined(SOL_USING_CXX_LUA)
|
||||||
|
#define SOL_USE_LUA_HPP_I_ SOL_OFF
|
||||||
#elif defined(__has_include)
|
#elif defined(__has_include)
|
||||||
#if __has_include(<lua.hpp>)
|
#if __has_include(<lua.hpp>)
|
||||||
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
#define SOL_USE_LUA_HPP_I_ SOL_ON
|
||||||
@ -1242,7 +1246,7 @@ namespace sol { namespace meta {
|
|||||||
|
|
||||||
#endif // noexcept is part of a function's type
|
#endif // noexcept is part of a function's type
|
||||||
|
|
||||||
#if defined(_MSC_VER) && defined(_M_IX86)
|
#if SOL_IS_ON(SOL_COMPILER_VCXX_I_) && SOL_IS_ON(SOL_PLATFORM_X86_I_)
|
||||||
template <typename R, typename... Args>
|
template <typename R, typename... Args>
|
||||||
struct fx_traits<R __stdcall(Args...), false> : basic_traits<false, false, void, R, Args...> {
|
struct fx_traits<R __stdcall(Args...), false> : basic_traits<false, false, void, R, Args...> {
|
||||||
typedef R(__stdcall* function_pointer_type)(Args...);
|
typedef R(__stdcall* function_pointer_type)(Args...);
|
||||||
@ -1426,10 +1430,12 @@ namespace sol { namespace meta {
|
|||||||
#endif // __stdcall x86 VC++ bug
|
#endif // __stdcall x86 VC++ bug
|
||||||
|
|
||||||
template <typename Signature>
|
template <typename Signature>
|
||||||
struct fx_traits<Signature, true> : fx_traits<typename fx_traits<decltype(&Signature::operator())>::function_type, false> {};
|
struct fx_traits<Signature, true>
|
||||||
|
: public fx_traits<typename fx_traits<decltype(&Signature::operator())>::function_type, false> {};
|
||||||
|
|
||||||
template <typename Signature, bool b = std::is_member_object_pointer<Signature>::value>
|
template <typename Signature, bool b = std::is_member_object_pointer<Signature>::value>
|
||||||
struct callable_traits : fx_traits<std::decay_t<Signature>> {};
|
struct callable_traits
|
||||||
|
: public fx_traits<std::decay_t<Signature>> {};
|
||||||
|
|
||||||
template <typename R, typename T>
|
template <typename R, typename T>
|
||||||
struct callable_traits<R(T::*), true> {
|
struct callable_traits<R(T::*), true> {
|
||||||
@ -16914,8 +16920,8 @@ namespace sol {
|
|||||||
else {
|
else {
|
||||||
using traits_type = lua_bind_traits<F>;
|
using traits_type = lua_bind_traits<F>;
|
||||||
using return_type = typename traits_type::return_type;
|
using return_type = typename traits_type::return_type;
|
||||||
constexpr bool is_const = std::is_const_v<std::remove_reference_t<return_type>>;
|
constexpr bool ret_is_const = std::is_const_v<std::remove_reference_t<return_type>>;
|
||||||
if constexpr (is_const) {
|
if constexpr (ret_is_const) {
|
||||||
(void)fx;
|
(void)fx;
|
||||||
(void)detail::swallow{ 0, (static_cast<void>(args), 0)... };
|
(void)detail::swallow{ 0, (static_cast<void>(args), 0)... };
|
||||||
return luaL_error(L, "sol: cannot write to a readonly (const) variable");
|
return luaL_error(L, "sol: cannot write to a readonly (const) variable");
|
||||||
@ -18445,7 +18451,7 @@ namespace sol {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct unqualified_pusher<detail::tagged<T, no_construction>> {
|
struct unqualified_pusher<detail::tagged<T, no_construction>> {
|
||||||
static int push(lua_State* L, no_construction) {
|
static int push(lua_State* L, detail::tagged<T, no_construction>) {
|
||||||
lua_CFunction cf = &function_detail::no_construction_error;
|
lua_CFunction cf = &function_detail::no_construction_error;
|
||||||
return stack::push(L, cf);
|
return stack::push(L, cf);
|
||||||
}
|
}
|
||||||
|
@ -24,3 +24,4 @@
|
|||||||
|
|
||||||
add_subdirectory(runtime_tests)
|
add_subdirectory(runtime_tests)
|
||||||
add_subdirectory(compile_tests)
|
add_subdirectory(compile_tests)
|
||||||
|
add_subdirectory(regression_tests)
|
||||||
|
99
tests/regression_tests/CMakeLists.txt
Normal file
99
tests/regression_tests/CMakeLists.txt
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
# # # # sol3
|
||||||
|
# The MIT License (MIT)
|
||||||
|
#
|
||||||
|
# Copyright (c) 2013-2019 Rapptz, ThePhD, and contributors
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
# this software and associated documentation files (the "Software"), to deal in
|
||||||
|
# the Software without restriction, including without limitation the rights to
|
||||||
|
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
# the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
# subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in all
|
||||||
|
# copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
# # # # sol3 tests - runtime tests
|
||||||
|
|
||||||
|
file(GLOB SOL2_RUNTIME_TEST_SOURCES source/*.cpp)
|
||||||
|
source_group(test_sources FILES ${SOL2_RUNTIME_TEST_SOURCES})
|
||||||
|
|
||||||
|
function(CREATE_TEST test_target_name test_name target_sol)
|
||||||
|
add_executable(${test_target_name} ${SOL2_RUNTIME_TEST_SOURCES})
|
||||||
|
set_target_properties(${test_target_name}
|
||||||
|
PROPERTIES
|
||||||
|
OUTPUT_NAME ${test_name}
|
||||||
|
EXPORT_NAME sol2::${test_name})
|
||||||
|
target_link_libraries(${test_target_name}
|
||||||
|
PUBLIC Threads::Threads ${LUA_LIBRARIES} ${target_sol})
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
if (NOT CMAKE_COMPILER_ID MATCHES "Clang")
|
||||||
|
target_compile_options(${test_target_name}
|
||||||
|
PRIVATE /bigobj /W4)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
target_compile_options(${test_target_name}
|
||||||
|
PRIVATE -std=c++1z -pthread
|
||||||
|
-Wno-unknown-warning -Wno-unknown-warning-option
|
||||||
|
-Wall -Wpedantic -Werror -pedantic -pedantic-errors
|
||||||
|
-Wno-noexcept-type)
|
||||||
|
|
||||||
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
|
# For another day, when C++ is not so crap
|
||||||
|
# and we have time to audit the entire lib
|
||||||
|
# for all uses of `detail::swallow`...
|
||||||
|
#target_compile_options(${test_target_name}
|
||||||
|
# PRIVATE -Wcomma)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (IS_X86)
|
||||||
|
if(MINGW)
|
||||||
|
set_target_properties(${test_target_name}
|
||||||
|
PROPERTIES
|
||||||
|
LINK_FLAGS -static-libstdc++)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if (MSVC)
|
||||||
|
target_compile_options(${test_target_name}
|
||||||
|
PRIVATE /EHsc /std:c++latest)
|
||||||
|
target_compile_definitions(${test_target_name}
|
||||||
|
PRIVATE UNICODE _UNICODE
|
||||||
|
_CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE)
|
||||||
|
else()
|
||||||
|
target_compile_options(${test_target_name}
|
||||||
|
PRIVATE -std=c++1z -Wno-unknown-warning -Wno-unknown-warning-option
|
||||||
|
-Wall -Wextra -Wpedantic -pedantic -pedantic-errors)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (SOL2_CI)
|
||||||
|
target_compile_definitions(${test_target_name}
|
||||||
|
PRIVATE SOL2_CI)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (CMAKE_DL_LIBS)
|
||||||
|
target_link_libraries(${test_target_name}
|
||||||
|
PRIVATE ${CMAKE_DL_LIBS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_test(NAME ${test_name} COMMAND ${test_target_name})
|
||||||
|
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
|
||||||
|
endfunction(CREATE_TEST)
|
||||||
|
|
||||||
|
if (SOL2_TESTS)
|
||||||
|
CREATE_TEST(regression_tests "regression_tests" sol2::sol2)
|
||||||
|
endif()
|
||||||
|
if (SOL2_TESTS_SINGLE)
|
||||||
|
CREATE_TEST(regression_tests_single "regression_tests.single" sol2::sol2_single)
|
||||||
|
endif()
|
||||||
|
if (SOL2_TESTS_SINGLE_GENERATED)
|
||||||
|
CREATE_TEST(regression_tests_generated_single "regression_tests.single.generated" sol2::sol2_single_generated)
|
||||||
|
endif()
|
14
tests/regression_tests/source/1008.cpp
Normal file
14
tests/regression_tests/source/1008.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#define SOL_ALL_SAFETIES_ON 1
|
||||||
|
|
||||||
|
#include <sol/sol.hpp>
|
||||||
|
|
||||||
|
int regression_1008() {
|
||||||
|
|
||||||
|
sol::state lua;
|
||||||
|
lua.create_named_table("t");
|
||||||
|
|
||||||
|
sol::table t = lua["t"];
|
||||||
|
t["f"] = sol::as_function([]() {});
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
15
tests/regression_tests/source/main.cpp
Normal file
15
tests/regression_tests/source/main.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
extern int regression_1008();
|
||||||
|
|
||||||
|
int main(int, char*[]) {
|
||||||
|
using f_ptr = int (*)();
|
||||||
|
const f_ptr regressions[] = { ®ression_1008 };
|
||||||
|
const int sizeof_regressions = sizeof(regressions) / sizeof(regressions[0]);
|
||||||
|
int r = 0;
|
||||||
|
for (std::size_t i = 0; i < sizeof_regressions; ++i) {
|
||||||
|
f_ptr f = regressions[0];
|
||||||
|
r += static_cast<int>(f() != 0);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user