Unitt is a lean unit-test tool for the
Arturo Programming language
Installation
arturo -p install unitt
Setup & Execution
Create the file test
on the root of your project:
#! arturo
import {unitt}!
tryOr: $[action :block alt :any][
(throws? [val:] ++ action)? -> alt -> val
]
files: switch empty? args\values
-> findTests "tests"
-> args\values
runTests
.fatal: tryOr [args\fatal] false
.suppress: tryOr [args\suppress] false
files
# Runs test/test*.art by default
./test
# Glob Pattern from Shell
./test test/*test.art
A real example of tests:
import {unitt}!
unix?: true
describe "binary appending" [
it "should operate integers" [
b: to :binary 0
expects.be: 'equal? @[as.binary 2 append b 1]
expects.be: 'equal? @[as.binary 1 b ++ 1]
]
it "should return a binary" [
b: to :binary 0
expects.be: 'binary? @[append b 1]
expects.be: 'binary? @[b ++ 1]
]
]
test.skip: unix? "split should deal with windows's paths" [
expects.be: 'equal? @[
["." "splited" "path"]
split.path ".\\splited\\path"
]
]
test "split should deal with unix path" [
expects.be: 'equal? @[
["." "splited" "path"]
split.path "./splited/path"
]
]
This will show you:
===== example.art =====
Suite: binary appending
❌ - assert that should operate integers
❌: equal? 10 00 01
❌: equal? 1 00 01
✅ - assert that should return a binary
✅: binary? 00 01
✅: binary? 00 01
⏩ - assert that split should deal with windows's paths
skipped!
✅ - assert that split should deal with unix path
✅: equal? ["." "splited" "path"] ["." "splited" "path"]
===== Statistics =====
⏏️ TOTAL: 3 assertions
✅ PASSED: 2 assertions
⏩ SKIPPED: 1 assertions
❌ FAILED: 1 assertions
===== ========== =====
describe: $[description :string tests :block]
: Groups tests around some feature.it: $[description :string, testCase :block]
: The test case itself, you need to pass a clear description to it, And the logic that you're trying to assert..prop
: Indicates that a test is property-based. The indicator is the~
separator on the description..skip :logical
: Skips tests for some condition. Will just skip if no condition is provided.
expects: $[condition :block]
: A function that is only available inside theit
/test
case, makes an assertion given thecondition
..to :literal
(or.be
) Uses some function to evaluate the statement. This helps to show the function name on display, instead of atrue
/false
..static :logical
: Shows it as static code.
This section includes the old-syntax inspired by XUnit. Kept for compatibilities with our 1st version.
test: $[description :string, testCase :block]
: The same asit
. Not only kept for compatibility issues, but great to be used when not into adescribe
/suite
block..prop
.skip :logical
assert: $[condition :block]
: The same asexpects
.with
The same as.to
and.be
.static: :logical
suite: $[description :string tests :block]
: The same asdescribe
.
runTests: $[tests [:string]]
: The runner function, this executes alltests
, show statistics and return a value..fatal
: Fails on the first error found (per file)..suppress
: Always return 0 as error code.
findTests: $[folder :string]
: Looks for tests insidefolder
. The default test pattern is "test*.art"..thatMatches :string
: Defines what is a test-file via a kind-of glob pattern. Use a*
as spliter.- Obs.: That is a kind-of glob pattern, not a real one.
So just use one and only one
*
to split the pre and suffix.
- Obs.: That is a kind-of glob pattern, not a real one.
So just use one and only one
Warning
Never import this lib as .lean
, or this will break the current code.
This happens due to the nature of Arturo (being concatenative),
and the way we importings are working right now.
This may change in future.
Background photo on "At a Glance" by Artem Sapegin on Unsplash