-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
append unit testing framework #121
Changes from all commits
7b8d14d
bff387b
6cf15e6
a5afe1e
dd83c73
ffb36cf
be9e2a8
06e8008
fa34d76
dfcd7bb
9dd402c
cb1595d
69c75b5
33f099a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ directml*/ | |
|
||
# Build artifacts | ||
build/ | ||
test_build/ | ||
lib/ | ||
bin/ | ||
core/_core.cpp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(VoiceVoxCoreTest) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare( | ||
Catch2 | ||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git | ||
GIT_TAG v3.0.0-preview5) | ||
FetchContent_MakeAvailable(Catch2) | ||
file(GLOB_RECURSE unit_test_files "unit_tests/*.cpp") | ||
add_executable(unit_test ${unit_test_files}) | ||
Yosshi999 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
target_compile_options( | ||
unit_test PRIVATE $<$<CXX_COMPILER_ID:MSVC>: /W4 /utf-8> | ||
$<$<CXX_COMPILER_ID:GNU>: -Wall -Wextra>) | ||
set_property(TARGET unit_test PROPERTY CXX_STANDARD 20) | ||
set_property(TARGET Catch2 PROPERTY CXX_STANDARD 20) | ||
target_include_directories(unit_test PRIVATE ${Catch2_SOURCE_DIR}/src) | ||
target_include_directories(unit_test PRIVATE ${CORE_DIR}/src) | ||
target_link_libraries(unit_test PRIVATE Catch2::Catch2WithMain) | ||
target_link_libraries(unit_test PRIVATE core) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [QUESTION] これ僕の環境だとリンクに失敗するんですが他の方再現しますか?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. エラーメッセージ的に標準ライブラリとのリンクに失敗しているようだったので、unit_testとcoreの標準ライブラリのバージョンをそろえてみました There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 修正後のコードでコンパイルしてみたところ、同じエラーが出たっぽいです。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catch2が原因ぽそうだけど直せるだろうか・・・ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. おそらくcoreがextract_one_characterをexportしてないせいでリンクが通らないので、 またshared版はもう一つ課題があって、リンクが通ったとしても今度はcore.dllとonnxruntime.dllをunit_testのバイナリがあるところにコピーしてくる必要があります。これはcmakeでやるのは結構厳しくて、cmake 3.21の依存dllを引っぱってくる機能
ではcore.dllしか拾ってくれません。(ちなみにcore.dllを持ってくるだけなら3.21に上げる必要は無く、 $<TARGET_FILE:core> がcore.dllへのパスを指してるのでそれを つまり現状core/CMakeLists.txtで定義したONNXRUNTIME_LIBSとかをこっちに持ってきて別途 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yosshi999@7b4d430 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yosshi999 そのcommitを参考に修正しました There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 問題なくテストできてそうなことを確認しました!!
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. こちらでも動作確認できました! |
||
if (WIN32) | ||
add_custom_command(TARGET unit_test POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
"$<TARGET_FILE:core>;${DEPENDENT_DLLS}" $<TARGET_FILE_DIR:unit_test> | ||
COMMAND_EXPAND_LISTS ) | ||
endif (WIN32) | ||
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras) | ||
include(Catch) | ||
include(CTest) | ||
catch_discover_tests(unit_test) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "engine/kana_parser.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <catch2/generators/catch_generators.hpp> | ||
|
||
using namespace voicevox::core::engine; | ||
|
||
TEST_CASE("extract_one_character") { | ||
struct TestCase { | ||
std::string name; | ||
struct { | ||
std::string text; | ||
size_t pos; | ||
} given; | ||
struct { | ||
std::string one_char; | ||
size_t after_size; | ||
} expected; | ||
}; | ||
auto t = GENERATE(TestCase{.name = "target_is_alphabet", | ||
.given = {.text = "abcd", .pos = 2}, | ||
.expected = {.one_char = "c", .after_size = 1}}, | ||
TestCase{.name = "target_is_hiragana", | ||
.given = {.text = "acあd", .pos = 2}, | ||
.expected = {.one_char = "あ", .after_size = 3}}, | ||
TestCase{.name = "target_is_4byte_kanji", | ||
.given = {.text = "ace𠀋", .pos = 3}, | ||
.expected = {.one_char = "𠀋", .after_size = 4}}); | ||
|
||
SECTION(t.name) { | ||
size_t size; | ||
auto actual_one_char = extract_one_character(t.given.text, t.given.pos, size); | ||
CHECK(t.expected.one_char == actual_one_char); | ||
CHECK(t.expected.after_size == size); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
完全に余談ですがCatch2のドキュメントでcmakeのFetchContent機能を知りました。
このプロジェクトが依存してるopenjtalkもcmakeで作られてるようなので、やろうと思えばopenjtalkもFetchContentでとってくるようにし、git submoduleの依存から脱却できそうだなと思いました。
もっとも将来的にcmakeを使ってないライブラリに依存するようになった場合はまたgit submoduleを使わないといけなさそうですが