Split the tests into two files for the interpreter and others

This commit is contained in:
Olivier Goffart 2021-03-22 11:24:11 +01:00
parent 0e82faf845
commit d79131f18f
3 changed files with 61 additions and 42 deletions

View file

@ -134,15 +134,20 @@ if(BUILD_TESTING)
FetchContent_MakeAvailable(Catch2)
add_executable(api_tests tests/tests.cpp)
target_link_libraries(api_tests PRIVATE SixtyFPS Catch2::Catch2)
target_compile_definitions(api_tests PRIVATE
SOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\"
)
add_test(api_tests ${CMAKE_CURRENT_BINARY_DIR}/api_tests)
# 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 api_tests PROPERTY WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
endif()
macro(sixtyfps_test NAME)
add_executable(test_${NAME} tests/${NAME}.cpp)
target_link_libraries(test_${NAME} PRIVATE SixtyFPS Catch2::Catch2)
target_compile_definitions(test_${NAME} PRIVATE
SOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\"
)
add_test(test_${NAME} ${CMAKE_CURRENT_BINARY_DIR}/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_BINARY_DIR}")
endif()
endmacro(sixtyfps_test)
sixtyfps_test(datastructures)
sixtyfps_test(interpreter)
endif()

View file

@ -0,0 +1,44 @@
/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
SPDX-License-Identifier: GPL-3.0-only
This file is also available under commercial licensing terms.
Please contact info@sixtyfps.io for more information.
LICENSE END */
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
#include <sixtyfps.h>
SCENARIO("SharedString API")
{
sixtyfps::SharedString str;
REQUIRE(str.empty());
SECTION("Construct from string_view")
{
std::string foo("Foo");
std::string_view foo_view(foo);
str = foo_view;
REQUIRE(str == "Foo");
}
}
TEST_CASE("Basic SharedVector API", "[vector]")
{
sixtyfps::SharedVector<int> vec;
REQUIRE(vec.empty());
SECTION("Initializer list")
{
sixtyfps::SharedVector<int> vec({ 1, 4, 10 });
REQUIRE(vec.size() == 3);
REQUIRE(vec[0] == 1);
REQUIRE(vec[1] == 4);
REQUIRE(vec[2] == 10);
}
}

View file

@ -14,36 +14,6 @@ LICENSE END */
#include <sixtyfps.h>
#include <sixtyfps_interpreter.h>
SCENARIO("SharedString API")
{
sixtyfps::SharedString str;
REQUIRE(str.empty());
SECTION("Construct from string_view")
{
std::string foo("Foo");
std::string_view foo_view(foo);
str = foo_view;
REQUIRE(str == "Foo");
}
}
TEST_CASE("Basic SharedVector API", "[vector]")
{
sixtyfps::SharedVector<int> vec;
REQUIRE(vec.empty());
SECTION("Initializer list")
{
sixtyfps::SharedVector<int> vec({ 1, 4, 10 });
REQUIRE(vec.size() == 3);
REQUIRE(vec[0] == 1);
REQUIRE(vec[1] == 4);
REQUIRE(vec[2] == 10);
}
}
SCENARIO("Value API")
{
using namespace sixtyfps::interpreter;
@ -293,4 +263,4 @@ SCENARIO("Component Compiler")
auto result = compiler.build_from_path(SOURCE_DIR "/tests/test.60");
REQUIRE(result.has_value());
}
}
}