/
testing.ysh
99 lines (80 loc) · 1.72 KB
/
testing.ysh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# testing.ysh
#
# Usage:
# source --builtin testing.sh
#
# func f(x) { return (x + 1) }
#
# describe foo {
# assert (43 === f(42))
# }
#
# if is-main {
# run-tests @ARGV # --filter
# }
module stdlib/testing || return 0
source --builtin args.ysh
# Opt in to lazy evaluation
proc assert ( ; cond LAZY ) {
echo hi
# TODO: evalExpr() builtin
var val = evalExpr(cond)
if (not val) {
# TODO: if it's an expr.Binary
# Then
#
# Then print $left != $right
#
# I think you need to introspect on the source code
#
# Or print '5 != 3'
#
# Or you can evaluate left and right separately, and then compare them
echo
}
}
# What happens when there are duplicate test IDs?
#
# Also I think filter by "$test_id/$case_id"
proc __it (case_id ; ; ; block) {
# This uses a clean directory
echo TODO
}
# is this accessible to users?
# It can contain a global list of things to run
# Naming convention: a proc named 'describe' mutates a global named _describe?
# Or maybe _describe_list ?
var _describe_list = []
proc describe (test_id ; ; ; block) {
echo describe
= desc
# TODO:
# - need append
# - need ::
# _ _describe->append(cmd)
#
# Need to clean this up
# append (_describe, cmd) # does NOT work!
_ _describe_list->append(block)
}
# Problem: this creates a global variable?
Args :spec {
flag --filter 'Regex of test descriptions'
}
proc run-tests {
# TODO: fix this crap
var opt = null
var i = null
setvar opt, i = parseArgs(spec, ARGV)
# TODO:
# - parse --filter foo, which you can use eggex for!
for cmd in (_describe) {
# TODO: print filename and 'describe' name?
try {
eval (cmd)
}
if (_status !== 0) {
echo 'failed'
}
}
}