-
Notifications
You must be signed in to change notification settings - Fork 3
/
Guardfile
41 lines (34 loc) · 968 Bytes
/
Guardfile
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
guard :shell, :all_after_pass => true do
watch(%r{.*\.cabal$}) do
ncmd("cabal configure && cabal build && cabal test")
end
def ncmd(cmd, msg = cmd)
output = `#{cmd}`
puts output
summary = output.lines.grep(/examples/).first
if $?.success?
n "Build Success!", summary
else
n "Failed", summary
end
end
def run_tests(mod)
specfile = "test/#{mod}Spec.hs"
if File.exists?(specfile)
files = [specfile]
else
files = Dir['test/**/*.hs']
end
if package_db = Dir[".cabal-sandbox/*packages.conf.d", "cabal-dev/*packages.conf.d"].first
package_db_flag = "-package-db #{package_db}"
end
ncmd("ghc -isrc -itest #{package_db_flag} -e 'Test.Hspec.hspec spec' #{files.join(' ')}")
end
# can we join these? why does run all loop through each file?
watch(%r{src/(.+)\.hs$}) do |m|
run_tests(m[1])
end
watch(%r{test/(.+)Spec\.hs$}) do |m|
run_tests(m[1])
end
end