script tests fail with unspecified output

Bug #662509 reported by Neil Martinsen-Burrell
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
Undecided
Neil Martinsen-Burrell

Bug Description

With Martin's changes to bzrlib/tests/script.py, commands with unspecified output now result in an error. The docs in doc/developers/testing.txt clearly say "When no output is specified, any ouput from the command is accepted
and execution continue." however this is no longer the case. To reproduce:

$ echo "$ bzr init" > /tmp/testscript
$ bzr test-script /tmp/testscript
bzr selftest: /Users/nmb/src/bzr/bzr.dev/bzr
   /Users/nmb/src/bzr/bzr.dev/bzrlib
   bzr-2.3.0dev3 python-2.6.5 Darwin-10.4.0-i386-32bit

FAIL: script.Test.test_it
    Text attachment: log
------------
0.401 creating repository in file:///private/var/folders/o1/o1uqBGiCHxysyrhc-DXvGE%2B%2B%2BTI/-Tmp-/testbzr-osSDSK.tmp/.bzr/.
0.408 creating branch <bzrlib.branch.BzrBranchFormat7 object at 0x11b0390> in file:///private/var/folders/o1/o1uqBGiCHxysyrhc-DXvGE%2B%2B%2BTI/-Tmp-/testbzr-osSDSK.tmp/
0.427 trying to create missing lock '/private/var/folders/o1/o1uqBGiCHxysyrhc-DXvGE+++TI/-Tmp-/testbzr-osSDSK.tmp/.bzr/checkout/dirstate'
0.428 opening working tree '/private/var/folders/o1/o1uqBGiCHxysyrhc-DXvGE+++TI/-Tmp-/testbzr-osSDSK.tmp'
0.447 run bzr: ['init']
0.448 bazaar version: 2.3.0dev3
0.448 bzr arguments: ['init']
0.452 encoding stdout as sys.stdout encoding 'UTF-8'
0.456 bzr-hg: using Mercurial 1.6.3
0.466 creating repository in file:///private/var/folders/o1/o1uqBGiCHxysyrhc-DXvGE%2B%2B%2BTI/-Tmp-/testbzr-osSDSK.tmp/bzrlib.tests.script.Test.test_it/work/.bzr/.
0.472 creating branch <bzrlib.branch.BzrBranchFormat7 object at 0x1996730> in file:///private/var/folders/o1/o1uqBGiCHxysyrhc-DXvGE%2B%2B%2BTI/-Tmp-/testbzr-osSDSK.tmp/bzrlib.tests.script.Test.test_it/work/
0.490 trying to create missing lock '/private/var/folders/o1/o1uqBGiCHxysyrhc-DXvGE+++TI/-Tmp-/testbzr-osSDSK.tmp/bzrlib.tests.script.Test.test_it/work/.bzr/checkout/dirstate'
0.491 opening working tree '/private/var/folders/o1/o1uqBGiCHxysyrhc-DXvGE+++TI/-Tmp-/testbzr-osSDSK.tmp/bzrlib.tests.script.Test.test_it/work'
0.504 opening working tree '/private/var/folders/o1/o1uqBGiCHxysyrhc-DXvGE+++TI/-Tmp-/testbzr-osSDSK.tmp/bzrlib.tests.script.Test.test_it/work'
0.513 output:
'Created a standalone tree (format: 2a)\n'
0.525 opening working tree '/private/var/folders/o1/o1uqBGiCHxysyrhc-DXvGE+++TI/-Tmp-/testbzr-osSDSK.tmp'
------------
Text attachment: traceback
------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/testtools/runtest.py", line 144, in _run_user
    return fn(*args)
  File "/Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/testtools/testcase.py", line 465, in _run_test_method
    testMethod()
  File "/Users/nmb/src/bzr/bzr.dev/bzrlib/tests/script.py", line 538, in test_it
    self.run_script(script)
  File "/Users/nmb/src/bzr/bzr.dev/bzrlib/tests/script.py", line 507, in run_script
    return self.script_runner.run_script(self, script)
  File "/Users/nmb/src/bzr/bzr.dev/bzrlib/tests/script.py", line 210, in run_script
    self.run_command(test_case, cmd, input, output, error)
  File "/Users/nmb/src/bzr/bzr.dev/bzrlib/tests/script.py", line 229, in run_command
    raise AssertionError(str(e) + " in stdout of command %s" % cmd)
AssertionError: texts not equal:
+ Created a standalone tree (format: 2a)
 in stdout of command ['bzr', 'init']
------------

This change makes many, many falsely failing tests in bzr-colo which is a heavy consumer of script tests, particularly those with unspecified command output.

Related branches

Revision history for this message
John A Meinel (jameinel) wrote :

This was an intentional change, and the documentation should be updated to match.

The problem was that things were easily succeeding accidentally. We generally *do* care about what content is produced. If a given test does not care, I believe it can use:

>...

To say that it can match anything.

Changed in bzr:
status: New → Confirmed
Revision history for this message
Martin Pool (mbp) wrote : Re: [Bug 662509] Re: script tests fail with unspecified output

I'm really glad that you were finding script like tests useful, and
I'm sorry this inadvertently broke bzr-colo. Maybe we can get it
running in Babune to catch this earlier?

Anyhow, as John says, this was an intentional change, but we can also
learn from the feedback and there are a couple of options

1- Go through and add
...
in the tests, which is what I did for the builtin tests; then we can
mark this wontfix in bzr itself. That should still work against older
bzrs, if you're trying to support them from bzr-colo trunk.

2- Add an option on ScriptRunner that says "blank matches anything",
off by default. Then you can either explicitly turn it on in some
tests, or we could even add a fixture that turns it on across the
whole test class. This is a better choice if you really feel the
original behaviour is better rather than just needing an update. This
would be a bit like the options regexps have to match case-insensitive
or ignoring trailing whitespace...

If you want 2 I'll try to do it...

--
Martin

Revision history for this message
Neil Martinsen-Burrell (nmb) wrote :

On 2010-10-18 21:51 , Martin Pool wrote:
> I'm really glad that you were finding script like tests useful, and
> I'm sorry this inadvertently broke bzr-colo. Maybe we can get it
> running in Babune to catch this earlier?
>
> Anyhow, as John says, this was an intentional change, but we can also
> learn from the feedback and there are a couple of options
>
> 1- Go through and add
> ...
> in the tests, which is what I did for the builtin tests; then we can
> mark this wontfix in bzr itself. That should still work against older
> bzrs, if you're trying to support them from bzr-colo trunk.
>
> 2- Add an option on ScriptRunner that says "blank matches anything",
> off by default. Then you can either explicitly turn it on in some
> tests, or we could even add a fixture that turns it on across the
> whole test class. This is a better choice if you really feel the
> original behaviour is better rather than just needing an update. This
> would be a bit like the options regexps have to match case-insensitive
> or ignoring trailing whitespace...

I think that I am okay with 1. Besides the large one-time load of work
for me, it is a better design (explicit better than implicit). 2 would
be reasonably explicit, but I think that updating my tests to match the
style that is used for the builtin tests is the most consistent way
forward. Now to come up with the search-and-replace that does it all in
one fell swoop...

Changed in bzr:
status: Confirmed → Won't Fix
Revision history for this message
Neil Martinsen-Burrell (nmb) wrote :

Unfortunately, this seems like it is fairly ugly for lengthy script-based tests, making them look much, much less readable.

Consider the following original test for "bzr colo-branch --from-branch"

    def test_colo_branch_from(self):
        self.run_script("""
$ bzr colo-init
$ bzr ci -m 'commit in trunk' --unchanged
$ bzr colo-branch new
$ bzr ci -m 'commit in new branch' --unchanged
$ bzr colo-branch --from-branch=trunk new2
$ bzr log --line
1: ...
""")

This seems like a succinct description of what should work for the test, which is what Vincent intended when he created script-based tests from Maritza's idea. The new minimal working version is

    def test_colo_branch_from(self):
        self.run_script("""
$ bzr colo-init
...
$ bzr ci -m 'commit in trunk' --unchanged
2>...
$ bzr colo-branch new
2>...
$ bzr ci -m 'commit in new branch' --unchanged
2>...
$ bzr colo-branch --from-branch=trunk new2
2>...
$ bzr log --line
1: ...
""")

where it is even necessary to know which commands produce their output on stdout and which on stderr. This test is much less clear about what is supposed to be happening. I agree that we need a way to test if a command really does produce no output, but it seems like a bad trade-off to have to fill other tests that don't care about output with repeated explicit indications that they don't care about the output.

I thought this was wont-fix, but it looks like I would prefer a flag (False by default) for "ignore_blanks". I can certainly look at adding such a feature myself.

Changed in bzr:
status: Won't Fix → New
Revision history for this message
Martin Packman (gz) wrote :

I've found liberal use of -q for preparatory steps the easiest option. That way if something goes wrong you still fail on output mismatch.

Really though, script tests are not a substitute for proper unit tests. If you're writing a bunch where you don't actually care about the console interaction, I'd suggest that's a sign you need more focused testing.

Revision history for this message
Vincent Ladeuil (vila) wrote :

>>>>> Martin [gz] <email address hidden> writes:

    > I've found liberal use of -q for preparatory steps the easiest option.
    > That way if something goes wrong you still fail on output mismatch.

    > Really though, script tests are not a substitute for proper unit tests.
    > If you're writing a bunch where you don't actually care about the
    > console interaction, I'd suggest that's a sign you need more focused
    > testing.

Right, may be we should add that to the doc so I don't repeat it each
the meme surfaces again :)

Shell-like tests are *not* intended to replace unit tests, there main
target is people that don't know [yet] what unit test to write or just
want a way to easily reproduce a bug.

     Vincent

Vincent Ladeuil (vila)
Changed in bzr:
assignee: nobody → Neil Martinsen-Burrell (nmb)
status: New → In Progress
milestone: none → 2.3b3
Vincent Ladeuil (vila)
Changed in bzr:
milestone: 2.3b3 → none
Vincent Ladeuil (vila)
Changed in bzr:
milestone: none → 2.3b4
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.