On 29 October 2011 18:20, Michael G Schwern <schw...@pobox.com> wrote: > On 2011.10.29 1:51 AM, Adrian Howard wrote: >> On 29 Oct 2011, at 09:18, Michael G Schwern <schw...@pobox.com> wrote: >> [snip] >>> Do you find *blocks with their own name and plan* convenient, or subtests >>> which have their own separate test state (as currently implemented) >> >> This may be me being dim - but I'm not really groking the distinction you're >> making. Could you give an example of the kind of difference that you're > proposing? > > It's *mostly* internal, but here's an example to explain the difference. > > Here's how subtests currently work: > > use Test::More; > > pass("First test"); > > subtest 'An example subtest' => sub { > plan tests => 2; > > pass("This is a subtest"); > pass("So is this"); > }; > > pass("Third test"); > > done_testing(); > __END__ > This would produce. > > ok 1 - First test > 1..2 > ok 1 - This is a subtest > ok 2 - So is this > ok 2 - An example subtest > ok 3 - Third test > 1..3 > > As far as the state of the test is concerned, there's not a lot of difference > between > > subtest 'An example subtest' => sub { > plan tests => 2; > > pass("This is a subtest"); > pass("So is this"); > }; > > and > > pass("An example subtest"); > > The subtest is one test. Its internals have no more effect on the overall > test than any single test, whether it runs one or one hundred. > > What I'm asking would it make much difference to how subtests are used if it > was like this: > > use Test::More; > > pass("First test"); > > subtest 'An example subtest' => sub { > plan tests => 2; > > pass("This is a subtest"); > pass("So is this"); > }; > > pass("Last test"); > > done_testing(); > __END__ > This would produce. > > ok 1 - First test > # An example of a subtest > ok 2 - This is a subtest > ok 3 - So is this > ok 4 - Last test > 1..4 > > Now the subtest is just a block with its own name and plan. The plan is > internally enforced by Test::Builder, TB makes sure that two tests are run > inside the block. Otherwise tests run inside a subtest are no different from > any other. > > Another example is: > > subtest 'An example subtest' => sub { > plan tests => 2; > plan skip_all => "Because" if $something; > > pass("This is a subtest"); > pass("So is this"); > }; > > would become exactly equivalent to: > > SKIP: { > skip "Because", 2 if $something; > > pass("This is a subtest"); > pass("So is this"); > } > > It becomes just a better way of writing a skip block. > > David already pointed out that if you're the sort of person who eyeballs TAP > (I do), the indentation is a nice visual distinction. Anything else?
It seems like it's impossible then to declare a global plan in advance if you use subtests unless you go counting all the sub tests which is no fun, F > > -- > Alligator sandwich, and make it snappy! >