##// END OF EJS Templates
tests: test that abbreviated command alias is also paged...
Gregory Szorc -
r32073:04629b2d stable
parent child Browse files
Show More
@@ -1,284 +1,294 b''
1 1 $ cat >> fakepager.py <<EOF
2 2 > import sys
3 3 > for line in sys.stdin:
4 4 > sys.stdout.write('paged! %r\n' % line)
5 5 > EOF
6 6
7 7 Enable ui.formatted because pager won't fire without it, and set up
8 8 pager and tell it to use our fake pager that lets us see when the
9 9 pager was running.
10 10 $ cat >> $HGRCPATH <<EOF
11 11 > [ui]
12 12 > formatted = yes
13 13 > color = no
14 14 > [pager]
15 15 > pager = python $TESTTMP/fakepager.py
16 16 > EOF
17 17
18 18 $ hg init repo
19 19 $ cd repo
20 20 $ echo a >> a
21 21 $ hg add a
22 22 $ hg ci -m 'add a'
23 23 $ for x in `python $TESTDIR/seq.py 1 10`; do
24 24 > echo a $x >> a
25 25 > hg ci -m "modify a $x"
26 26 > done
27 27
28 28 By default diff and log are paged, but id is not:
29 29
30 30 $ hg diff -c 2 --pager=yes
31 31 paged! 'diff -r f4be7687d414 -r bce265549556 a\n'
32 32 paged! '--- a/a\tThu Jan 01 00:00:00 1970 +0000\n'
33 33 paged! '+++ b/a\tThu Jan 01 00:00:00 1970 +0000\n'
34 34 paged! '@@ -1,2 +1,3 @@\n'
35 35 paged! ' a\n'
36 36 paged! ' a 1\n'
37 37 paged! '+a 2\n'
38 38
39 39 $ hg log --limit 2
40 40 paged! 'changeset: 10:46106edeeb38\n'
41 41 paged! 'tag: tip\n'
42 42 paged! 'user: test\n'
43 43 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
44 44 paged! 'summary: modify a 10\n'
45 45 paged! '\n'
46 46 paged! 'changeset: 9:6dd8ea7dd621\n'
47 47 paged! 'user: test\n'
48 48 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
49 49 paged! 'summary: modify a 9\n'
50 50 paged! '\n'
51 51
52 52 $ hg id
53 53 46106edeeb38 tip
54 54
55 55 We can enable the pager on id:
56 56
57 57 BROKEN: should be paged
58 58 $ hg --config pager.attend-id=yes id
59 59 46106edeeb38 tip
60 60
61 61 Setting attend-$COMMAND to a false value works, even with pager in
62 62 core:
63 63 $ hg --config pager.attend-diff=no diff -c 2
64 64 diff -r f4be7687d414 -r bce265549556 a
65 65 --- a/a Thu Jan 01 00:00:00 1970 +0000
66 66 +++ b/a Thu Jan 01 00:00:00 1970 +0000
67 67 @@ -1,2 +1,3 @@
68 68 a
69 69 a 1
70 70 +a 2
71 71
72 72 Command aliases should have same behavior as main command
73 73
74 74 $ hg history --limit 2
75 75 paged! 'changeset: 10:46106edeeb38\n'
76 76 paged! 'tag: tip\n'
77 77 paged! 'user: test\n'
78 78 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
79 79 paged! 'summary: modify a 10\n'
80 80 paged! '\n'
81 81 paged! 'changeset: 9:6dd8ea7dd621\n'
82 82 paged! 'user: test\n'
83 83 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
84 84 paged! 'summary: modify a 9\n'
85 85 paged! '\n'
86 86
87 Abbreviated command alias should also be paged
88
89 $ hg hist -l 1
90 paged! 'changeset: 10:46106edeeb38\n'
91 paged! 'tag: tip\n'
92 paged! 'user: test\n'
93 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
94 paged! 'summary: modify a 10\n'
95 paged! '\n'
96
87 97 Pager should not start if stdout is not a tty.
88 98
89 99 $ hg log -l1 -q --config ui.formatted=False
90 100 10:46106edeeb38
91 101
92 102 Pager should be disabled if pager.pager is empty (otherwise the output would
93 103 be silently lost.)
94 104
95 105 $ hg log -l1 -q --config pager.pager=
96 106 10:46106edeeb38
97 107
98 108 Pager with color enabled allows colors to come through by default,
99 109 even though stdout is no longer a tty.
100 110 $ cat >> $HGRCPATH <<EOF
101 111 > [ui]
102 112 > color = yes
103 113 > [color]
104 114 > mode = ansi
105 115 > EOF
106 116 $ hg log --limit 3
107 117 paged! '\x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m\n'
108 118 paged! 'tag: tip\n'
109 119 paged! 'user: test\n'
110 120 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
111 121 paged! 'summary: modify a 10\n'
112 122 paged! '\n'
113 123 paged! '\x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m\n'
114 124 paged! 'user: test\n'
115 125 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
116 126 paged! 'summary: modify a 9\n'
117 127 paged! '\n'
118 128 paged! '\x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m\n'
119 129 paged! 'user: test\n'
120 130 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
121 131 paged! 'summary: modify a 8\n'
122 132 paged! '\n'
123 133
124 134 An invalid pager command name is reported sensibly if we don't have to
125 135 use shell=True in the subprocess call:
126 136 $ hg log --limit 3 --config pager.pager=this-command-better-never-exist
127 137 missing pager command 'this-command-better-never-exist', skipping pager
128 138 \x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m (esc)
129 139 tag: tip
130 140 user: test
131 141 date: Thu Jan 01 00:00:00 1970 +0000
132 142 summary: modify a 10
133 143
134 144 \x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m (esc)
135 145 user: test
136 146 date: Thu Jan 01 00:00:00 1970 +0000
137 147 summary: modify a 9
138 148
139 149 \x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m (esc)
140 150 user: test
141 151 date: Thu Jan 01 00:00:00 1970 +0000
142 152 summary: modify a 8
143 153
144 154
145 155 A complicated pager command gets worse behavior. Bonus points if you can
146 156 improve this.
147 157 $ hg log --limit 3 \
148 158 > --config pager.pager='this-command-better-never-exist --seriously' \
149 159 > 2>/dev/null || true
150 160
151 161 Pager works with shell aliases.
152 162
153 163 $ cat >> $HGRCPATH <<EOF
154 164 > [alias]
155 165 > echoa = !echo a
156 166 > EOF
157 167
158 168 $ hg echoa
159 169 a
160 170 BROKEN: should be paged
161 171 $ hg --config pager.attend-echoa=yes echoa
162 172 a
163 173
164 174 Pager works with hg aliases including environment variables.
165 175
166 176 $ cat >> $HGRCPATH <<'EOF'
167 177 > [alias]
168 178 > printa = log -T "$A\n" -r 0
169 179 > EOF
170 180
171 181 $ A=1 hg --config pager.attend-printa=yes printa
172 182 paged! '1\n'
173 183 $ A=2 hg --config pager.attend-printa=yes printa
174 184 paged! '2\n'
175 185
176 186 Something that's explicitly attended is still not paginated if the
177 187 pager is globally set to off using a flag:
178 188 $ A=2 hg --config pager.attend-printa=yes printa --pager=no
179 189 2
180 190
181 191 Pager should not override the exit code of other commands
182 192
183 193 $ cat >> $TESTTMP/fortytwo.py <<'EOF'
184 194 > from mercurial import cmdutil, commands
185 195 > cmdtable = {}
186 196 > command = cmdutil.command(cmdtable)
187 197 > @command('fortytwo', [], 'fortytwo', norepo=True)
188 198 > def fortytwo(ui, *opts):
189 199 > ui.write('42\n')
190 200 > return 42
191 201 > EOF
192 202
193 203 $ cat >> $HGRCPATH <<'EOF'
194 204 > [extensions]
195 205 > fortytwo = $TESTTMP/fortytwo.py
196 206 > EOF
197 207
198 208 $ hg fortytwo --pager=on
199 209 paged! '42\n'
200 210 [42]
201 211
202 212 A command that asks for paging using ui.pager() directly works:
203 213 $ hg blame a
204 214 paged! ' 0: a\n'
205 215 paged! ' 1: a 1\n'
206 216 paged! ' 2: a 2\n'
207 217 paged! ' 3: a 3\n'
208 218 paged! ' 4: a 4\n'
209 219 paged! ' 5: a 5\n'
210 220 paged! ' 6: a 6\n'
211 221 paged! ' 7: a 7\n'
212 222 paged! ' 8: a 8\n'
213 223 paged! ' 9: a 9\n'
214 224 paged! '10: a 10\n'
215 225 but not with HGPLAIN
216 226 $ HGPLAIN=1 hg blame a
217 227 0: a
218 228 1: a 1
219 229 2: a 2
220 230 3: a 3
221 231 4: a 4
222 232 5: a 5
223 233 6: a 6
224 234 7: a 7
225 235 8: a 8
226 236 9: a 9
227 237 10: a 10
228 238 explicit flags work too:
229 239 $ hg blame --pager=no a
230 240 0: a
231 241 1: a 1
232 242 2: a 2
233 243 3: a 3
234 244 4: a 4
235 245 5: a 5
236 246 6: a 6
237 247 7: a 7
238 248 8: a 8
239 249 9: a 9
240 250 10: a 10
241 251
242 252 Put annotate in the ignore list for pager:
243 253 $ cat >> $HGRCPATH <<EOF
244 254 > [pager]
245 255 > ignore = annotate
246 256 > EOF
247 257 $ hg blame a
248 258 0: a
249 259 1: a 1
250 260 2: a 2
251 261 3: a 3
252 262 4: a 4
253 263 5: a 5
254 264 6: a 6
255 265 7: a 7
256 266 8: a 8
257 267 9: a 9
258 268 10: a 10
259 269
260 270 Environment variables like LESS and LV are set automatically:
261 271 $ cat > $TESTTMP/printlesslv.py <<EOF
262 272 > import os, sys
263 273 > sys.stdin.read()
264 274 > for name in ['LESS', 'LV']:
265 275 > sys.stdout.write(('%s=%s\n') % (name, os.environ.get(name, '-')))
266 276 > sys.stdout.flush()
267 277 > EOF
268 278
269 279 $ cat >> $HGRCPATH <<EOF
270 280 > [alias]
271 281 > noop = log -r 0 -T ''
272 282 > [ui]
273 283 > formatted=1
274 284 > [pager]
275 285 > pager = $PYTHON $TESTTMP/printlesslv.py
276 286 > EOF
277 287 $ unset LESS
278 288 $ unset LV
279 289 $ hg noop --pager=on
280 290 LESS=FRX
281 291 LV=-c
282 292 $ LESS=EFGH hg noop --pager=on
283 293 LESS=EFGH
284 294 LV=-c
General Comments 0
You need to be logged in to leave comments. Login now