From c1d2e3647b24719745c5861eaf9e4e5f5b9c47d4 Mon Sep 17 00:00:00 2001 From: Igor Sharonov Date: Mon, 8 Apr 2024 16:47:06 +0300 Subject: [PATCH] meson: Support all tests from cmake Unified test launch for both meson and cmake: make/ninja test. Support tests for cmake through ctest. Enable jid test in libdino. Enable tests for win64 CI/CD. --- .github/workflows/build-win64.yml | 4 +-- .github/workflows/build.yml | 5 ++-- CMakeLists.txt | 2 ++ build-win64.sh | 30 ++++++++++++++++----- configure | 6 ++--- libdino/CMakeLists.txt | 6 +++-- libdino/meson.build | 9 +++++++ libdino/tests/common.vala | 1 + libdino/tests/jid.vala | 43 ++++++++++++++++++++----------- plugins/omemo/CMakeLists.txt | 5 ++-- xmpp-vala/CMakeLists.txt | 5 ++-- xmpp-vala/meson.build | 11 ++++++++ 12 files changed, 91 insertions(+), 36 deletions(-) diff --git a/.github/workflows/build-win64.yml b/.github/workflows/build-win64.yml index affd635c..4ed2ed1c 100644 --- a/.github/workflows/build-win64.yml +++ b/.github/workflows/build-win64.yml @@ -19,10 +19,10 @@ jobs: msys2 -c './build-win64.sh --prepare' - name: Build Dino (Meson, without saving) run: | - msys2 -c './build-win64.sh -s meson -c -b -w' + msys2 -c './build-win64.sh -s meson -c -b -t -w' - name: Build Dino (CMake) run: | - msys2 -c './build-win64.sh -s cmake -c -b -i' + msys2 -c './build-win64.sh -s cmake -c -b -t -i' - name: Build Dino installer run: | msys2 -c './build-win64.sh --build-installer' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a22a5c35..aaa66b8d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,8 +12,7 @@ jobs: - run: sudo apt-get install -y build-essential gettext cmake valac libgee-0.8-dev libsqlite3-dev libgtk-4-dev libnotify-dev libgpgme-dev libsoup2.4-dev libgcrypt20-dev libqrencode-dev libnice-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libsrtp2-dev libwebrtc-audio-processing-dev libadwaita-1-dev libsignal-protocol-c-dev libcanberra-dev - run: ./configure --with-tests --with-libsignal-in-tree - run: make - - run: build/xmpp-vala-test - - run: build/omemo-test + - run: make test build-meson: runs-on: ubuntu-22.04 steps: @@ -25,7 +24,7 @@ jobs: - run: sudo apt-get install -y build-essential gettext libadwaita-1-dev libcanberra-dev libgcrypt20-dev libgee-0.8-dev libgpgme-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev libgtk-4-dev libnice-dev libnotify-dev libqrencode-dev libsignal-protocol-c-dev libsoup2.4-dev libsqlite3-dev libsrtp2-dev libwebrtc-audio-processing-dev meson valac - run: meson setup build -Dcrypto-backend=auto -Dplugin-ice=enabled -Duse-soup2=true - run: meson compile -C build - - run: build/plugins/omemo/test_omemo + - run: meson test -C build build-flatpak: runs-on: ubuntu-22.04 container: diff --git a/CMakeLists.txt b/CMakeLists.txt index 80465c41..0078f203 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,8 @@ else () set(PROJECT_VERSION ${VERSION_FULL}) endif () +include(CTest) + # Prepare Plugins set(DEFAULT_PLUGINS omemo;openpgp;http-files;ice;rtp) if (WIN32) diff --git a/build-win64.sh b/build-win64.sh index a0d6c1b1..1ef593a5 100644 --- a/build-win64.sh +++ b/build-win64.sh @@ -95,7 +95,7 @@ prepare() configure_cmake() { msg "Running configuration for Windows" - ./configure --program-prefix="$DIST_DIR" --no-debug --release --disable-fast-vapi --with-libsoup3 + ./configure --program-prefix="$DIST_DIR" --no-debug --release --disable-fast-vapi --with-libsoup3 --with-tests msg "Configured!" } @@ -108,6 +108,12 @@ build_cmake() make install } +test_cmake() +{ + msg "Run tests" + make test +} + configure_meson() { arg=${1:-"none"} @@ -125,9 +131,14 @@ configure_meson() build_meson() { - cd $BUILD_DIR && ninja - ninja install - cd $PROJ_DIR + meson compile -C $BUILD_DIR + meson install -C $BUILD_DIR +} + +test_meson() +{ + msg "Run tests" + meson test -C $BUILD_DIR } dist_install() @@ -205,7 +216,7 @@ help() Usage: $0 [option] - Note: you may set the multiple options, but be surem that they will be + Note: you may set the multiple options, but be sure that they will be processed sequentially (one-by-one), e.g. command $0 -s meson -c -b will run buld config and _after_ that run build using meson, while @@ -230,7 +241,10 @@ help() configure build using selected build-system. --build, -b - invoked build. + invoke build. + + --test, -t + run tests. --reconfig, -r reconfigure project, if minor changes were @@ -281,6 +295,9 @@ do --build|-b) build_${build_sys} ;; + --test|-t) + test_${build_sys} + ;; --reconfig|-r) configure_${build_sys} reconfig ;; @@ -306,6 +323,7 @@ do exit 1; fi build_sys=$2 + shift ;; -*) echo "Unknown option $1" diff --git a/configure b/configure index ab22d840..f3b6d4f2 100755 --- a/configure +++ b/configure @@ -15,7 +15,7 @@ eval set -- "$OPTS" PREFIX=${PREFIX:-/usr/local} ENABLED_PLUGINS= DISABLED_PLUGINS= -BUILD_TESTS= +BUILD_TESTS=no BUILD_TYPE=Debug DISABLE_FAST_VAPI= LIB_SUFFIX= @@ -207,7 +207,7 @@ cmake -G "$cmake_type" \ -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \ -DENABLED_PLUGINS="$ENABLED_PLUGINS" \ -DDISABLED_PLUGINS="$DISABLED_PLUGINS" \ - -DBUILD_TESTS="$BUILD_TESTS" \ + -DBUILD_TESTING="$BUILD_TESTS" \ -DUSE_SOUP3="$USE_SOUP3" \ -DVALA_EXECUTABLE="$VALAC" \ -DCMAKE_VALA_FLAGS="$VALACFLAGS" \ @@ -238,8 +238,6 @@ default: @sh -c "cd build; $exec_command" distclean: clean uninstall -test: default - echo "make test not yet supported" %: @sh -c "cd build; $exec_command \"\$@\"" EOF diff --git a/libdino/CMakeLists.txt b/libdino/CMakeLists.txt index d52f9184..2475fde8 100644 --- a/libdino/CMakeLists.txt +++ b/libdino/CMakeLists.txt @@ -112,12 +112,13 @@ install(TARGETS libdino ${TARGET_INSTALL}) install(FILES ${CMAKE_BINARY_DIR}/exports/dino.vapi ${CMAKE_BINARY_DIR}/exports/dino.deps DESTINATION ${VAPI_INSTALL_DIR}) install(FILES ${CMAKE_BINARY_DIR}/exports/dino.h ${CMAKE_BINARY_DIR}/exports/dino_i18n.h DESTINATION ${INCLUDE_INSTALL_DIR}) -if(BUILD_TESTS) +if(BUILD_TESTING) vala_precompile(LIBDINO_TEST_VALA_C SOURCES "tests/weak_map.vala" "tests/testcase.vala" "tests/common.vala" + "tests/jid.vala" CUSTOM_VAPIS ${CMAKE_BINARY_DIR}/exports/dino_internal.vapi ${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi @@ -131,4 +132,5 @@ if(BUILD_TESTS) add_definitions(${VALA_CFLAGS}) add_executable(libdino-test ${LIBDINO_TEST_VALA_C}) target_link_libraries(libdino-test libdino) -endif(BUILD_TESTS) + add_test(NAME libdino COMMAND libdino-test) +endif(BUILD_TESTING) diff --git a/libdino/meson.build b/libdino/meson.build index cc2c4213..c1cbbb70 100644 --- a/libdino/meson.build +++ b/libdino/meson.build @@ -88,3 +88,12 @@ dep_dino = declare_dependency(link_with: lib_dino, include_directories: include_ install_data('dino.deps', install_dir: get_option('datadir') / 'vala/vapi') # TODO: workaround for https://github.com/mesonbuild/meson/issues/9756 install_headers('src/dino_i18n.h') + +sources = files( + 'tests/weak_map.vala', + 'tests/testcase.vala', + 'tests/common.vala', + 'tests/jid.vala', +) +test_libdino = executable('test_libdino', sources, dependencies: dependencies + [dep_dino]) +test('libdino', test_libdino) diff --git a/libdino/tests/common.vala b/libdino/tests/common.vala index 2a0b189b..75ad74a1 100644 --- a/libdino/tests/common.vala +++ b/libdino/tests/common.vala @@ -4,6 +4,7 @@ int main(string[] args) { GLib.Test.init(ref args); GLib.Test.set_nonfatal_assertions(); TestSuite.get_root().add_suite(new WeakMapTest().get_suite()); + TestSuite.get_root().add_suite(new JidTest().get_suite()); return GLib.Test.run(); } diff --git a/libdino/tests/jid.vala b/libdino/tests/jid.vala index 08ec5c3a..4b3d495c 100644 --- a/libdino/tests/jid.vala +++ b/libdino/tests/jid.vala @@ -1,4 +1,5 @@ using Dino.Entities; +using Xmpp; namespace Dino.Test { @@ -12,27 +13,39 @@ class JidTest : Gee.TestCase { } private void test_parse() { - Jid jid = new Jid("user@example.com/res"); - fail_if(jid.localpart != "user"); - fail_if(jid.domainpart != "example.com"); - fail_if(jid.resourcepart != "res"); - fail_if(jid.to_string() != "user@example.com/res"); + try { + Jid jid = new Jid("user@example.com/res"); + fail_if(jid.localpart != "user"); + fail_if(jid.domainpart != "example.com"); + fail_if(jid.resourcepart != "res"); + fail_if(jid.to_string() != "user@example.com/res"); + } catch (Error e) { + fail_if_reached(@"Throws $(e.message)"); + } } private void test_components() { - Jid jid = new Jid.components("user", "example.com", "res"); - fail_if(jid.localpart != "user"); - fail_if(jid.domainpart != "example.com"); - fail_if(jid.resourcepart != "res"); - fail_if(jid.to_string() != "user@example.com/res"); + try { + Jid jid = new Jid.components("user", "example.com", "res"); + fail_if(jid.localpart != "user"); + fail_if(jid.domainpart != "example.com"); + fail_if(jid.resourcepart != "res"); + fail_if(jid.to_string() != "user@example.com/res"); + } catch (Error e) { + fail_if_reached(@"Throws $(e.message)"); + } } private void test_with_res() { - Jid jid = new Jid.with_resource("user@example.com", "res"); - fail_if(jid.localpart != "user"); - fail_if(jid.domainpart != "example.com"); - fail_if(jid.resourcepart != "res"); - fail_if(jid.to_string() != "user@example.com/res"); + try { + Jid jid = new Jid("user@example.com").with_resource("res"); + fail_if(jid.localpart != "user"); + fail_if(jid.domainpart != "example.com"); + fail_if(jid.resourcepart != "res"); + fail_if(jid.to_string() != "user@example.com/res"); + } catch (Error e) { + fail_if_reached(@"Throws $(e.message)"); + } } } diff --git a/plugins/omemo/CMakeLists.txt b/plugins/omemo/CMakeLists.txt index 83e6426f..9e2790a0 100644 --- a/plugins/omemo/CMakeLists.txt +++ b/plugins/omemo/CMakeLists.txt @@ -104,7 +104,7 @@ set_target_properties(omemo PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_D install(TARGETS omemo ${PLUGIN_INSTALL}) -if(BUILD_TESTS) +if(BUILD_TESTING) vala_precompile(OMEMO_TEST_VALA_C SOURCES "tests/signal/common.vala" @@ -127,4 +127,5 @@ if(BUILD_TESTS) add_executable(omemo-test ${OMEMO_TEST_VALA_C}) add_dependencies(omemo-test omemo) target_link_libraries(omemo-test omemo ${OMEMO_PACKAGES}) -endif(BUILD_TESTS) + add_test(NAME omemo COMMAND omemo-test) +endif(BUILD_TESTING) diff --git a/xmpp-vala/CMakeLists.txt b/xmpp-vala/CMakeLists.txt index cfbc0aaf..654f3875 100644 --- a/xmpp-vala/CMakeLists.txt +++ b/xmpp-vala/CMakeLists.txt @@ -177,7 +177,7 @@ install(TARGETS xmpp-vala ${TARGET_INSTALL}) install(FILES ${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi ${CMAKE_BINARY_DIR}/exports/xmpp-vala.deps DESTINATION ${VAPI_INSTALL_DIR}) install(FILES ${CMAKE_BINARY_DIR}/exports/xmpp-vala.h DESTINATION ${INCLUDE_INSTALL_DIR}) -if(BUILD_TESTS) +if(BUILD_TESTING) vala_precompile(ENGINE_TEST_VALA_C SOURCES "tests/common.vala" @@ -198,4 +198,5 @@ if(BUILD_TESTS) add_definitions(${VALA_CFLAGS}) add_executable(xmpp-vala-test ${ENGINE_TEST_VALA_C}) target_link_libraries(xmpp-vala-test xmpp-vala ${SIGNAL_PROTOCOL_PACKAGES}) -endif(BUILD_TESTS) + add_test(NAME xmpp-vala COMMAND xmpp-vala-test) +endif(BUILD_TESTING) diff --git a/xmpp-vala/meson.build b/xmpp-vala/meson.build index 0b92be99..e2f00d2b 100644 --- a/xmpp-vala/meson.build +++ b/xmpp-vala/meson.build @@ -136,3 +136,14 @@ lib_xmpp_vala = library('xmpp-vala', sources, c_args: c_args, vala_args: vala_ar dep_xmpp_vala = declare_dependency(link_with: lib_xmpp_vala, include_directories: include_directories('.')) install_data('xmpp-vala.deps', install_dir: get_option('datadir') / 'vala/vapi') # TODO: workaround for https://github.com/mesonbuild/meson/issues/9756 + +sources = files( + 'tests/common.vala', + 'tests/testcase.vala', + 'tests/jid.vala', + 'tests/stanza.vala', + 'tests/color.vala', + 'tests/util.vala', +) +test_xmpp_vala = executable('test_xmpp_vala', sources, vala_args: vala_args, dependencies: dependencies + [dep_xmpp_vala]) +test('xmpp-vala', test_xmpp_vala)