t4205, t6006, t7102: make functions better readable
Function 'test_format' has become harder to read after its change in de6029a2 (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26). Simplify it by moving its "should we expect it to fail?" parameter to the end. Note, current code does not use this last parameter as far as there are no tests expected to fail. We can keep that for future use. Also, reformat comments. Signed-off-by: Alexey Shumkin <Alex.Crezoff@gmail.com> Improved-by: Johannes Sixt <j.sixt@viscovery.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alexey Shumkin committed
Jul 5, 2013 at 16:01 UTC
17cc2ef1c5f160056f5ca8cf4bd795ddd9b76bd3
3 files changed
+16
-25
t/t4205-log-pretty-formats.sh
+2
-1
@@ -8,7 +8,8 @@ test_description='Test pretty formats'
8
. ./test-lib.sh
9
10
commit_msg () {
11
- # String "initial. initial" partly in German (translated with Google Translate),
11
+ # String "initial. initial" partly in German
12
+ # (translated with Google Translate),
13
# encoded in UTF-8, used as a commit log message below.
14
msg=$(printf "initial. anf\303\244nglich")
15
if test -n "$1"
t/t6006-rev-list-format.sh
+8
-20
@@ -9,8 +9,9 @@ test_description='git rev-list --pretty=format test'
9
. "$TEST_DIRECTORY"/lib-terminal.sh
10
11
test_tick
12
-# String "added" in German (translated with Google Translate), encoded in UTF-8,
13
-# used as a commit log message below.
12
+# String "added" in German
13
+# (translated with Google Translate),
14
+# encoded in UTF-8, used as a commit log message below.
15
added=$(printf "added (hinzugef\303\274gt) foo")
16
added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1)
17
# same but "changed"
@@ -35,26 +36,13 @@ test_expect_success 'setup' '
36
git config --unset i18n.commitEncoding
37
'
38
38
-# usage: test_format [failure] name format_string <expected_output
39
+# usage: test_format name format_string [failure] <expected_output
40
test_format () {
40
- must_fail=0
41
- # if parameters count is more than 2 then test must fail
42
- if test $# -gt 2
43
- then
44
- must_fail=1
45
- # remove first parameter which is flag for test failure
46
- shift
47
- fi
41
cat >expect.$1
49
- name="format $1"
50
- command="git rev-list --pretty=format:'$2' master >output.$1 &&
51
- test_cmp expect.$1 output.$1"
52
- if test $must_fail -eq 1
53
- then
54
- test_expect_failure "$name" "$command"
55
- else
56
- test_expect_success "$name" "$command"
57
- fi
42
+ test_expect_${3:-success} "format $1" "
43
+ git rev-list --pretty=format:'$2' master >output.$1 &&
44
+ test_cmp expect.$1 output.$1
45
+ "
46
}
47
48
# Feed to --format to provide predictable colored sequences.
t/t7102-reset.sh
+6
-4
@@ -10,14 +10,16 @@ Documented tests for git reset'
10
. ./test-lib.sh
11
12
commit_msg () {
13
- # String "modify 2nd file (changed)" partly in German(translated with Google Translate),
13
+ # String "modify 2nd file (changed)" partly in German
14
+ # (translated with Google Translate),
15
# encoded in UTF-8, used as a commit log message below.
15
- msg=$(printf "modify 2nd file (ge\303\244ndert)")
16
+ msg="modify 2nd file (ge\303\244ndert)\n"
17
if test -n "$1"
18
then
18
- msg=$(echo $msg | iconv -f utf-8 -t $1)
19
+ printf "$msg" | iconv -f utf-8 -t "$1"
20
+ else
21
+ printf "$msg"
22
fi
20
- echo $msg
23
}
24
25
test_expect_success 'creating initial files and commits' '