Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Merge branch 'check'
jlaffaye committed 15 years ago
commit 0aeaa8b388fbfda079f32feeec958855eca1cf4f
parent 31ccec67d7ee6409014dcad172cebc619b0bf81e
5 files changed +143 -2
modified libpkg/pkg_util.c
@@ -230,7 +230,7 @@ file_fetch(const char *url, const char *dest)
	off_t tfetched, rfetched, wfetched;
	int retry = 3;
	time_t begin_dl, now;
-
	char buf[BUFSIZ], sz[8];
+
	char buf[BUFSIZ];

	if ((fetchStatURL(url, &st, "") < 0) || st.size == -1) {
		/* TODO error handling */
@@ -272,7 +272,8 @@ file_fetch(const char *url, const char *dest)

		tfetched +=  rfetched;
		now = time(NULL);
-

+
/* TODO: callback, this is the job of the UI */
+
#if 0
		if ((now - begin_dl) > 0)
			humanize_number(sz, 8, (int64_t)(tfetched / (now - begin_dl)),
					"Bps", HN_AUTOSCALE, HN_DECIMAL);
@@ -280,6 +281,7 @@ file_fetch(const char *url, const char *dest)
			humanize_number(sz, 8, 0,
					"Bps", HN_AUTOSCALE, HN_DECIMAL);
		printf("\r%s\t%s %d%%", url, sz, (int)(((float)tfetched / (float)st.size) * 100));
+
#endif
	}
	printf("\n");

added tests/Makefile
@@ -0,0 +1,17 @@
+
PROG=	test
+
SRCS=	test.c		\
+
	manifest.c	\
+

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

+
run: ${PROG}
+
	@env LD_LIBRARY_PATH=../libpkg ./${PROG}
+

+
.include <bsd.prog.mk>
added tests/manifest.c
@@ -0,0 +1,99 @@
+
#include <check.h>
+
#include <pkg.h>
+
#include <string.h>
+

+
#include "manifest.h"
+

+
char manifest[] = ""
+
	"@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"
+
	"@exec true && echo hello\n"
+
	"@exec false || echo world\n"
+
	"@option foo true\n"
+
	"@option bar false\n";
+

+
START_TEST(parse_manifest)
+
{
+
	struct pkg *p;
+
	struct pkg **deps;
+
	struct pkg_conflict **conflicts;
+
	struct pkg_exec **execs;
+
	struct pkg_options **options;
+
	int i;
+

+
	fail_unless(pkg_new(&p) == 0);
+
	fail_unless(pkg_parse_manifest(p, manifest) == 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_OSVERSION), "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);
+

+
	deps = pkg_deps(p);
+
	fail_if(deps == NULL);
+
	for (i = 0; deps[i] != NULL; i++) {
+
		if (i == 0) {
+
			fail_unless(strcmp(pkg_get(deps[i], PKG_NAME), "depfoo") == 0);
+
			fail_unless(strcmp(pkg_get(deps[i], PKG_ORIGIN), "dep/foo") == 0);
+
			fail_unless(strcmp(pkg_get(deps[i], PKG_VERSION), "1.2") == 0);
+
		} else if (i == 1) {
+
			fail_unless(strcmp(pkg_get(deps[i], PKG_NAME), "depbar") == 0);
+
			fail_unless(strcmp(pkg_get(deps[i], PKG_ORIGIN), "dep/bar") == 0);
+
			fail_unless(strcmp(pkg_get(deps[i], PKG_VERSION), "3.4") == 0);
+
		}
+
	}
+
	fail_unless(i == 2);
+

+
	conflicts = pkg_conflicts(p);
+
	fail_if(conflicts == NULL);
+
	for (i = 0; conflicts[i] != NULL; i++) {
+
		if (i == 0) {
+
			fail_unless(strcmp(pkg_conflict_glob(conflicts[i]), "foo-*") == 0);
+
		} else if (i == 1) {
+
			fail_unless(strcmp(pkg_conflict_glob(conflicts[i]), "bar-*") == 0);
+
		}
+
	}
+
	fail_unless(i == 2);
+

+
	execs = pkg_execs(p);
+
	fail_if(execs == NULL);
+
	/* TODO when this bug is resolved */
+

+
	options = pkg_options(p);
+
	fail_if(options == NULL);
+
	for (i = 0; options[i] != NULL; i++) {
+
		if (i == 0) {
+
			fail_unless(strcmp(pkg_option_opt(options[i]), "foo") == 0);
+
			fail_unless(strcmp(pkg_option_value(options[i]), "true") == 0);
+
		} else if (i == 1) {
+
			fail_unless(strcmp(pkg_option_opt(options[i]), "bar") == 0);
+
			fail_unless(strcmp(pkg_option_value(options[i]), "false") == 0);
+
		}
+
	}
+
	fail_unless(i == 2);
+
}
+
END_TEST
+

+
TCase *
+
tcase_manifest(void)
+
{
+
	TCase *tc = tcase_create("Manifest");
+
	tcase_add_test(tc, parse_manifest);
+

+
	return (tc);
+
}
added tests/manifest.h
@@ -0,0 +1,3 @@
+
#include <check.h>
+

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

+
#include "manifest.h"
+

+
int
+
main()
+
{
+
	int nfailed = 0;
+
	Suite *s = suite_create("pkgng");
+

+
	suite_add_tcase(s, tcase_manifest());
+

+
	/* 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);
+
}