Mercurial > hg
annotate tests/test-dispatch.t @ 24545:9e0c67e84896
json: implement {tags} template
Tags is pretty easy to implement. Let's start there.
The output is slightly different from `hg tags -Tjson`. For reference,
the CLI has the following output:
[
{
"node": "e2049974f9a23176c2addb61d8f5b86e0d620490",
"rev": 29880,
"tag": "tip",
"type": ""
},
...
]
Our output has the format:
{
"node": "0aeb19ea57a6d223bacddda3871cb78f24b06510",
"tags": [
{
"node": "e2049974f9a23176c2addb61d8f5b86e0d620490",
"tag": "tag1",
"date": [1427775457.0, 25200]
},
...
]
}
"rev" is omitted because it isn't a reliable identifier. We shouldn't
be exposing them in web APIs and giving the impression it remotely
resembles a stable identifier. Perhaps we could one day hide this behind
a config option (it might be useful to expose when running servers
locally).
The "type" of the tag isn't defined because this information isn't yet
exposed to the hgweb templater (it could be in a follow-up) and because
it is questionable whether different types should be exposed at all.
(Should the web interface really be exposing "local" tags?)
We use an object for the outer type instead of Array for a few reasons.
First, it is extensible. If we ever need to throw more global properties
into the output, we can do that without breaking backwards compatibility
(property additions should be backwards compatible). Second, uniformity
in web APIs is nice. Having everything return objects seems much saner than
a mix of array and object. Third, there are security issues with arrays
in older browsers. The JSON web services world almost never uses arrays
as the main type for this reason.
Another possibly controversial part about this patch is how dates are
defined. While JSON has a Date type, it is based on the JavaScript Date
type, which is widely considered a pile of garbage. It is a non-starter
for this reason.
Many of Mercurial's built-in date filters drop seconds resolution. So
that's a non-starter as well, since we want the API to be lossless where
possible. rfc3339date, rfc822date, isodatesec, and date are all lossless.
However, they each require the client to perform string parsing on top of
JSON decoding. While date parsing libraries are pretty ubiquitous, some
languages don't have them out of the box. However, pretty much every
programming language can deal with UNIX timestamps (which are just
integers or floats). So, we choose to use Mercurial's internal date
representation, which in JSON is modeled as float seconds since UNIX
epoch and an integer timezone offset from UTC (keep in mind
JavaScript/JSON models all "Numbers" as double prevision floating point
numbers, so there isn't a difference between ints and floats in JSON).
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 31 Mar 2015 14:52:21 -0700 |
parents | c1d93edcf004 |
children | 7109d5ddeb0c |
rev | line source |
---|---|
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
1 test command parsing and dispatch |
4563
8044be585b91
dispatch: restore a dropped shlex import
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
2 |
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
3 $ hg init a |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
4 $ cd a |
14115
1d5faa2c970f
tests: move test-issue436 in test-dispatch where fancyopts is tested
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
13967
diff
changeset
|
5 |
1d5faa2c970f
tests: move test-issue436 in test-dispatch where fancyopts is tested
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
13967
diff
changeset
|
6 Redundant options used to crash (issue436): |
1d5faa2c970f
tests: move test-issue436 in test-dispatch where fancyopts is tested
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
13967
diff
changeset
|
7 $ hg -v log -v |
1d5faa2c970f
tests: move test-issue436 in test-dispatch where fancyopts is tested
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
13967
diff
changeset
|
8 $ hg -v log -v x |
1d5faa2c970f
tests: move test-issue436 in test-dispatch where fancyopts is tested
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
13967
diff
changeset
|
9 |
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
10 $ echo a > a |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
11 $ hg ci -Ama |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
12 adding a |
4563
8044be585b91
dispatch: restore a dropped shlex import
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
13 |
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
14 Missing arg: |
4621
6fc26982f203
dispatch: fix handling of incorrect number of arguments
Matt Mackall <mpm@selenic.com>
parents:
4563
diff
changeset
|
15 |
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
16 $ hg cat |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
17 hg cat: invalid arguments |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
18 hg cat [OPTION]... FILE... |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
19 |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
20 output the current or given revision of files |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
21 |
22117
c1d93edcf004
help: fold repeatable option message into option table header
Matt Mackall <mpm@selenic.com>
parents:
22111
diff
changeset
|
22 options ([+] can be repeated): |
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
23 |
15145
ff26712a0c50
help: use RST to format option lists
Matt Mackall <mpm@selenic.com>
parents:
14115
diff
changeset
|
24 -o --output FORMAT print output to file with formatted name |
ff26712a0c50
help: use RST to format option lists
Matt Mackall <mpm@selenic.com>
parents:
14115
diff
changeset
|
25 -r --rev REV print the given revision |
ff26712a0c50
help: use RST to format option lists
Matt Mackall <mpm@selenic.com>
parents:
14115
diff
changeset
|
26 --decode apply any matching decode filter |
ff26712a0c50
help: use RST to format option lists
Matt Mackall <mpm@selenic.com>
parents:
14115
diff
changeset
|
27 -I --include PATTERN [+] include names matching the given patterns |
ff26712a0c50
help: use RST to format option lists
Matt Mackall <mpm@selenic.com>
parents:
14115
diff
changeset
|
28 -X --exclude PATTERN [+] exclude names matching the given patterns |
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
29 |
22111
aa5e256839d5
help: improve command summary hint
Matt Mackall <mpm@selenic.com>
parents:
18506
diff
changeset
|
30 (use "hg cat -h" to show more help) |
12316
4134686b83e1
tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents:
12157
diff
changeset
|
31 [255] |
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
32 |
4563
8044be585b91
dispatch: restore a dropped shlex import
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
33 [defaults] |
4621
6fc26982f203
dispatch: fix handling of incorrect number of arguments
Matt Mackall <mpm@selenic.com>
parents:
4563
diff
changeset
|
34 |
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
35 $ hg cat a |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
36 a |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
37 $ cat >> $HGRCPATH <<EOF |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
38 > [defaults] |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
39 > cat = -r null |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
40 > EOF |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
41 $ hg cat a |
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
42 a: no such file in rev 000000000000 |
12316
4134686b83e1
tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents:
12157
diff
changeset
|
43 [1] |
4654
e0e73ba37983
Fix dispatch error message when not in a repo
Brendan Cully <brendan@kublai.com>
parents:
4621
diff
changeset
|
44 |
17014
50fbe9063ff2
tests: convert some 'hghave no-outer-repo' to #if
Mads Kiilerich <mads@kiilerich.com>
parents:
15145
diff
changeset
|
45 $ cd "$TESTTMP" |
50fbe9063ff2
tests: convert some 'hghave no-outer-repo' to #if
Mads Kiilerich <mads@kiilerich.com>
parents:
15145
diff
changeset
|
46 |
18506
ef60083b5536
tests: fix for windows - slashes and no serve
Mads Kiilerich <madski@unity3d.com>
parents:
18227
diff
changeset
|
47 OSError "No such file or directory" / "The system cannot find the path |
ef60083b5536
tests: fix for windows - slashes and no serve
Mads Kiilerich <madski@unity3d.com>
parents:
18227
diff
changeset
|
48 specified" should include filename even when it is empty |
18227
720308f741cb
dispatch: show empty filename in OSError aborts
Mads Kiilerich <mads@kiilerich.com>
parents:
18226
diff
changeset
|
49 |
720308f741cb
dispatch: show empty filename in OSError aborts
Mads Kiilerich <mads@kiilerich.com>
parents:
18226
diff
changeset
|
50 $ hg -R a archive '' |
18506
ef60083b5536
tests: fix for windows - slashes and no serve
Mads Kiilerich <madski@unity3d.com>
parents:
18227
diff
changeset
|
51 abort: *: '' (glob) |
18227
720308f741cb
dispatch: show empty filename in OSError aborts
Mads Kiilerich <mads@kiilerich.com>
parents:
18226
diff
changeset
|
52 [255] |
720308f741cb
dispatch: show empty filename in OSError aborts
Mads Kiilerich <mads@kiilerich.com>
parents:
18226
diff
changeset
|
53 |
17014
50fbe9063ff2
tests: convert some 'hghave no-outer-repo' to #if
Mads Kiilerich <mads@kiilerich.com>
parents:
15145
diff
changeset
|
54 #if no-outer-repo |
50fbe9063ff2
tests: convert some 'hghave no-outer-repo' to #if
Mads Kiilerich <mads@kiilerich.com>
parents:
15145
diff
changeset
|
55 |
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
56 No repo: |
4659
7a7d4937272b
Kill trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4654
diff
changeset
|
57 |
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
58 $ hg cat |
13967
f85c9b0fdb32
dispatch: improve repository not found message
Matt Mackall <mpm@selenic.com>
parents:
13950
diff
changeset
|
59 abort: no repository found in '$TESTTMP' (.hg not found)! |
12316
4134686b83e1
tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents:
12157
diff
changeset
|
60 [255] |
12157
88250a460bf8
tests: unify test-dispatch
Adrian Buehlmann <adrian@cadifra.com>
parents:
12028
diff
changeset
|
61 |
17014
50fbe9063ff2
tests: convert some 'hghave no-outer-repo' to #if
Mads Kiilerich <mads@kiilerich.com>
parents:
15145
diff
changeset
|
62 #endif |