pkgsh/test/ns/test-@::-nons.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 absent namespace
#
# 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/>.
#
# If no namespace exists on the function in which `@::` is used, then the
# command should be invoked normally, without any namespace prefix.
##
source src/ns.sh
declare -a expected=("o n e" two three)
declare -a given=()
# attempts to invoke `next` within the same namespace
try()
{
# SUT
@:: next "$@"
}
next()
{
given=("$@")
}
try "${expected[@]}"
set -- "${given[@]}"
2014-06-14 00:40:43 -04:00
assert $# -eq "${#expected[@]}"
2014-06-13 23:28:47 -04:00
# all arguments should be passed, properly quoted
declare -i i=0
while true; do
2014-06-14 00:40:43 -04:00
assert "$1" == "${expected[i]}"
2014-06-13 23:28:47 -04:00
shift || break
((++i))
done