diff options
author | Niels De Graef <nielsdegraef@gmail.com> | 2018-07-27 01:36:33 +0200 |
---|---|---|
committer | Niels De Graef <nielsdegraef@gmail.com> | 2018-07-27 01:56:55 +0200 |
commit | 9fbd6798f45f93879e5b08fe885219e6340c7892 (patch) | |
tree | ac5ec0fa740db2ef13a277e96b72d480395a6871 | |
parent | df90f1d4ddcdc6b48dea4f5bacbc07b7d6896b75 (diff) | |
download | gnome-contacts-9fbd6798f45f93879e5b08fe885219e6340c7892.tar.gz |
Allow adding tests.
* Have a very basic test that calls something from Contacts.Utils, so we
know that it was able to properly compile and link.
* Some function access modifiers had to be changed to public, or they
wouldn't be recoginzed outside of the static library.
* Also make sure our CI actually runs the tests.
-rw-r--r-- | .gitlab-ci.yml | 5 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | src/contacts-contact.vala | 2 | ||||
-rw-r--r-- | src/contacts-utils.vala | 2 | ||||
-rw-r--r-- | src/meson.build | 97 | ||||
-rw-r--r-- | tests/basic-test.vala | 31 | ||||
-rw-r--r-- | tests/meson.build | 12 |
7 files changed, 103 insertions, 47 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 446605f..412c225 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,13 +21,12 @@ flatpak:master: - flatpak-builder --finish-only --repo=repo app data/flatpak/org.gnome.Contacts.json # Make a Flatpak Contacts bundle for people to test - flatpak build-bundle repo contacts-dev.flatpak --runtime-repo=https://sdk.gnome.org/gnome-nightly.flatpakrepo org.gnome.Contacts - # TODO: Run automatic tests inside the Flatpak env - # - xvfb-run -a -s "-screen 0 1024x768x24" flatpak build app ninja -C _build test + - xvfb-run -a -s "-screen 0 1024x768x24" flatpak build app ninja -C _build test artifacts: paths: - contacts-dev.flatpak - _build/meson-logs/meson-log.txt - # - _build/meson-logs/testlog.txt + - _build/meson-logs/testlog.txt expire_in: 2 days cache: paths: diff --git a/meson.build b/meson.build index 18bffa6..66304a2 100644 --- a/meson.build +++ b/meson.build @@ -92,3 +92,4 @@ subdir('man') if docs_enabled subdir('docs') endif +subdir('tests') diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala index b537e73..db13c9d 100644 --- a/src/contacts-contact.vala +++ b/src/contacts-contact.vala @@ -503,7 +503,7 @@ public class Contacts.Contact : GLib.Object { return p; } - internal static async void set_persona_property (Persona persona, + public static async void set_persona_property (Persona persona, string property_name, Value new_value) throws PropertyError, IndividualAggregatorError, ContactError, PropertyError { if (persona is FakePersona) { var fake = persona as FakePersona; diff --git a/src/contacts-utils.vala b/src/contacts-utils.vala index c1a9d74..5552e8c 100644 --- a/src/contacts-utils.vala +++ b/src/contacts-utils.vala @@ -23,7 +23,7 @@ using GLib; using Gdk; namespace Contacts { - private bool is_set (string? str) { + public bool is_set (string? str) { return str != null && str != ""; } diff --git a/src/meson.build b/src/meson.build index 5669450..d471144 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,36 +4,15 @@ install_data('org.gnome.Contacts.gschema.xml', install_dir: join_paths(datadir, 'glib-2.0', 'schemas'), ) -# The gnome-contacts binary -contacts_vala_sources = files( - 'contacts-accounts-list.vala', - 'contacts-app.vala', - 'contacts-avatar.vala', - 'contacts-avatar-selector.vala', - 'contacts-contact-editor.vala', - 'contacts-contact-form.vala', - 'contacts-contact-list.vala', - 'contacts-contact-pane.vala', - 'contacts-contact-sheet.vala', +# Common library +libcontacts_sources = [ 'contacts-contact.vala', - 'contacts-crop-cheese-dialog.vala', 'contacts-esd-setup.vala', 'contacts-im-service.vala', - 'contacts-in-app-notification.vala', - 'contacts-link-suggestion-grid.vala', - 'contacts-linked-personas-dialog.vala', - 'contacts-linking.vala', - 'contacts-list-pane.vala', - 'contacts-max-width-bin.vala', - 'contacts-settings.vala', - 'contacts-setup-window.vala', 'contacts-store.vala', 'contacts-types.vala', - 'contacts-ui-state.vala', 'contacts-utils.vala', - 'contacts-window.vala', - 'main.vala', -) +] contacts_vala_args = [ '--target-glib=@0@'.format(min_glib_version), @@ -41,10 +20,6 @@ contacts_vala_args = [ '--pkg', 'custom', ] -contacts_c_sources = [ - 'cc-crop-area.c', -] - contacts_c_args = [ '-include', 'config.h', '-DGNOME_DESKTOP_USE_UNSTABLE_API', @@ -70,7 +45,6 @@ contacts_deps = [ if cheese_enabled contacts_deps += [ cheese, cheese_gtk ] contacts_vala_args += [ '-D', 'HAVE_CHEESE' ] - contacts_c_sources += 'cheese-flash.c' endif if telepathy_enabled @@ -78,37 +52,76 @@ if telepathy_enabled contacts_vala_args += [ '-D', 'HAVE_TELEPATHY' ] endif +libcontacts = static_library('contacts', + libcontacts_sources, + include_directories: config_h_dir, + vala_args: contacts_vala_args, + c_args: contacts_c_args, + dependencies: contacts_deps, +) + +libcontacts_dep = declare_dependency( + link_with: libcontacts, + include_directories: include_directories('.'), + dependencies: contacts_deps, +) + + +# The gnome-contacts binary +contacts_vala_sources = files( + 'contacts-accounts-list.vala', + 'contacts-app.vala', + 'contacts-avatar.vala', + 'contacts-avatar-selector.vala', + 'contacts-contact-editor.vala', + 'contacts-contact-form.vala', + 'contacts-contact-list.vala', + 'contacts-contact-pane.vala', + 'contacts-contact-sheet.vala', + 'contacts-crop-cheese-dialog.vala', + 'contacts-in-app-notification.vala', + 'contacts-link-suggestion-grid.vala', + 'contacts-linked-personas-dialog.vala', + 'contacts-linking.vala', + 'contacts-list-pane.vala', + 'contacts-max-width-bin.vala', + 'contacts-settings.vala', + 'contacts-setup-window.vala', + 'contacts-ui-state.vala', + 'contacts-window.vala', + 'main.vala', +) + +contacts_c_sources = [ + 'cc-crop-area.c', +] + +if cheese_enabled + contacts_c_sources += 'cheese-flash.c' +endif + contacts_sources = [ contacts_c_sources, contacts_vala_sources, resources, ] - executable('gnome-contacts', contacts_sources, include_directories: config_h_dir, vala_args: contacts_vala_args, c_args: contacts_c_args, - dependencies: contacts_deps, + dependencies: libcontacts_dep, install: true, ) + # The search provider -contact_search_provider_sources = [ - 'contacts-contact.vala', - 'contacts-esd-setup.vala', - 'contacts-im-service.vala', +executable('gnome-contacts-search-provider', 'contacts-shell-search-provider.vala', - 'contacts-store.vala', - 'contacts-types.vala', - 'contacts-utils.vala', -] - -executable('gnome-contacts-search-provider', contact_search_provider_sources, + dependencies: libcontacts_dep, include_directories: config_h_dir, vala_args: contacts_vala_args, c_args: contacts_c_args, - dependencies: contacts_deps, install: true, install_dir: libexecdir, ) diff --git a/tests/basic-test.vala b/tests/basic-test.vala new file mode 100644 index 0000000..9cf1517 --- /dev/null +++ b/tests/basic-test.vala @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2018 Niels De Graef <nielsdegraef@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +using Gee; + +void main (string[] args) { + Test.init (ref args); + Test.add_func ("/utils/get_first", Contacts.UtilsTests.get_first); + Test.run (); +} + +namespace Contacts.UtilsTests { + private void get_first () { + Collection<Object> empty = Collection.empty (); + assert_true (Utils.get_first (empty) == null); + } +} diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..ddf0cb5 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,12 @@ +test_names = [ + 'basic-test', +] + +foreach _test : test_names + test_bin = executable(_test, + '@0@.vala'.format(_test), + dependencies: libcontacts_dep, + ) + + test(_test, test_bin) +endforeach |