[libgweather/ebassi/gtk4] Move tests and tools out of the way



commit 559d57cdcd5d4fee52f8f608640dca3e327ed3db
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Oct 11 18:06:04 2021 +0100

    Move tests and tools out of the way
    
    We should write tests and tools that look like tests in the same way
    we'd write code that depends on the library, instead of assuming that
    everything works out because it sits in the same directory.

 libgweather/meson.build                      | 57 +++-------------------------
 libgweather/tests/meson.build                | 15 ++++++++
 libgweather/{ => tests}/test_libgweather.c   | 25 +++---------
 libgweather/tools/meson.build                | 40 +++++++++++++++++++
 libgweather/{ => tools}/test_locations.c     | 10 +++--
 libgweather/{ => tools}/test_locations_utc.c | 12 ++++--
 libgweather/{ => tools}/test_metar.c         |  0
 libgweather/{ => tools}/test_sun_moon.c      |  0
 libgweather/{ => tools}/test_weather.c       |  0
 9 files changed, 82 insertions(+), 77 deletions(-)
---
diff --git a/libgweather/meson.build b/libgweather/meson.build
index 0dbf41bd..68518676 100644
--- a/libgweather/meson.build
+++ b/libgweather/meson.build
@@ -156,7 +156,10 @@ libgweather_static = static_library('gweather',
 )
 
 libgweather_static_dep = declare_dependency(sources: gweather_c_sources,
-  include_directories: include_directories('..'),
+  include_directories: [
+    include_directories('.'),
+    include_directories('..'),
+  ],
   dependencies: deps_libgweather,
   link_with: libgweather_static,
 )
@@ -210,53 +213,5 @@ if enable_vala
   )
 endif
 
-test_cargs = [
-  '-DTEST_LOCATIONS="@0@"'.format(locations_bin.full_path()),
-  '-DSCHEMASDIR="@0@/schemas"'.format(meson.source_root()),
-  '-DSCHEMAS_BUILDDIR="@0@/schemas"'.format(meson.build_root()),
-]
-
-executable('test_locations',
-  sources: ['test_locations.c'],
-  c_args: test_cargs,
-  dependencies: libgweather_static_dep,
-  install: false,
-)
-
-executable('test_locations_utc',
-  sources: ['test_locations_utc.c'],
-  c_args: test_cargs,
-  dependencies: libgweather_static_dep,
-  install: false,
-)
-
-test('test_libgweather',
-  executable('test_libgweather',
-    sources: ['test_libgweather.c'],
-    c_args: test_cargs,
-    dependencies: libgweather_static_dep,
-    install: false,
-  ),
-  depends: [locations_bin],
-)
-
-executable('test_metar',
-  sources: ['test_metar.c', gweather_c_sources, gweather_priv_sources],
-  c_args: test_cargs,
-  dependencies: libgweather_static_dep,
-  install: false,
-)
-
-executable('test_sun_moon',
-  sources: ['test_sun_moon.c', 'weather-sun.c', 'weather-moon.c'],
-  c_args: test_cargs,
-  dependencies: libgweather_static_dep,
-  install: false,
-)
-
-executable('test_weather',
-  sources: ['test_weather.c'],
-  c_args: test_cargs,
-  dependencies: libgweather_static_dep,
-  install: false,
-)
+subdir('tests')
+subdir('tools')
diff --git a/libgweather/tests/meson.build b/libgweather/tests/meson.build
new file mode 100644
index 00000000..201fd393
--- /dev/null
+++ b/libgweather/tests/meson.build
@@ -0,0 +1,15 @@
+test_cargs = [
+  '-DTEST_LOCATIONS="@0@"'.format(locations_bin.full_path()),
+  '-DSCHEMASDIR="@0@/schemas"'.format(meson.source_root()),
+  '-DSCHEMAS_BUILDDIR="@0@/schemas"'.format(meson.build_root()),
+]
+
+test('test_libgweather',
+  executable('test_libgweather',
+    sources: ['test_libgweather.c'],
+    c_args: test_cargs,
+    dependencies: libgweather_static_dep,
+    install: false,
+  ),
+  depends: [locations_bin],
+)
diff --git a/libgweather/test_libgweather.c b/libgweather/tests/test_libgweather.c
similarity index 96%
rename from libgweather/test_libgweather.c
rename to libgweather/tests/test_libgweather.c
index 1a710fec..d00159d4 100644
--- a/libgweather/test_libgweather.c
+++ b/libgweather/tests/test_libgweather.c
@@ -1,20 +1,7 @@
-/*
- * (c) 2017 Bastien Nocera <hadess hadess net>
+/* test_libgweather.c: Test suite for libgweather
  *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301  USA.
+ * SPDX-FileCopyrightText: 2017 Bastien Nocera <hadess hadess net>
+ * SPDX-License-Identifier: LGPL-2.0-or-later
  */
 
 #include "config.h"
@@ -23,9 +10,9 @@
 #include <string.h>
 #include <libsoup/soup.h>
 
-#include <gweather-version.h>
-#include "gweather-location.h"
-#include "gweather-weather.h"
+#include <libgweather/gweather-version.h>
+
+/* We use internal API */
 #include "gweather-private.h"
 
 /* We use/test gweather_location_get_children */
diff --git a/libgweather/tools/meson.build b/libgweather/tools/meson.build
new file mode 100644
index 00000000..c1f63c68
--- /dev/null
+++ b/libgweather/tools/meson.build
@@ -0,0 +1,40 @@
+tools = [
+  {
+    'name': 'locations',
+  },
+  {
+    'name': 'locations_utc',
+  },
+  {
+    'name': 'metar',
+  },
+  {
+    'name': 'sun_moon',
+    'sources': [
+      'test_sun_moon.c',
+      '../weather-sun.c',
+      '../weather-moon.c',
+    ],
+  },
+  {
+    'name': 'weather',
+  }
+]
+
+tools_cargs = [
+  '-DTEST_LOCATIONS="@0@"'.format(locations_bin.full_path()),
+  '-DSCHEMASDIR="@0@/schemas"'.format(meson.source_root()),
+  '-DSCHEMAS_BUILDDIR="@0@/schemas"'.format(meson.build_root()),
+]
+
+foreach tool: tools
+  tool_name = tool.get('name')
+  tool_sources = tool.get('sources', ['test_' + tool_name + '.c'])
+
+  executable('test_' + tool_name,
+    sources: tool_sources,
+    c_args: tools_cargs,
+    dependencies: libgweather_static_dep,
+    install: false,
+  )
+endforeach
diff --git a/libgweather/test_locations.c b/libgweather/tools/test_locations.c
similarity index 89%
rename from libgweather/test_locations.c
rename to libgweather/tools/test_locations.c
index 37b333e0..c930101c 100644
--- a/libgweather/test_locations.c
+++ b/libgweather/tools/test_locations.c
@@ -1,7 +1,11 @@
+/* test_locations.c: Test GWeatherLocationEntry
+ *
+ * SPDX-FileCopyrightText: The GWeather authors
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
-#include <gweather-version.h>
-#include "gweather-location-entry.h"
-#include "gweather-timezone-menu.h"
+#include <gtk/gtk.h>
+#include <libgweather/gweather.h>
 
 static void
 deleted (GtkWidget *widget, GdkEvent *event, gpointer data)
diff --git a/libgweather/test_locations_utc.c b/libgweather/tools/test_locations_utc.c
similarity index 88%
rename from libgweather/test_locations_utc.c
rename to libgweather/tools/test_locations_utc.c
index 2804448d..105f1ed4 100644
--- a/libgweather/test_locations_utc.c
+++ b/libgweather/tools/test_locations_utc.c
@@ -1,7 +1,11 @@
-
-#include <gweather-version.h>
-#include "gweather-location-entry.h"
-#include "gweather-timezone-menu.h"
+/* test_locations_utc.c: Test GWeatherLocationEntry with UTC time zone
+ *
+ * SPDX-FileCopyrightText: The GWeather authors
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <gtk/gtk.h>
+#include <libgweather/gweather.h>
 
 static void
 deleted (GtkWidget *widget, GdkEvent *event, gpointer data)
diff --git a/libgweather/test_metar.c b/libgweather/tools/test_metar.c
similarity index 100%
rename from libgweather/test_metar.c
rename to libgweather/tools/test_metar.c
diff --git a/libgweather/test_sun_moon.c b/libgweather/tools/test_sun_moon.c
similarity index 100%
rename from libgweather/test_sun_moon.c
rename to libgweather/tools/test_sun_moon.c
diff --git a/libgweather/test_weather.c b/libgweather/tools/test_weather.c
similarity index 100%
rename from libgweather/test_weather.c
rename to libgweather/tools/test_weather.c


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]