]>
Commit | Line | Data |
---|---|---|
60b6e220 JN |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test automatic use of a pager.' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | rm -f stdout_is_tty | |
2d3ca216 | 8 | test_expect_success 'set up terminal for tests' ' |
60b6e220 JN |
9 | if test -t 1 |
10 | then | |
11 | : > stdout_is_tty | |
2d3ca216 JN |
12 | elif |
13 | test_have_prereq PERL && | |
14 | "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \ | |
15 | sh -c "test -t 1" | |
16 | then | |
17 | : > test_terminal_works | |
60b6e220 JN |
18 | fi |
19 | ' | |
20 | ||
21 | if test -e stdout_is_tty | |
22 | then | |
2d3ca216 JN |
23 | test_terminal() { "$@"; } |
24 | test_set_prereq TTY | |
25 | elif test -e test_terminal_works | |
26 | then | |
27 | test_terminal() { | |
28 | "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl "$@" | |
29 | } | |
60b6e220 JN |
30 | test_set_prereq TTY |
31 | else | |
2d3ca216 | 32 | say no usable terminal, so skipping some tests |
60b6e220 JN |
33 | fi |
34 | ||
35 | unset GIT_PAGER GIT_PAGER_IN_USE | |
36 | git config --unset core.pager | |
37 | PAGER='cat > paginated.out' | |
38 | export PAGER | |
39 | ||
40 | test_expect_success 'setup' ' | |
41 | test_commit initial | |
42 | ' | |
43 | ||
44 | rm -f paginated.out | |
45 | test_expect_success TTY 'some commands use a pager' ' | |
2d3ca216 | 46 | test_terminal git log && |
60b6e220 JN |
47 | test -e paginated.out |
48 | ' | |
49 | ||
50 | rm -f paginated.out | |
51 | test_expect_success TTY 'some commands do not use a pager' ' | |
2d3ca216 | 52 | test_terminal git rev-list HEAD && |
60b6e220 JN |
53 | ! test -e paginated.out |
54 | ' | |
55 | ||
56 | rm -f paginated.out | |
57 | test_expect_success 'no pager when stdout is a pipe' ' | |
58 | git log | cat && | |
59 | ! test -e paginated.out | |
60 | ' | |
61 | ||
62 | rm -f paginated.out | |
63 | test_expect_success 'no pager when stdout is a regular file' ' | |
64 | git log > file && | |
65 | ! test -e paginated.out | |
66 | ' | |
67 | ||
68 | rm -f paginated.out | |
69 | test_expect_success TTY 'git --paginate rev-list uses a pager' ' | |
2d3ca216 | 70 | test_terminal git --paginate rev-list HEAD && |
60b6e220 JN |
71 | test -e paginated.out |
72 | ' | |
73 | ||
74 | rm -f file paginated.out | |
75 | test_expect_success 'no pager even with --paginate when stdout is a pipe' ' | |
76 | git --paginate log | cat && | |
77 | ! test -e paginated.out | |
78 | ' | |
79 | ||
80 | rm -f paginated.out | |
81 | test_expect_success TTY 'no pager with --no-pager' ' | |
2d3ca216 | 82 | test_terminal git --no-pager log && |
60b6e220 JN |
83 | ! test -e paginated.out |
84 | ' | |
85 | ||
86 | # A colored commit log will begin with an appropriate ANSI escape | |
87 | # for the first color; the text "commit" comes later. | |
88 | colorful() { | |
89 | read firstline < $1 | |
90 | ! expr "$firstline" : "^[a-zA-Z]" >/dev/null | |
91 | } | |
92 | ||
93 | rm -f colorful.log colorless.log | |
94 | test_expect_success 'tests can detect color' ' | |
95 | git log --no-color > colorless.log && | |
96 | git log --color > colorful.log && | |
97 | ! colorful colorless.log && | |
98 | colorful colorful.log | |
99 | ' | |
100 | ||
101 | rm -f colorless.log | |
102 | git config color.ui auto | |
103 | test_expect_success 'no color when stdout is a regular file' ' | |
104 | git log > colorless.log && | |
105 | ! colorful colorless.log | |
106 | ' | |
107 | ||
108 | rm -f paginated.out | |
109 | git config color.ui auto | |
110 | test_expect_success TTY 'color when writing to a pager' ' | |
2d3ca216 | 111 | TERM=vt100 test_terminal git log && |
60b6e220 JN |
112 | colorful paginated.out |
113 | ' | |
114 | ||
115 | rm -f colorful.log | |
116 | git config color.ui auto | |
117 | test_expect_success 'color when writing to a file intended for a pager' ' | |
118 | TERM=vt100 GIT_PAGER_IN_USE=true git log > colorful.log && | |
119 | colorful colorful.log | |
120 | ' | |
121 | ||
122 | unset PAGER GIT_PAGER | |
123 | git config --unset core.pager | |
124 | test_expect_success 'determine default pager' ' | |
125 | less=$(git var GIT_PAGER) && | |
126 | test -n "$less" | |
127 | ' | |
128 | ||
129 | if expr "$less" : '^[a-z]*$' > /dev/null && test_have_prereq TTY | |
130 | then | |
131 | test_set_prereq SIMPLEPAGER | |
132 | fi | |
133 | ||
134 | unset PAGER GIT_PAGER | |
135 | git config --unset core.pager | |
136 | rm -f default_pager_used | |
137 | test_expect_success SIMPLEPAGER 'default pager is used by default' ' | |
138 | cat > $less <<-EOF && | |
139 | #!$SHELL_PATH | |
8c33b4cf | 140 | wc > default_pager_used |
60b6e220 JN |
141 | EOF |
142 | chmod +x $less && | |
2d3ca216 | 143 | PATH=.:$PATH test_terminal git log && |
60b6e220 JN |
144 | test -e default_pager_used |
145 | ' | |
146 | ||
147 | unset GIT_PAGER | |
148 | git config --unset core.pager | |
149 | rm -f PAGER_used | |
150 | test_expect_success TTY 'PAGER overrides default pager' ' | |
8c33b4cf | 151 | PAGER="wc > PAGER_used" && |
60b6e220 | 152 | export PAGER && |
2d3ca216 | 153 | test_terminal git log && |
60b6e220 JN |
154 | test -e PAGER_used |
155 | ' | |
156 | ||
157 | unset GIT_PAGER | |
158 | rm -f core.pager_used | |
159 | test_expect_success TTY 'core.pager overrides PAGER' ' | |
8c33b4cf | 160 | PAGER=wc && |
60b6e220 | 161 | export PAGER && |
8c33b4cf | 162 | git config core.pager "wc > core.pager_used" && |
2d3ca216 | 163 | test_terminal git log && |
60b6e220 JN |
164 | test -e core.pager_used |
165 | ' | |
166 | ||
167 | rm -f GIT_PAGER_used | |
168 | test_expect_success TTY 'GIT_PAGER overrides core.pager' ' | |
8c33b4cf JN |
169 | git config core.pager wc && |
170 | GIT_PAGER="wc > GIT_PAGER_used" && | |
60b6e220 | 171 | export GIT_PAGER && |
2d3ca216 | 172 | test_terminal git log && |
60b6e220 JN |
173 | test -e GIT_PAGER_used |
174 | ' | |
175 | ||
176 | test_done |