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