Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Link libpkg against libutil + make manifest parsing send a warning when it finds an unknown keyword. Add a test for that
Baptiste Daroussin committed 14 years ago
commit e75462c690c801c53050edaaf1237be32ddf1a11
parent e2e24c8
4 files changed +42 -2
modified libpkg/Makefile
@@ -38,6 +38,7 @@ LDADD+= -L${.CURDIR}/../external/sqlite \
		-lsbuf \
		-lfetch \
		-lelf \
+
		-lutil \
		-lpthread

DEBUG_FLAGS+=  -g
modified libpkg/pkg_manifest.c
@@ -269,7 +269,7 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
	int i, j;
	char *buf_ptr;
	size_t next;
-

+
	int found;

	nbel = split_chr(buf, '\n');

@@ -283,8 +283,10 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
	buf_ptr += next + 1;
	next = strlen(buf_ptr);
	for (i = 1; i <= nbel; i++) {
+
		found = 0;
		for (j = 0; j < manifest_key_len; j++) {
			if (STARTS_WITH(buf_ptr, manifest_key[j].key)) {
+
				found = 1;
				if (manifest_key[j].parse(pkg, buf_ptr +
					strlen(manifest_key[j].key)) != EPKG_OK) {

@@ -295,6 +297,9 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
				break;
			}
		}
+
		if (found == 0 && buf_ptr[0] != '\0') {
+
			warnx("Unknown line #%d: %s (ignored)", i + 1,  buf_ptr);
+
		}
		/* We need to compute `next' only if we are not at the end of the manifest */
		if (i != nbel) {
			buf_ptr += next + 1;
modified pkg/main.c
@@ -24,7 +24,7 @@ static struct commands {
	const char * const name;
	int (*exec)(int argc, char **argv);
	void (* const usage)(void);
-
} cmd[] = { 
+
} cmd[] = {
	{ "add", exec_add, usage_add},
	{ "create", exec_create, usage_create},
	{ "delete", exec_delete, usage_delete},
modified tests/manifest.c
@@ -28,6 +28,7 @@ char manifest[] = ""
	"@file /usr/local/bin/foo "
		"01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b\n";

+
/* Name empty */
char wrong_manifest1[] = ""
	"@pkg_format_version 0.9\n"
	"@name\n"
@@ -47,6 +48,7 @@ char wrong_manifest1[] = ""
	"@option foo true\n"
	"@option bar false\n";

+
/* bad dependency line */
char wrong_manifest2[] = ""
	"@pkg_format_version 0.9\n"
	"@name foobar\n"
@@ -66,6 +68,7 @@ char wrong_manifest2[] = ""
	"@option foo true\n"
	"@option bar false\n";

+
/* bad conflict line */
char wrong_manifest3[] = ""
	"@pkg_format_version 0.9\n"
	"@name foobar\n"
@@ -85,6 +88,7 @@ char wrong_manifest3[] = ""
	"@option foo true\n"
	"@option bar false\n";

+
/* bad exec line */
char wrong_manifest4[] = ""
	"@pkg_format_version 0.9\n"
	"@name foobar\n"
@@ -104,6 +108,7 @@ char wrong_manifest4[] = ""
	"@option foo true\n"
	"@option bar false\n";

+
/* bad option line */
char wrong_manifest5[] = ""
	"@pkg_format_version 0.9\n"
	"@name foobar\n"
@@ -123,6 +128,7 @@ char wrong_manifest5[] = ""
	"@option \n"
	"@option bar false\n";

+
/* bad option line */
char wrong_manifest6[] = ""
	"@pkg_format_version 0.9\n"
	"@name foobar\n"
@@ -142,6 +148,25 @@ char wrong_manifest6[] = ""
	"@option foo true\n"
	"@option bar\n";

+
char wrong_manifest7[] = ""
+
	"@pkg_format_version 0.9\n"
+
	"@name foobar\n"
+
	"@version 0.3\n"
+
	"@origin foo/bar\n"
+
	"@comment A dummy manifest\n"
+
	"@arch amd64\n"
+
	"@osversion 800500\n"
+
	"@www http://www.foobar.com\n"
+
	"@maintainer test@pkgng.lan\n"
+
	"@dep depfoo dep/foo 1.2\n"
+
	"@dep depbar dep/bar 3.4\n"
+
	"@conflict foo-*\n"
+
	"@conflict bar-*\n"
+
	"@keyword bla\n"
+
	"@exec true && echo hello\n"
+
	"@exec false || echo world\n"
+
	"@option foo true\n";
+

START_TEST(parse_manifest)
{
	struct pkg *p;
@@ -292,6 +317,14 @@ START_TEST(parse_wrong_manifest6)
}
END_TEST

+
START_TEST(parse_wrong_manifest7)
+
{
+
	struct pkg *p;
+
	fail_unless(pkg_new(&p) == EPKG_OK);
+
	fail_unless(pkg_parse_manifest(p, wrong_manifest7) == EPKG_OK);
+
}
+
END_TEST
+

TCase *
tcase_manifest(void)
{
@@ -303,6 +336,7 @@ tcase_manifest(void)
	tcase_add_test(tc, parse_wrong_manifest4);
	tcase_add_test(tc, parse_wrong_manifest5);
	tcase_add_test(tc, parse_wrong_manifest6);
+
	tcase_add_test(tc, parse_wrong_manifest7);

	return (tc);
}