Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 119 lines (87 sloc) 2.243 kB
e8f9e72 @vito kernel reorganization; add atomy module
authored
1 use("atomy")
7ebfce2 @vito refactor io printing methods into module functions
authored
2
0739d7d @vito use locals for qualified imports
authored
3 io = require("io")
5514b4f @vito remove send_message silliness; just be explicit
authored
4 condition = require("condition")
78c90cf @vito clean up therie
authored
5
bc2282b @vito cleanups
authored
6 nesting-level = dynamic(0)
7 running-stats = dynamic
2bf6ba3 clean-up and document therie
Alex Suraci authored
8
98d7af6 @vito use . rather than # for particles/symbols
authored
9 data(Stats(@passed = 0, @failed = 0))
2bf6ba3 clean-up and document therie
Alex Suraci authored
10
00d271c @vito introduce functions
authored
11 indented(s) = " " * (^nesting-level * 2) + s
78c90cf @vito clean up therie
authored
12
00d271c @vito introduce functions
authored
13 colored(color, s) = do:
416a17f @vito update kernel/ and lib/ for constant changes
authored
14 unless(^(io OutputPort) tty?):
78c90cf @vito clean up therie
authored
15 return(s)
16
bc2282b @vito cleanups
authored
17 codes = [
18 .black
19 .red
20 .green
21 .yellow
22 .blue
23 .magenta
24 .cyan
25 .white
26 ]
78c90cf @vito clean up therie
authored
27
bc2282b @vito cleanups
authored
28 i"\e[3#{codes index(color)}m#{s}\e[0m"
78c90cf @vito clean up therie
authored
29
4e396b6 remove in-code documentation experiment
Alex Suraci authored
30
7fabf05 @vito move BlockPass out of arglists, add particle proc-arg shorthand
authored
31 theorize &tests :=
bc2282b @vito cleanups
authored
32 let(running-stats = Stats new):
4e396b6 remove in-code documentation experiment
Alex Suraci authored
33 tests call
7ebfce2 @vito refactor io printing methods into module functions
authored
34 puts("")
4e396b6 remove in-code documentation experiment
Alex Suraci authored
35
236fec5 @vito cleanups
authored
36 stats = ^running-stats
37
38 puts(
39 f"total of %d tests (%s passed, %s failed)" [
40 stats failed + stats passed
41 colored(.green, stats passed)
42 if(stats failed == 0)
43 then: "0"
44 else: colored(.red, stats failed)
45 ])
46
47 stats
4e396b6 remove in-code documentation experiment
Alex Suraci authored
48
49
7fabf05 @vito move BlockPass out of arglists, add particle proc-arg shorthand
authored
50 describe(what) &body := do:
7ebfce2 @vito refactor io printing methods into module functions
authored
51 puts(indented(f"- %s" [what]))
4e396b6 remove in-code documentation experiment
Alex Suraci authored
52
bc2282b @vito cleanups
authored
53 let(nesting-level = ^nesting-level + 1):
4e396b6 remove in-code documentation experiment
Alex Suraci authored
54 body call
55
56 nil
57
58
7fabf05 @vito move BlockPass out of arglists, add particle proc-arg shorthand
authored
59 it(description) &tests := do:
4e396b6 remove in-code documentation experiment
Alex Suraci authored
60 { tests call
7ebfce2 @vito refactor io printing methods into module functions
authored
61 puts(indented(colored(.green, f"✓ %s" [description])))
4e396b6 remove in-code documentation experiment
Alex Suraci authored
62 } rescue {
63 e:
bc2282b @vito cleanups
authored
64 when(^running-stats):
65 ^running-stats failed += 1
4e396b6 remove in-code documentation experiment
Alex Suraci authored
66
7ebfce2 @vito refactor io printing methods into module functions
authored
67 puts(indented(colored(.red, f"✗ %s" [description])))
68 puts(
69 indented(
70 colored(
71 .yellow
72 f" ` %s: %s" [
73 e class name
74 e message
75 ])))
4e396b6 remove in-code documentation experiment
Alex Suraci authored
76
40c1283 @vito use and/or/not errywhere
authored
77 e backtrace first((ENV["THERIE_BT_LIMIT"] or 5) to-i) each [l]:
7ebfce2 @vito refactor io printing methods into module functions
authored
78 puts(indented(f" %s" [colored(.cyan, l)]))
4e396b6 remove in-code documentation experiment
Alex Suraci authored
79 } else:
bc2282b @vito cleanups
authored
80 when(^running-stats):
81 ^running-stats passed += 1
4e396b6 remove in-code documentation experiment
Alex Suraci authored
82
83 nil
84
85
86 macro(~x should ~(check: Block)):
87 `(unless(~x onto ~check):
66c9bfc @vito refactor pretty kernel to use module functions
authored
88 raise(f"assertion failed for %v" ['~x]))
4e396b6 remove in-code documentation experiment
Alex Suraci authored
89
90
91 x should-be(y) :=
92 unless(x == y):
93 raise(f"expected %v, got %v" [y, x])
94
95
96 x should-raise(y) :=
97 x rescue {
98 e ->
52fb31e @vito fully inflexible identifiers
authored
99 unless(e kind-of(y)?):
52dc18e cleanup should-raise reporting
Alex Suraci authored
100 raise(f"expected exception %s, got: %s" [y, e class])
4e396b6 remove in-code documentation experiment
Alex Suraci authored
101 } else:
102 raise("#should-raise - no exception raised")
103
104
105 x should-error(y) :=
106 { with-restarts(errored -> nil):
107 x call
108 raise("#should-error - no error signaled")
109 } bind {
110 (e: ExceptionError) ->
111 raise(e exception)
112
113 (e: Error):
52fb31e @vito fully inflexible identifiers
authored
114 when(e kind-of(y)?):
5514b4f @vito remove send_message silliness; just be explicit
authored
115 condition restart(.errored)
210dbfe use a dynamic var for therie nesting level
Alex Suraci authored
116
4e396b6 remove in-code documentation experiment
Alex Suraci authored
117 raise(f"expected error %s, got: %s" [y, e message])
118 }
Something went wrong with that request. Please try again.