🔧 Make tests read mo-file from subdir
This commit is contained in:
parent
5c00a6ff3e
commit
fe422db632
@ -1,6 +1,6 @@
|
||||
set(Catch2_FOUND TRUE)
|
||||
|
||||
set(CATCH2_VERSION "v2.13.4")
|
||||
set(CATCH2_VERSION "v2.13.7")
|
||||
set(CATCH2_INCLUDEDIR "${CMAKE_BINARY_DIR}/catch-${CATCH2_VERSION}")
|
||||
list(APPEND CMAKE_MODULE_PATH "${CATCH2_INCLUDEDIR}")
|
||||
|
||||
|
@ -4,13 +4,12 @@ find_package(Catch2 REQUIRED)
|
||||
include(CTest)
|
||||
include(Catch)
|
||||
|
||||
add_executable(${PROJECT_NAME} test.cpp link_test.cpp)
|
||||
add_executable(${PROJECT_NAME} main.cpp test.cpp link_test.cpp)
|
||||
target_include_directories(moFileReaderTest PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Catch2::Catch2)
|
||||
catch_discover_tests(${PROJECT_NAME})
|
||||
|
||||
add_custom_command(
|
||||
TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test.mo $<TARGET_FILE_DIR:moFileReaderTest>/test.mo
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test.mo ${CMAKE_CURRENT_BINARY_DIR}/test.mo
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/languages/nl.mo $<TARGET_FILE_DIR:moFileReaderTest>/languages/nl.mo
|
||||
)
|
||||
|
@ -1,2 +1,2 @@
|
||||
#!/bin/sh
|
||||
msgfmt -o test.mo test.po
|
||||
msgfmt -o languages/nl.mo languages/nl.po
|
2
test/main.cpp
Normal file
2
test/main.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
@ -1,17 +1,17 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "moFileReader.hpp"
|
||||
|
||||
using namespace moFileLib;
|
||||
|
||||
#define MO_TEST_FILE "languages/nl.mo"
|
||||
|
||||
#define _L(str) moFR.Lookup(str)
|
||||
#define _LC(ctx, str) moFR.LookupWithContext(ctx, str)
|
||||
|
||||
TEST_CASE("Load mo-file", "[ReadFile]")
|
||||
{
|
||||
moFileReader moFR;
|
||||
CHECK(moFR.ReadFile("test.mo") == moFileReader::EC_SUCCESS);
|
||||
CHECK(moFR.ReadFile(MO_TEST_FILE) == moFileReader::EC_SUCCESS);
|
||||
}
|
||||
|
||||
TEST_CASE("Load not existing mo-file", "[ReadFile-fail]")
|
||||
@ -23,14 +23,14 @@ TEST_CASE("Load not existing mo-file", "[ReadFile-fail]")
|
||||
TEST_CASE("Count number of strings", "[Count]")
|
||||
{
|
||||
moFileReader moFR;
|
||||
moFR.ReadFile("test.mo");
|
||||
moFR.ReadFile(MO_TEST_FILE);
|
||||
CHECK(7 == moFR.GetNumStrings());
|
||||
}
|
||||
|
||||
TEST_CASE("Empties the Lookup-Table", "[Count]")
|
||||
{
|
||||
moFileReader moFR;
|
||||
moFR.ReadFile("test.mo");
|
||||
moFR.ReadFile(MO_TEST_FILE);
|
||||
CHECK("Text Nederlands Een" == moFR.Lookup("String English One"));
|
||||
CHECK(7 == moFR.GetNumStrings());
|
||||
moFR.ClearTable();
|
||||
@ -41,7 +41,7 @@ TEST_CASE("Empties the Lookup-Table", "[Count]")
|
||||
TEST_CASE("Lookup string", "[Lookup]")
|
||||
{
|
||||
moFileReader moFR;
|
||||
moFR.ReadFile("test.mo");
|
||||
moFR.ReadFile(MO_TEST_FILE);
|
||||
/* This is the first comment. */
|
||||
CHECK("Text Nederlands Een" == _L("String English One"));
|
||||
/* This is the second comment. */
|
||||
@ -53,7 +53,7 @@ TEST_CASE("Lookup string", "[Lookup]")
|
||||
TEST_CASE("Lookup string with context", "[LookupWithContext]")
|
||||
{
|
||||
moFileReader moFR;
|
||||
moFR.ReadFile("test.mo");
|
||||
moFR.ReadFile(MO_TEST_FILE);
|
||||
/* This is the first comment. */
|
||||
CHECK("Text Nederlands Een" == _LC("TEST|String|1", "String English"));
|
||||
/* This is the second comment. */
|
||||
@ -65,7 +65,7 @@ TEST_CASE("Lookup string with context", "[LookupWithContext]")
|
||||
TEST_CASE("Lookup not existing strings", "[Lookup-fail]")
|
||||
{
|
||||
moFileReader moFR;
|
||||
moFR.ReadFile("test.mo");
|
||||
moFR.ReadFile(MO_TEST_FILE);
|
||||
CHECK("No match" == moFR.Lookup("No match"));
|
||||
CHECK("Can't touch this" == moFR.Lookup("Can't touch this"));
|
||||
}
|
||||
@ -73,7 +73,7 @@ TEST_CASE("Lookup not existing strings", "[Lookup-fail]")
|
||||
TEST_CASE("Lookup not existing strings with context", "[LookupWithContext-fail]")
|
||||
{
|
||||
moFileReader moFR;
|
||||
moFR.ReadFile("test.mo");
|
||||
moFR.ReadFile(MO_TEST_FILE);
|
||||
CHECK("String English" == _LC("Nope", "String English"));
|
||||
CHECK("Not this one" == _LC("TEST|String|1", "Not this one"));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user