Unit test library for Inform 6?

Is there a unit test library somewhere for Inform 6?

If not, no problem, I can write one myself for my own needs! But I wouldn’t say no for some advice.

I’m thinking of something a bit like Python’s unittest with a UnitTest class that has assert methods. You could then write:

UnitTest "Unit test example"
with
    test [;
        self.assert_equal(1 + 1, 2);
        self.assert_greaterthan(3, 2);
    ]
;

And you would loop over the UnitTest objects and execute their test method. You could also add a before and after methods that are run before and after each test. (You could subclass UnitTest for that). We could also maybe group unit tests in a parent to have group-wide befores and afters.

It would be great to allow arbitrary-named methods (like test_A, test_B) and run every one that starts with “test”, but I don’ think Inform 6 has this level of introspection.

Any thoughts?

1 Like

Unfortunately it does not, no. But you could always run it through a preprocessor that creates a test_collation method that calls all other tests!

1 Like

Well, I’m not sure I want to go the preprocessor way.

Would it be possible to have a property holding an array of routines? (Like name but with routines instead of dict words.) Would it even be a good idea?

Else I think I can live with only one test routine per UnitTest object.

Sure. The I6 “before” and “after” properties are exactly this.