Skip to content
Merged
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
23 changes: 16 additions & 7 deletions bin/run.moon
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ json = (require 'dkjson').use_lpeg!
getopt = require 'alt_getopt'
local verbose

import p from require 'moon'
-- import p from require 'moon'


-- -----------------------------------------------------------
Expand Down Expand Up @@ -47,12 +47,12 @@ validate = (args) ->
-- -----------------------------------------------------------
run_tests = (slug, dir) ->
ok, err = lfs.chdir dir
assert ok, err
assert ok, "run_tests: cannot change to directory #{dir}: #{err}"

-- unskip tests
cmd = "perl -i.bak -pe 's{^\\s*\\Kpending\\b}{it}' *_spec.moon"
ok, result_type, status = os.execute cmd
assert ok
assert ok, "run_tests: failed to unskip tests with command #{cmd}: #{result_type} #{status}"

-- launch `busted`
fh = io.popen 'busted -o json', 'r'
Expand Down Expand Up @@ -114,14 +114,15 @@ run_tests = (slug, dir) ->
name: test.element.name,
message: test.trace.message,
}


-- p results
results


-- -----------------------------------------------------------
get_test_bodies = (slug, dir) ->
ok, err = lfs.chdir dir
assert ok, err
assert ok, "get_test_bodies: cannot change to directory #{dir}: #{err}"

order = {}
bodies = {}
Expand All @@ -139,6 +140,9 @@ get_test_bodies = (slug, dir) ->
in_test = false

for line in fh\lines!
-- do not look for any tests after this line, they won't run in test environment
break if line\match '-- The next tests are optional.'
Comment on lines +143 to +144
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main fix. Bonus tests reside below this marker. They are not run in the test runner, and the runner complains (down below on line 187) if the test output does not match the test bodies.


if line\match '^%s+describe '
if test_name
bodies[test_name] = table.concat test_body, '\n'
Expand All @@ -160,13 +164,14 @@ get_test_bodies = (slug, dir) ->

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


-- -----------------------------------------------------------
write_results = (slug, test_results, names, bodies, dir) ->
ok, err = lfs.chdir dir
assert ok, "#{err}: #{dir}"
assert ok, "write_results: cannot change to directory #{dir}: #{err}"

results = version: 2, status: nil, tests: {}

Expand All @@ -179,7 +184,11 @@ write_results = (slug, test_results, names, bodies, dir) ->
status = 'pass'
for name in *names
test = test_results[name]
assert test, "no test result for #{name}"
if not test
status = 'error'
results.message = "missing test result for #{name}"
break
Comment on lines +187 to +190
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That assertion was causing tests to error out with "An error occurred while running your tests.". I need to properly return the test results with a more appropriate message.


status = 'fail' if test.status != 'pass'
test.test_code = bodies[name]
table.insert results.tests, test
Expand Down
Loading