Skip to content

Commit 93f0992

Browse files
authored
Tester improvements (refactor, report, arbitrary validators) (#163)
- feature: eucalypt's test mode (`eu -T`) now generates an HTML test report including results and stdout / stdin of the test execution - feature: HTML test reports generated by `eu -T` can now be automatically opened in a browser using the `-O` flag - fix: error message fix - no longar panics on invalid yaml or json - feature: The experimental test mode now supports arbitrary validations applied to the output. Single argument functions in the test subject file can be listed in the `:validations` key of the test target metadata. These run against the evidence data generated by the test and have access to `stdout`, `stderr`, `result`, `stats`
1 parent 5152831 commit 93f0992

22 files changed

+753
-223
lines changed

Cargo.lock

+31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ toml = { version = "0.5.8", features = ["preserve_order"] }
3838
dirs = "3.0.2"
3939
html5ever = "0.25.1"
4040
lru = "0.6.5"
41+
uuid = { version = "0.8.2", features = ["serde", "v4"] }
42+
webbrowser = "0.5.5"
4143

4244
[[bench]]
4345
harness = false

Eufile

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ new-version: [version.major,
6363

6464
` {target: :build-meta
6565
doc: "build metadata to embed as resource in binary"}
66-
main: {
66+
build-meta: {
6767
version: new-version
6868
commit: build.commit
6969
url: build.url

harness/test/010_prelude.eu

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ tests: {
4242
t5: ({ k: :k } lookup(:k)) = (:k lookup-in({ k: :k }))
4343
t6: ({ k: :k } lookup-or(:x, 1234)) = lookup-or-in({ k: :k }, :x, 1234)
4444
t7: ({ c: 22 } lookup-alts([:a, :b, :c], 0)) = ({ a: 22 c: 18 } lookup-alts([:a, :b, :c], 0))
45+
t8: [{}, {}, {foo: 66}] lookup-across(:foo, 77) //= 66
4546

4647
pass: [t1, t2, t3, t4, t5, t6, t7] all-true?
4748
}

harness/test/049_tester.eu

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
title: "049 tester"
3+
test-formats: [:yaml, :json]
4+
}
5+
6+
(x ⊕ y): x + y
7+
8+
` { target: :'test-⊕'
9+
doc: "`⊕` correctly adds two numbers"
10+
verify: [:all-values-true, :beta-specifically-is-true] }
11+
tests: {
12+
α: 2 ⊕ 3 //= 5
13+
β: -1 ⊕ -1 //= -2
14+
}
15+
16+
` "all equalities evaluate to true"
17+
all-values-true(context): context.result values all-true? then(:PASS, :FAIL)
18+
19+
` "beta calculation evaluates to true"
20+
beta-specifically-is-true(context): context.result.β then(:PASS, :FAIL)
21+
22+
` { target: :test-fail
23+
verify: [:all-values-false] }
24+
failures: {
25+
α: 2 ⊕ 2 //= 5
26+
β: 1 ⊕ 1 //= 3
27+
}
28+
29+
` "all equalities evaluate to false"
30+
all-values-false(context): context.result values all(= false) then(:PASS, :FAIL)
31+
32+
` { target: :test-default-expectation }
33+
test-default-expectation: {
34+
RESULT: :PASS
35+
}

lib/prelude.eu

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Eucalypt standard prelude
1+
"eucalypt standard prelude"
22

33
##
44
## Prelude versioning and run metadata
@@ -128,9 +128,17 @@ lookup-or(s, d, b): __LOOKUPOR(s, d, b)
128128
` "`lookup-or-in(b, s, d)` - look up symbol `s` in block `b`, default `d` if not found."
129129
lookup-or-in(b, s, d): lookup-or(s, d, b)
130130

131-
` "`lookup-alts(syms, d)` - look up symbols `syms` in turn in block `b` until a value is found, default `d` if none."
131+
` "`lookup-alts(syms, d, b)` - look up symbols `syms` in turn in block `b` until a value is found, default `d` if none."
132132
lookup-alts(syms, d, b): foldr(lookup-or-in(b), d, syms)
133133

134+
` "`lookup-in-alts(bs, s, d)` - look up symbol `s` in turn in each of blocks `bs` until a value is found, default `d` if none."
135+
lookup-across(s, d, bs): {
136+
f(b, acc): lookup-or(s, acc, b)
137+
}.(foldr(f, d, bs))
138+
139+
` "`lookup-path(ks, b)` - look up value at key path `ks` in block `b`"
140+
lookup-path(ks, b): foldl(lookup-in, b, ks)
141+
134142
##
135143
## Boolean
136144
##
@@ -607,13 +615,13 @@ reverse(l): foldl(cons flip, [], l)
607615
` "`all-true?(l)` - true if and only if all items in list `l` are true."
608616
all-true?(l): foldl(and, true, l)
609617

610-
` "`all-true?(l)` - true if and only if all items in list `l` satisfy predicate `p?`."
618+
` "`all(p?, l)` - true if and only if all items in list `l` satisfy predicate `p?`."
611619
all(p?, l): l map(p?) all-true?
612620

613621
` "`any-true?(l)` - true if and only if any items in list `l` are true."
614622
any-true?(l): foldr(or, false, l)
615623

616-
` "`any-true?(l)` - true if and only if any items in list `l` satisfy predicate `p?`."
624+
` "`any(p?, l)` - true if and only if any items in list `l` satisfy predicate `p?`."
617625
any(p?, l): l map(p?) any-true?
618626

619627
` "`window(n, step, l)` - list of lists of sliding windows over list `l` of size `n` and offest `step`"

0 commit comments

Comments
 (0)