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
16 changes: 15 additions & 1 deletion bin/run.moon
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,25 @@ run_tests = (slug, dir) ->
data = json.decode json_output

if not data
output = json_output

if output\match "^Failed to encode test results to json"
-- This is a syntax error: moon can't compile it.
-- Busted cannot output JSON results.
-- Grab the output from vanilla busted.
fh = io.popen 'busted', 'r'
output = fh\read 'a'
fh\close!
-- trim off some non-determinant output
output = output\gsub " : [%d.]+ seconds", ""
output = output\gsub "(%s)/[%w./-]-/(base.lua)", "%1%2"

return {
status: 'error',
message: json_output
message: output
}


if exit_status != 0 and #data.successes == 0 and #data.failures == 0 and #data.errors > 0
return {
status: 'error',
Expand Down
2 changes: 1 addition & 1 deletion tests/example-syntax-error/expected_results.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"tests":[],"version":2,"message":"Failed to encode test results to json: type 'function' is not supported by JSON.\n","status":"error"}
{"message":"*\n0 successes / 0 failures / 1 error / 0 pending\n\nError -> base.lua @ 3\nsuite ./example_syntax_error_spec.moon\nbase.lua:81: ./example_syntax_error.moon: Failed to parse:\n [1] >> leap_year =\n","version":2,"status":"error","tests":[]}
5 changes: 5 additions & 0 deletions tests/failed-to-parse/.busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return {
default = {
ROOT = { '.' }
}
}
1 change: 1 addition & 0 deletions tests/failed-to-parse/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"tests":[],"status":"error","message":"*\n0 successes / 0 failures / 1 error / 0 pending\n\nError -> base.lua @ 3\nsuite ./failed_to_parse_spec.moon\nbase.lua:81: ./failed_to_parse.moon: Failed to parse:\n [2] >> (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0)\n","version":2}
4 changes: 4 additions & 0 deletions tests/failed-to-parse/failed_to_parse.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
leap_year = (year) ->
(year % 4 == 0) && (year % 100 != 0 || year % 400 == 0)

return leap_year
29 changes: 29 additions & 0 deletions tests/failed-to-parse/failed_to_parse_spec.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
is_leap_year = require 'failed_to_parse'

describe 'leap', ->
it 'year not divisible by 4 in common year', ->
assert.is_false is_leap_year 2015

it 'year divisible by 2, not divisible by 4 in common year', ->
assert.is_false is_leap_year 1970

it 'year divisible by 4, not divisible by 100 in leap year', ->
assert.is_true is_leap_year 1996

it 'year divisible by 4 and 5 is still a leap year', ->
assert.is_true is_leap_year 1960

it 'year divisible by 100, not divisible by 400 in common year', ->
assert.is_false is_leap_year 2100

it 'year divisible by 100 but not by 3 is still not a leap year', ->
assert.is_false is_leap_year 1900

it 'year divisible by 400 is leap year', ->
assert.is_true is_leap_year 2000

it 'year divisible by 400 but not by 125 is still a leap year', ->
assert.is_true is_leap_year 2400

it 'year divisible by 200, not divisible by 400 in common year', ->
assert.is_false is_leap_year 1800
Loading