Skip to content

Commit a3dc10b

Browse files
committed
test: add test for library functions
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
1 parent 96e0ea2 commit a3dc10b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/sharness.t

+38
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,44 @@ test_expect_success INTERACTIVE 'Interactive tests work' '
677677
test "$var" = "yes"
678678
'
679679

680+
test_expect_success 'loading of library functions works' '
681+
# Act as if we have a new installation of sharness with a library of
682+
# functions, then test that those functions are automatically loaded.
683+
# Also check that the srcdir is automatically obtained in bash and zsh.
684+
mkdir lib &&
685+
(
686+
cd lib &&
687+
mkdir -p sharness/lib-sharness &&
688+
cat >sharness/lib-sharness/functions.sh <<-EOF &&
689+
test_true() {
690+
true
691+
}
692+
EOF
693+
ln -sf $SHARNESS_TEST_SRCDIR/sharness.sh sharness &&
694+
cat >test-lib.t <<-\EOF &&
695+
test_description="test sharness library"
696+
. ./sharness/sharness.sh
697+
test_expect_success "library functions are present" "
698+
test_true
699+
"
700+
test_done
701+
EOF
702+
unset SHARNESS_TEST_DIRECTORY SHARNESS_TEST_SRCDIR &&
703+
if test -z "${BASH_VERSION-}" -a -z "${ZSH_VERSION-}"; then
704+
SHARNESS_TEST_SRCDIR=sharness &&
705+
export SHARNESS_TEST_SRCDIR
706+
fi &&
707+
chmod +x ./test-lib.t &&
708+
$SHELL_PATH ./test-lib.t >out 2>err &&
709+
cat >expected <<-\EOF &&
710+
ok 1 - library functions are present
711+
# passed all 1 test(s)
712+
1..1
713+
EOF
714+
test_cmp expected out
715+
)
716+
'
717+
680718
test_done
681719

682720
# vi: set ft=sh.sharness :

0 commit comments

Comments
 (0)