mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
make helper to make sure right moonscript code is tested, add to lang spec
This commit is contained in:
parent
e26fc29784
commit
aeca8864ae
@ -6,4 +6,37 @@ unindent = (str) ->
|
||||
return str unless indent
|
||||
(str\gsub("\n#{indent}", "\n")\gsub "%s+$", "")
|
||||
|
||||
{ :unindent }
|
||||
in_dev = false
|
||||
|
||||
-- this will ensure any moonscript modules included come from the local
|
||||
-- directory
|
||||
with_dev = (fn) ->
|
||||
error "already in dev mode" if in_dev
|
||||
|
||||
-- a package loader that only looks in currect directory
|
||||
import make_loader from require "loadkit"
|
||||
loader = make_loader "lua", nil, "./?.lua"
|
||||
|
||||
import setup, teardown from require "busted"
|
||||
|
||||
old_require = _G.require
|
||||
dev_cache = {}
|
||||
|
||||
setup ->
|
||||
_G.require = (mod) ->
|
||||
return dev_cache[mod] if dev_cache[mod]
|
||||
|
||||
if mod\match("moonscript%.") or mod == "moonscript"
|
||||
dev_cache[mod] = assert(loadfile(assert loader mod))!
|
||||
return dev_cache[mod]
|
||||
|
||||
old_require mod
|
||||
|
||||
if fn
|
||||
fn!
|
||||
|
||||
teardown ->
|
||||
_G.require = old_require
|
||||
in_dev = false
|
||||
|
||||
{ :unindent, :with_dev }
|
||||
|
@ -1,12 +1,10 @@
|
||||
lfs = require "lfs"
|
||||
|
||||
parse = require "moonscript.parse"
|
||||
compile = require "moonscript.compile"
|
||||
util = require "moonscript.util"
|
||||
import with_dev from require "spec.helpers"
|
||||
|
||||
pattern = ...
|
||||
|
||||
import unpack from util
|
||||
unpack = table.unpack or unpack
|
||||
|
||||
options = {
|
||||
in_dir: "spec/inputs",
|
||||
@ -20,7 +18,7 @@ options = {
|
||||
tool: "git diff --no-index --color" --color-words"
|
||||
filter: (str) ->
|
||||
-- strip the first four lines
|
||||
table.concat [line for line in *util.split(str, "\n")[5,]], "\n"
|
||||
table.concat [l for l in *([line for line in str\gmatch("[^\n]+")])[5,]], "\n"
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,12 +79,18 @@ input_fname = (base) ->
|
||||
output_fname = (base) ->
|
||||
options.out_dir .. "/" .. base .. options.output_ext
|
||||
|
||||
describe "input tests", ->
|
||||
inputs = for file in lfs.dir options.in_dir
|
||||
with match = file\match options.input_pattern
|
||||
continue unless match
|
||||
inputs = for file in lfs.dir options.in_dir
|
||||
with match = file\match options.input_pattern
|
||||
continue unless match
|
||||
|
||||
table.sort inputs
|
||||
table.sort inputs
|
||||
|
||||
describe "input tests", ->
|
||||
local parse, compile
|
||||
|
||||
with_dev ->
|
||||
parse = require "moonscript.parse"
|
||||
compile = require "moonscript.compile"
|
||||
|
||||
for name in *inputs
|
||||
input = input_fname name
|
||||
|
Loading…
Reference in New Issue
Block a user