summaryrefslogtreecommitdiff
path: root/devel
diff options
context:
space:
mode:
authorjmmv <jmmv@pkgsrc.org>2013-03-08 17:45:13 +0000
committerjmmv <jmmv@pkgsrc.org>2013-03-08 17:45:13 +0000
commitee8a18abe6d5ecbbcdb5347099312ad8492be993 (patch)
tree0fe9aa0e662069972e734e8cd71bbc827b4351c0 /devel
parent69f464c22a18c8dfa8838c48bac7823c7b5d8040 (diff)
downloadpkgsrc-ee8a18abe6d5ecbbcdb5347099312ad8492be993.tar.gz
Update to 1.1:
- Added the shtk_config_run_hook function to invoke a hook in the context of a configuration file.
Diffstat (limited to 'devel')
-rw-r--r--devel/shtk/Makefile4
-rw-r--r--devel/shtk/files/config.subr26
-rw-r--r--devel/shtk/files/config_test.sh57
3 files changed, 85 insertions, 2 deletions
diff --git a/devel/shtk/Makefile b/devel/shtk/Makefile
index 5943f8c68a9..ced350d843a 100644
--- a/devel/shtk/Makefile
+++ b/devel/shtk/Makefile
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.2 2012/10/31 11:19:46 asau Exp $
+# $NetBSD: Makefile,v 1.3 2013/03/08 17:45:13 jmmv Exp $
-DISTNAME= shtk-1.0
+DISTNAME= shtk-1.1
CATEGORIES= devel
MASTER_SITES= # empty
DISTFILES= # empty
diff --git a/devel/shtk/files/config.subr b/devel/shtk/files/config.subr
index f62ec8a678e..ee92521c234 100644
--- a/devel/shtk/files/config.subr
+++ b/devel/shtk/files/config.subr
@@ -299,3 +299,29 @@ shtk_config_override() {
_Shtk_ConfigOverrides="${_Shtk_ConfigOverrides} unset:${var}"
fi
}
+
+
+# Executes a hook in the context of a configuration file.
+#
+# The caller should not invoke the hook directly because then the hook would
+# not have access to the configuration variables defined in the same file.
+# Requiring the hook to use the various shtk_config_* methods would be weird.
+#
+# \post Any errors in the execution of the hook terminate the script.
+#
+# \param hook Name of the function to invoke.
+# \param ... Arguments to pass to the hook.
+shtk_config_run_hook() {
+ local hook="${1}"; shift
+
+ (
+ for var in ${_Shtk_ConfigVars}; do
+ if shtk_config_has "${var}"; then
+ eval "${var}"=\"$(shtk_config_get "${var}")\"
+ else
+ unset "${var}"
+ fi
+ done
+ "${hook}" "${@}"
+ ) || shtk_cli_error "The hook ${hook} returned an error"
+}
diff --git a/devel/shtk/files/config_test.sh b/devel/shtk/files/config_test.sh
index 2a5b9a873c3..194f7e23d77 100644
--- a/devel/shtk/files/config_test.sh
+++ b/devel/shtk/files/config_test.sh
@@ -383,6 +383,60 @@ override__unknown_variable_body() {
}
+atf_test_case run_hook__ok
+run_hook__ok_body() {
+ shtk_config_init VAR1 VAR2 VAR3
+ shtk_config_set VAR1 "first"
+ shtk_config_set VAR3 "third"
+
+ test_hook() {
+ echo "ARGS=${*}"
+ echo "VAR1=${VAR1:-unset}"
+ echo "VAR2=${VAR2:-unset}"
+ echo "VAR3=${VAR3:-unset}"
+ }
+
+ VAR1=ignore-this; VAR2=ignore-this; VAR3=ignore-this
+ shtk_config_run_hook test_hook arg1 arg2 >out 2>err
+
+ cat >expout <<EOF
+ARGS=arg1 arg2
+VAR1=first
+VAR2=unset
+VAR3=third
+EOF
+ atf_check -o file:expout cat out
+ atf_check -o empty cat err
+}
+
+
+atf_test_case run_hook__fail
+run_hook__fail_body() {
+ shtk_config_init VAR1
+ shtk_config_set VAR1 "first"
+
+ test_hook() {
+ echo "VAR1=${VAR1:-unset}"
+ false
+ }
+
+ (
+ if shtk_config_run_hook test_hook >out 2>err; then
+ atf_fail "Hook failure did not report an error"
+ fi
+ )
+
+ cat >expout <<EOF
+VAR1=first
+EOF
+ cat >experr <<EOF
+EOF
+ atf_check -o file:expout cat out
+ grep "The hook test_hook returned an error" err >/dev/null \
+ || atf_fail "Expected error message not found"
+}
+
+
atf_init_test_cases() {
atf_add_test_case is_valid__true
atf_add_test_case is_valid__false
@@ -421,4 +475,7 @@ atf_init_test_cases() {
atf_add_test_case override__not_ok_after_load
atf_add_test_case override__invalid_format
atf_add_test_case override__unknown_variable
+
+ atf_add_test_case run_hook__ok
+ atf_add_test_case run_hook__fail
}