Fri Mar 8 17:45:14 2013 UTC ()
Update to 1.1:

- Added the shtk_config_run_hook function to invoke a hook in the context
  of a configuration file.


(jmmv)
diff -r1.2 -r1.3 pkgsrc/devel/shtk/Makefile
diff -r1.1 -r1.2 pkgsrc/devel/shtk/files/config.subr
diff -r1.1 -r1.2 pkgsrc/devel/shtk/files/config_test.sh

cvs diff -r1.2 -r1.3 pkgsrc/devel/shtk/Makefile (expand / switch to unified diff)

--- pkgsrc/devel/shtk/Makefile 2012/10/31 11:19:46 1.2
+++ pkgsrc/devel/shtk/Makefile 2013/03/08 17:45:13 1.3
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1# $NetBSD: Makefile,v 1.2 2012/10/31 11:19:46 asau Exp $ 1# $NetBSD: Makefile,v 1.3 2013/03/08 17:45:13 jmmv Exp $
2 2
3DISTNAME= shtk-1.0 3DISTNAME= shtk-1.1
4CATEGORIES= devel 4CATEGORIES= devel
5MASTER_SITES= # empty 5MASTER_SITES= # empty
6DISTFILES= # empty 6DISTFILES= # empty
7 7
8MAINTAINER= jmmv@NetBSD.org 8MAINTAINER= jmmv@NetBSD.org
9COMMENT= Shell-scripting modules that provide common functionality 9COMMENT= Shell-scripting modules that provide common functionality
10LICENSE= modified-bsd 10LICENSE= modified-bsd
11 11
12PKG_INSTALLATION_TYPES= overwrite pkgviews 12PKG_INSTALLATION_TYPES= overwrite pkgviews
13 13
14WRKSRC= ${WRKDIR} 14WRKSRC= ${WRKDIR}
15NO_CONFIGURE= YES 15NO_CONFIGURE= YES
16 16

cvs diff -r1.1 -r1.2 pkgsrc/devel/shtk/files/Attic/config.subr (expand / switch to unified diff)

--- pkgsrc/devel/shtk/files/Attic/config.subr 2012/08/15 21:18:13 1.1
+++ pkgsrc/devel/shtk/files/Attic/config.subr 2013/03/08 17:45:14 1.2
@@ -289,13 +289,39 @@ shtk_config_override() { @@ -289,13 +289,39 @@ shtk_config_override() {
289 289
290 [ -n "${var}" ] || shtk_cli_usage_error "Invalid configuration override" \ 290 [ -n "${var}" ] || shtk_cli_usage_error "Invalid configuration override" \
291 "${arg}; must be of the form variable=value" 291 "${arg}; must be of the form variable=value"
292 shtk_config_is_valid "${var}" \ 292 shtk_config_is_valid "${var}" \
293 || shtk_cli_usage_error "Unknown configuration variable ${var}" 293 || shtk_cli_usage_error "Unknown configuration variable ${var}"
294 294
295 if [ -n "${value}" ]; then 295 if [ -n "${value}" ]; then
296 eval "shtk_config_override_var_${var}=\"${value}\"" 296 eval "shtk_config_override_var_${var}=\"${value}\""
297 _Shtk_ConfigOverrides="${_Shtk_ConfigOverrides} set:${var}" 297 _Shtk_ConfigOverrides="${_Shtk_ConfigOverrides} set:${var}"
298 else 298 else
299 _Shtk_ConfigOverrides="${_Shtk_ConfigOverrides} unset:${var}" 299 _Shtk_ConfigOverrides="${_Shtk_ConfigOverrides} unset:${var}"
300 fi 300 fi
301} 301}
 302
 303
 304# Executes a hook in the context of a configuration file.
 305#
 306# The caller should not invoke the hook directly because then the hook would
 307# not have access to the configuration variables defined in the same file.
 308# Requiring the hook to use the various shtk_config_* methods would be weird.
 309#
 310# \post Any errors in the execution of the hook terminate the script.
 311#
 312# \param hook Name of the function to invoke.
 313# \param ... Arguments to pass to the hook.
 314shtk_config_run_hook() {
 315 local hook="${1}"; shift
 316
 317 (
 318 for var in ${_Shtk_ConfigVars}; do
 319 if shtk_config_has "${var}"; then
 320 eval "${var}"=\"$(shtk_config_get "${var}")\"
 321 else
 322 unset "${var}"
 323 fi
 324 done
 325 "${hook}" "${@}"
 326 ) || shtk_cli_error "The hook ${hook} returned an error"
 327}

cvs diff -r1.1 -r1.2 pkgsrc/devel/shtk/files/Attic/config_test.sh (expand / switch to unified diff)

--- pkgsrc/devel/shtk/files/Attic/config_test.sh 2012/08/15 21:18:13 1.1
+++ pkgsrc/devel/shtk/files/Attic/config_test.sh 2013/03/08 17:45:14 1.2
@@ -373,26 +373,80 @@ override__unknown_variable_body() { @@ -373,26 +373,80 @@ override__unknown_variable_body() {
373 shtk_config_init Z VAR1 373 shtk_config_init Z VAR1
374 for arg in A=b VAR2=d; do 374 for arg in A=b VAR2=d; do
375 if ( shtk_config_override "${arg}" ) >out 2>err; then 375 if ( shtk_config_override "${arg}" ) >out 2>err; then
376 atf_fail "Invalid configuration override ${arg} succeeded" 376 atf_fail "Invalid configuration override ${arg} succeeded"
377 else 377 else
378 cat err 378 cat err
379 grep "Unknown configuration variable ${var}" err >/dev/null \ 379 grep "Unknown configuration variable ${var}" err >/dev/null \
380 || atf_fail "Expected error message not found" 380 || atf_fail "Expected error message not found"
381 fi 381 fi
382 done 382 done
383} 383}
384 384
385 385
 386atf_test_case run_hook__ok
 387run_hook__ok_body() {
 388 shtk_config_init VAR1 VAR2 VAR3
 389 shtk_config_set VAR1 "first"
 390 shtk_config_set VAR3 "third"
 391
 392 test_hook() {
 393 echo "ARGS=${*}"
 394 echo "VAR1=${VAR1:-unset}"
 395 echo "VAR2=${VAR2:-unset}"
 396 echo "VAR3=${VAR3:-unset}"
 397 }
 398
 399 VAR1=ignore-this; VAR2=ignore-this; VAR3=ignore-this
 400 shtk_config_run_hook test_hook arg1 arg2 >out 2>err
 401
 402 cat >expout <<EOF
 403ARGS=arg1 arg2
 404VAR1=first
 405VAR2=unset
 406VAR3=third
 407EOF
 408 atf_check -o file:expout cat out
 409 atf_check -o empty cat err
 410}
 411
 412
 413atf_test_case run_hook__fail
 414run_hook__fail_body() {
 415 shtk_config_init VAR1
 416 shtk_config_set VAR1 "first"
 417
 418 test_hook() {
 419 echo "VAR1=${VAR1:-unset}"
 420 false
 421 }
 422
 423 (
 424 if shtk_config_run_hook test_hook >out 2>err; then
 425 atf_fail "Hook failure did not report an error"
 426 fi
 427 )
 428
 429 cat >expout <<EOF
 430VAR1=first
 431EOF
 432 cat >experr <<EOF
 433EOF
 434 atf_check -o file:expout cat out
 435 grep "The hook test_hook returned an error" err >/dev/null \
 436 || atf_fail "Expected error message not found"
 437}
 438
 439
386atf_init_test_cases() { 440atf_init_test_cases() {
387 atf_add_test_case is_valid__true 441 atf_add_test_case is_valid__true
388 atf_add_test_case is_valid__false 442 atf_add_test_case is_valid__false
389 443
390 atf_add_test_case has__true__empty 444 atf_add_test_case has__true__empty
391 atf_add_test_case has__true__not_empty 445 atf_add_test_case has__true__not_empty
392 atf_add_test_case has__false 446 atf_add_test_case has__false
393 447
394 atf_add_test_case get__ok__empty 448 atf_add_test_case get__ok__empty
395 atf_add_test_case get__ok__not_empty 449 atf_add_test_case get__ok__not_empty
396 atf_add_test_case get__undefined_variable 450 atf_add_test_case get__undefined_variable
397 451
398 atf_add_test_case get_bool__true 452 atf_add_test_case get_bool__true
@@ -411,14 +465,17 @@ atf_init_test_cases() { @@ -411,14 +465,17 @@ atf_init_test_cases() {
411 atf_add_test_case unset__ok 465 atf_add_test_case unset__ok
412 atf_add_test_case unset__unknown_variable 466 atf_add_test_case unset__unknown_variable
413 467
414 atf_add_test_case load__filter_variables 468 atf_add_test_case load__filter_variables
415 atf_add_test_case load__allow_undefine 469 atf_add_test_case load__allow_undefine
416 atf_add_test_case load__current_directory 470 atf_add_test_case load__current_directory
417 atf_add_test_case load__missing_file 471 atf_add_test_case load__missing_file
418 atf_add_test_case load__invalid_file 472 atf_add_test_case load__invalid_file
419 473
420 atf_add_test_case override__ok_before_load 474 atf_add_test_case override__ok_before_load
421 atf_add_test_case override__not_ok_after_load 475 atf_add_test_case override__not_ok_after_load
422 atf_add_test_case override__invalid_format 476 atf_add_test_case override__invalid_format
423 atf_add_test_case override__unknown_variable 477 atf_add_test_case override__unknown_variable
 478
 479 atf_add_test_case run_hook__ok
 480 atf_add_test_case run_hook__fail
424} 481}