diff options
Diffstat (limited to 'test/librechroot-test.sh')
-rw-r--r-- | test/librechroot-test.sh | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/test/librechroot-test.sh b/test/librechroot-test.sh new file mode 100644 index 0000000..76afb56 --- /dev/null +++ b/test/librechroot-test.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env roundup + +describe librechroot + +. ./test-common.sh + +before() { + _before librechroot + mkdir -p "$XDG_CONFIG_HOME"/libretools + echo "CHROOTDIR='$tmpdir/chrootdir'" > "$XDG_CONFIG_HOME"/libretools/chroot.conf + echo "CHROOT='default'" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf + echo "CHROOTEXTRAPKG=()" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf +} + +after() { + _after_sudo +} + +it_creates_repo_for_new_chroots() { + require network sudo || return 0 + libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty + testsudo librechroot run test -r /repo/repo.db +} + +it_cleans_the_local_repo_correctly() { + require network sudo || return 0 + libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty + testsudo librechroot make + testsudo librechroot clean-repo + testsudo librechroot run test -r /repo/repo.db + # TODO: inspect /repo/* more +} + +it_displays_help_as_normal_user() { + rm -rf "$XDG_CONFIG_HOME" + LANG=C librechroot help >$tmpdir/stdout 2>$tmpdir/stderr + + [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] + [[ -z "$(cat $tmpdir/stderr)" ]] +} + +it_otherwise_fails_as_normal_user() { + librechroot run true >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ -z "$(cat $tmpdir/stdout)" ]] + [[ -n "$(cat $tmpdir/stderr)" ]] +} + +it_displays_help_and_fails_with_0_args() { + LANG=C librechroot >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ -z "$(cat $tmpdir/stdout)" ]] + [[ "$(sed 1q $tmpdir/stderr)" =~ Usage:.* ]] +} + +# requires sudo so we know it's not failing because it needs root +it_fails_for_unknown_commands() { + require sudo || return 0 + testsudo librechroot phony >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ -z "$(cat $tmpdir/stdout)" ]] + [[ -n "$(cat $tmpdir/stderr)" ]] +} + +# requires sudo so we know it's not failing because it needs root +it_fails_for_unknown_flags() { + require sudo || return 0 + testsudo librechroot -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ -z "$(cat $tmpdir/stdout)" ]] + [[ -n "$(cat $tmpdir/stderr)" ]] +} |