mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Change asm generation to be on by default. Augment add_gsl_test to generate ASM when requested.
This commit is contained in:
parent
346093c99e
commit
6a7f0d44f0
@ -69,6 +69,15 @@ target_compile_definitions(gsl_tests_config INTERFACE
|
||||
GSL_THROW_ON_CONTRACT_VIOLATION
|
||||
)
|
||||
|
||||
# Set the location asm files are output into
|
||||
if(DEFINED GSL_ASM_FOLDER)
|
||||
set(ASM_LOCATION ${CMAKE_SOURCE_DIR}\\asm\\${GSL_ASM_FOLDER})
|
||||
else()
|
||||
set(ASM_LOCATION ${CMAKE_SOURCE_DIR}\\asm\\${CMAKE_GENERATOR})
|
||||
endif()
|
||||
|
||||
file(MAKE_DIRECTORY ${ASM_LOCATION})
|
||||
|
||||
# create the main executable for each test. this reduces the compile time
|
||||
# of each test by pre-compiling catch.
|
||||
add_library(test_catch STATIC test.cpp)
|
||||
@ -79,13 +88,33 @@ target_link_libraries(test_catch
|
||||
add_dependencies(test_catch catch)
|
||||
set_property(TARGET test_catch PROPERTY FOLDER "GSL_tests")
|
||||
|
||||
function(add_gsl_test name)
|
||||
function(add_gsl_test name gen_asm)
|
||||
add_executable(${name} ${name}.cpp)
|
||||
|
||||
#Set the asm options if used
|
||||
if(${gen_asm})
|
||||
add_library(${name}_asm INTERFACE)
|
||||
target_compile_options(${name}_asm INTERFACE
|
||||
$<$<BOOL:${gen_asm}>:
|
||||
$<$<CXX_COMPILER_ID:MSVC>:
|
||||
/FA
|
||||
/Fa${ASM_LOCATION}\\${name}.asm
|
||||
>
|
||||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:
|
||||
-S
|
||||
-o ${ASM_LOCATION}\\${name}.s
|
||||
>
|
||||
>
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${name}
|
||||
GSL
|
||||
test_catch
|
||||
gsl_tests_config
|
||||
$<$<BOOL:${gen_asm}>:${name}_asm>
|
||||
)
|
||||
|
||||
add_dependencies(${name} catch)
|
||||
add_test(
|
||||
${name}
|
||||
@ -95,19 +124,19 @@ function(add_gsl_test name)
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "GSL_tests")
|
||||
endfunction()
|
||||
|
||||
add_gsl_test(span_tests)
|
||||
add_gsl_test(multi_span_tests)
|
||||
add_gsl_test(strided_span_tests)
|
||||
add_gsl_test(string_span_tests)
|
||||
add_gsl_test(at_tests)
|
||||
add_gsl_test(bounds_tests)
|
||||
add_gsl_test(notnull_tests)
|
||||
add_gsl_test(assertion_tests)
|
||||
add_gsl_test(utils_tests)
|
||||
add_gsl_test(owner_tests)
|
||||
add_gsl_test(byte_tests)
|
||||
add_gsl_test(algorithm_tests)
|
||||
add_gsl_test(sloppy_notnull_tests)
|
||||
add_gsl_test(span_tests TRUE)
|
||||
add_gsl_test(multi_span_tests FALSE)
|
||||
add_gsl_test(strided_span_tests FALSE)
|
||||
add_gsl_test(string_span_tests FALSE)
|
||||
add_gsl_test(at_tests FALSE)
|
||||
add_gsl_test(bounds_tests FALSE)
|
||||
add_gsl_test(notnull_tests FALSE)
|
||||
add_gsl_test(assertion_tests FALSE)
|
||||
add_gsl_test(utils_tests FALSE)
|
||||
add_gsl_test(owner_tests FALSE)
|
||||
add_gsl_test(byte_tests FALSE)
|
||||
add_gsl_test(algorithm_tests FALSE)
|
||||
add_gsl_test(sloppy_notnull_tests FALSE)
|
||||
|
||||
|
||||
# No exception tests
|
||||
@ -172,23 +201,18 @@ endfunction()
|
||||
add_gsl_test_noexcept(no_exception_throw_tests)
|
||||
add_gsl_test_noexcept(no_exception_ensure_tests)
|
||||
|
||||
set(ASM_LOCATION ${CMAKE_SOURCE_DIR}\\asm\\${CMAKE_GENERATOR})
|
||||
file(MAKE_DIRECTORY ${ASM_LOCATION})
|
||||
|
||||
add_custom_target(asm_tests)
|
||||
|
||||
function(add_gsl_asm_test name)
|
||||
add_library(${name}_asm ${name}.cpp)
|
||||
|
||||
target_compile_options(${name}_asm PRIVATE
|
||||
add_library(${name}_asm_options INTERFACE)
|
||||
target_compile_options(${name}_asm_options INTERFACE
|
||||
$<$<CXX_COMPILER_ID:MSVC>:
|
||||
/FA
|
||||
/Fa${ASM_LOCATION}\\${name}_asm.asm
|
||||
/Fa${ASM_LOCATION}\\${name}.asm
|
||||
>
|
||||
${GSL_CPLUSPLUS_OPT}
|
||||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:
|
||||
-S
|
||||
-o ${ASM_LOCATION}\${name}.s
|
||||
-o ${ASM_LOCATION}\\${name}.s
|
||||
>
|
||||
)
|
||||
|
||||
@ -196,11 +220,12 @@ function(add_gsl_asm_test name)
|
||||
GSL
|
||||
test_catch
|
||||
gsl_tests_config
|
||||
${name}_asm_options
|
||||
)
|
||||
|
||||
add_dependencies(${name}_asm catch)
|
||||
add_dependencies(asm_tests ${name}_asm)
|
||||
# group all tests under GSL_tests
|
||||
set_property(TARGET ${name}_asm PROPERTY FOLDER "GSL_tests")
|
||||
# group all tests under GSL_asm_tests
|
||||
set_property(TARGET ${name}_asm PROPERTY FOLDER "GSL_asm_tests")
|
||||
endfunction()
|
||||
|
||||
add_gsl_asm_test(span_tests)
|
||||
add_gsl_asm_test(span_compile_only)
|
65
tests/span_compile_only.cpp
Normal file
65
tests/span_compile_only.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// This code is licensed under the MIT License (MIT).
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include <catch/catch.hpp> // for AssertionHandler, StringRef, CHECK, TEST_...
|
||||
|
||||
#include <gsl/gsl_byte> // for byte
|
||||
#include <gsl/gsl_util> // for narrow_cast, at
|
||||
#include <gsl/span> // for span, span_iterator, operator==, operator!=
|
||||
|
||||
#include <array> // for array
|
||||
#include <iostream> // for ptrdiff_t
|
||||
#include <iterator> // for reverse_iterator, operator-, operator==
|
||||
#include <memory> // for unique_ptr, shared_ptr, make_unique, allo...
|
||||
#include <regex> // for match_results, sub_match, match_results<>...
|
||||
#include <stddef.h> // for ptrdiff_t
|
||||
#include <string> // for string
|
||||
#include <type_traits> // for integral_constant<>::value, is_default_co...
|
||||
#include <vector> // for vector
|
||||
|
||||
namespace gsl {
|
||||
struct fail_fast;
|
||||
} // namespace gsl
|
||||
|
||||
using namespace std;
|
||||
using namespace gsl;
|
||||
|
||||
namespace
|
||||
{
|
||||
struct BaseClass
|
||||
{
|
||||
};
|
||||
struct DerivedClass : BaseClass
|
||||
{
|
||||
};
|
||||
struct AddressOverloaded
|
||||
{
|
||||
AddressOverloaded operator&() const { return {}; }
|
||||
};
|
||||
}
|
||||
|
||||
GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
|
||||
TEST_CASE("default_constructor")
|
||||
{
|
||||
{
|
||||
span<int> s;
|
||||
CHECK((s.size() == 0 && s.data() == nullptr));
|
||||
|
||||
span<const int> cs;
|
||||
CHECK((cs.size() == 0 && cs.data() == nullptr));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user