https://github.com/rickbarretto/unitt
Unitt is a basic unit-test tool for the Arturo Programming language.
https://github.com/rickbarretto/unitt
arturo arturo-lang package unit-tests
Last synced: 5 months ago
JSON representation
Unitt is a basic unit-test tool for the Arturo Programming language.
- Host: GitHub
- URL: https://github.com/rickbarretto/unitt
- Owner: RickBarretto
- License: mit
- Created: 2024-01-26T18:49:57.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-04T19:45:01.000Z (5 months ago)
- Last Synced: 2025-05-12T05:49:38.702Z (5 months ago)
- Topics: arturo, arturo-lang, package, unit-tests
- Homepage: https://unitt.pkgr.art/
- Size: 9.32 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
Unitt
Unitt is a lean unit-test tool for the
Arturo Programming language
![]()
![]()
## At a Glance
![]()
## Trying Unitt
**Installation**
```
arturo -p install unitt
```**Setup & Execution**
Create the file `test` on the root of your project:
```art
#! arturoimport {unitt}!
tryOr: $[action :block alt :any][
(throws? [val:] ++ action)? -> alt -> val
]files: switch empty? args\values
-> findTests "tests"
-> args\valuesrunTests
.fatal: tryOr [args\fatal] false
.suppress: tryOr [args\suppress] false
files
``````sh
# Runs test/test*.art by default
./test
``````sh
# Glob Pattern from Shell
./test test/*test.art
```### Testing code
A real example of tests:
```art
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===== ========== =====
```## Documentation
### *Unitt*
- `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 the `it`/`test` case,
makes an assertion given the `condition`.
- `.to :literal` (or `.be`)
Uses some function to evaluate the statement.
This helps to show the function name on display,
instead of a `true`/`false`.
- `.static :logical`:
Shows it as static code.## *Compatibility*
This section includes the old-syntax inspired by XUnit.
Kept for compatibilities with our 1st version.- `test: $[description :string, testCase :block]`:
The same as `it`.
Not only kept for compatibility issues,
but great to be used when not into a `describe`/`suite` block.
- `.prop`
- `.skip :logical`
- `assert: $[condition :block]`:
The same as `expects`
- `.with`
The same as `.to` and `.be`
- `.static: :logical`
- `suite: $[description :string tests :block]`:
The same as `describe`.### *Setup*
- `runTests: $[tests [:string]]`:
The *runner function*, this executes all `tests`,
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* inside `folder`.
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.> [!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"](#at-a-glance)
by [Artem Sapegin](https://unsplash.com/@sapegin?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash)
on [Unsplash](https://unsplash.com/photos/brown-wooden-boat-floating-on-body-of-water-XGDBdSQ70O0?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash)