3 # Setup test environment.
5 # Copyright (c) 2014 Jonas Fonseca <jonas.fonseca@gmail.com>
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of
10 # the License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
19 test="$(basename "$0")"
20 source_dir
="$(cd "$
(dirname "$0")" && pwd)"
21 base_dir
="$(echo "$source_dir" | sed -n 's#\(.*/test\)\([/].*\)*#\1#p')"
22 prefix_dir
="$(echo "$source_dir" | sed -n 's#\(.*/test/\)\([/].*\)*#\2#p')"
23 output_dir
="$base_dir/tmp/$prefix_dir/$test"
24 tmp_dir
="$base_dir/tmp"
25 output_dir
="$tmp_dir/$prefix_dir/$test"
27 [ -t 1 ] && diff_color_arg
=--color
34 while [ $# -gt 0 ]; do
37 verbose
) verbose
=yes ;;
42 [ -e "$output_dir" ] && rm -rf "$output_dir"
43 mkdir
-p "$output_dir"
45 if [ ! -d "$tmp_dir/.git" ]; then
46 # Create a dummy repository to avoid reading .git/config
47 # settings from the tig repository.
48 git init
-q "$tmp_dir"
51 # The locale must specify UTF-8 for Ncurses to output correctly. Since C.UTF-8
52 # does not exist on Mac OS X, we end up with en_US as the only sane choice.
53 export LANG
=en_US.UTF-8
54 export LC_ALL
=en_US.UTF-8
59 export HOME
="$output_dir"
64 export GIT_CONFIG_NOSYSTEM
65 unset GIT_CONFIG GIT_DIR
66 unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
67 unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE
93 mkdir
-p "$(dirname "$path")"
96 stdin|expected
*) cat ;;
100 printf '%s' "$@" > "$path"
105 # Ensure that the steps finish by quitting
106 printf '%s\n:quit\n' "$@" \
107 |
sed -e 's/^[ ]*//' -e '/^$/d' \
108 |
sed "s|:save-display\s\+\(\S*\)|:save-display $HOME/\1|" \
110 export TIG_SCRIPT
="$HOME/steps"
118 file "$HOME/.tigrc" "$@"
122 file "$HOME/.gitconfig" "$@"
126 # Test runners and assertion checking.
133 file "expected/$file" "$@"
135 if [ -e "$file" ]; then
136 git
diff --no-index $diff_color_arg "expected/$file" "$file" > "$file.diff" || true
137 if [ -s "$file.diff" ]; then
138 echo "[FAIL] $file != expected/$file" >> .test-result
139 cat "$file.diff" >> .test-result
141 echo " [OK] $file assertion" >> .test-result
145 echo "[FAIL] $file not found" >> .test-result
151 if [ ! -e .test-result
]; then
153 sed "s/^/[stderr] /" < stderr
154 [ -e stderr.orig
] &&
155 sed "s/^/[stderr] /" < stderr.orig
156 echo "No test results found"
157 elif grep FAIL
-q < .test-result
; then
158 failed
="$(grep FAIL < .test-result | wc -l)"
159 count
="$(sed -n '/\(FAIL\|OK\)/p' < .test-result | wc -l)"
161 printf "Failed %d out of %d test(s)%s\n" $failed $count
163 # Show output from stderr if no output is expected
164 [ -e expected
/stderr
] ||
165 sed "s/^/[stderr] /" < stderr
167 [ -e .test-result
] &&
169 elif [ "$verbose" ]; then
170 count
="$(sed -n '/\(OK\)/p' < .test-result | wc -l)"
171 printf "Passed %d assertions\n" $count
172 fi |
sed "s/^/$indent| /"
175 trap 'show_test_results' EXIT
179 export TIG_NO_DISPLAY
=
181 (cd "$work_dir" && tig
"$@") < stdin
> stdout
2> stderr.orig
182 # Normalize paths in stderr output
183 sed "s#$output_dir#HOME#" < stderr.orig
> stderr
189 test-graph $@
> stdout
2> stderr.orig