Added test_util unit tests

This commit is contained in:
Bartek Kryza
2021-03-02 22:47:08 +01:00
parent e53294905e
commit 32961cb42e
4 changed files with 165 additions and 46 deletions

View File

@@ -7,6 +7,14 @@ set(CMAKE_CXX_STANDARD 17)
file(GLOB_RECURSE TEST_CASE_SOURCES t*/*.cc)
file(GLOB_RECURSE TEST_CASE_CONFIGS t*/.clanguml)
set(CLANG_UML_TEST_UTIL_SRC
test_util.cc
${TEST_UTIL_SOURCES}
)
set(CLANG_UML_TEST_UTIL_HEADER
catch.h
)
set(CLANG_UML_TEST_CASES_SRC
test_cases.cc
${TEST_CASE_SOURCES}
@@ -15,6 +23,17 @@ set(CLANG_UML_TEST_CASES_HEADER
catch.h
)
add_executable(test_util
${CLANG_UML_TEST_UTIL_SRC}
${CLANG_UML_TEST_UTIL_HEADER})
target_link_libraries(test_util
PRIVATE
${LIBCLANG_LIBRARIES}
${YAML_CPP_LIBRARIES}
spdlog::spdlog clang-umllib)
add_executable(test_cases
${CLANG_UML_TEST_CASES_SRC}
${CLANG_UML_TEST_CASES_HEADER})
@@ -37,4 +56,5 @@ foreach(TEST_CASE_CONFIG ${TEST_CASE_CONFIGS})
COPYONLY)
endforeach()
add_test(NAME test_util COMMAND test_util)
add_test(NAME test_cases COMMAND test_cases)

42
tests/test_util.cc Normal file
View File

@@ -0,0 +1,42 @@
/**
* tests/test_util.cc
*
* Copyright (c) 2021 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define CATCH_CONFIG_MAIN
#include "util/util.h"
#include "catch.h"
TEST_CASE("Test split", "[unit-test]")
{
using C = std::vector<std::string>;
using namespace clanguml::util;
const C empty{};
CHECK(split("", " ") == C{""});
CHECK(split("ABCD", " ") == C{"ABCD"});
CHECK(split("std::vector::detail", "::") == C{"std", "vector", "detail"});
}
TEST_CASE("Test ns_relative", "[unit-test]")
{
using namespace clanguml::util;
CHECK(ns_relative({}, "std::vector") == "std::vector");
}