592 |
592 |
593 # We keep track of whether or not we're in a Python block so we |
593 # We keep track of whether or not we're in a Python block so we |
594 # can generate the surrounding doctest magic |
594 # can generate the surrounding doctest magic |
595 inpython = False |
595 inpython = False |
596 |
596 |
|
597 # True or False when in a true or false conditional section |
|
598 skipping = None |
|
599 |
|
600 def hghave(reqs): |
|
601 # TODO: do something smarter when all other uses of hghave is gone |
|
602 proc = Popen4('%s -c "%s/hghave %s"' % |
|
603 (options.shell, TESTDIR, ' '.join(reqs)), TESTDIR, 0) |
|
604 proc.communicate() |
|
605 ret = proc.wait() |
|
606 if wifexited(ret): |
|
607 ret = os.WEXITSTATUS(ret) |
|
608 return ret == 0 |
|
609 |
597 f = open(test) |
610 f = open(test) |
598 t = f.readlines() |
611 t = f.readlines() |
599 f.close() |
612 f.close() |
600 |
613 |
601 script = [] |
614 script = [] |
604 if os.getenv('MSYSTEM'): |
617 if os.getenv('MSYSTEM'): |
605 script.append('alias pwd="pwd -W"\n') |
618 script.append('alias pwd="pwd -W"\n') |
606 for n, l in enumerate(t): |
619 for n, l in enumerate(t): |
607 if not l.endswith('\n'): |
620 if not l.endswith('\n'): |
608 l += '\n' |
621 l += '\n' |
609 if l.startswith(' >>> '): # python inlines |
622 if l.startswith('#if'): |
|
623 if skipping is not None: |
|
624 after.setdefault(pos, []).append(' !!! nested #if\n') |
|
625 skipping = not hghave(l.split()[1:]) |
|
626 after.setdefault(pos, []).append(l) |
|
627 elif l.startswith('#else'): |
|
628 if skipping is None: |
|
629 after.setdefault(pos, []).append(' !!! missing #if\n') |
|
630 skipping = not skipping |
|
631 after.setdefault(pos, []).append(l) |
|
632 elif l.startswith('#endif'): |
|
633 if skipping is None: |
|
634 after.setdefault(pos, []).append(' !!! missing #if\n') |
|
635 skipping = None |
|
636 after.setdefault(pos, []).append(l) |
|
637 elif skipping: |
|
638 after.setdefault(pos, []).append(l) |
|
639 elif l.startswith(' >>> '): # python inlines |
610 after.setdefault(pos, []).append(l) |
640 after.setdefault(pos, []).append(l) |
611 prepos = pos |
641 prepos = pos |
612 pos = n |
642 pos = n |
613 if not inpython: |
643 if not inpython: |
614 # we've just entered a Python block, add the header |
644 # we've just entered a Python block, add the header |
615 inpython = True |
645 inpython = True |
616 addsalt(prepos, False) # make sure we report the exit code |
646 addsalt(prepos, False) # make sure we report the exit code |
617 script.append('%s -m heredoctest <<EOF\n' % PYTHON) |
647 script.append('%s -m heredoctest <<EOF\n' % PYTHON) |
618 addsalt(n, True) |
648 addsalt(n, True) |
619 script.append(l[2:]) |
649 script.append(l[2:]) |
620 if l.startswith(' ... '): # python inlines |
650 elif l.startswith(' ... '): # python inlines |
621 after.setdefault(prepos, []).append(l) |
651 after.setdefault(prepos, []).append(l) |
622 script.append(l[2:]) |
652 script.append(l[2:]) |
623 elif l.startswith(' $ '): # commands |
653 elif l.startswith(' $ '): # commands |
624 if inpython: |
654 if inpython: |
625 script.append("EOF\n") |
655 script.append("EOF\n") |
642 # non-command/result - queue up for merged output |
672 # non-command/result - queue up for merged output |
643 after.setdefault(pos, []).append(l) |
673 after.setdefault(pos, []).append(l) |
644 |
674 |
645 if inpython: |
675 if inpython: |
646 script.append("EOF\n") |
676 script.append("EOF\n") |
|
677 if skipping is not None: |
|
678 after.setdefault(pos, []).append(' !!! missing #endif\n') |
647 addsalt(n + 1, False) |
679 addsalt(n + 1, False) |
648 |
680 |
649 # Write out the script and execute it |
681 # Write out the script and execute it |
650 fd, name = tempfile.mkstemp(suffix='hg-tst') |
682 fd, name = tempfile.mkstemp(suffix='hg-tst') |
651 try: |
683 try: |
1195 # can't remove on solaris |
1227 # can't remove on solaris |
1196 os.environ[k] = '' |
1228 os.environ[k] = '' |
1197 del os.environ[k] |
1229 del os.environ[k] |
1198 |
1230 |
1199 global TESTDIR, HGTMP, INST, BINDIR, PYTHONDIR, COVERAGE_FILE |
1231 global TESTDIR, HGTMP, INST, BINDIR, PYTHONDIR, COVERAGE_FILE |
1200 TESTDIR = os.environ["TESTDIR"] = os.getcwd() |
1232 TESTDIR = os.environ["TESTDIR"] = os.getcwd().replace('\\', '/') |
1201 if options.tmpdir: |
1233 if options.tmpdir: |
1202 options.keep_tmpdir = True |
1234 options.keep_tmpdir = True |
1203 tmpdir = options.tmpdir |
1235 tmpdir = options.tmpdir |
1204 if os.path.exists(tmpdir): |
1236 if os.path.exists(tmpdir): |
1205 # Meaning of tmpdir has changed since 1.3: we used to create |
1237 # Meaning of tmpdir has changed since 1.3: we used to create |