C++: cmake: move the build instruction for the tests in the tests dir

This commit is contained in:
Olivier Goffart 2023-01-16 12:26:56 +01:00 committed by Olivier Goffart
parent 0d23478469
commit 8d0cdc6ec2
4 changed files with 55 additions and 51 deletions

View file

@ -0,0 +1,50 @@
# Copyright © SixtyFPS GmbH <info@slint-ui.com>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.8
)
FetchContent_MakeAvailable(Catch2)
find_package(Threads REQUIRED)
macro(slint_test NAME)
add_executable(test_${NAME} ${NAME}.cpp)
target_link_libraries(test_${NAME} PRIVATE Slint Catch2::Catch2)
target_compile_definitions(test_${NAME} PRIVATE
SOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\"
)
add_test(NAME test_${NAME} COMMAND test_${NAME})
# Somehow the wrong relative rpath ends up in the binary, requiring us to change the
# working directory.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set_property(TEST test_${NAME} PROPERTY WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endif()
if(MSVC)
target_compile_options(test_${NAME} PRIVATE /W3)
else()
target_compile_options(test_${NAME} PRIVATE -Wall -Wextra -Werror)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
# that warning has false positives
target_compile_options(test_${NAME} PRIVATE -Wno-maybe-uninitialized)
endif()
endmacro(slint_test)
slint_test(datastructures)
if(SLINT_FEATURE_INTERPRETER)
slint_test(interpreter)
endif()
slint_test(properties)
slint_test(eventloop)
target_link_libraries(test_eventloop PRIVATE Threads::Threads)
slint_test(models)
slint_test(window)

View file

@ -161,7 +161,7 @@ TEST_CASE("Image")
REQUIRE(!img.path().has_value());
}
img = Image::load_from_path(SOURCE_DIR "/../../logo/slint-logo-square-light-128x128.png");
img = Image::load_from_path(SOURCE_DIR "/../../../logo/slint-logo-square-light-128x128.png");
{
auto size = img.size();
REQUIRE(size.width == 128.);
@ -170,7 +170,7 @@ TEST_CASE("Image")
{
auto actual_path = img.path();
REQUIRE(actual_path.has_value());
REQUIRE(*actual_path == SOURCE_DIR "/../../logo/slint-logo-square-light-128x128.png");
REQUIRE(*actual_path == SOURCE_DIR "/../../../logo/slint-logo-square-light-128x128.png");
}
}

View file

@ -97,7 +97,7 @@ SCENARIO("Value API")
{
REQUIRE(!value.to_image().has_value());
slint::Image image = slint::Image::load_from_path(
SOURCE_DIR "/../../logo/slint-logo-square-light-128x128.png");
SOURCE_DIR "/../../../logo/slint-logo-square-light-128x128.png");
REQUIRE(image.size().width == 128);
value = Value(image);
REQUIRE(value.type() == Value::Type::Image);
@ -308,7 +308,7 @@ SCENARIO("Component Compiler")
SECTION("Compile from path")
{
auto result = compiler.build_from_path(SOURCE_DIR "/tests/test.slint");
auto result = compiler.build_from_path(SOURCE_DIR "/test.slint");
REQUIRE(result.has_value());
}
}