pkgsh/test/ns/test-@::-multi.sh

57 lines
1.3 KiB
Bash
Raw Normal View History

2014-06-13 23:28:47 -04:00
#!/bin/bash
# Tests current namespace application on nested namespaces
#
# Copyright (C) 2014 Mike Gerwitz
#
# This file is part of pkgsh.
#
# pkgsh is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# `@::` should take the full namespace path of any arbitrary depth, not just
# the first namespace (up to the first `::`).
##
source src/ns.sh
declare -a expected=("o n e" two three)
declare -a given=()
# attempts to invoke `next` within the same namespace
foo::bar::baz::try()
{
# SUT
@:: next "$@"
}
foo::bar::baz::next()
{
given=("$@")
}
foo::bar::baz::try "${expected[@]}"
set -- "${given[@]}"
test $# -eq "${#expected[@]}"
# all arguments should be passed, properly quoted
declare -i i=0
while true; do
test "$1" == "${expected[i]}"
shift || break
((++i))
done