~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/script.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-11-08 11:35:49 UTC
  • mfrom: (5531.1.3 662509-ignore-empty)
  • Revision ID: pqm@pqm.ubuntu.com-20101108113549-e4mhhq2fe1i0etbf
(vila) Add an option to accept any output from commands in shell-like tests.
 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
196
196
        self.output_checker = doctest.OutputChecker()
197
197
        self.check_options = doctest.ELLIPSIS
198
198
 
199
 
    def run_script(self, test_case, text):
 
199
    def run_script(self, test_case, text, null_output_matches_anything=False):
200
200
        """Run a shell-like script as a test.
201
201
 
202
202
        :param test_case: A TestCase instance that should provide the fail(),
204
204
            attribute used as a jail root.
205
205
 
206
206
        :param text: A shell-like script (see _script_to_commands for syntax).
 
207
 
 
208
        :param null_output_matches_anything: For commands with no specified
 
209
            output, ignore any output that does happen, including output on
 
210
            standard error.
207
211
        """
 
212
        self.null_output_matches_anything = null_output_matches_anything
208
213
        for cmd, input, output, error in _script_to_commands(text):
209
214
            self.run_command(test_case, cmd, input, output, error)
210
215
 
245
250
            else:
246
251
                test_case.fail('expected output: %r, but found nothing'
247
252
                            % (expected,))
 
253
 
 
254
        null_output_matches_anything = getattr(
 
255
            self, 'null_output_matches_anything', False)
 
256
        if null_output_matches_anything and expected is None:
 
257
            return
 
258
 
248
259
        expected = expected or ''
249
260
        matching = self.output_checker.check_output(
250
261
            expected, actual, self.check_options)
473
484
        super(TestCaseWithMemoryTransportAndScript, self).setUp()
474
485
        self.script_runner = ScriptRunner()
475
486
 
476
 
    def run_script(self, script):
477
 
        return self.script_runner.run_script(self, script)
 
487
    def run_script(self, script, null_output_matches_anything=False):
 
488
        return self.script_runner.run_script(self, script, 
 
489
                   null_output_matches_anything=null_output_matches_anything)
478
490
 
479
491
    def run_command(self, cmd, input, output, error):
480
492
        return self.script_runner.run_command(self, cmd, input, output, error)
502
514
        super(TestCaseWithTransportAndScript, self).setUp()
503
515
        self.script_runner = ScriptRunner()
504
516
 
505
 
    def run_script(self, script):
506
 
        return self.script_runner.run_script(self, script)
 
517
    def run_script(self, script, null_output_matches_anything=False):
 
518
        return self.script_runner.run_script(self, script,
 
519
                   null_output_matches_anything=null_output_matches_anything)
507
520
 
508
521
    def run_command(self, cmd, input, output, error):
509
522
        return self.script_runner.run_command(self, cmd, input, output, error)
510
523
 
511
524
 
512
 
def run_script(test_case, script_string):
 
525
def run_script(test_case, script_string, null_output_matches_anything=False):
513
526
    """Run the given script within a testcase"""
514
 
    return ScriptRunner().run_script(test_case, script_string)
 
527
    return ScriptRunner().run_script(test_case, script_string,
 
528
               null_output_matches_anything=null_output_matches_anything)
515
529