t9001: style modernisation phase #3
[gitweb.git] / t / test-lib-functions.sh
index 6bb7e9767b643899f15db176379f8fa2bd794e4c..0d93e33de4759bff71739c19be803cac981f0770 100644 (file)
@@ -491,6 +491,17 @@ test_path_is_dir () {
        fi
 }
 
+# Check if the directory exists and is empty as expected, barf otherwise.
+test_dir_is_empty () {
+       test_path_is_dir "$1" &&
+       if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
+       then
+               echo "Directory '$1' is not empty, it contains:"
+               ls -la "$1"
+               return 1
+       fi
+}
+
 test_path_is_missing () {
        if test -e "$1"
        then
@@ -545,7 +556,7 @@ test_must_fail () {
        if test $exit_code = 0; then
                echo >&2 "test_must_fail: command succeeded: $*"
                return 1
-       elif test $exit_code -gt 129 -a $exit_code -le 192; then
+       elif test $exit_code -gt 129 && test $exit_code -le 192; then
                echo >&2 "test_must_fail: died by signal: $*"
                return 1
        elif test $exit_code = 127; then
@@ -572,7 +583,7 @@ test_must_fail () {
 test_might_fail () {
        "$@"
        exit_code=$?
-       if test $exit_code -gt 129 -a $exit_code -le 192; then
+       if test $exit_code -gt 129 && test $exit_code -le 192; then
                echo >&2 "test_might_fail: died by signal: $*"
                return 1
        elif test $exit_code = 127; then
@@ -626,6 +637,15 @@ test_cmp_bin() {
        cmp "$@"
 }
 
+# Call any command "$@" but be more verbose about its
+# failure. This is handy for commands like "test" which do
+# not output anything when they fail.
+verbose () {
+       "$@" && return 0
+       echo >&2 "command failed: $(git rev-parse --sq-quote "$@")"
+       return 1
+}
+
 # Check if the file expected to be empty is indeed empty, and barfs
 # otherwise.
 
@@ -729,6 +749,11 @@ test_ln_s_add () {
        fi
 }
 
+# This function writes out its parameters, one per line
+test_write_lines () {
+       printf "%s\n" "$@"
+}
+
 perl () {
        command "$PERL_PATH" "$@"
 }