Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions bin/run.moon
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ get_test_bodies = (slug, dir) ->

fh = io.open test_file, 'r'

pattern = (word) -> '^%s+' .. word .. '%s+[\'"](.+)[\'"],%s+->'
pattern = (word) -> '^(%s+)' .. word .. '%s+[\'"](.+)[\'"],%s+->'
patterns = it: pattern('it'), pending: pattern('pending')

local test_name
Expand All @@ -152,25 +152,33 @@ get_test_bodies = (slug, dir) ->
test_body = {}
test_name = nil

indent_level = 1 + #indent / 2
sections = {table.unpack sections, 1, indent_level} -- discard any deeper indents
sections[indent_level] = section_name
group_indent_level = #indent // 2 + 1
sections = {table.unpack sections, 1, group_indent_level} -- discard any deeper indents
sections[group_indent_level] = section_name
in_test = false

m = line\match(patterns.it) or line\match(patterns.pending)
if not m
indent, name = line\match(patterns.it)
if not indent
indent, name = line\match(patterns.pending)
-- p {:line, :indent, :name}
if not name
if in_test
table.insert test_body, line
else
if in_test
bodies[test_name] = table.concat test_body, '\n'
test_body = {}
test_name = table.concat(sections, ' ') .. ' ' .. m

group_indent_level = #indent // 2 -- note this is one less than the "describe" group level
-- p {:group_indent_level, :name, :sections}
sections = {table.unpack sections, 1, group_indent_level} -- discard any deeper indents
test_name = table.concat(sections, ' ') .. ' ' .. name
table.insert order, test_name
in_test = true

fh\close!
bodies[test_name] = table.concat test_body, '\n'
if test_name
bodies[test_name] = table.concat test_body, '\n'
-- p {:order, :bodies}
order, bodies

Expand All @@ -193,7 +201,7 @@ write_results = (slug, test_results, names, bodies, dir) ->
test = test_results[name]
if not test
status = 'error'
results.message = "missing test result for #{name}"
results.message = "missing test result for «#{name}»"
break

status = 'fail' if test.status != 'pass'
Expand Down
5 changes: 5 additions & 0 deletions tests/deep-groups/.busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return {
default = {
ROOT = { '.' }
}
}
18 changes: 18 additions & 0 deletions tests/deep-groups/deep_groups_spec.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- no requires

describe 'root:', ->
describe 'first child:', ->
it 'test1', ->
true
it 'root-level test', ->
true
describe 'second child:', ->
describe 'grandchild 1:', ->
it 'first granchild test', ->
true
it 'second child test', ->
true
describe 'grandchild 2:', ->
it 'second grandchild test', ->
it 'another root-level test', ->
true
1 change: 1 addition & 0 deletions tests/deep-groups/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"status":"pass","version":2,"tests":[{"name":"root: first child: test1","status":"pass","test_code":" true"},{"name":"root: root-level test","status":"pass","test_code":" true"},{"name":"root: second child: grandchild 1: first granchild test","status":"pass","test_code":" true"},{"name":"root: second child: second child test","status":"pass","test_code":" true"},{"name":"root: second child: grandchild 2: second grandchild test","status":"pass","test_code":""},{"name":"root: another root-level test","status":"pass","test_code":" true"}]}
Loading