[PATCH 1 of 4] tests: new test for line matching functions in run-tests
Augie Fackler
raf at durin42.com
Thu Jan 16 14:39:22 UTC 2014
On Thu, Jan 16, 2014 at 12:33:28PM +0100, Simon Heimberg wrote:
> # HG changeset patch
> # User Simon Heimberg <simohe at besonet.ch>
> # Date 1389870207 -3600
> # Thu Jan 16 12:03:27 2014 +0100
> # Node ID c785585c3d9356a9275966fbe05fde250610822e
> # Parent 5661c2e827ad3863bc28f98a9a2c929f1298c1cd
> tests: new test for line matching functions in run-tests
>
> Test for failing matches and warnings. (The existing test-run-tests.t can not
> do both by design.) And simulate matching on other os.
>
> diff -r 5661c2e827ad -r c785585c3d93 tests/test-run-tests.py
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/tests/test-run-tests.py Thu Jan 16 12:03:27 2014 +0100
> @@ -0,0 +1,82 @@
> +r"""test line matching with some failing examples and some which warn
> +
> +run-test.t only checks positive matches and can not see warnings
> +(both by design)
> +
> +does it generally work?
> + >>> lm('h*e (glob)\n', 'here\n')
> + True
> +
> + fail on bad test data
Is it intentional that this is indented so far, or should it be back in column 1?
> + >>> try: lm('a\n','a')
> + ... except AssertionError, ex: print ex
> + missing newline
> + >>> try: lm('single backslash\n', 'single \backslash\n')
> + ... except AssertionError, ex: print ex
> + single backslash or unknown char
> +"""
> +
> +
> +import doctest, os, re
> +run_tests = __import__('run-tests')
> +
> +def lm(expected, output):
> + "check if output matches expected"
> + assert expected.endswith('\n') and output.endswith('\n'), 'missing newline'
> + assert not re.search(r'[^ a-z\\/\r\n()*?]', expected + output), \
> + 'single backslash or unknown char'
> + match = run_tests.linematch(expected, output)
> + return bool(match)
> +
> +def wintests():
> + r"""test matching like running on windows
> +
> + enable windows matching on any os
> + >>> _osaltsep = os.altsep
> + >>> os.altsep = True
> +
> + valid match on windows
> + >>> lm('g/a*/d (glob)\n', 'g\\abc/d\n')
> + True
> +
> + direct matching, glob unnecessary
> + >>> lm('g/b (glob)\n', 'g/b\n')
> + <BLANKLINE>
> + Info, unnecessary glob: g/b (glob)
> + True
> +
> + missing glob
> + >>> lm('/g/c/d/fg\n', '\\g\\c\\d/fg\n')
> + False
> +
> + restore os.altsep
> + >>> os.altsep = _osaltsep
> + """
> + os.altsep # for pyflakes, because it does not see os in the doctest
> +
> +def otherostests():
> + r"""test matching like running on non-windows os
> +
> + disable windows matching on any os
> + >>> _osaltsep = os.altsep
> + >>> os.altsep = False
> +
> + backslash does not match slash
> + >>> lm('h/a* (glob)\n', 'h\\ab\n')
> + False
> +
> + direct matching glob can not be recognized
> + >>> lm('h/b (glob)\n', 'h/b\n')
> + True
> +
> + missing glob can not not be recognized
> + >>> lm('/h/c/df/g/\n', '\\h/c\\df/g\\\n')
> + False
> +
> + restore os.altsep
> + >>> os.altsep = _osaltsep
> + """
> + pass
> +
> +if __name__ == '__main__':
> + doctest.testmod()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list