On Wed, 21 Jan 2009, Dave Whipp wrote:

Moritz Lenz wrote:
A few months ago Larry proposed to add some testing
facilites to the language itself, because we want to
culturally encourage testing, and because the test
suite defines the language, so we need to specify the
behaviour of our testing facilities anyway.

If we're going to revamp the testing primitives, then I'd like to suggest importing some concepts from hardware verification langauges, whose entire purpose is to define tests. Not too much, but just a few defns:

        I love the basic ideas, but I have a few queries along the way.

* Define a "property" as an expression whose truth is of interest (properties may be named, or may be anonymous inline).

* An "assert <property>" statement (aka "ok <property>") indicates that a violation of the property is to be considered an error

* An "assume <property>" statement indicates that a violation of the property implies an incorrect test.

It seems to me that, from your description, that "assert <property>" is more like:

if(! <property>) { throw exception }

        ...and that assume <property> is more like ok().

class Foo {
 has $.a;
 has $.b;

 property conserve_sum { $.a + $.b == 42 },
   "a+b must sum to 42, but a=$.a + b=$.b == { $.a+$.b }";

 method foo() does assume<conserve_sum> { ... }
 method bar() does ensure<conserve_sum> { ... }

        Is "ensure" equivalent to the "assert" that you describe above?

 method baz() { bar; ok conserve_sum; foo; }

I'd suggest that we don't even need to have "ok" here; we'd be better off just going "conserve_sum()", and assuming that, because it's a property, the "ok" will be automatically attached. I know you're not being picky about syntax at the moment, but I wanted to throw the idea into the ring.

An interesting type of property is one that tracks a series of events through time: a so called "temporal" property. A simple idea might be that "conserve_sum" should actually mean "sum does't change", instead of "is constant 42":

class Foo {
 ...

 coro property conserve_sum {
   my $sum = $.a + $.b;
   leave True;
   ok $.a + $.b == $sum,
      "sum not conserved: expected $sum, actual {$.a+$.b}"
 }

 method foo() does maintain<conserve_sum> { --$.a; ++$.b }
}

        Vote++ :)


---------------------------------------------------------------------
| Name: Tim Nelson                 | Because the Creator is,        |
| E-mail: wayl...@wayland.id.au    | I am                           |
---------------------------------------------------------------------

----BEGIN GEEK CODE BLOCK----
Version 3.12
GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y-
-----END GEEK CODE BLOCK-----

Reply via email to