summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-09-30 12:06:49 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-09-30 12:07:44 -0400
commit505cf3ea3c09b390a57c715e47b65fea764d726d (patch)
tree1d6410c460e2df89fe64fe45e11df9dbbffbf647 /test
parent3473a80a47f2cadc729f3be05fa7485ae5b12e22 (diff)
test-common.sh: add an empty() routine to check if a file is empty, use it
Diffstat (limited to 'test')
-rw-r--r--test/aur-test.sh6
-rw-r--r--test/is_built-test.sh22
-rw-r--r--test/lib-blacklist-test.sh24
-rw-r--r--test/lib-messages-test.sh8
-rw-r--r--test/librechroot-test.sh16
-rw-r--r--test/librelib-test.sh12
-rw-r--r--test/libremakepkg-test.sh6
-rw-r--r--test/librestage-test.sh10
-rw-r--r--test/pkgbuild-check-licenses-test.sh2
-rw-r--r--test/pkgbuild-check-nonfree-test.sh18
-rw-r--r--test/test-common.sh10
11 files changed, 70 insertions, 64 deletions
diff --git a/test/aur-test.sh b/test/aur-test.sh
index 1fbe659..8b175eb 100644
--- a/test/aur-test.sh
+++ b/test/aur-test.sh
@@ -16,15 +16,15 @@ it_displays_help() {
LANG=C aur -h >$tmpdir/stdout 2>$tmpdir/stderr
[[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stderr
}
it_fails_with_0_args() {
aur >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
}
# TODO: Actually test
diff --git a/test/is_built-test.sh b/test/is_built-test.sh
index c547b93..e76ffc0 100644
--- a/test/is_built-test.sh
+++ b/test/is_built-test.sh
@@ -16,30 +16,30 @@ it_displays_help() {
LANG=C is_built -h >$tmpdir/stdout 2>$tmpdir/stderr
[[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stderr
}
it_fails_with_0_args() {
is_built >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat -gt 1 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
}
it_succeeds_with_1_arg() {
is_built sh >$tmpdir/stdout 2>$tmpdir/stderr
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ empty $tmpdir/stderr
}
it_returns_1_for_non_existent_package() {
is_built phony-ne-package 100 >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat == 1 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ empty $tmpdir/stderr
}
it_returns_1_for_future_packages() {
@@ -47,14 +47,14 @@ it_returns_1_for_future_packages() {
is_built emacs 100 >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat == 1 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ empty $tmpdir/stderr
}
it_returns_0_for_past_packages() {
# If emacs ever goes rapid release, we might need to change this :P
is_built emacs 1 >$tmpdir/stdout 2>$tmpdir/stderr
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ empty $tmpdir/stderr
}
diff --git a/test/lib-blacklist-test.sh b/test/lib-blacklist-test.sh
index c496167..c77e5ea 100644
--- a/test/lib-blacklist-test.sh
+++ b/test/lib-blacklist-test.sh
@@ -52,8 +52,8 @@ it_fails_update_when_there_is_no_blacklist_or_network() {
libreblacklist update >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
}
it_fails_cat_when_there_is_no_blacklist_or_network() {
@@ -63,8 +63,8 @@ it_fails_cat_when_there_is_no_blacklist_or_network() {
libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
}
it_fails_update_when_BLACKLIST_is_unset() {
@@ -74,8 +74,8 @@ it_fails_update_when_BLACKLIST_is_unset() {
libreblacklist update >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
}
it_fails_cat_when_syntax_error_in_conf() {
@@ -86,8 +86,8 @@ it_fails_cat_when_syntax_error_in_conf() {
libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
}
it_downloads_the_blacklist_as_needed() {
@@ -97,7 +97,7 @@ it_downloads_the_blacklist_as_needed() {
libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr
- [[ -n "$(cat $tmpdir/stdout)" ]]
+ ! empty $tmpdir/stdout
}
it_downloads_the_blacklist_repeatedly() {
@@ -113,7 +113,7 @@ it_displays_help_and_fails_with_no_args() {
LANG=C libreblacklist >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
+ empty $tmpdir/stdout
[[ "$(sed 1q $tmpdir/stderr)" =~ 'Usage: libreblacklist ' ]]
}
@@ -121,12 +121,12 @@ it_displays_help_when_given_h() {
LANG=C libreblacklist -h >$tmpdir/stdout 2>$tmpdir/stderr
[[ "$(sed 1q $tmpdir/stdout)" =~ 'Usage: libreblacklist ' ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stderr
}
it_displays_help_when_given_h_cat() {
LANG=C libreblacklist -h cat >$tmpdir/stdout 2>$tmpdir/stderr
[[ "$(sed 1q $tmpdir/stdout)" == 'Usage: libreblacklist cat' ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stderr
}
diff --git a/test/lib-messages-test.sh b/test/lib-messages-test.sh
index 826556b..fffff36 100644
--- a/test/lib-messages-test.sh
+++ b/test/lib-messages-test.sh
@@ -30,15 +30,15 @@ it_works_with_no_color_and_set_euE() (
msg Foo
) >$tmpdir/stdout 2>$tmpdir/stderr
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
)
it_can_be_called_without_including() {
libremessages msg Foo >$tmpdir/stdout 2>$tmpdir/stderr
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
}
it_fails_with_msg_and_no_args() {
diff --git a/test/librechroot-test.sh b/test/librechroot-test.sh
index 76afb56..90d0adc 100644
--- a/test/librechroot-test.sh
+++ b/test/librechroot-test.sh
@@ -36,22 +36,22 @@ it_displays_help_as_normal_user() {
LANG=C librechroot help >$tmpdir/stdout 2>$tmpdir/stderr
[[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $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)" ]]
+ empty $tmpdir/stdout
+ ! empty $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)" ]]
+ empty $tmpdir/stdout
[[ "$(sed 1q $tmpdir/stderr)" =~ Usage:.* ]]
}
@@ -61,8 +61,8 @@ it_fails_for_unknown_commands() {
testsudo librechroot phony >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
}
# requires sudo so we know it's not failing because it needs root
@@ -71,6 +71,6 @@ it_fails_for_unknown_flags() {
testsudo librechroot -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
}
diff --git a/test/librelib-test.sh b/test/librelib-test.sh
index e86dffe..23c38dc 100644
--- a/test/librelib-test.sh
+++ b/test/librelib-test.sh
@@ -16,7 +16,7 @@ it_displays_help_and_fails_with_0_args() {
ret=0
librelib >$tmpdir/stdout 2>$tmpdir/stderr || ret=$?
- [[ -z "$(cat $tmpdir/stdout)" ]]
+ empty $tmpdir/stdout
[[ "$(sed 1q $tmpdir/stderr)" =~ Usage:.* ]]
[[ $ret != 0 ]]
}
@@ -25,8 +25,8 @@ it_fails_with_2_args() {
ret=0
librelib a b >$tmpdir/stdout 2>$tmpdir/stderr || ret=$?
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
[[ $ret != 0 ]]
}
@@ -34,7 +34,7 @@ it_displays_usage_text() {
librelib -h >$tmpdir/stdout 2>$tmpdir/stderr
[[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stderr
}
# libremessages is executable
@@ -67,7 +67,7 @@ it_fails_to_find_phony() {
ret=0
librelib phony >$tmpdir/stdout 2>$tmpdir/stderr || ret=$?
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
[[ $ret != 0 ]]
}
diff --git a/test/libremakepkg-test.sh b/test/libremakepkg-test.sh
index be19e17..2fb7f2f 100644
--- a/test/libremakepkg-test.sh
+++ b/test/libremakepkg-test.sh
@@ -47,7 +47,7 @@ it_displays_help_as_normal_user() {
LANG=C libremakepkg -h >$tmpdir/stdout 2>$tmpdir/stderr
[[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stderr
}
it_otherwise_fails_as_normal_user() {
@@ -58,6 +58,6 @@ it_otherwise_fails_as_normal_user() {
libremakepkg >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
}
diff --git a/test/librestage-test.sh b/test/librestage-test.sh
index 849a68c..5c7487b 100644
--- a/test/librestage-test.sh
+++ b/test/librestage-test.sh
@@ -26,23 +26,23 @@ it_displays_usage_text() {
LANG=C librestage -h >$tmpdir/stdout 2>$tmpdir/stderr
[[ "$(sed 1q "$tmpdir/stdout")" =~ Usage:.* ]]
- [[ -z "$(cat "$tmpdir/stderr")" ]]
+ empty "$tmpdir/stderr"
}
it_fails_with_0_args() {
librestage >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
- [[ -z "$(cat "$tmpdir/stdout")" ]]
- [[ -n "$(cat "$tmpdir/stderr")" ]]
+ empty "$tmpdir/stdout"
+ ! empty "$tmpdir/stderr"
}
it_fails_with_invalid_args() {
librestage -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
- [[ -z "$(cat "$tmpdir/stdout")" ]]
- [[ -n "$(cat "$tmpdir/stderr")" ]]
+ empty "$tmpdir/stdout"
+ ! empty "$tmpdir/stderr"
}
# This was an actual bug I hit with md/emacs-mdmua a long time ago; solution was
diff --git a/test/pkgbuild-check-licenses-test.sh b/test/pkgbuild-check-licenses-test.sh
index 220ef6b..efb4875 100644
--- a/test/pkgbuild-check-licenses-test.sh
+++ b/test/pkgbuild-check-licenses-test.sh
@@ -22,6 +22,6 @@ it_displays_usage_text() {
stat=$?
[[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stderr
[[ $stat == 0 ]]
}
diff --git a/test/pkgbuild-check-nonfree-test.sh b/test/pkgbuild-check-nonfree-test.sh
index d547e24..80bfc47 100644
--- a/test/pkgbuild-check-nonfree-test.sh
+++ b/test/pkgbuild-check-nonfree-test.sh
@@ -30,31 +30,31 @@ it_displays_usage_text() {
stat=$?
[[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
- [[ -z "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stderr
[[ $stat == 0 ]]
}
it_succeeds_for_free_depends() {
$pcn $pcn.d/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
[[ $stat == 0 ]]
}
it_succeeds_for_nonfree_depend_with_replacement() {
$pcn $pcn.d/PKGBUILD.nonfree-replacement >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
[[ $stat == 0 ]]
}
it_fails_with_15_for_nonfree_depend() {
$pcn $pcn.d/PKGBUILD.nonfree >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
[[ $stat == 15 ]]
}
@@ -65,7 +65,7 @@ it_fails_when_there_is_no_blacklist() {
$pcn $pcn.d/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
- [[ -z "$(cat $tmpdir/stdout)" ]]
- [[ -n "$(cat $tmpdir/stderr)" ]]
+ empty $tmpdir/stdout
+ ! empty $tmpdir/stderr
[[ $stat != 0 ]] && [[ $stat != 15 ]]
}
diff --git a/test/test-common.sh b/test/test-common.sh
index 01b1b35..4e528d5 100644
--- a/test/test-common.sh
+++ b/test/test-common.sh
@@ -22,7 +22,8 @@ _after_sudo() {
fi
}
-require() {
+require() (
+ set +x
local missing=()
if libremessages in_array "network" "$@" && ! [[ $NETWORK ]]; then
missing+=('networking')
@@ -35,4 +36,9 @@ require() {
return 1
fi
return 0;
-}
+)
+
+empty() (
+ set +x
+ [[ $(stat -c %s "$1") -eq 0 ]]
+)