tests/test-check-help.t
author Anton Shestakov <av6@dwimlabs.net>
Mon, 31 Jan 2022 18:13:00 +0300
changeset 48789 ef50a62eec40
parent 41000 b6c610bf567e
child 48876 42d2b31cee0b
permissions -rw-r--r--
obsolete: don't use os.stat in repo.obsstore.__nonzero__ if it's static HTTP If a repo is accessed via static HTTP, then we obviously can't use os.stat() to just peek at the file size. Let's download the entire file to check its size. Yes, this feels wasteful, but: 1. If we're cloning or pulling a repo from a static HTTP server, we need the contents of the obsstore anyway. 2. Implementing statichttpvfs.stat() that uses HEAD will result in one more request to a static-only HTTP server, which is already slow. Also parsing a response to a HEAD request to construct os.stat_result is pretty hacky. There's also a question of the remote server properly supporting HEAD method and reporting at least file size. 3. Implementing statichttpvfs.stat() that uses GET is pretty much the same thing as we do here, except we can't even cache the response easily, unlike simply accessing obsstore._data, which is @propertycache'd. Importing statichttprepo locally to avoid circular import. See also: 4507bc001365 and commit message of f8f2ecdde4b5. Differential Revision: https://phab.mercurial-scm.org/D12195
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30880
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     1
#require test-repo
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     2
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     3
  $ . "$TESTDIR/helpers-testrepo.sh"
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     4
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     5
  $ cat <<'EOF' > scanhelptopics.py
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     6
  > from __future__ import absolute_import, print_function
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     7
  > import re
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     8
  > import sys
31498
a248bbfa0bc7 test-check-help: fix to work on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 30880
diff changeset
     9
  > if sys.platform == "win32":
40091
c36846abbcd3 tests: import multiple modules separately
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 39707
diff changeset
    10
  >     import msvcrt
c36846abbcd3 tests: import multiple modules separately
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 39707
diff changeset
    11
  >     import os
31498
a248bbfa0bc7 test-check-help: fix to work on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 30880
diff changeset
    12
  >     msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
41000
b6c610bf567e py3: use bytes stdout in test-check-help.t
Matt Harbison <matt_harbison@yahoo.com>
parents: 40091
diff changeset
    13
  > stdout = getattr(sys.stdout, 'buffer', sys.stdout)
30880
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    14
  > topics = set()
35947
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33204
diff changeset
    15
  > topicre = re.compile(br':hg:`help ([a-z0-9\-.]+)`')
30880
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    16
  > for fname in sys.argv:
35949
80e5210df25c py3: make sure we open the file in bytes mode
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35947
diff changeset
    17
  >     with open(fname, 'rb') as f:
30880
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    18
  >         topics.update(m.group(1) for m in topicre.finditer(f.read()))
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    19
  > for s in sorted(topics):
41000
b6c610bf567e py3: use bytes stdout in test-check-help.t
Matt Harbison <matt_harbison@yahoo.com>
parents: 40091
diff changeset
    20
  >     stdout.write(b'%s\n' % s)
30880
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    21
  > EOF
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    22
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    23
  $ cd "$TESTDIR"/..
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    24
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    25
Check if ":hg:`help TOPIC`" is valid:
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    26
(use "xargs -n1 -t" to see which help commands are executed)
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    27
33204
ddd65b4f3ae6 tests: alias syshg and syshgenv so they can be switched conditionally
Yuya Nishihara <yuya@tcha.org>
parents: 33116
diff changeset
    28
  $ testrepohg files 'glob:{hgdemandimport,hgext,mercurial}/**/*.py' \
33116
6c113a7dec52 tests: use the system hg for examining the local repository
Adam Simpkins <simpkins@fb.com>
parents: 32940
diff changeset
    29
  > | sed 's|\\|/|g' \
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39652
diff changeset
    30
  > | xargs "$PYTHON" "$TESTTMP/scanhelptopics.py" \
39652
d2c81e83de2a phabricator: move extension from contrib to hgext
Augie Fackler <raf@durin42.com>
parents: 35949
diff changeset
    31
  > | xargs -n1 hg help --config extensions.phabricator= > /dev/null