Writing a primitive test first in Exupery

bryce at kampjes.demon.co.uk bryce at kampjes.demon.co.uk
Mon Jun 18 20:38:35 UTC 2007


Here's a quick sketch of what's needed to write a primitive test
first in Exupery. This is aimed at getting Yakov started on his
SummerTalk project but should also be useful to others who wish
to write primitives for Exupery.

Exupery is written test first using two layers of testing. First
story tests are written to cover the functionality, they run compiled
methods and check the compiled method does the right thing. Then
programmer tests are written to cover the actual code. Ideally all
new functionality is covered by both a full set of story tests and
programmer tests. 

Primitive code is implemented in IntermediateSimplifier which
converts high level intermediate into low level intermediate.

I normally write the story tests first, often all the ones I can think
of while reading through the interpreters implementation.  Then I
write the programmer tests one by one while implementing the code. I
normally run the story tests to figure out what programmer test is
needed next.

First write a story test:

      ExuperyStoryTests>>testReturnTrue
	self compile: ' ^ true'.
	self should: [self example = true]

This test will cover the case where the method is compiled
directly, another test may be written to handle the inlined
case for completeness.

Now look at IntermediateSimplifierTests>>testAtPrimitive. Use
this as an example to write a test for the "^ true" primitive.
It should be possible to figure out what the primitive number is
by debugging the failing testReturnTrue test.

Browse around IntermediateEmitter to find out what facilities are
there. In this case trueAddress and falseAddress look interesting.
MockIntermediateEmitter is used during testing, it checks that the
simplifier is producing the right intermediate and fails immediately
if there's a problem. The aim is to write a test then write the code
in the debugger produced from the failing test.

Bryce


More information about the Exupery mailing list