Merge branch 'jc/clear-pathspec'
[gitweb.git] / t / test-lib-functions.sh
index 3978fc0b45de2645560207cc6e884a505506215d..48884d520813998a735d89d406b45c63b0bf748d 100644 (file)
@@ -939,3 +939,25 @@ mingw_read_file_strip_cr_ () {
                eval "$1=\$$1\$line"
        done
 }
+
+# Like "env FOO=BAR some-program", but run inside a subshell, which means
+# it also works for shell functions (though those functions cannot impact
+# the environment outside of the test_env invocation).
+test_env () {
+       (
+               while test $# -gt 0
+               do
+                       case "$1" in
+                       *=*)
+                               eval "${1%%=*}=\${1#*=}"
+                               eval "export ${1%%=*}"
+                               shift
+                               ;;
+                       *)
+                               "$@"
+                               exit
+                               ;;
+                       esac
+               done
+       )
+}