tests/test-check-help.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 48876 42d2b31cee0b
permissions -rw-r--r--
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.
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
  > import re
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     7
  > import sys
31498
a248bbfa0bc7 test-check-help: fix to work on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 30880
diff changeset
     8
  > if sys.platform == "win32":
40091
c36846abbcd3 tests: import multiple modules separately
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 39707
diff changeset
     9
  >     import msvcrt
c36846abbcd3 tests: import multiple modules separately
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 39707
diff changeset
    10
  >     import os
31498
a248bbfa0bc7 test-check-help: fix to work on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 30880
diff changeset
    11
  >     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
    12
  > 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
    13
  > topics = set()
35947
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33204
diff changeset
    14
  > 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
    15
  > 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
    16
  >     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
    17
  >         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
    18
  > 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
    19
  >     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
    20
  > EOF
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    21
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    22
  $ cd "$TESTDIR"/..
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    23
b6c051cd1231 help: test if "hg help TOPIC" reference is valid
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    24
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
    25
(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
    26
33204
ddd65b4f3ae6 tests: alias syshg and syshgenv so they can be switched conditionally
Yuya Nishihara <yuya@tcha.org>
parents: 33116
diff changeset
    27
  $ 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
    28
  > | sed 's|\\|/|g' \
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39652
diff changeset
    29
  > | xargs "$PYTHON" "$TESTTMP/scanhelptopics.py" \
39652
d2c81e83de2a phabricator: move extension from contrib to hgext
Augie Fackler <raf@durin42.com>
parents: 35949
diff changeset
    30
  > | xargs -n1 hg help --config extensions.phabricator= > /dev/null