From: Michael Tremer Date: Tue, 17 May 2022 15:02:32 +0000 (+0000) Subject: tests: makefile: Add test for dist X-Git-Tag: 0.9.28~788 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f80a6cd34987e28ec3f9e15c95fadebe47c34f27;p=pakfire.git tests: makefile: Add test for dist This test tries to create a source package for a dummy package. We then evaluate if we can read correct information back again. Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 77f8cf75e..980795746 100644 --- a/Makefile.am +++ b/Makefile.am @@ -789,6 +789,8 @@ EXTRA_DIST += \ tests/data/compress/data.xz \ tests/data/compress/data.zst \ \ + tests/data/packages/dummy/dummy.nm \ + \ tests/data/parser/test-comments.txt \ tests/data/parser/test-conditionals.txt \ tests/data/parser/test-declarations.txt \ diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index a2f686c8c..03160a8d1 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -181,8 +181,10 @@ int pakfire_read_makefile(struct pakfire_parser** parser, struct pakfire* pakfir // Finally, parse the makefile r = pakfire_parser_read_file(*parser, path, error); - if (r) + if (r) { + ERROR(pakfire, "Could not read makefile %s: %m\n", path); goto ERROR; + } return 0; diff --git a/tests/data/packages/dummy/dummy.nm b/tests/data/packages/dummy/dummy.nm new file mode 100644 index 000000000..89e20fe96 --- /dev/null +++ b/tests/data/packages/dummy/dummy.nm @@ -0,0 +1,27 @@ +############################################################################### +# IPFire.org - An Open Source Firewall Solution # +# Copyright (C) - IPFire Development Team # +############################################################################### + +name = dummy +version = 1.0 +release = 1 + +groups = Dummy +url = https://www.example.org +license = GPLv2+ +summary = This is a dummy package + +description + This package is a dummy package and its sole purpose is to have something + that we can use for packaging in the test environment. + + This package purposefully does not download any files. +end + +sources = + +# This package has a simple build requirement +build + requires = gcc +end diff --git a/tests/libpakfire/makefile.c b/tests/libpakfire/makefile.c index 75dac1c95..b8218377e 100644 --- a/tests/libpakfire/makefile.c +++ b/tests/libpakfire/makefile.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -163,10 +164,95 @@ FAIL: return r; } +/* + This test tries to dist() on a dummy package +*/ +static int test_dist_dummy(const struct test* t) { + int r = EXIT_FAILURE; + + struct pakfire_archive* archive = NULL; + struct pakfire_package* package = NULL; + + // Create a directory to write packages to + char* tmp = test_mkdtemp(); + ASSERT(tmp); + + char* filename = NULL; + + // Attempt to dist the dummy package + ASSERT_SUCCESS(pakfire_dist(t->pakfire, + TEST_SRC_PATH "data/packages/dummy/dummy.nm", tmp, &filename)); + + // Check if filename is set + ASSERT(filename); + + // Check if we can read the archive + ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, filename)); + + // Extract all package metadata + ASSERT_SUCCESS(pakfire_archive_make_package(archive, NULL, &package)); + + // Check name + const char* name = pakfire_package_get_name(package); + ASSERT_STRING_EQUALS(name, "dummy"); + + // Check EVR + const char* evr = pakfire_package_get_evr(package); + ASSERT_STRING_EQUALS(evr, "1.0-1"); + + // Check arch + const char* arch = pakfire_package_get_arch(package); + ASSERT_STRING_EQUALS(arch, "src"); + + // Check vendor + const char* vendor = pakfire_package_get_vendor(package); + ASSERT_STRING_EQUALS(vendor, pakfire_get_distro_vendor(t->pakfire)); + + // Check UUID + const char* uuid = pakfire_package_get_uuid(package); + ASSERT(uuid); + + // Check groups + const char* groups = pakfire_package_get_groups(package); + ASSERT_STRING_EQUALS(groups, "Dummy"); + + // Check URL + const char* url = pakfire_package_get_url(package); + ASSERT_STRING_EQUALS(url, "https://www.example.org"); + + // Check license + const char* license = pakfire_package_get_license(package); + ASSERT_STRING_EQUALS(license, "GPLv2+"); + + // Check summary + const char* summary = pakfire_package_get_summary(package); + ASSERT_STRING_EQUALS(summary, "This is a dummy package"); + + // Check description + const char* description = pakfire_package_get_description(package); + ASSERT(description); + + // Check size + size_t installed_size = pakfire_package_get_installsize(package); + ASSERT(installed_size == 0); + + // Everything okay + r = EXIT_SUCCESS; + +FAIL: + if (archive) + pakfire_archive_unref(archive); + if (package) + pakfire_package_unref(package); + + return r; +} + int main(int argc, char** argv) { testsuite_add_test(test_macros); testsuite_add_test(test_parse); testsuite_add_test(test_packages); + testsuite_add_test(test_dist_dummy); return testsuite_run(); }