#!/bin/bash # Tests importing a fully qualified 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 . # # This is equalent to `source`ing a package, except that it may perform # additional processing that is required to properly load the package. ## source src/ns.sh test-ok() { # this should auto-load test/fixture/pkg-stub.sh import-fqns test::fixture::pkg-stub # we should now have access to the functions as if we sourced it result="$( test::fixture::pkg-stub::try foo )" assert "$result" == "pkg-stub foo" } test-bad() { local -i ok=0 local -r badns=test::does::not::exist # this package does not exist; should error result="$( import-fqns "$badns" 2>&1 )" || { # good; this is what we want, but we need to handle this failure, since # -e is set ok=1 } assert "$ok" -eq 1 # ensure that an error is output [[ "$result" =~ error ]] || assert -z "missing 'error'" [[ "$result" =~ "$badns" ]] || assert -z "missing ns name in error" } test-ok test-bad