Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# RedUnit

RedUnit is a free, open source **unit testing framework** for **Red** language.
RedUnit is a free, open source **unit testing framework** for **Red** language.
Inspired by xUnit, nUnit, PhpUnit and other similar libraries.

### Motivation

The main reason is the possibility to building your own projects faster and easier.

The TDD (test driven-development) approach is now possible using the **RedUnit** tool, so you can eliminate bad cases at the early stage.
The TDD (test driven-development) approach is now possible using the **RedUnit** tool, so you can eliminate bad cases at the early stage.

## Docs
## Docs

* [Getting started](docs/getting-started.md) - usage, assertions and error handling

Expand Down
10 changes: 5 additions & 5 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Version: **0.0.3**
Test framework for running tests of Red language scripts. Inspired by *PhpUnit*, *xUnit*, *nUnit* and other similar libraries.

**RedUnit** expects that you will give him a filepath (`file!`) to Red script with `object!`, which will contain test methods.
Each test method name should be started with word `test`.
Each test method name should be started with word `test`.

Optionally `setup` method will be executed before each test separately (only if `object!` consist method with name `setup`).

Expand Down Expand Up @@ -165,7 +165,7 @@ redunit/run %tests/poc-tests.red
Console output:

```bash
./red-063-linux -s examples/run-one-file.red
./red-063-linux -s examples/run-one-file.red
┌────────────────┐
│ RedUnit v0.0.3 │
└────────────────┘
Expand Down Expand Up @@ -203,7 +203,7 @@ FF...F...F
### Caused by assertions (example 1)

```bash
./red-063-linux examples/run-directory.red
./red-063-linux examples/run-directory.red
┌────────────────┐
│ RedUnit v0.0.3 │
└────────────────┘
Expand Down Expand Up @@ -250,11 +250,11 @@ Time: 84.951 ms
│ File : tests/poc-tests.red
│ Method : test-replace-unregistered-name

Runtime error detected, but there was not any assertion dedicated for expecting error.
Runtime error detected, but there was not any assertion dedicated for expecting error.

*** User Error: "Can not replace an unregistered object"
*** Where: do
*** Stack: rejoin first last cause-error
*** Stack: rejoin first last cause-error

┌─ ─┐
│ Status: Failure │
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/poc-tests.red
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ context [
"Registering not allowed types will throw an error"
] [
not-allowed-types: [
"string"
"string"
["list"]
1234
email@address.com
Expand Down
14 changes: 7 additions & 7 deletions src/modules/assertions.red
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Red [

context [
assertions-count: 0

increment-assertion: does [
assertions-count: assertions-count + 1
]
Expand All @@ -24,7 +24,7 @@ context [

assert-true: func [
"Value is true?"
value[logic!]
value[logic!]
] [
increment-assertion
unless value [
Expand All @@ -35,7 +35,7 @@ context [

assert-false: func [
"Value is false?"
value[logic!]
value[logic!]
] [
increment-assertion
if value [
Expand All @@ -50,7 +50,7 @@ context [
] [
increment-assertion
different-data: not (strict-equal? expected actual)

if different-data [
message: "Expected equivalent values, but they are different."
fail-test message "equals"
Expand All @@ -63,7 +63,7 @@ context [
] [
increment-assertion
same-data: strict-equal? expected actual

if same-data [
message: "Expected different values, but they are equivalent."
fail-test message "not-equals"
Expand All @@ -76,7 +76,7 @@ context [
] [
increment-assertion
different-memory-location: not (same? expected actual)

if different-memory-location [
message: "Expected identical values, regarding memory location, but they are different."
fail-test message "identical"
Expand All @@ -89,7 +89,7 @@ context [
] [
increment-assertion
identical-memory-location: same? expected actual

if identical-memory-location [
message: "Expected different values, regarding memory location, but they are identical."
fail-test message "not-identical"
Expand Down
6 changes: 3 additions & 3 deletions src/modules/general.red
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ context [
print-summary

comment {
CLI exit code for continuous integration
CLI exit code for continuous integration
(0 - success, 1 - failure)
}
quit-when-errors
]

set-test-filename-prefix: func [
set-test-filename-prefix: func [
text[string!]
] [
prefix: text
]

set-test-filename-postfix: func [
set-test-filename-postfix: func [
text[string!]
] [
postfix: text
Expand Down
38 changes: 19 additions & 19 deletions src/modules/internal.red
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ context [
testable: do code

run-object testable

; revert boot directory
change-dir boot-dir
]
Expand All @@ -61,7 +61,7 @@ context [
testable[object!]
] [
process-testable-methods testable

started: now/time/precise/utc

foreach test tests [
Expand All @@ -81,7 +81,7 @@ context [
setup-detected: false
tests: copy []

methods: words-of testable
methods: words-of testable

foreach method methods [
method-name: to string! method
Expand Down Expand Up @@ -115,8 +115,8 @@ context [

errors-before: length? errors

was-error: none? attempt [
result: try [do test]
was-error: none? attempt [
result: try [do test]
]

unless none? result [
Expand All @@ -139,14 +139,14 @@ context [
]

errors-after: length? errors

print-last-test-status errors-before errors-after
]

/local print-last-test-status: func [
errors-before[integer!] errors-after[integer!]
][
; Disable time for printing the console output
] [
; Disable time for printing the console output
printing-started: now/time/precise/utc

either errors-before <> errors-after [
Expand Down Expand Up @@ -207,10 +207,10 @@ context [
keys: reflect errors 'words
foreach key keys [
prin rejoin [
key
newline
select errors key
newline
key
newline
select errors key
newline
newline
]
]
Expand All @@ -219,7 +219,7 @@ context [
] [
print-cornered-header "Status: Success"
]

print-execution-time
print-counters
]
Expand All @@ -245,8 +245,8 @@ context [
steps: (length? header)
space: ""

loop steps [
space: rejoin [space space-char]
loop steps [
space: rejoin [space space-char]
]

prin rejoin [
Expand All @@ -261,8 +261,8 @@ context [
error-count: (length? errors)

prin rejoin [
length? tests " tests"
", " assertions-count " assertions"
length? tests " tests"
", " assertions-count " assertions"
]

if (error-count > 0) [
Expand All @@ -274,7 +274,7 @@ context [
]


;-- Returns EXIT CODE 1 - when there were some failed tests
;-- Returns EXIT CODE 1 - when there were some failed tests
/local quit-when-errors: does [
if (length? errors) > 0 [
quit-return 1
Expand Down Expand Up @@ -333,7 +333,7 @@ context [

pre-length: length? prefix
post-length: length? postfix

if filename-length < (pre-length + post-length) [
return false
]
Expand Down