Skip to content

Commit 17cc2ef

Browse files
ashumkingitster
authored andcommitted
t4205, t6006, t7102: make functions better readable
Function 'test_format' has become harder to read after its change in de6029a (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 <[email protected]> Improved-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3445f7 commit 17cc2ef

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

t/t4205-log-pretty-formats.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ test_description='Test pretty formats'
88
. ./test-lib.sh
99

1010
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),
1213
# encoded in UTF-8, used as a commit log message below.
1314
msg=$(printf "initial. anf\303\244nglich")
1415
if test -n "$1"

t/t6006-rev-list-format.sh

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ test_description='git rev-list --pretty=format test'
99
. "$TEST_DIRECTORY"/lib-terminal.sh
1010

1111
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.
1415
added=$(printf "added (hinzugef\303\274gt) foo")
1516
added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1)
1617
# same but "changed"
@@ -35,26 +36,13 @@ test_expect_success 'setup' '
3536
git config --unset i18n.commitEncoding
3637
'
3738

38-
# usage: test_format [failure] name format_string <expected_output
39+
# usage: test_format name format_string [failure] <expected_output
3940
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
4841
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+
"
5846
}
5947

6048
# Feed to --format to provide predictable colored sequences.

t/t7102-reset.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ Documented tests for git reset'
1010
. ./test-lib.sh
1111

1212
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),
1415
# 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"
1617
if test -n "$1"
1718
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"
1922
fi
20-
echo $msg
2123
}
2224

2325
test_expect_success 'creating initial files and commits' '

0 commit comments

Comments
 (0)