Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Convert tests (quick & dirty) to ATF
Baptiste Daroussin committed 13 years ago
commit 599eb9d25eb4325d86b0b2c49a85907f6ea60034
parent a5e7de0
5 files changed +88 -101
modified tests/Makefile
@@ -1,18 +1,23 @@
PROG=	test
SRCS=	test.c		\
	manifest.c	\
-
	pkg.c		\
+
	pkg.c

CFLAGS+=-I.			\
	-I/usr/local/include	\
	-I../libpkg
LDADD+=	-L/usr/local/lib	\
-
	-lcheck			\
+
	-latf-c			\
	-L../libpkg		\
	-lpkg
NO_MAN=	true

+
TESTS=	manifest \
+
	pkg
+

run: ${PROG}
-
	@env LD_LIBRARY_PATH=../libpkg ./${PROG}
+
.for test in ${TESTS}
+
	@env LD_LIBRARY_PATH=../libpkg ./${PROG} ${test}
+
.endfor

.include <bsd.prog.mk>
modified tests/manifest.c
@@ -1,4 +1,4 @@
-
#include <check.h>
+
#include <atf-c.h>
#include <pkg.h>
#include <string.h>

@@ -113,7 +113,8 @@ char wrong_manifest4[] = ""
	"files:\n"
	"  /usr/local/bin/foo: 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b\n";

-
START_TEST(parse_manifest)
+
void
+
test_manifest(void)
{
	struct pkg *p = NULL;
	struct pkg_dep *dep = NULL;
@@ -122,119 +123,93 @@ START_TEST(parse_manifest)
	struct pkg_file *file = NULL;
	int i;

-
	fail_unless(pkg_new(&p, PKG_FILE) == EPKG_OK);
-
	fail_unless(p != NULL);
-
	fail_unless(pkg_parse_manifest(p, manifest) == EPKG_OK);
+
	ATF_REQUIRE_EQ(EPKG_OK, pkg_new(&p, PKG_FILE));
+
	ATF_REQUIRE(p != NULL);
+
	ATF_REQUIRE_EQ(EPKG_OK, pkg_parse_manifest(p, manifest));

#if 0
-
	fail_unless(strcmp(pkg_get(p, PKG_NAME), "foobar") == 0);
-
	fail_unless(strcmp(pkg_get(p, PKG_VERSION), "0.3") == 0);
-
	fail_unless(strcmp(pkg_get(p, PKG_ORIGIN), "foo/bar") == 0);
-
	fail_unless(strcmp(pkg_get(p, PKG_COMMENT), "A dummy manifest") == 0);
-
	fail_unless(strcmp(pkg_get(p, PKG_ARCH), "amd64") == 0);
-
	fail_unless(strcmp(pkg_get(p, PKG_VERSION), "800500") == 0);
-
	fail_unless(strcmp(pkg_get(p, PKG_WWW), "http://www.foobar.com") == 0);
-
	fail_unless(strcmp(pkg_get(p, PKG_MAINTAINER), "test@pkgng.lan") == 0);
+
	ATF_REQUIRE(strcmp(pkg_get(p, PKG_NAME), "foobar") == 0);
+
	ATF_REQUIRE(strcmp(pkg_get(p, PKG_VERSION), "0.3") == 0);
+
	ATF_REQUIRE(strcmp(pkg_get(p, PKG_ORIGIN), "foo/bar") == 0);
+
	ATF_REQUIRE(strcmp(pkg_get(p, PKG_COMMENT), "A dummy manifest") == 0);
+
	ATF_REQUIRE(strcmp(pkg_get(p, PKG_ARCH), "amd64") == 0);
+
	ATF_REQUIRE(strcmp(pkg_get(p, PKG_VERSION), "800500") == 0);
+
	ATF_REQUIRE(strcmp(pkg_get(p, PKG_WWW), "http://www.foobar.com") == 0);
+
	ATF_REQUIRE(strcmp(pkg_get(p, PKG_MAINTAINER), "test@pkgng.lan") == 0);
#endif

	i = 0;
	while (pkg_deps(p, &dep) == EPKG_OK) {
		if (i == 0) {
-
			fail_unless(strcmp(pkg_dep_name(dep), "depfoo") == 0);
-
			fail_unless(strcmp(pkg_dep_origin(dep), "dep/foo") == 0);
-
			fail_unless(strcmp(pkg_dep_version(dep), "1.2") == 0);
+
			ATF_REQUIRE(strcmp(pkg_dep_name(dep), "depfoo") == 0);
+
			ATF_REQUIRE(strcmp(pkg_dep_origin(dep), "dep/foo") == 0);
+
			ATF_REQUIRE(strcmp(pkg_dep_version(dep), "1.2") == 0);
		} else if (i == 1) {
-
			fail_unless(strcmp(pkg_dep_name(dep), "depbar") == 0);
-
			fail_unless(strcmp(pkg_dep_origin(dep), "dep/bar") == 0);
-
			fail_unless(strcmp(pkg_dep_version(dep), "3.4") == 0);
+
			ATF_REQUIRE(strcmp(pkg_dep_name(dep), "depbar") == 0);
+
			ATF_REQUIRE(strcmp(pkg_dep_origin(dep), "dep/bar") == 0);
+
			ATF_REQUIRE(strcmp(pkg_dep_version(dep), "3.4") == 0);
		}
		i++;
	}
-
	fail_unless(i == 2);
+
	ATF_REQUIRE(i == 2);

	i = 0;
#if 0
	while (pkg_conflicts(p, &conflict) == EPKG_OK) {
		if (i == 0) {
-
			fail_unless(strcmp(pkg_conflict_glob(conflict), "foo-*") == 0);
+
			ATF_REQUIRE(strcmp(pkg_conflict_glob(conflict), "foo-*") == 0);
		} else if (i == 1) {
-
			fail_unless(strcmp(pkg_conflict_glob(conflict), "bar-*") == 0);
+
			ATF_REQUIRE(strcmp(pkg_conflict_glob(conflict), "bar-*") == 0);
		}
		i++;
	}
-
	fail_unless(i == 2);
+
	ATF_REQUIRE(i == 2);
#endif

	i = 0;
	while (pkg_options(p, &option) == EPKG_OK) {
		if (i == 0) {
-
			fail_unless(strcmp(pkg_option_opt(option), "foo") == 0);
-
			fail_unless(strcmp(pkg_option_value(option), "true") == 0);
+
			ATF_REQUIRE(strcmp(pkg_option_opt(option), "foo") == 0);
+
			ATF_REQUIRE(strcmp(pkg_option_value(option), "true") == 0);
		} else if (i == 1) {
-
			fail_unless(strcmp(pkg_option_opt(option), "bar") == 0);
-
			fail_unless(strcmp(pkg_option_value(option), "false") == 0);
+
			ATF_REQUIRE(strcmp(pkg_option_opt(option), "bar") == 0);
+
			ATF_REQUIRE(strcmp(pkg_option_value(option), "false") == 0);
		}
		i++;
	}
-
	fail_unless(i == 2);
+
	ATF_REQUIRE(i == 2);

-
	fail_unless(pkg_files(p, &file) == EPKG_OK);
-
	fail_unless(strcmp(pkg_file_path(file), "/usr/local/bin/foo") ==
+
	ATF_REQUIRE(pkg_files(p, &file) == EPKG_OK);
+
	ATF_REQUIRE(strcmp(pkg_file_path(file), "/usr/local/bin/foo") ==
				0);
#if 0
-
	fail_unless(strcmp(pkg_file_sha256(file),
+
	ATF_REQUIRE(strcmp(pkg_file_sha256(file),
				"01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b")
				== 0);
#endif
-
}
-
END_TEST
+
	pkg_free(p);
+
/*	p = NULL;

-
START_TEST(parse_wrong_manifest1)
-
{
-
	struct pkg *p = NULL;
-

-
	fail_unless(pkg_new(&p, PKG_FILE) == EPKG_OK);
-
	fail_unless(pkg_parse_manifest(p, wrong_manifest1) == EPKG_FATAL);
-
}
-
END_TEST
+
	ATF_REQUIRE(pkg_new(&p, PKG_FILE) == EPKG_OK);
+
	ATF_REQUIRE(pkg_parse_manifest(p, wrong_manifest1) == EPKG_FATAL);

-
START_TEST(parse_wrong_manifest2)
-
{
-
	struct pkg *p = NULL;
-

-
	fail_unless(pkg_new(&p, PKG_FILE) == EPKG_OK);
-
	fail_unless(pkg_parse_manifest(p, wrong_manifest2) == EPKG_FATAL);
-
}
-
END_TEST
+
	pkg_free(p);
+
	p = NULL;

-
START_TEST(parse_wrong_manifest3)
-
{
-
	struct pkg *p = NULL;
+
	ATF_REQUIRE(pkg_new(&p, PKG_FILE) == EPKG_OK);
+
	ATF_REQUIRE(pkg_parse_manifest(p, wrong_manifest2) == EPKG_FATAL);

-
	fail_unless(pkg_new(&p, PKG_FILE) == EPKG_OK);
-
	fail_unless(pkg_parse_manifest(p, wrong_manifest3) == EPKG_FATAL);
-
}
-
END_TEST
+
	pkg_free(p);
+
	p = NULL;

-
START_TEST(parse_wrong_manifest4)
-
{
-
	struct pkg *p = NULL;
+
	ATF_REQUIRE(pkg_new(&p, PKG_FILE) == EPKG_OK);
+
	ATF_REQUIRE(pkg_parse_manifest(p, wrong_manifest3) == EPKG_FATAL);

-
	fail_unless(pkg_new(&p, PKG_FILE) == EPKG_OK);
-
	fail_unless(pkg_parse_manifest(p, wrong_manifest4) == EPKG_FATAL);
-
}
-
END_TEST
+
	pkg_free(p);
+
	p = NULL;

-
TCase *
-
tcase_manifest(void)
-
{
-
	TCase *tc = tcase_create("Manifest");
-
	tcase_add_test(tc, parse_manifest);
-
#if 0
-
	tcase_add_test(tc, parse_wrong_manifest1);
-
	tcase_add_test(tc, parse_wrong_manifest2);
-
	tcase_add_test(tc, parse_wrong_manifest3);
-
	tcase_add_test(tc, parse_wrong_manifest4);
-
#endif
-
	return (tc);
+
	ATF_REQUIRE(pkg_new(&p, PKG_FILE) == EPKG_OK);
+
	ATF_REQUIRE(pkg_parse_manifest(p, wrong_manifest4) == EPKG_FATAL);
+
	pkg_free(p);
+
*/
}
modified tests/pkg.c
@@ -1,9 +1,7 @@
-
#include <check.h>
+
#include <atf-c.h>
#include <pkg.h>

-
TCase *tcase_pkg(void)
+
void
+
test_pkg(void)
{
-
	TCase *tc = tcase_create("Pkg");
-

-
	return (tc);
}
modified tests/test.c
@@ -1,21 +1,29 @@
-
#include <check.h>
-

+
#include <atf-c.h>
#include "tests.h"

-
int
-
main()
+
ATF_TC(manifest);
+
ATF_TC_HEAD(manifest, tc)
+
{
+
    atf_tc_set_md_var(tc, "descr", "Testing manifest loading...");
+
}
+
ATF_TC_BODY(manifest, tc)
{
-
	int nfailed = 0;
-
	Suite *s = suite_create("pkgng");
+
    test_manifest();
+
}

-
	suite_add_tcase(s, tcase_manifest());
-
	suite_add_tcase(s, tcase_pkg());
+
ATF_TC(pkg);
+
ATF_TC_HEAD(pkg, tc)
+
{
+
    atf_tc_set_md_var(tc, "descr", "Testing pkg interface...");
+
}

-
	/* Run the tests ...*/
-
	SRunner *sr = srunner_create(s);
-
	srunner_set_log(sr, "test.log");
-
	srunner_run_all(sr, CK_NORMAL);
-
	nfailed = srunner_ntests_failed(sr);
-
	srunner_free(sr);
-
	return (nfailed == 0 ? 0 : 1);
+
ATF_TC_BODY(pkg, tc)
+
{
+
    test_pkg();
+
}
+
ATF_TP_ADD_TCS(tp)
+
{
+
    ATF_TP_ADD_TC(tp, manifest);
+
    ATF_TP_ADD_TC(tp, pkg);
+
    return atf_no_error();
}
modified tests/tests.h
@@ -1,4 +1,5 @@
-
#include <check.h>
+
#include <atf-c.h>
+

+
void test_manifest(void);
+
void test_pkg(void);

-
TCase * tcase_manifest(void);
-
TCase * tcase_pkg(void);