Basic

Testing a compiler

A compiler is tested with pairs of source and answer. The pairs are a file, and the file is the contract of the language so far.

What you will see

change allowed. A failing pair would refuse, which is the gate.

About 1 min of reading

Try It

Write the contract file

1

Write a good pair

printf 'src=1+2 want=3\n' > /tmp/p.txt; cat /tmp/p.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line with both sides. Both sides written is the claim.
2

Write a bad pair

printf 'src=1+ want=place:2\n' >> /tmp/p.txt; wc -l < /tmp/p.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
2. The bad case is in the same file, which is the contract.
3

Run the suite and gate

printf 'fail=0\n' | awk '{print ($1=="fail=0") ? "change allowed" : "change refused"}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
change allowed. A failing pair would refuse, which is the gate.

Data Flow

A pair to a gate
1 The pair is written with both sides
↓
2 The bad pairs are written in the same file
↓
3 Every pair runs
↓
4 A failing pair refuses the change
Why this works
The suite gates the change

A language change that fails the suite is refused. The refusal is the same shape as every other refusal in this site.

When you have a choice

Why the tree is compared rather than the answer

Two trees can give one answer. Comparing the tree compares the meaning, which is the stronger claim.

Examples

The pair is source to answer

Both sides are written. A test with both sides written is a test that cannot be talked around.

The bad pairs are in the same file

A pair that expects a place is a pair like any other. The bad cases are part of the contract, not apart from it.

The file is the suite

Every pair runs. A suite that is a file is a suite that a change to the language must pass.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Errors that name a place
Previous Lesson
Errors that name a place
Next Lesson
Types as a claim about values
Types as a claim about values →