##// END OF EJS Templates
posix: always seek to EOF when opening a file in append mode...
posix: always seek to EOF when opening a file in append mode Python 3 already does this, so skip it there. Consider the program: #include <stdio.h> int main() { FILE *f = fopen("narf", "w"); fprintf(f, "narf\n"); fclose(f); f = fopen("narf", "a"); printf("%ld\n", ftell(f)); fprintf(f, "troz\n"); printf("%ld\n", ftell(f)); return 0; } on macOS, FreeBSD, and Linux with glibc, this program prints 5 10 but on musl libc (Alpine Linux and probably others) this prints 0 10 By my reading of https://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html this is technically correct, specifically: > Opening a file with append mode (a as the first character in the > mode argument) shall cause all subsequent writes to the file to be > forced to the then current end-of-file, regardless of intervening > calls to fseek(). in other words, the file position doesn't really matter in append-mode files, and we can't depend on it being at all meaningful unless we perform a seek() before tell() after open(..., 'a'). Experimentally after a .write() we can do a .tell() and it'll always be reasonable, but I'm unclear from reading the specification if that's a smart thing to rely on. This matches what we do on Windows and what Python 3 does for free, so let's just be consistent. Thanks to Yuya for the idea.

File last commit:

r42636:d3c81439 default
r42778:97ada9b8 5.0.2 stable
Show More
test-phabricator.t
121 lines | 4.5 KiB | text/troff | Tads3Lexer
/ tests / test-phabricator.t
Augie Fackler
tests: add some basic tests of phabricator interactions...
r39687 #require vcr
$ cat >> $HGRCPATH <<EOF
> [extensions]
Augie Fackler
phabricator: move extension from contrib to hgext...
r39688 > phabricator =
Augie Fackler
tests: add some basic tests of phabricator interactions...
r39687 > EOF
$ hg init repo
$ cd repo
$ cat >> .hg/hgrc <<EOF
> [phabricator]
> url = https://phab.mercurial-scm.org/
> callsign = HG
>
> [auth]
> hgphab.schemes = https
> hgphab.prefix = phab.mercurial-scm.org
> # When working on the extension and making phabricator interaction
> # changes, edit this to be a real phabricator token. When done, edit
> # it back, and make sure to also edit your VCR transcripts to match
> # whatever value you put here.
> hgphab.phabtoken = cli-hahayouwish
> EOF
$ VCR="$TESTDIR/phabricator"
Error is handled reasonably. We override the phabtoken here so that
when you're developing changes to phabricator.py you can edit the
above config and have a real token in the test but not have to edit
this test.
$ hg phabread --config auth.hgphab.phabtoken=cli-notavalidtoken \
> --test-vcr "$VCR/phabread-conduit-error.json" D4480 | head
abort: Conduit Error (ERR-INVALID-AUTH): API token "cli-notavalidtoken" has the wrong length. API tokens should be 32 characters long.
Basic phabread:
$ hg phabread --test-vcr "$VCR/phabread-4480.json" D4480 | head
# HG changeset patch
exchangev2: start to implement pull with wire protocol v2
Wire protocol version 2 will take a substantially different
approach to exchange than version 1 (at least as far as pulling
is concerned).
This commit establishes a new exchangev2 module for holding
code related to exchange using wire protocol v2. I could have
added things to the existing exchange module. But it is already
phabupdate with an accept:
$ hg phabupdate --accept D4564 \
> -m 'I think I like where this is headed. Will read rest of series later.'\
> --test-vcr "$VCR/accept-4564.json"
Create a differential diff:
Ian Moody
phabricator: convert conduit response JSON unicode to bytes inside callconduit...
r42063 $ HGENCODING=utf-8; export HGENCODING
Augie Fackler
tests: add some basic tests of phabricator interactions...
r39687 $ echo alpha > alpha
Ian Moody
phabricator: convert conduit response JSON unicode to bytes inside callconduit...
r42063 $ hg ci --addremove -m 'create alpha for phabricator test €'
Augie Fackler
tests: add some basic tests of phabricator interactions...
r39687 adding alpha
$ hg phabsend -r . --test-vcr "$VCR/phabsend-create-alpha.json"
Ian Moody
phabricator: convert conduit response JSON unicode to bytes inside callconduit...
r42063 D6054 - created - d386117f30e6: create alpha for phabricator test \xe2\x82\xac (esc)
saved backup bundle to $TESTTMP/repo/.hg/strip-backup/d386117f30e6-24ffe649-phabsend.hg
Augie Fackler
tests: add some basic tests of phabricator interactions...
r39687 $ echo more >> alpha
$ HGEDITOR=true hg ci --amend
Ian Moody
phabricator: convert conduit response JSON unicode to bytes inside callconduit...
r42063 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/cb03845d6dd9-870f61a6-amend.hg
Augie Fackler
tests: add some basic tests of phabricator interactions...
r39687 $ echo beta > beta
$ hg ci --addremove -m 'create beta for phabricator test'
adding beta
$ hg phabsend -r ".^::" --test-vcr "$VCR/phabsend-update-alpha-create-beta.json"
Ian Moody
phabricator: convert conduit response JSON unicode to bytes inside callconduit...
r42063 D6054 - updated - 939d862f0318: create alpha for phabricator test \xe2\x82\xac (esc)
D6055 - created - f55f947ed0f8: create beta for phabricator test
saved backup bundle to $TESTTMP/repo/.hg/strip-backup/f55f947ed0f8-0d1e502e-phabsend.hg
$ unset HGENCODING
Augie Fackler
phabricator: add tests of templatekeyword...
r39689
Matt Harbison
phabricator: warn if unable to amend, instead of aborting after posting...
r41198 The amend won't explode after posting a public commit. The local tag is left
behind to identify it.
$ echo 'public change' > beta
$ hg ci -m 'create public change for phabricator testing'
$ hg phase --public .
$ echo 'draft change' > alpha
$ hg ci -m 'create draft change for phabricator testing'
$ hg phabsend --amend -r '.^::' --test-vcr "$VCR/phabsend-create-public.json"
Ian Moody
phabricator: convert conduit response JSON unicode to bytes inside callconduit...
r42063 D5544 - created - a56e5ebd77e6: create public change for phabricator testing
D5545 - created - 6a0ade3e3ec2: create draft change for phabricator testing
warning: not updating public commit 2:a56e5ebd77e6
saved backup bundle to $TESTTMP/repo/.hg/strip-backup/6a0ade3e3ec2-aca7d23c-phabsend.hg
Matt Harbison
phabricator: warn if unable to amend, instead of aborting after posting...
r41198 $ hg tags -v
Ian Moody
phabricator: convert conduit response JSON unicode to bytes inside callconduit...
r42063 tip 3:90532860b5e1
D5544 2:a56e5ebd77e6 local
Matt Harbison
phabricator: warn if unable to amend, instead of aborting after posting...
r41198
Matt Harbison
phabricator: properly encode boolean types in the request body...
r41073 $ hg debugcallconduit user.search --test-vcr "$VCR/phab-conduit.json" <<EOF
> {
> "constraints": {
> "isBot": true
> }
> }
> EOF
{
"cursor": {
"after": null,
"before": null,
"limit": 100,
"order": null
},
"data": [],
"maps": {},
"query": {
"queryKey": null
}
}
Augie Fackler
phabricator: add tests of templatekeyword...
r39689 Template keywords
$ hg log -T'{rev} {phabreview|json}\n'
Matt Harbison
phabricator: warn if unable to amend, instead of aborting after posting...
r41198 3 {"id": "D5545", "url": "https://phab.mercurial-scm.org/D5545"}
Matt Harbison
phabricator: teach {phabreview} to work without --amend...
r41199 2 {"id": "D5544", "url": "https://phab.mercurial-scm.org/D5544"}
Ian Moody
phabricator: convert conduit response JSON unicode to bytes inside callconduit...
r42063 1 {"id": "D6055", "url": "https://phab.mercurial-scm.org/D6055"}
0 {"id": "D6054", "url": "https://phab.mercurial-scm.org/D6054"}
Augie Fackler
phabricator: add tests of templatekeyword...
r39689
Matt Harbison
phabricator: warn if unable to amend, instead of aborting after posting...
r41198 $ hg log -T'{rev} {if(phabreview, "{phabreview.url} {phabreview.id}")}\n'
3 https://phab.mercurial-scm.org/D5545 D5545
Matt Harbison
phabricator: teach {phabreview} to work without --amend...
r41199 2 https://phab.mercurial-scm.org/D5544 D5544
Ian Moody
phabricator: convert conduit response JSON unicode to bytes inside callconduit...
r42063 1 https://phab.mercurial-scm.org/D6055 D6055
0 https://phab.mercurial-scm.org/D6054 D6054
Augie Fackler
phabricator: add tests of templatekeyword...
r39689
Augie Fackler
tests: add some basic tests of phabricator interactions...
r39687 $ cd ..