##// END OF EJS Templates
heredoctest: use the same dict for local/global contexts as in doctest...
Yuya Nishihara -
r22564:9599e861 default
parent child Browse files
Show More
@@ -1,19 +1,18 b''
1 import sys
1 import sys
2
2
3 globalvars = {}
3 globalvars = {}
4 localvars = {}
5 lines = sys.stdin.readlines()
4 lines = sys.stdin.readlines()
6 while lines:
5 while lines:
7 l = lines.pop(0)
6 l = lines.pop(0)
8 if l.startswith('SALT'):
7 if l.startswith('SALT'):
9 print l[:-1]
8 print l[:-1]
10 elif l.startswith('>>> '):
9 elif l.startswith('>>> '):
11 snippet = l[4:]
10 snippet = l[4:]
12 while lines and lines[0].startswith('... '):
11 while lines and lines[0].startswith('... '):
13 l = lines.pop(0)
12 l = lines.pop(0)
14 snippet += "\n" + l[4:]
13 snippet += "\n" + l[4:]
15 c = compile(snippet, '<heredoc>', 'single')
14 c = compile(snippet, '<heredoc>', 'single')
16 try:
15 try:
17 exec c in globalvars, localvars
16 exec c in globalvars
18 except Exception, inst:
17 except Exception, inst:
19 print repr(inst)
18 print repr(inst)
@@ -1,124 +1,129 b''
1 Test that the syntax of "unified tests" is properly processed
1 Test that the syntax of "unified tests" is properly processed
2 ==============================================================
2 ==============================================================
3
3
4 Simple commands:
4 Simple commands:
5
5
6 $ echo foo
6 $ echo foo
7 foo
7 foo
8 $ printf 'oh no'
8 $ printf 'oh no'
9 oh no (no-eol)
9 oh no (no-eol)
10 $ printf 'bar\nbaz\n' | cat
10 $ printf 'bar\nbaz\n' | cat
11 bar
11 bar
12 baz
12 baz
13
13
14 Multi-line command:
14 Multi-line command:
15
15
16 $ foo() {
16 $ foo() {
17 > echo bar
17 > echo bar
18 > }
18 > }
19 $ foo
19 $ foo
20 bar
20 bar
21
21
22 Return codes before inline python:
22 Return codes before inline python:
23
23
24 $ sh -c 'exit 1'
24 $ sh -c 'exit 1'
25 [1]
25 [1]
26
26
27 Doctest commands:
27 Doctest commands:
28
28
29 >>> print 'foo'
29 >>> print 'foo'
30 foo
30 foo
31 $ echo interleaved
31 $ echo interleaved
32 interleaved
32 interleaved
33 >>> for c in 'xyz':
33 >>> for c in 'xyz':
34 ... print c
34 ... print c
35 x
35 x
36 y
36 y
37 z
37 z
38 >>> print
38 >>> print
39
39
40 >>> foo = 'global name'
41 >>> def func():
42 ... print foo, 'should be visible in func()'
43 >>> func()
44 global name should be visible in func()
40
45
41 Regular expressions:
46 Regular expressions:
42
47
43 $ echo foobarbaz
48 $ echo foobarbaz
44 foobar.* (re)
49 foobar.* (re)
45 $ echo barbazquux
50 $ echo barbazquux
46 .*quux.* (re)
51 .*quux.* (re)
47
52
48 Globs:
53 Globs:
49
54
50 $ printf '* \\foobarbaz {10}\n'
55 $ printf '* \\foobarbaz {10}\n'
51 \* \\fo?bar* {10} (glob)
56 \* \\fo?bar* {10} (glob)
52
57
53 Literal match ending in " (re)":
58 Literal match ending in " (re)":
54
59
55 $ echo 'foo (re)'
60 $ echo 'foo (re)'
56 foo (re)
61 foo (re)
57
62
58 Windows: \r\n is handled like \n and can be escaped:
63 Windows: \r\n is handled like \n and can be escaped:
59
64
60 #if windows
65 #if windows
61 $ printf 'crlf\r\ncr\r\tcrlf\r\ncrlf\r\n'
66 $ printf 'crlf\r\ncr\r\tcrlf\r\ncrlf\r\n'
62 crlf
67 crlf
63 cr\r (no-eol) (esc)
68 cr\r (no-eol) (esc)
64 \tcrlf (esc)
69 \tcrlf (esc)
65 crlf\r (esc)
70 crlf\r (esc)
66 #endif
71 #endif
67
72
68 Combining esc with other markups - and handling lines ending with \r instead of \n:
73 Combining esc with other markups - and handling lines ending with \r instead of \n:
69
74
70 $ printf 'foo/bar\r'
75 $ printf 'foo/bar\r'
71 fo?/bar\r (no-eol) (glob) (esc)
76 fo?/bar\r (no-eol) (glob) (esc)
72 #if windows
77 #if windows
73 $ printf 'foo\\bar\r'
78 $ printf 'foo\\bar\r'
74 foo/bar\r (no-eol) (glob) (esc)
79 foo/bar\r (no-eol) (glob) (esc)
75 #endif
80 #endif
76 $ printf 'foo/bar\rfoo/bar\r'
81 $ printf 'foo/bar\rfoo/bar\r'
77 foo.bar\r \(no-eol\) (re) (esc)
82 foo.bar\r \(no-eol\) (re) (esc)
78 foo.bar\r \(no-eol\) (re)
83 foo.bar\r \(no-eol\) (re)
79
84
80 testing hghave
85 testing hghave
81
86
82 $ "$TESTDIR/hghave" true
87 $ "$TESTDIR/hghave" true
83 $ "$TESTDIR/hghave" false
88 $ "$TESTDIR/hghave" false
84 skipped: missing feature: nail clipper
89 skipped: missing feature: nail clipper
85 [1]
90 [1]
86 $ "$TESTDIR/hghave" no-true
91 $ "$TESTDIR/hghave" no-true
87 skipped: system supports yak shaving
92 skipped: system supports yak shaving
88 [1]
93 [1]
89 $ "$TESTDIR/hghave" no-false
94 $ "$TESTDIR/hghave" no-false
90
95
91 Conditional sections based on hghave:
96 Conditional sections based on hghave:
92
97
93 #if true
98 #if true
94 $ echo tested
99 $ echo tested
95 tested
100 tested
96 #else
101 #else
97 $ echo skipped
102 $ echo skipped
98 #endif
103 #endif
99
104
100 #if false
105 #if false
101 $ echo skipped
106 $ echo skipped
102 #else
107 #else
103 $ echo tested
108 $ echo tested
104 tested
109 tested
105 #endif
110 #endif
106
111
107 #if no-false
112 #if no-false
108 $ echo tested
113 $ echo tested
109 tested
114 tested
110 #else
115 #else
111 $ echo skipped
116 $ echo skipped
112 #endif
117 #endif
113
118
114 #if no-true
119 #if no-true
115 $ echo skipped
120 $ echo skipped
116 #else
121 #else
117 $ echo tested
122 $ echo tested
118 tested
123 tested
119 #endif
124 #endif
120
125
121 Exit code:
126 Exit code:
122
127
123 $ (exit 1)
128 $ (exit 1)
124 [1]
129 [1]
General Comments 0
You need to be logged in to leave comments. Login now