diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-06-01 15:54:05 -0600 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-06-05 20:01:05 -0600 |
commit | c129ad75fceba7eb980874bb15954a1889d1f33a (patch) | |
tree | 363642b588f24cc7eee97a332bff054964c109d4 /test | |
parent | e25ea3cdf25c061de02507f11265730ca74ab7e7 (diff) |
Add tests for librechroot's help system, make them pass.
They didn't pass because on several errors it printed to stdout, not stderr
Diffstat (limited to 'test')
-rw-r--r-- | test/librechroot-test.sh | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/librechroot-test.sh b/test/librechroot-test.sh index d8f7299..c9fa130 100644 --- a/test/librechroot-test.sh +++ b/test/librechroot-test.sh @@ -6,6 +6,7 @@ before() { tmpdir=$(mktemp -d --tmpdir test-librechroot.XXXXXXXXXXXX) mkdir -p "$XDG_CONFIG_HOME"/libretools echo "CHROOTDIR='$tmpdir'" > "$XDG_CONFIG_HOME"/libretools/chroot.conf + stat=0 } after() { @@ -15,3 +16,42 @@ after() { it_creates_repo_for_new_chroots() { sudo librechroot run test -r /repo/repo.db } + +it_displays_help_as_normal_user() { + 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() { + librechroot >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ -z "$(cat $tmpdir/stdout)" ]] + [[ "$(sed 1q $tmpdir/stderr)" =~ Usage:.* ]] +} + +it_fails_for_unknown_commands() { + sudo librechroot phony >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ -z "$(cat $tmpdir/stdout)" ]] + [[ -n "$(cat $tmpdir/stderr)" ]] +} + +it_fails_for_unknown_flags() { + sudo librechroot -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ -z "$(cat $tmpdir/stdout)" ]] + [[ -n "$(cat $tmpdir/stderr)" ]] +} |