From 7e9c7d7aa04f9b7a4009b4ee8dc9c1a1ee21776a Mon Sep 17 00:00:00 2001 From: woclass <5158738+inkydragon@users.noreply.github.com> Date: Mon, 24 May 2021 11:33:33 +0800 Subject: [PATCH] Run tests (#125) * [git] ignore IDE setting, Meson subprojects * [win_installer] rename *.mo -> *.gmo * [win_installer] only add aeg translations * [win_installer] split aeg/wx translations * [win_installer] gen & pack translations * [git] ignore hunspell source dir * [git] ignore uchardet source dir * [test] Generate the test executable run with `meson test` * [test] add tools to remove test data files `unset.bat FULL_PATH` * [test] set to correct Error type * [test] Set Source character sets to UTF-8 for MSVC * [test] move test data files to build_root * [git] remove IDE dir * [git] ignore gtest subprojects * [ci] run test in ci * [meson/test] use more meaningful name * [test] Add more comments and help msg --- .github/workflows/ci.yml | 3 ++ .gitignore | 1 + meson.build | 1 + tests/meson.build | 88 ++++++++++++++++++++++++++++++++++++++++ tests/tests/keyframe.cpp | 5 ++- tests/unset.bat | 23 +++++++++++ 6 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 tests/meson.build create mode 100644 tests/unset.bat diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3661ee3a2..70f1abd6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,6 +98,9 @@ jobs: - name: Build run: meson compile -C build + + - name: Run test + run: meson test -C build --verbose - name: Generate Windows installer if: matrix.config.os == 'windows-latest' diff --git a/.gitignore b/.gitignore index e07ce77b9..6d5927351 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ subprojects/fontconfig* subprojects/freetype2 subprojects/fribidi subprojects/glib* +subprojects/googletest-* subprojects/harfbuzz subprojects/icu subprojects/libass diff --git a/meson.build b/meson.build index f96178726..3edcd25d2 100644 --- a/meson.build +++ b/meson.build @@ -320,6 +320,7 @@ subdir('libaegisub') subdir('packages') subdir('po') subdir('src') +subdir('tests') aegisub_cpp_pch = ['src/include/agi_pre.h'] aegisub_c_pch = ['src/include/agi_pre_c.h'] diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 000000000..32eaa677b --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,88 @@ +all_test_deps = [] +all_test_dep_libs = [] +all_test_sources = [] + + +gtest_proj = subproject('gtest') +gtest_dep = gtest_proj.get_variable('gtest_dep') +gmock_dep = gtest_proj.get_variable('gmock_dep') + + +all_test_deps += [ + gtest_dep, + gmock_dep, + iconv_dep, + boost_dep +] +all_test_dep_libs += [ + libaegisub +] +all_test_sources += [ + 'support/main.cpp', + 'support/util.cpp', + + 'tests/access.cpp', + 'tests/audio.cpp', + 'tests/cajun.cpp', + 'tests/calltip_provider.cpp', + 'tests/character_count.cpp', + 'tests/color.cpp', + 'tests/dialogue_lexer.cpp', + 'tests/format.cpp', + 'tests/fs.cpp', + 'tests/hotkey.cpp', + 'tests/iconv.cpp', + 'tests/ifind.cpp', + 'tests/karaoke_matcher.cpp', + 'tests/keyframe.cpp', + 'tests/line_iterator.cpp', + 'tests/line_wrap.cpp', + 'tests/mru.cpp', + 'tests/option.cpp', + 'tests/path.cpp', + 'tests/signals.cpp', + 'tests/split.cpp', + 'tests/syntax_highlight.cpp', + 'tests/thesaurus.cpp', + 'tests/time.cpp', + 'tests/type_name.cpp', + 'tests/util.cpp', + 'tests/uuencode.cpp', + 'tests/vfr.cpp', + 'tests/word_split.cpp' +] + +test_inc = include_directories('support') + +# force UTF8 for MSVC +if host_machine.system() == 'windows' + extra_args = ['/utf-8'] +else + extra_args = [] +endif + +runner = executable( + 'gtest-main', + all_test_sources, + include_directories : [test_inc, libaegisub_inc, deps_inc], + dependencies : all_test_deps, + cpp_args : extra_args, + link_with : all_test_dep_libs, +) +test('gtest main', runner) + + +# setup test env +if host_machine.system() == 'windows' + setup_sh = find_program('setup.bat') +else + setup_sh = find_program('setup.sh') +endif + +test_data_des = meson.project_build_root() +custom_target('setup-test-data', + input: runner, + output: 'applied_test_setup', + command: [setup_sh, test_data_des], + build_by_default: true +) diff --git a/tests/tests/keyframe.cpp b/tests/tests/keyframe.cpp index e664b54b7..5b4e49788 100644 --- a/tests/tests/keyframe.cpp +++ b/tests/tests/keyframe.cpp @@ -41,8 +41,9 @@ TEST(lagi_keyframe, save) { TEST(lagi_keyframe, bad_files) { EXPECT_THROW(Load(""), agi::fs::FileSystemError); - EXPECT_THROW(Load("data/keyframe/empty.txt"), Error); - EXPECT_THROW(Load("data/keyframe/garbage.txt"), Error); + // TODO: use more clearly error type + EXPECT_THROW(Load("data/keyframe/empty.txt"), agi::InvalidInputException); + EXPECT_THROW(Load("data/keyframe/garbage.txt"), agi::InvalidInputException); } TEST(lagi_keyframe, xvid) { diff --git a/tests/unset.bat b/tests/unset.bat new file mode 100644 index 000000000..28241512b --- /dev/null +++ b/tests/unset.bat @@ -0,0 +1,23 @@ +@echo off + +IF [%1]==[] GOTO :help + + +:main +@REM Switch to the build directory +cd %1 + +@REM Restores all permissions to the four read-only and access denied files +icacls data\file_access_denied /grant %USERNAME%:F +icacls data\file_read_only /grant %USERNAME%:W +icacls data\dir_access_denied /grant %USERNAME%:F +icacls data\dir_read_only /grant %USERNAME%:W + +@REM Delete the entire test data folder +rmdir /s/q data + + +:help +@REM Show help information +ECHO Restore access and delete the test data folder. +ECHO Usage: unset PATH_TO_BUILD_DIR