jckarter/clay — Issue #131: In-module test library
Author: jckarter
Created: 2012-01-03 20:30:26+00:00
State: open

The current options for testing Clay code all kind of suck. A better option would be something more like D or Rust's in-line testing support. A `test.module` module could provide a `testMain` function that looks through the main module for member functions beginning with `TEST_` and returning `Bool`, and execute all of those functions. The compiler frontend could then be given a `-main=testMain` flag to set a custom entry point.

```
// sum.clay
public import test.module.(testMain);

in sum;

sum(xs) = reduce(add, 0, xs);

TEST_empty_sum() = sum(Vector[Int]()) == 0;
TEST_single_sum() = sum(Vector[Int](1)) == 1;
TEST_multi_sum() = sum(Vector[Int](1,2,3)) == 6;
```

```
clay -main=testMain -run sum.clay
```