summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/is_built6
-rw-r--r--test/is_built-test.sh9
2 files changed, 7 insertions, 8 deletions
diff --git a/src/is_built b/src/is_built
index e6797fd..a1da507 100755
--- a/src/is_built
+++ b/src/is_built
@@ -2,7 +2,7 @@
cmd=${0##*/}
usage() {
- echo "Usage: $cmd [-h] pkgname pkgver"
+ echo "Usage: $cmd [-h] pkgname [pkgver]"
echo
echo "Detect if a given package version is already in repos"
echo "Assuming you want greater or equal."
@@ -21,13 +21,13 @@ while getopts 'h' arg; do
*) usage >&2; exit 2 ;;
esac
done
-if [[ $# != 2 ]]; then
+if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then
usage >&2
exit 2
fi
pkg=${1}
-ver=${2}
+ver=${2:-0}
pver=$(LC_ALL=C pacman -Sddp --print-format '%v' "${pkg}" 2>/dev/null)
# if pacman fails or returns nothing
diff --git a/test/is_built-test.sh b/test/is_built-test.sh
index bcd46f5..04b17cd 100644
--- a/test/is_built-test.sh
+++ b/test/is_built-test.sh
@@ -21,17 +21,16 @@ it_displays_help() {
it_fails_with_0_args() {
is_built >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
- [[ $stat > 1 ]]
+ [[ $stat -gt 1 ]]
[[ -z "$(cat $tmpdir/stdout)" ]]
[[ -n "$(cat $tmpdir/stderr)" ]]
}
-it_fails_with_1_arg() {
- is_built sh >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+it_succeeds_with_1_arg() {
+ is_built sh >$tmpdir/stdout 2>$tmpdir/stderr
- [[ $stat > 1 ]]
[[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ [[ -z "$(cat $tmpdir/stderr)" ]]
}
it_returns_1_for_non_existent_package() {