Loading ...
Sorry, an error occurred while loading the content.

423Re: [extremeperl] Declarative Testing

Expand Messages
  • Rob Nagler
    Aug 31, 2005
      Curtis Poe writes:
      > Despite the complaints that Adrian Howard's code had a lot of
      > duplication, the Bivio code still had duplication in the call to
      > Bivio::DieCode->DIE.

      That is an interesting point, and one I have struggle with for some
      time. There's also the class name duplication "EMA". The name of any
      thing in bOP is the file in which it resides (class) and its entry
      point (sub). We don't export variables except in one case
      (Bivio::IO::Trace). The name Bivio::DieCode->DIE is *long*, but it
      does not duplicate the concept it implements.

      I believe you didn't make as big of a deal about the duplicate EMA,
      because it is short. Bivio::Test is repeated, and so is use strict.
      I have considered dropping both as we have done in our acceptance
      infrastructure, which provides an excellent extension mechanism with
      short names. Here's how I might refactor it:

      EMA => [
      new => [
      -2 => DIE(),
      0 => DIE(),
      2.5 => DIE(),
      1 => undef,

      These could be "bunit" files, just like our acceptance tests (which
      require and interpreter to run) are called "btest". Something I may
      get around to.

      > use Bivio::Test;
      > Bivio::Test->new('EMA')->unit([
      > # is the duplicate "EMA" necessary?
      > EMA => [
      > new => [
      > [ -2, 0, 2.5 ] => Bivio::DieCode->DIE,
      > 1 => undef,
      > ],
      > ],
      > ]);

      There's a problem with this refactoring. The non-shortcut syntax for
      a method's input is:

      [1] => undef,

      This means pass a single argument to the method, and ignore the return
      result. Since single argument methods are common in bOP, the
      shorthand is this:

      1 => undef,

      It's syntactic sugar, which removes clutter. However if EMA took
      another argument, it would have to be in brackets:

      [1, 'other arg'] => undef,

      Here's how I would refactor it to remove the duplication of DIE:

      EMA => [
      new => [
      map(($_ => Bivio::DieCode->DIE), -2, 0, 2.5),
      1 => undef,

      While this removes the duplication, it introduces a new concept
      (different inputs yielding the same result). We often use map, but I
      wrote this test in the spirit of "one line per case". That's "good
      enough" for me, and it does serve as excellent documentation. OTOH,
      you are absolutely correct that it requires unnecessary duplication.

      > Given that most are unlikely to use Bivio, perhaps someone can propose
      > a Test::Declare framework using Perl's standard testing tools? What
      > would the syntax be?

      Talk about NIH. ;-) I would expect that you would find that any
      serious attempt at Test::Declarative would run into the same problems
      that Bivio::Test has: abstractions are difficult to understand.
      However, the more the merrier. :-)

    • Show all 8 messages in this topic