Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add new messages entries to keywords Add regression tests about messages
Baptiste Daroussin committed 10 years ago
commit 311b7a03262c91944efe266a7cce35f59567e19e
parent fbd072e
2 files changed +120 -19
modified libpkg/pkg_ports.c
@@ -110,6 +110,17 @@ keyword_open_schema(void)
		"    post-deinstall = { type = string }; "
		"    pre-upgrade = { type = string }; "
		"    post-upgrade = { type = string }; "
+
		"    messages: {"
+
		"        type = array; "
+
		"        items = {"
+
		"            type = object;"
+
		"            properties {"
+
		"                message = { type = string };"
+
		"                type = { enum = [ upgrade, remove, install ] };"
+
		"            };"
+
		"            required [ message ];"
+
		"        };"
+
		"    };"
		"  }"
		"}";

@@ -871,7 +882,9 @@ parse_attributes(const ucl_object_t *o, struct file_attr **a)
static int
apply_keyword_file(ucl_object_t *obj, struct plist *p, char *line, struct file_attr *attr)
{
-
	const ucl_object_t *o;
+
	const ucl_object_t *o, *cur, *elt;
+
	ucl_object_iter_t it = NULL;
+
	struct pkg_message *msg;
	char *cmd;
	char **args = NULL;
	char *buf, *tofree = NULL;
@@ -939,6 +952,31 @@ apply_keyword_file(ucl_object_t *obj, struct plist *p, char *line, struct file_a
		free(cmd);
	}

+
	if ((o = ucl_object_find_key(obj, "messages"))) {
+
		while ((cur = ucl_iterate_object(o, &it, true))) {
+
			elt = ucl_object_find_key(cur, "message");
+
			msg = calloc(1, sizeof(*msg));
+

+
			if (msg == NULL) {
+
				pkg_emit_errno("malloc", "struct pkg_message");
+
				return (EPKG_FATAL);
+
			}
+

+
			msg->str = strdup(ucl_object_tostring(elt));
+
			msg->type = PKG_MESSAGE_ALWAYS;
+
			elt = ucl_object_find_key(cur, "type");
+
			if (elt != NULL) {
+
				if (strcasecmp(ucl_object_tostring(elt), "install") == 0)
+
					msg->type = PKG_MESSAGE_INSTALL;
+
				else if (strcasecmp(ucl_object_tostring(elt), "remove") == 0)
+
					msg->type = PKG_MESSAGE_REMOVE;
+
				else if (strcasecmp(ucl_object_tostring(elt), "upgrade") == 0)
+
					msg->type = PKG_MESSAGE_UPGRADE;
+
			}
+
			LL_APPEND(p->pkg->message, msg);
+
		}
+
	}
+

	if ((o = ucl_object_find_key(obj,  "actions")))
		ret = parse_actions(o, p, line, attr, argc, args);

modified tests/frontend/create.sh
@@ -17,7 +17,9 @@ tests_init \
	create_from_plist_ignore \
	${nonlinux} \
	create_from_plist_with_keyword_arguments \
-
	create_from_manifest_and_plist
+
	create_from_manifest_and_plist \
+
	create_from_plist_pkg_descr \
+
	create_from_plist_with_keyword_and_message

genmanifest() {
	cat << EOF >> +MANIFEST
@@ -360,21 +362,82 @@ EOF
		pkg info -R --raw-format=ucl -F test-1.txz
}

-
atf_init_test_cases() {
-
	. $(atf_get_srcdir)/test_environment.sh
-

-
	atf_add_test_case create_from_plist
-
	atf_add_test_case create_from_plist_set_owner
-
	atf_add_test_case create_from_plist_set_group
-
	atf_add_test_case create_from_plist_gather_mode
-
	atf_add_test_case create_from_plist_set_mode
-
	atf_add_test_case create_from_plist_mini
-
	atf_add_test_case create_from_plist_dirrm
-
	atf_add_test_case create_from_plist_ignore
-
	if [ `uname -s` != "Linux" ] ; then
-
		atf_add_test_case create_from_plist_fflags
-
		atf_add_test_case create_from_plist_bad_fflags
-
	fi
-
	atf_add_test_case create_from_plist_with_keyword_arguments
-
	atf_add_test_case create_from_manifest_and_plist
+
create_from_plist_pkg_descr_body() {
+
	genmanifest
+
cat << EOF > ./+DISPLAY
+
Message
+
EOF
+

+
OUTPUT="test-1:
+
Always:
+
Message
+

+
"
+
	atf_check pkg create -m . -r ${TMPDIR}
+
	atf_check -o inline:"${OUTPUT}" pkg info -D -F ./test-1.txz
+

+
cat << EOF > ./+DISPLAY
+
[
+
	{ message: "message" },
+
	{ message: "message upgrade", type = "upgrade" },
+
]
+
EOF
+

+
OUTPUT='test-1:
+
Always:
+
[
+
	{ message: "message" },
+
	{ message: "message upgrade", type = "upgrade" },
+
]
+

+
'
+
	atf_check pkg create -m . -r ${TMPDIR}
+
	atf_check -o inline:"${OUTPUT}" pkg info -D -F ./test-1.txz
+

+
OUTPUT='test-1:
+
Always:
+
message
+

+
On upgrade:
+
message upgrade
+

+
'
+
	mv +DISPLAY +DISPLAY.ucl
+
	atf_check pkg create -m . -r ${TMPDIR}
+
	atf_check -o inline:"${OUTPUT}" pkg info -D -F ./test-1.txz
+

+
}
+

+
create_from_plist_with_keyword_and_message_body() {
+
	genmanifest
+
	genplist "@showmsg plop"
+
cat << EOF > showmsg.ucl
+
actions: []
+
messages: [
+
	{ message: "always" },
+
	{ message: "on upgrade";type = "upgrade" },
+
	{ message: "on install"; type = "install" },
+
]
+
EOF
+
cat << EOF > +DISPLAY
+
old message
+
EOF
+

+
OUTPUT='test-1:
+
Always:
+
old message
+

+
Always:
+
always
+

+
On upgrade:
+
on upgrade
+

+
On install:
+
on install
+

+
'
+
	atf_check pkg -o PLIST_KEYWORDS_DIR=. create -m . -r ${TMPDIR} -p test.plist
+
	atf_check -o inline:"${OUTPUT}" pkg info -D -F ./test-1.txz
+

}