.hgtags
author Idan Kamara <idankk86@gmail.com>
Wed, 12 Oct 2011 22:01:14 +0200
branchstable
changeset 987 5fc540826f9f
parent 200 7eae2cfd26fa
permissions -rw-r--r--
tests: add support for inline doctests in test files This adds doctest like syntax to .t files, that can be interleaved with regular shell code: $ echo -n a > file >>> print open('file').read() a >>> open('file', 'a').write('b') $ cat file ab The syntax is exactly the same as regular doctests, so multiline statements look like this: >>> for i in range(3): ... print i 0 1 2 Each block has its own context, i.e.: >>> x = 0 >>> print x 0 $ echo 'foo' foo >>> print x will result in a NameError. Errors are displayed in standard doctest format: >>> print 'foo' bar --- /home/idan/dev/hg/default/tests/test-test.t +++ /home/idan/dev/hg/default/tests/test-test.t.err @@ -2,3 +2,16 @@ > >>> print 'foo' > bar > EOF + ********************************************************************** + File "/tmp/tmps8X_0ohg-tst", line 1, in tmps8X_0ohg-tst + Failed example: + print 'foo' + Expected: + bar + Got: + foo + ********************************************************************** + 1 items had failures: + 1 of 1 in tmps8X_0ohg-tst + ***Test Failed*** 1 failures. + [1] As for the implementation, it's quite simple: when the test runner sees a line starting with '>>>' it converts it, and all subsequent lines until the next line that begins with '$' to a 'python -m heredoctest <<EOF' call with the proper heredoc to follow. So if we have this test file: >>> for c in 'abcd': ... print c a b c d $ echo foo foo It gets converted to: $ python -m heredoctest <<EOF > >>> for c in 'abcd': > ... print c > a > b > c > d > EOF $ echo foo foo And then processed like every other test file by converting it to a sh script. [ original upstream message ]

536c1797202d57efb77bea098e10968ff01602ce universal_scheme
ba000e29ecf3b8df09e0fd363a78cabbe3c2a78f cvs_scheme
1fe48bf82d056f1ece05baccab888357c10c5ab8 r0.1
2e930f84224222ad6514a3c5dc6e00350e199e92 very_cvs
99dc49c5bcfba9d5b412c5fa6d0bf3ba20d68df1 hgkw_standalone_setup
15e8cd7f5295728b089fc8ba236c0f079572fb1d nohook
0c8b7e5c25a6b9a0d2782eaa3748eb546f5a254f archive
0000000000000000000000000000000000000000 universal_scheme
0000000000000000000000000000000000000000 cvs_scheme
0000000000000000000000000000000000000000 r0.1
0000000000000000000000000000000000000000 very_cvs
0000000000000000000000000000000000000000 hgkw_standalone_setup
0000000000000000000000000000000000000000 nohook
0000000000000000000000000000000000000000 archive