Debian Codegraph @

tests/test-dispatch.t

raw
1 test command parsing and dispatch
2
3 $ hg init a
4 $ cd a
5
6 Redundant options used to crash (issue436):
7 $ hg -v log -v
8 $ hg -v log -v x
9
10 $ echo a > a
11 $ hg ci -Ama
12 adding a
13
14 Missing arg:
15
16 $ hg cat
17 hg cat: invalid arguments
18 hg cat [OPTION]... FILE...
19
20 output the current or given revision of files
21
22 options ([+] can be repeated):
23
24 -o --output FORMAT print output to file with formatted name
25 -r --rev REV print the given revision
26 --decode apply any matching decode filter
27 -I --include PATTERN [+] include names matching the given patterns
28 -X --exclude PATTERN [+] exclude names matching the given patterns
29 -T --template TEMPLATE display with template
30
31 (use 'hg cat -h' to show more help)
32 [10]
33
34 Missing parameter for early option:
35
36 $ hg log -R 2>&1 | grep 'hg log'
37 hg log: option -R requires argument
38 hg log [OPTION]... [FILE]
39 (use 'hg log -h' to show more help)
40
41 "--" may be an option value:
42
43 $ hg -R -- log
44 abort: repository -- not found
45 [255]
46 $ hg log -R --
47 abort: repository -- not found
48 [255]
49 $ hg log -T --
50 -- (no-eol)
51 $ hg log -T -- -k nomatch
52
53 Parsing of early options should stop at "--":
54
55 $ hg cat -- --config=hooks.pre-cat=false
56 --config=hooks.pre-cat=false: no such file in rev cb9a9f314b8b
57 [1]
58 $ hg cat -- --debugger
59 --debugger: no such file in rev cb9a9f314b8b
60 [1]
61
62 Unparsable form of early options:
63
64 $ hg cat --debugg
65 abort: option --debugger may not be abbreviated
66 [10]
67
68 Parsing failure of early options should be detected before executing the
69 command:
70
71 $ hg log -b '--config=hooks.pre-log=false' default
72 abort: option --config may not be abbreviated
73 [10]
74 $ hg log -b -R. default
75 abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo
76 [10]
77 $ hg log --cwd .. -b --cwd=. default
78 abort: option --cwd may not be abbreviated
79 [10]
80
81 However, we can't prevent it from loading extensions and configs:
82
83 $ cat <<EOF > bad.py
84 > raise Exception('bad')
85 > EOF
86 $ hg log -b '--config=extensions.bad=bad.py' default
87 *** failed to import extension "bad" from bad.py: bad
88 abort: option --config may not be abbreviated
89 [10]
90
91 $ mkdir -p badrepo/.hg
92 $ echo 'invalid-syntax' > badrepo/.hg/hgrc
93 $ hg log -b -Rbadrepo default
94 config error at badrepo/.hg/hgrc:1: invalid-syntax
95 [30]
96
97 $ hg log -b --cwd=inexistent default
98 abort: $ENOENT$: 'inexistent'
99 [255]
100
101 $ hg log -b '--config=ui.traceback=yes' 2>&1 | "$PYTHON" "$TESTDIR/filtertraceback.py"
102 Traceback (most recent call last):
103 mercurial.error.InputError: option --config may not be abbreviated
104 abort: option --config may not be abbreviated
105 $ hg log -b '--config=profiling.enabled=yes' 2>&1 | grep -i sample
106 Sample count: .*|No samples recorded\. (re)
107
108 Early options can't be specified in [aliases] and [defaults] because they are
109 applied before the command name is resolved:
110
111 (rhg doesn't combine multiple errors the way hg.py does)
112 #if rhg
113 $ hg log -b '--config=alias.log=log --config=hooks.pre-log=false'
114 config error: error in definition for alias 'log': --config may only be given on the command line
115 [30]
116 #else
117 $ hg log -b '--config=alias.log=log --config=hooks.pre-log=false'
118 hg log: option -b not recognized
119 error in definition for alias 'log': --config may only be given on the command
120 line
121 [10]
122 #endif
123
124 $ hg log -b '--config=defaults.log=--config=hooks.pre-log=false'
125 abort: option --config may not be abbreviated
126 [10]
127
128 Shell aliases bypass any command parsing rules but for the early one:
129
130 $ hg log -b '--config=alias.log=!echo howdy'
131 howdy
132
133 Early options must come first if HGPLAIN=+strictflags is specified:
134 (BUG: chg cherry-picks early options to pass them as a server command)
135
136 #if no-chg
137 $ HGPLAIN=+strictflags hg log -b --config='hooks.pre-log=false' default
138 abort: unknown revision '--config=hooks.pre-log=false'
139 [10]
140 $ HGPLAIN=+strictflags hg log -b -R. default
141 abort: unknown revision '-R.'
142 [10]
143 $ HGPLAIN=+strictflags hg log -b --cwd=. default
144 abort: unknown revision '--cwd=.'
145 [10]
146 #endif
147 $ HGPLAIN=+strictflags hg log -b --debugger default
148 abort: unknown revision '--debugger'
149 [10]
150 $ HGPLAIN=+strictflags hg log -b --config='alias.log=!echo pwned' default
151 abort: unknown revision '--config=alias.log=!echo pwned'
152 [10]
153
154 $ HGPLAIN=+strictflags hg log --config='hooks.pre-log=false' -b default
155 abort: option --config may not be abbreviated
156 [10]
157 $ HGPLAIN=+strictflags hg log -q --cwd=.. -b default
158 abort: option --cwd may not be abbreviated
159 [10]
160 $ HGPLAIN=+strictflags hg log -q -R . -b default
161 abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo
162 [10]
163
164 $ HGPLAIN=+strictflags hg --config='hooks.pre-log=false' log -b default
165 abort: pre-log hook exited with status 1
166 [40]
167 $ HGPLAIN=+strictflags hg --cwd .. -q -Ra log -b default
168 0:cb9a9f314b8b
169 $ HGPLAIN=+strictflags hg --cwd .. -q --repository a log -b default
170 0:cb9a9f314b8b
171 $ HGPLAIN=+strictflags hg --cwd .. -q --repo a log -b default
172 0:cb9a9f314b8b
173
174 For compatibility reasons, HGPLAIN=+strictflags is not enabled by plain HGPLAIN:
175
176 $ HGPLAIN= hg log --config='hooks.pre-log=false' -b default
177 abort: pre-log hook exited with status 1
178 [40]
179 $ HGPLAINEXCEPT= hg log --cwd .. -q -Ra -b default
180 0:cb9a9f314b8b
181
182 [defaults]
183
184 $ hg cat a
185 a
186 $ cat >> $HGRCPATH <<EOF
187 > [defaults]
188 > cat = -r null
189 > EOF
190 $ hg cat a
191 a: no such file in rev 000000000000
192 [1]
193
194 $ cd "$TESTTMP"
195
196 OSError "No such file or directory" / "The system cannot find the path
197 specified" should include filename even when it is empty
198
199 $ hg -R a archive ''
200 abort: $ENOENT$: '' (no-windows !)
201 abort: $ENOTDIR$: '' (windows !)
202 [255]
203
204 #if no-outer-repo
205
206 No repo:
207
208 $ hg cat
209 abort: no repository found in '$TESTTMP' (.hg not found)
210 [10]
211
212 #endif
213
214 #if rmcwd
215
216 Current directory removed:
217
218 $ mkdir $TESTTMP/repo1
219 $ cd $TESTTMP/repo1
220 $ rm -rf $TESTTMP/repo1
221
222 The output could be one of the following and something else:
223 chg: abort: failed to getcwd (errno = *) (glob)
224 abort: error getting current working directory: * (glob)
225 sh: 0: getcwd() failed: $ENOENT$
226 Since the exact behavior depends on the shell, only check it returns non-zero.
227 $ HGDEMANDIMPORT=disable hg version -q 2>/dev/null || false
228 [1]
229
230 #endif