2014-06-07 07:04:26 +00:00
|
|
|
|
|
|
|
-- remove front indentation from a multiline string, making it suitable to be
|
|
|
|
-- parsed
|
|
|
|
unindent = (str) ->
|
|
|
|
indent = str\match "^%s+"
|
|
|
|
return str unless indent
|
2015-09-27 02:31:01 +00:00
|
|
|
(str\gsub("\n#{indent}", "\n")\gsub("%s+$", "")\gsub "^%s+", "")
|
2014-06-07 07:04:26 +00:00
|
|
|
|
2015-09-27 02:07:04 +00:00
|
|
|
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]
|
|
|
|
|
2015-09-27 02:31:01 +00:00
|
|
|
testable = mod\match("moonscript%.") or mod == "moonscript" or
|
|
|
|
mod\match("moon%.") or mod == "moon"
|
|
|
|
|
|
|
|
if testable
|
2016-04-14 02:47:37 +00:00
|
|
|
fname = assert loader(mod), "failed to find module: #{mod}"
|
|
|
|
dev_cache[mod] = assert(loadfile fname)!
|
2015-09-27 02:07:04 +00:00
|
|
|
return dev_cache[mod]
|
|
|
|
|
|
|
|
old_require mod
|
|
|
|
|
|
|
|
if fn
|
|
|
|
fn!
|
|
|
|
|
|
|
|
teardown ->
|
|
|
|
_G.require = old_require
|
|
|
|
in_dev = false
|
|
|
|
|
2015-09-27 02:31:01 +00:00
|
|
|
dev_cache
|
|
|
|
|
2015-09-27 02:07:04 +00:00
|
|
|
{ :unindent, :with_dev }
|