~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/script.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-16 16:40:10 UTC
  • mto: This revision was merged to the branch mainline in revision 6391.
  • Revision ID: jelmer@samba.org-20111216164010-z3hy00xrnclnkf7a
Update tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
25
25
import os
26
26
import shlex
27
27
import textwrap
28
 
from cStringIO import StringIO
29
28
 
30
29
from bzrlib import (
31
 
    errors,
32
30
    osutils,
33
31
    tests,
34
32
    )
196
194
        self.output_checker = doctest.OutputChecker()
197
195
        self.check_options = doctest.ELLIPSIS
198
196
 
199
 
    def run_script(self, test_case, text):
 
197
    def run_script(self, test_case, text, null_output_matches_anything=False):
200
198
        """Run a shell-like script as a test.
201
199
 
202
200
        :param test_case: A TestCase instance that should provide the fail(),
204
202
            attribute used as a jail root.
205
203
 
206
204
        :param text: A shell-like script (see _script_to_commands for syntax).
 
205
 
 
206
        :param null_output_matches_anything: For commands with no specified
 
207
            output, ignore any output that does happen, including output on
 
208
            standard error.
207
209
        """
 
210
        self.null_output_matches_anything = null_output_matches_anything
208
211
        for cmd, input, output, error in _script_to_commands(text):
209
212
            self.run_command(test_case, cmd, input, output, error)
210
213
 
213
216
        method = getattr(self, mname, None)
214
217
        if method is None:
215
218
            raise SyntaxError('Command not found "%s"' % (cmd[0],),
216
 
                              None, 1, ' '.join(cmd))
 
219
                              (None, 1, 1, ' '.join(cmd)))
217
220
        if input is None:
218
221
            str_input = ''
219
222
        else:
245
248
            else:
246
249
                test_case.fail('expected output: %r, but found nothing'
247
250
                            % (expected,))
 
251
 
 
252
        null_output_matches_anything = getattr(
 
253
            self, 'null_output_matches_anything', False)
 
254
        if null_output_matches_anything and expected is None:
 
255
            return
 
256
 
248
257
        expected = expected or ''
249
258
        matching = self.output_checker.check_output(
250
259
            expected, actual, self.check_options)
472
481
    def setUp(self):
473
482
        super(TestCaseWithMemoryTransportAndScript, self).setUp()
474
483
        self.script_runner = ScriptRunner()
 
484
        # FIXME: See shelf_ui.Shelver._char_based. This allow using shelve in
 
485
        # scripts while providing a line-based input (better solution in
 
486
        # progress). -- vila 2011-09-28
 
487
        self.overrideEnv('INSIDE_EMACS', '1')
475
488
 
476
 
    def run_script(self, script):
477
 
        return self.script_runner.run_script(self, script)
 
489
    def run_script(self, script, null_output_matches_anything=False):
 
490
        return self.script_runner.run_script(self, script, 
 
491
                   null_output_matches_anything=null_output_matches_anything)
478
492
 
479
493
    def run_command(self, cmd, input, output, error):
480
494
        return self.script_runner.run_command(self, cmd, input, output, error)
501
515
    def setUp(self):
502
516
        super(TestCaseWithTransportAndScript, self).setUp()
503
517
        self.script_runner = ScriptRunner()
 
518
        # FIXME: See shelf_ui.Shelver._char_based. This allow using shelve in
 
519
        # scripts while providing a line-based input (better solution in
 
520
        # progress). -- vila 2011-09-28
 
521
        self.overrideEnv('INSIDE_EMACS', '1')
504
522
 
505
 
    def run_script(self, script):
506
 
        return self.script_runner.run_script(self, script)
 
523
    def run_script(self, script, null_output_matches_anything=False):
 
524
        return self.script_runner.run_script(self, script,
 
525
                   null_output_matches_anything=null_output_matches_anything)
507
526
 
508
527
    def run_command(self, cmd, input, output, error):
509
528
        return self.script_runner.run_command(self, cmd, input, output, error)
510
529
 
511
530
 
512
 
def run_script(test_case, script_string):
 
531
def run_script(test_case, script_string, null_output_matches_anything=False):
513
532
    """Run the given script within a testcase"""
514
 
    return ScriptRunner().run_script(test_case, script_string)
 
533
    return ScriptRunner().run_script(test_case, script_string,
 
534
               null_output_matches_anything=null_output_matches_anything)
515
535