Skip to content

Commit

Permalink
meson: Support all tests from cmake
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
igsha authored and mxlgv committed Apr 9, 2024
1 parent a74f2d0 commit c1d2e36
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-win64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 24 additions & 6 deletions build-win64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
}

Expand All @@ -108,6 +108,12 @@ build_cmake()
make install
}

test_cmake()
{
msg "Run tests"
make test
}

configure_meson()
{
arg=${1:-"none"}
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -281,6 +295,9 @@ do
--build|-b)
build_${build_sys}
;;
--test|-t)
test_${build_sys}
;;
--reconfig|-r)
configure_${build_sys} reconfig
;;
Expand All @@ -306,6 +323,7 @@ do
exit 1;
fi
build_sys=$2
shift
;;
-*)
echo "Unknown option $1"
Expand Down
6 changes: 2 additions & 4 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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" \
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions libdino/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
9 changes: 9 additions & 0 deletions libdino/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions libdino/tests/common.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
43 changes: 28 additions & 15 deletions libdino/tests/jid.vala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dino.Entities;
using Xmpp;

namespace Dino.Test {

Expand All @@ -12,27 +13,39 @@ class JidTest : Gee.TestCase {
}

private void test_parse() {
Jid jid = new Jid("[email protected]/res");
fail_if(jid.localpart != "user");
fail_if(jid.domainpart != "example.com");
fail_if(jid.resourcepart != "res");
fail_if(jid.to_string() != "[email protected]/res");
try {
Jid jid = new Jid("[email protected]/res");
fail_if(jid.localpart != "user");
fail_if(jid.domainpart != "example.com");
fail_if(jid.resourcepart != "res");
fail_if(jid.to_string() != "[email protected]/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() != "[email protected]/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() != "[email protected]/res");
} catch (Error e) {
fail_if_reached(@"Throws $(e.message)");
}
}

private void test_with_res() {
Jid jid = new Jid.with_resource("[email protected]", "res");
fail_if(jid.localpart != "user");
fail_if(jid.domainpart != "example.com");
fail_if(jid.resourcepart != "res");
fail_if(jid.to_string() != "[email protected]/res");
try {
Jid jid = new Jid("[email protected]").with_resource("res");
fail_if(jid.localpart != "user");
fail_if(jid.domainpart != "example.com");
fail_if(jid.resourcepart != "res");
fail_if(jid.to_string() != "[email protected]/res");
} catch (Error e) {
fail_if_reached(@"Throws $(e.message)");
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions plugins/omemo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
5 changes: 3 additions & 2 deletions xmpp-vala/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
11 changes: 11 additions & 0 deletions xmpp-vala/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit c1d2e36

Please sign in to comment.