tests/test-i18n.t
author Gregory Szorc <gregory.szorc@gmail.com>
Tue, 28 Aug 2018 15:02:48 -0700
changeset 39411 aeb551a3bb8a
parent 36645 7bc33d677c0c
child 39707 5abc47d4ca6b
permissions -rw-r--r--
cborutil: implement sans I/O decoder The vendored CBOR package decodes by calling read(n) on an object. There are a number of disadvantages to this: * Uses blocking I/O. If sufficient data is not available, the decoder will hang until it is. * No support for partial reads. If the read(n) returns less data than requested, the decoder raises an error. * Requires the use of a file like object. If the original data is in say a buffer, we need to "cast" it to e.g. a BytesIO to appease the decoder. In addition, the vendored CBOR decoder doesn't provide flexibility that we desire. Specifically: * It buffers indefinite length bytestrings instead of streaming them. * It doesn't allow limiting the set of types that can be decoded. This property is useful when implementing a "hardened" decoder that is less susceptible to abusive input. * It doesn't provide sufficient "hook points" and introspection to institute checks around behavior. These are useful for implementing a "hardened" decoder. This all adds up to a reasonable set of justifications for writing our own decoder. So, this commit implements our own CBOR decoder. At the heart of the decoder is a function that decodes a single "item" from a buffer. This item can be a complete simple value or a special value, such as "start of array." Using this function, we can build a decoder that effectively iterates over the stream of decoded items and builds up higher-level values, such as arrays, maps, sets, and indefinite length bytestrings. And we can do this without performing I/O in the decoder itself. The core of the sans I/O decoder will probably not be used directly. Instead, it is expected that we'll build utility functions for invoking the decoder given specific input types. This will allow extreme flexibility in how data is delivered to the decoder. I'm pretty happy with the state of the decoder modulo the TODO items to track wanted features to help with a "hardened" decoder. The one thing I could be convinced to change is the handling of semantic tags. Since we only support a single semantic tag (sets), I thought it would be easier to handle them inline in decodeitem(). This is simpler now. But if we add support for other semantic tags, it will likely be easier to move semantic tag handling outside of decodeitem(). But, properly supporting semantic tags opens up a whole can of worms, as many semantic tags imply new types. I'm optimistic we won't need these in Mercurial. But who knows. I'm also pretty happy with the test coverage. Writing comprehensive tests for partial decoding did flush out a handful of bugs. One general improvement to testing would be fuzz testing for partial decoding. I may implement that later. I also anticipate switching the wire protocol code to this new decoder will flush out any lingering bugs. Differential Revision: https://phab.mercurial-scm.org/D4414
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22046
7a9cbb315d84 tests: replace exit 80 with #require
Matt Mackall <mpm@selenic.com>
parents: 21024
diff changeset
     1
(Translations are optional)
13442
bb107a31820e test-i18n: make test conditional on msgfmt availability
Martin Geisler <mg@lazybytes.net>
parents: 13414
diff changeset
     2
26252
a3edce86f430 test-i18n: always run non gettext tests
timeless@mozdev.org
parents: 22046
diff changeset
     3
#if gettext no-outer-repo
17015
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 16981
diff changeset
     4
13414
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
     5
Test that translations are compiled and installed correctly.
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
     6
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
     7
Default encoding in tests is "ascii" and the translation is encoded
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
     8
using the "replace" error handler:
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
     9
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
    10
  $ LANGUAGE=pt_BR hg tip
14920
56848e2bb0c5 test-i18n, i18n-pt_BR: updated test message changed in 41c3a71c318d
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14914
diff changeset
    11
  abortado: n?o foi encontrado um reposit?rio em '$TESTTMP' (.hg n?o encontrado)!
13414
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
    12
  [255]
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
    13
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 20338
diff changeset
    14
Using a more accommodating encoding:
13414
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
    15
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
    16
  $ HGENCODING=UTF-8 LANGUAGE=pt_BR hg tip
14920
56848e2bb0c5 test-i18n, i18n-pt_BR: updated test message changed in 41c3a71c318d
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14914
diff changeset
    17
  abortado: n\xc3\xa3o foi encontrado um reposit\xc3\xb3rio em '$TESTTMP' (.hg n\xc3\xa3o encontrado)! (esc)
13414
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
    18
  [255]
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
    19
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
    20
Different encoding:
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
    21
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
    22
  $ HGENCODING=Latin-1 LANGUAGE=pt_BR hg tip
14920
56848e2bb0c5 test-i18n, i18n-pt_BR: updated test message changed in 41c3a71c318d
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14914
diff changeset
    23
  abortado: n\xe3o foi encontrado um reposit\xf3rio em '$TESTTMP' (.hg n\xe3o encontrado)! (esc)
13414
a0e49e129151 test-i18n: test translations
Martin Geisler <mg@aragost.com>
parents:
diff changeset
    24
  [255]
16895
430714e2a876 help: test keyword search in translated text.
Olav Reinert <seroton10@gmail.com>
parents: 14920
diff changeset
    25
17015
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 16981
diff changeset
    26
#endif
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 16981
diff changeset
    27
26252
a3edce86f430 test-i18n: always run non gettext tests
timeless@mozdev.org
parents: 22046
diff changeset
    28
#if gettext
a3edce86f430 test-i18n: always run non gettext tests
timeless@mozdev.org
parents: 22046
diff changeset
    29
16895
430714e2a876 help: test keyword search in translated text.
Olav Reinert <seroton10@gmail.com>
parents: 14920
diff changeset
    30
Test keyword search in translated help text:
430714e2a876 help: test keyword search in translated text.
Olav Reinert <seroton10@gmail.com>
parents: 14920
diff changeset
    31
30943
a0e4df5a4d5d tests: update test-i18n.t to not depend on the pager extension
Augie Fackler <augie@google.com>
parents: 26252
diff changeset
    32
  $ HGENCODING=UTF-8 LANGUAGE=de hg help -k Aktualisiert
20338
b9e7af5bd5e5 i18n-de: update many fuzzy entries and translate some simple ones
Simon Heimberg <simohe@besonet.ch>
parents: 20152
diff changeset
    33
  Themen:
16895
430714e2a876 help: test keyword search in translated text.
Olav Reinert <seroton10@gmail.com>
parents: 14920
diff changeset
    34
  
30943
a0e4df5a4d5d tests: update test-i18n.t to not depend on the pager extension
Augie Fackler <augie@google.com>
parents: 26252
diff changeset
    35
   subrepos Unterarchive
16895
430714e2a876 help: test keyword search in translated text.
Olav Reinert <seroton10@gmail.com>
parents: 14920
diff changeset
    36
  
30943
a0e4df5a4d5d tests: update test-i18n.t to not depend on the pager extension
Augie Fackler <augie@google.com>
parents: 26252
diff changeset
    37
  Befehle:
16895
430714e2a876 help: test keyword search in translated text.
Olav Reinert <seroton10@gmail.com>
parents: 14920
diff changeset
    38
  
30943
a0e4df5a4d5d tests: update test-i18n.t to not depend on the pager extension
Augie Fackler <augie@google.com>
parents: 26252
diff changeset
    39
   pull   Ruft \xc3\x84nderungen von der angegebenen Quelle ab (esc)
a0e4df5a4d5d tests: update test-i18n.t to not depend on the pager extension
Augie Fackler <augie@google.com>
parents: 26252
diff changeset
    40
   update Aktualisiert das Arbeitsverzeichnis (oder wechselt die Version)
16895
430714e2a876 help: test keyword search in translated text.
Olav Reinert <seroton10@gmail.com>
parents: 14920
diff changeset
    41
26252
a3edce86f430 test-i18n: always run non gettext tests
timeless@mozdev.org
parents: 22046
diff changeset
    42
#endif
a3edce86f430 test-i18n: always run non gettext tests
timeless@mozdev.org
parents: 22046
diff changeset
    43
20152
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17015
diff changeset
    44
Check Mercurial specific translation problems in each *.po files, and
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17015
diff changeset
    45
tool itself by doctest
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17015
diff changeset
    46
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17015
diff changeset
    47
  $ cd "$TESTDIR"/../i18n
32940
75be14993fda cleanup: use $PYTHON to run python in many more tests
Augie Fackler <augie@google.com>
parents: 30943
diff changeset
    48
  $ $PYTHON check-translation.py *.po
75be14993fda cleanup: use $PYTHON to run python in many more tests
Augie Fackler <augie@google.com>
parents: 30943
diff changeset
    49
  $ $PYTHON check-translation.py --doctest
20152
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17015
diff changeset
    50
  $ cd $TESTTMP
34660
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    51
34688
a88166a4dce3 test-i18n: guard gettext test appropriately
Yuya Nishihara <yuya@tcha.org>
parents: 34660
diff changeset
    52
#if gettext
a88166a4dce3 test-i18n: guard gettext test appropriately
Yuya Nishihara <yuya@tcha.org>
parents: 34660
diff changeset
    53
34660
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    54
Check i18n cache isn't reused after encoding change:
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    55
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    56
  $ cat > $TESTTMP/encodingchange.py << EOF
36645
7bc33d677c0c tests: fix various test-check-module-imports.t violations
Augie Fackler <augie@google.com>
parents: 34688
diff changeset
    57
  > from mercurial.i18n import _
34660
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    58
  > from mercurial import encoding, registrar
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    59
  > cmdtable = {}
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    60
  > command = registrar.command(cmdtable)
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    61
  > @command(b'encodingchange', norepo=True)
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    62
  > def encodingchange(ui):
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    63
  >     for encode in (b'ascii', b'UTF-8', b'ascii', b'UTF-8'):
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    64
  >         encoding.encoding = encode
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    65
  >         ui.write(b'%s\n' % _(b'(EXPERIMENTAL)'))
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    66
  > EOF
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    67
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    68
  $ LANGUAGE=ja hg --config extensions.encodingchange=$TESTTMP/encodingchange.py encodingchange
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    69
  (?????)
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    70
  (\xe5\xae\x9f\xe9\xa8\x93\xe7\x9a\x84\xe5\xae\x9f\xe8\xa3\x85) (esc)
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    71
  (?????)
d00ec62d156f i18n: cache translated messages per encoding
Yuya Nishihara <yuya@tcha.org>
parents: 32940
diff changeset
    72
  (\xe5\xae\x9f\xe9\xa8\x93\xe7\x9a\x84\xe5\xae\x9f\xe8\xa3\x85) (esc)
34688
a88166a4dce3 test-i18n: guard gettext test appropriately
Yuya Nishihara <yuya@tcha.org>
parents: 34660
diff changeset
    73
a88166a4dce3 test-i18n: guard gettext test appropriately
Yuya Nishihara <yuya@tcha.org>
parents: 34660
diff changeset
    74
#endif