Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add some new tests, and remame manigest.h to test.h in tests
Baptiste Daroussin committed 15 years ago
commit 997461335948106a89fb4d6c435f5bf4308d9e8d
parent f55f6b1
7 files changed +38 -7
modified libpkg/pkg.c
@@ -18,7 +18,11 @@ pkg_type(struct pkg *pkg)
}

const char *
-
pkg_get(struct pkg *pkg, pkg_attr attr) {
+
pkg_get(struct pkg *pkg, pkg_attr attr)
+
{
+
	if (pkg == NULL)
+
		return (NULL);
+

	switch (attr) {
		case PKG_NAME:
			return (sbuf_get(pkg->name));
@@ -52,6 +56,9 @@ pkg_get(struct pkg *pkg, pkg_attr attr) {
int
pkg_set(struct pkg *pkg, pkg_attr attr, const char *value)
{
+
	if (pkg == NULL)
+
		return (EPKG_FATAL);
+

	if (value == NULL) {
		pkg_set(pkg, PKG_ERR, "Value can not be NULL");
		return (EPKG_FATAL);
@@ -330,7 +337,7 @@ pkg_new(struct pkg **pkg)

	(*pkg)->err = sbuf_new_auto();

-
	return (0);
+
	return (EPKG_OK);
}

void
modified tests/Makefile
@@ -1,6 +1,7 @@
PROG=	test
SRCS=	test.c		\
	manifest.c	\
+
	pkg.c		\

CFLAGS+=-I.			\
	-I/usr/local/include	\
modified tests/manifest.c
@@ -2,7 +2,7 @@
#include <pkg.h>
#include <string.h>

-
#include "manifest.h"
+
#include "tests.h"

char manifest[] = ""
	"@pkg_format_version 0.9\n"
deleted tests/manifest.h
@@ -1,3 +0,0 @@
-
#include <check.h>
-

-
TCase * tcase_manifest(void);
added tests/pkg.c
@@ -0,0 +1,21 @@
+
#include <check.h>
+
#include <pkg.h>
+

+
START_TEST(pkg_null)
+
{
+
	struct pkg *p = NULL;
+
	fail_unless(pkg_get(p, PKG_NAME) ==NULL);
+
	fail_unless(pkg_set(p, PKG_NAME, "foobar") == EPKG_FATAL);
+

+
	fail_unless(pkg_new(&p) == EPKG_OK);
+
	fail_unless(pkg_set(p, PKG_NAME, NULL) == EPKG_FATAL);
+
}
+
END_TEST
+

+
TCase *tcase_pkg(void)
+
{
+
	TCase *tc = tcase_create("Pkg");
+
	tcase_add_test(tc, pkg_null);
+

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

-
#include "manifest.h"
+
#include "tests.h"

int
main()
@@ -9,6 +9,7 @@ main()
	Suite *s = suite_create("pkgng");

	suite_add_tcase(s, tcase_manifest());
+
	suite_add_tcase(s, tcase_pkg());

	/* Run the tests ...*/
	SRunner *sr = srunner_create(s);
added tests/tests.h
@@ -0,0 +1,4 @@
+
#include <check.h>
+

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