Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Postgres Backup S3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Circles
Postgres Backup S3
Commits
a2dbf3f1
Commit
a2dbf3f1
authored
1 year ago
by
Elliott Shugerman
Browse files
Options
Downloads
Patches
Plain Diff
more of the same
parent
54341518
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/lib.janet
+89
-92
89 additions, 92 deletions
test/lib.janet
with
89 additions
and
92 deletions
test/lib.janet
+
89
−
92
View file @
a2dbf3f1
...
...
@@ -5,109 +5,106 @@
(
def
divider-light
"--------------------------------------------------------------------------------"
)
# no reason to use a dynamic binding here since it's global anyway (?)
# actually, try an implicit toplevel group to simplifiy the code
(
def
toplevel
:private
@[])
(
defn-
group/new
[
&opt
toplevel
]
@{
:type
'
group
:toplevel
true
:description
nil
:children
@[]
:before
nil
:before-each
nil
:after
nil
:after-each
nil
})
(
setdyn
:group
(
group/new
true
))
(
defn
group
[
description
thunk
]
(
with-dyns
[
:children
@[]
:before
nil
:before-each
nil
:after
nil
:after-each
nil
]
(
thunk
)
(
array/push
toplevel
{
:type
'
group
:description
description
:children
(
dyn
:children
)
:before
(
dyn
:before
)
:before-each
(
dyn
:before-each
)
:after
(
dyn
:after
)
:after-each
(
dyn
:after-each
)})))
(
array/push
((
dyn
:group
)
:children
)
(
with-dyns
[
:group
(
group/new
)]
(
thunk
)
(
dyn
:group
))))
(
defn
before
[
thunk
]
(
setdyn
:before
thunk
))
(
set
((
dyn
:group
)
:before
)
thunk
))
(
defn
before-each
[
thunk
]
(
setdyn
:before-each
thunk
))
(
set
((
dyn
:group
)
:before-each
)
thunk
))
(
defn
after
[
thunk
]
(
setdyn
:after
thunk
))
(
set
((
dyn
:group
)
:after
)
thunk
))
(
defn
after-each
[
thunk
]
(
setdyn
:after-each
thunk
))
(
set
((
dyn
:group
)
:after-each
)
thunk
))
(
defn
test
[
description
thunk
]
(
array/push
(
dyn
:children
)
{
:type
'
test
:description
description
:thunk
thunk
}))
(
defn
execute-toplevel
[]
(
map
(
fn
[
group
]
# TODO: catch errors in hooks?
(
when-let
[
before
(
group
:before
)]
(
before
))
(
def
child-results
(
map
(
fn
[
child
]
(
when-let
[
before-each
(
group
:before-each
)]
(
before-each
))
(
match
child
{
:type
'
test
:thunk
thunk
:description
desc
}
(
try
(
do
((
test
:thunk
))
(
printf
"* %s ✅"
(
test
:description
))
{
:type
'
test
:test
test
:passed
true
})
([
err
]
(
printf
"* %s ❌"
(
test
:description
))
{
:type
'
test
:test
test
:passed
false
:error
err
}))
# TODO: :type 'group
)
(
when-let
[
after-each
(
group
:after-each
)]
(
after-each
)))
(
group
:children
)))
(
when-let
[
after
(
group
:after
)]
(
after
))
{
:type
'
group
:group
group
:children
child-results
})
toplevel
))
(
array/push
((
dyn
:group
)
:children
)
{
:type
'
test
:description
description
:thunk
thunk
}))
(
defn
execute-group
[
group
]
# TODO: catch errors in hooks?
(
when-let
[
before
(
group
:before
)]
(
before
))
(
def
child-results
(
map
(
fn
[
child
]
(
when-let
[
before-each
(
group
:before-each
)]
(
before-each
))
(
match
child
{
:type
'
test
:thunk
thunk
:description
desc
}
(
try
(
do
((
test
:thunk
))
(
printf
"* %s ✅"
(
test
:description
))
{
:type
'
test
:test
test
:passed
true
})
([
err
]
(
printf
"* %s ❌"
(
test
:description
))
{
:type
'
test
:test
test
:passed
false
:error
err
}))
{
:type
'
group
}
(
execute-group
child
))
(
when-let
[
after-each
(
group
:after-each
)]
(
after-each
)))
(
group
:children
)))
(
when-let
[
after
(
group
:after
)]
(
after
))
{
:type
'
group
:group
group
:children
child-results
})
(
defn
run-tests
[]
(
def
result
s
(
execute-
toplevel
))
(
def
result
(
execute-
group
(
dyn
:group
)
))
(
print
divider-heavy
)
(
report
result
s
)
(
report
result
)
(
let
# TODO: do better
[
is-repl
(
and
(
=
"janet"
(
path/basename
(
dyn
*executable*
)))
(
all
(
fn
[
arg
]
(
not=
".janet"
(
path/ext
arg
)))
(
dyn
*args*
)))
some-failed
(
some
(
fn
[
res
]
(
not
(
res
:passed
)))
result
s
)]
# TODO: do better
[
is-repl
(
and
(
=
"janet"
(
path/basename
(
dyn
*executable*
)))
(
all
(
fn
[
arg
]
(
not=
".janet"
(
path/ext
arg
)))
(
dyn
*args*
)))
some-failed
(
some
(
fn
[
res
]
(
not
(
res
:passed
)))
result
)]
(
when
(
and
some-failed
(
not
is-repl
))
(
os/exit
1
))))
(
defn-
report
"Default reporter"
[
results
]
(
defn-
get-spaces
[
n
]
(
string
(
splice
(
g/to-array
(
g/take
10
(
g/cycle
[
" "
])))))
(
->>
[
" "
]
(
generators/cycle
)
(
generators/take
10
)
(
generators/to-array
)
(
splice
)
(
string
)))
(
defn-
filter-failures
[
group
]
# TODO: return subset of tree that only has failures
)
(
defn-
report
"Default reporter"
[
result-node
]
(
print
"FAILURES:"
)
# TODO: recursion
(
def
failure-results
(
reduce
(
fn
[
acc
group-result
]
(
if-let
[
failed-children
(
filter
(
fn
[
res
]
(
not
(
res
:passed
)))
(
group-result
:children
))
failed-group-result
(
merge
group-result
{
:children
failed-children
})]
(
array/push
acc
failed-group-result
)
acc
))
(
array/new
)
results
))
(
defn
get-spaces
[
n
]
(
string
(
splice
(
g/to-array
(
g/take
10
(
g/cycle
[
" "
])))))
(
->>
[
" "
]
(
generators/cycle
)
(
generators/take
10
)
(
generators/to-array
)
(
splice
)
(
string
)))
(
defn
print-failure-results
[
result
depth
]
(
def
failures
(
filter-failures
result-node
))
(
defn
print-failures
[
result-node
depth
]
(
def
indent
(
get-spaces
(
*
2
depth
)))
(
match
result
(
match
result
-node
{
:type
'
group
:group
{
:description
desc
}
:children
child-results
}
(
do
(
print
indent
desc
)
...
...
@@ -119,18 +116,18 @@
(
print
err
)
(
print
))))
(
loop
[
result
:in
failure-results
]
(
print-failure-result
result
0
))
(
print
divider-heavy
)
(
print
"SUMMARY:"
)
(
print
divider-light
)
(
let
[
num-total
(
length
results
)
num-passed
(
sum
(
map
(
fn
[
res
]
(
if
(
res
:passed
)
1
0
))
results
))
num-failed
(
-
num-total
num-passed
)]
(
printf
"Total: %i"
num-total
)
(
printf
"Passing: %i"
num-passed
)
(
printf
"Failed: %i"
num-failed
))
(
print-failures
failures
)
# TODO
#
(print divider-heavy)
#
(print "SUMMARY:")
#
(print divider-light)
#
(let [num-total (length results)
#
num-passed (sum (map (fn [res] (if (res :passed) 1 0)) results))
#
num-failed (- num-total num-passed)]
#
(printf "Total: %i" num-total)
#
(printf "Passing: %i" num-passed)
#
(printf "Failed: %i" num-failed))
(
print
divider-heavy
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment