Testing
Quill has first-class support for testing. No frameworks to install, no configuration to write. Just use test and expect.
Test blocks
A test block groups related assertions under a descriptive name:
test "basic math":
expect 2 + 2 is 4
expect 10 - 3 is 7
expect 3 * 4 is 12
When you run this, you will see:
✓ basic math
1 passed, 0 failed
If a test fails:
✗ basic math: Expected (2 + 2) === 5 to be true
0 passed, 1 failed
The expect keyword
expect takes an expression that should evaluate to true. If the expression is false, the test fails with an error message.
-- Equality
expect name is "Alice"
-- Comparisons
expect age is greater than 18
expect count is less than 100
-- Membership
expect colors contains "red"
-- Function results
expect length("hello") is 5
expect upper("hello") is "HELLO"
Testing functions
Define your functions, then write tests for them:
to add a b:
give back a + b
to multiply a b:
give back a * b
to isEven n:
give back n % 2 is 0
test "addition":
expect add(2, 3) is 5
expect add(-1, 1) is 0
expect add(0, 0) is 0
test "multiplication":
expect multiply(3, 4) is 12
expect multiply(0, 100) is 0
expect multiply(-2, 3) is -6
test "even numbers":
expect isEven(4)
expect not isEven(3)
Running tests
Run your test file just like any Quill program:
quill run tests.quill
Or use the dedicated test command that only runs test blocks:
quill test tests.quill
Example output:
✓ addition
✓ multiplication
✓ even numbers
3 passed, 0 failed
Best practices
- Give each test a descriptive name that explains what it tests
- Keep tests small and focused -- one concept per test block
- Test edge cases: zero, negative numbers, empty strings, empty lists
- Place test files alongside your code with a
_testsuffix (e.g.,math_test.quill)
A complete test file
-- string_test.quill
test "upper and lower":
expect upper("hello") is "HELLO"
expect lower("HELLO") is "hello"
test "trim":
expect trim(" hi ") is "hi"
test "startsWith and endsWith":
expect startsWith("hello", "he")
expect endsWith("hello", "lo")
expect not startsWith("hello", "lo")
test "replace":
expect replace_text("hello world", "world", "Quill") is "hello Quill"
test "split and join":
words are split("a,b,c", ",")
expect length(words) is 3
expect join(words, "-") is "a-b-c"
Try it out! You can run test blocks in the Playground -- select the "Testing" example to see tests in action.