Skip to content

Commit afa2f86

Browse files
committed
initial
0 parents  commit afa2f86

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# suite
2+
3+
is a simple test suite abstraction.
4+
5+
## Usage
6+
7+
```clojure
8+
(load "[email protected]:carpentry-org/[email protected]")
9+
10+
(use Test)
11+
12+
(Suite.defsuite addition
13+
(assert-equal test
14+
2
15+
(+ 1 1)
16+
"integer addition works")
17+
)
18+
19+
(Suite.defsuite subtraction
20+
(assert-equal test
21+
1
22+
(- 2 1)
23+
"integer subtraction works")
24+
)
25+
26+
; will compile and run all the suites
27+
(Suite.run-all)
28+
```
29+
30+
will produce:
31+
32+
```
33+
Running suite subtraction
34+
Test 'integer subtraction works' passed
35+
Results:
36+
|==|
37+
Passed: 1 Failed: 0
38+
Running suite addition
39+
Test 'integer addition works' passed
40+
Results:
41+
|==|
42+
Passed: 1 Failed: 0
43+
```
44+
45+
<hr/>
46+
47+
Cheers!

main.carp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(load "Test.carp")
2+
3+
(defmodule Suite
4+
(defdynamic *suites* [])
5+
6+
(defmacro defsuite [name :rest forms]
7+
(let-do [sym (gensym)]
8+
(eval
9+
`(defn %sym []
10+
(let-do [test &(Test.State.init 0 0)]
11+
(IO.println %(str "Running suite " name))
12+
%(cons-last
13+
`@(Test.State.failed test)
14+
(cons-last
15+
`(Test.print-test-results test)
16+
`(do %@(with-test-internal 'test forms)))))))
17+
(set! Suite.*suites* (cons sym Suite.*suites*))))
18+
19+
(defmacro run-all []
20+
(do
21+
(eval
22+
`(defn main []
23+
(do %@(map (fn [suite] `(ignore (%suite))) Suite.*suites*))))
24+
(build)
25+
(run)
26+
(quit)))
27+
)

tests.carp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(load "main.carp")
2+
3+
(use Test)
4+
5+
(Suite.defsuite addition
6+
(assert-equal test
7+
2
8+
(+ 1 1)
9+
"integer addition works")
10+
(assert-equal test
11+
2.0
12+
(+ 1.0 1.0)
13+
"double addition works")
14+
)
15+
16+
(Suite.defsuite subtraction
17+
(assert-equal test
18+
1
19+
(- 2 1)
20+
"integer subtraction works")
21+
(assert-equal test
22+
1.0
23+
(- 2.0 1.0)
24+
"double subtraction works")
25+
)
26+
27+
(Suite.run-all)

0 commit comments

Comments
 (0)