##// END OF EJS Templates
tests: rewrite inline Python support...
Matt Mackall -
r15412:59fe460b default
parent child Browse files
Show More
@@ -521,26 +521,6 b' def escapef(m):'
521 def stringescape(s):
521 def stringescape(s):
522 return escapesub(escapef, s)
522 return escapesub(escapef, s)
523
523
524 def transformtst(lines):
525 inblock = False
526 for l in lines:
527 if inblock:
528 if l.startswith(' $ ') or not l.startswith(' '):
529 inblock = False
530 yield ' > EOF\n'
531 yield l
532 else:
533 yield ' > ' + l[2:]
534 else:
535 if l.startswith(' >>> '):
536 inblock = True
537 yield ' $ %s -m heredoctest <<EOF\n' % PYTHON
538 yield ' > ' + l[2:]
539 else:
540 yield l
541 if inblock:
542 yield ' > EOF\n'
543
544 def tsttest(test, wd, options, replacements):
524 def tsttest(test, wd, options, replacements):
545 t = open(test)
525 t = open(test)
546 out = []
526 out = []
@@ -550,10 +530,24 b' def tsttest(test, wd, options, replaceme'
550 pos = prepos = -1
530 pos = prepos = -1
551 after = {}
531 after = {}
552 expected = {}
532 expected = {}
553 for n, l in enumerate(transformtst(t)):
533 inpython = False
534 for n, l in enumerate(t):
554 if not l.endswith('\n'):
535 if not l.endswith('\n'):
555 l += '\n'
536 l += '\n'
556 if l.startswith(' $ '): # commands
537 if l.startswith(' >>> '):
538 if not inpython:
539 # we've just entered a Python block, add the header
540 inpython = True
541 script.append('echo %s %s $?\n' % (salt, n))
542 script.append('%s -m heredoctest <<EOF\n' % PYTHON)
543 prepos = pos
544 pos = n
545 after.setdefault(prepos, []).append(l)
546 script.append(l[2:])
547 elif l.startswith(' $ '): # commands
548 if inpython:
549 script.append("EOF\n")
550 inpython = False
557 after.setdefault(pos, []).append(l)
551 after.setdefault(pos, []).append(l)
558 prepos = pos
552 prepos = pos
559 pos = n
553 pos = n
@@ -563,12 +557,22 b' def tsttest(test, wd, options, replaceme'
563 after.setdefault(prepos, []).append(l)
557 after.setdefault(prepos, []).append(l)
564 script.append(l[4:])
558 script.append(l[4:])
565 elif l.startswith(' '): # results
559 elif l.startswith(' '): # results
566 # queue up a list of expected results
560 if inpython:
567 expected.setdefault(pos, []).append(l[2:])
561 script.append(l[2:])
562 after.setdefault(prepos, []).append(l)
563 else:
564 # queue up a list of expected results
565 expected.setdefault(pos, []).append(l[2:])
568 else:
566 else:
567 if inpython:
568 script.append("EOF\n")
569 inpython = False
569 # non-command/result - queue up for merged output
570 # non-command/result - queue up for merged output
570 after.setdefault(pos, []).append(l)
571 after.setdefault(pos, []).append(l)
571
572
573 if inpython:
574 script.append("EOF\n")
575
572 t.close()
576 t.close()
573
577
574 script.append('echo %s %s $?\n' % (salt, n + 1))
578 script.append('echo %s %s $?\n' % (salt, n + 1))
@@ -853,7 +857,7 b' def runone(options, test):'
853 refout = None # to match "out is None"
857 refout = None # to match "out is None"
854 elif os.path.exists(ref):
858 elif os.path.exists(ref):
855 f = open(ref, "r")
859 f = open(ref, "r")
856 refout = list(transformtst(splitnewlines(f.read())))
860 refout = list(splitnewlines(f.read()))
857 f.close()
861 f.close()
858 else:
862 else:
859 refout = []
863 refout = []
General Comments 0
You need to be logged in to leave comments. Login now