/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/script.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-10-15 11:33:33 UTC
  • mfrom: (5455.1.6 test-script)
  • Revision ID: pqm@pqm.ubuntu.com-20101015113333-auzmqh8gqjkzlgg0
(vila) Add a new hidden ``test-script`` command (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from cStringIO import StringIO
29
29
 
30
30
from bzrlib import (
 
31
    commands,
 
32
    errors,
31
33
    osutils,
32
34
    tests,
33
35
    )
511
513
def run_script(test_case, script_string):
512
514
    """Run the given script within a testcase"""
513
515
    return ScriptRunner().run_script(test_case, script_string)
 
516
 
 
517
 
 
518
class cmd_test_script(commands.Command):
 
519
    """Run a shell-like test from a file."""
 
520
 
 
521
    hidden = True
 
522
    takes_args = ['infile']
 
523
 
 
524
    @commands.display_command
 
525
    def run(self, infile):
 
526
 
 
527
        f = open(infile)
 
528
        try:
 
529
            script = f.read()
 
530
        finally:
 
531
            f.close()
 
532
 
 
533
        class Test(TestCaseWithTransportAndScript):
 
534
 
 
535
            script = None # Set before running
 
536
 
 
537
            def test_it(self):
 
538
                self.run_script(script)
 
539
 
 
540
        runner = tests.TextTestRunner(stream=self.outf)
 
541
        test = Test('test_it')
 
542
        test.path = os.path.realpath(infile)
 
543
        res = runner.run(test)
 
544
        return len(res.errors) + len(res.failures)