summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/chroot-tools/librechroot5
-rw-r--r--test/librechroot-test.sh40
2 files changed, 43 insertions, 2 deletions
diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot
index 80c7f4f..ca76569 100755
--- a/src/chroot-tools/librechroot
+++ b/src/chroot-tools/librechroot
@@ -133,13 +133,13 @@ main() {
}
;;
C|M) archroot_args+=(-$arg "$OPTARG");;
- *) usage; return 1;;
+ *) usage >/dev/stderr; return 1;;
esac
done
shift $(($OPTIND - 1))
if [[ $# < 1 ]]; then
error "Must specify a command"
- usage
+ usage >/dev/stderr
return 1
fi
mode=$1
@@ -243,6 +243,7 @@ main() {
;;
*)
error "Unrecognized command: \`$mode'"
+ usage >/dev/stderr
return 1
;;
esac
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)" ]]
+}