-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spookfile
149 lines (123 loc) · 4.64 KB
/
Spookfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
-- vim: syntax=moon
-- How much log output can you handle? (ERR, WARN, INFO, DEBUG)
log_level "INFO"
-- by overriding os.execute we get the benefits of the coroutine based execute which
-- can be interrupted
:execute = require 'process'
os.execute = execute
:repl, :cmdline = require('shell') ->
dir = getcwd!
if os.getenv('SPOOK_INTEGRATION') == 'yes'
dir .. ' integration testing on% '
else
dir .. ' integration testing off% '
package.path = "#{package.path};spec/support/?.lua;spec/support/?/init.lua"
-- If the spookfile is reloaded we just ensure we reload
-- the other stuff too.
package.loaded['moonpick'] = nil
package.loaded.lint_config = nil
moonpick = require "moonpick"
-- Require some things that come with spook
colors = require "ansicolors"
fs = require 'fs'
-- notify is a global variable. Let's make it a local
-- as is generally recommended in Lua.
-- Let's add the built-in terminal_notifier.
notify.add 'terminal_notifier'
-- If we find 'notifier' in the path, let's
-- add that notifier also. We fail silently otherwise.
pcall notify.add, 'notifier'
-- spookfile_helpers are included inside the spook binary,
-- when needed they should be made locals as generally
-- recommended for Lua.
{
:until_success
:command
:task_filter
:notifies
} = require 'spookfile_helpers'
-- since the built-in helpers (required above) can be
-- combined in different ways but usually in the same
-- way again and again, we wrap this up in a function
-- that takes the event and the task list (at least for
-- spook, that's the way I run the tests).
test = (event, tasks) ->
until_success ->
notifies event.path, event, tasks
-- we use this for notifications, by filtering out
-- the commands not runnable (because the mapped files
-- aren't present), we don't unnecessarily notify on
-- start / fail / success when nothing can actually
-- happen. For a spec runner, this makes sense.
task_list = task_filter fs.is_present
spec = command "./tools/luajit/bin/luajit spec/support/run_busted.lua"
exec = command "./tools/luajit/bin/luajit run.lua"
shpec = command "shpec", env: {SPOOK: "./tools/luajit/bin/luajit run.lua init.moon"}
lint = (file) ->
notify.info "LINTING #{file}"
status, res, err = pcall moonpick.lint_file, file
if status and res and #res > 0
output = moonpick.format_inspections res
io.stdout\write colors("\n[ %{yellow}LINT complaints ]\n%{white}#{output}\n\n")
error "Lint warning"
if not status or err
msg = err or res
io.stdout\write colors("\n[ %{red}LINT error ]\n%{white}#{file}\n#{msg}\n\n")
error "Lint error"
io.stdout\write colors("\n[ %{green}LINT: %{white}All good ]\n\n")
-- Watching for changes underneath . and matching them to handlers using
-- lua patterns (see: http://lua-users.org/wiki/PatternsTutorial for example).
watch ".", ignore: {'%.git', '%.direnv'}, ->
on_changed "^spec/spec_helper%.moon", (event) ->
test event, task_list(
lint, "spec/spec_helper.moon"
spec, "spec"
)
on_changed "^spec/(.*)%.moon", (event, name) ->
test event, task_list(
lint, "spec/#{name}.moon"
spec, "spec/#{name}.moon"
)
on_changed "^lib/(.*)/event_loop%.moon", (event, name) ->
test event, task_list(
lint, "lib/#{name}/event_loop.moon"
spec, "spec/event_loop_spec.moon"
)
on_changed "^lib/(.*)%.moon", (event, name) ->
test event, task_list(
lint, "lib/#{name}.moon"
spec, "spec/#{name}_spec.moon"
)
on_changed "^shpec/(.*)%.sh", (event, name) ->
return unless os.getenv('SPOOK_INTEGRATION') == 'yes'
test event, task_list(
shpec, "shpec/#{name}.sh"
)
on_changed "^playground/(.*)%.moon", (event, name) ->
exec "playground/#{name}.moon"
on_changed "^playground/(.*)%.lua", (event, name) ->
exec "playground/#{name}.lua"
on_changed "^Spookfile$", (event) ->
notify.info "Re-executing spook..."
reload_spook!
on_changed "^lint_config%.lua$", (event) ->
notify.info "Re-executing spook..."
reload_spook!
-- cmdline\cmd "spec_files", " - list all spec files", ->
-- os.execute "find spec -type f -name '*_spec.moon'"
-- this would execute any command in path
-- :concat, :insert = table
-- cmdline\dynamic (c, key, value) ->
-- (screen, ...) ->
-- args = {key}
-- insert args, arg for arg in *{...}
-- os.execute concat(args, ' ')
S = require 'syscall'
cmdline\cmd 'integration', '<on/off> Turn shpec integration tests on or off', (screen, what) ->
if what and what\lower! == 'on'
S.setenv('SPOOK_INTEGRATION', 'yes', true)
notify.info 'integration testing ON'
else
S.setenv('SPOOK_INTEGRATION', 'no', true)
notify.info 'integration testing OFF'
on_read S.stdin, repl