Skip to content

Instantly share code, notes, and snippets.

@aspiers
Last active December 10, 2017 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspiers/2a2dceca5f8919b421f15c4645c016d1 to your computer and use it in GitHub Desktop.
Save aspiers/2a2dceca5f8919b421f15c4645c016d1 to your computer and use it in GitHub Desktop.
Guardfile for testing SuperCollider
require 'colorize'
#directories %w(. lib/classes lib/tests) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
def sclang(test)
tester = ["sclang", "unit-test-cli.scd"]
cmd = ["timeout", "3"] + tester
if test
cmd << test
title = test
else
title = tester.join " "
end
outerr = ''
puts ("=" * (ENV["COLUMNS"] || "72").to_i).bold.blue
puts ("Running: " + cmd.join(" ")).bold.blue
puts
got_status = false
exit_status = nil
Open3.popen2e(*cmd) do |stdin, stdouterr, wait_thr|
stdouterr.each do |line|
if line =~ /^PASS:/
line = line.green
elsif line =~ /^FAIL:/
line = line.red
elsif line =~ /^ERROR:/
line = line.bold.red
elsif line =~ /^WARNING:/
line = line.yellow
end
status, msg, line = check_line_for_status(line)
if status
got_status = true
n msg, title, status
end
print line
end
exit_status = wait_thr.value
end
unless got_status
msg = "Pid %d exited with status %d" % [exit_status.pid, exit_status]
status = exit_status == 0 ? :success : :failed
n msg, title, status
color = status == :success ? :yellow : :red
puts msg.bold.send(color)
puts "Didn't find test results in output".bold.send(color)
end
end
def check_line_for_status(line)
status, msg = nil
if line =~ /Finished running test\(s\): (\d+ passes, (\d+) failures)/
msg, failures = $1, $2
status = failures == "0" ? :success : :failed # :pending also supported
if status == :success
line = line.bold.green
else
line = line.red
end
elsif line =~ /(Library has not been compiled successfully)\./
msg = $1
status = :failed
end
[status, msg, line]
end
guard :shell do
watch(%r{lib/(?:classes|tests)/(\w.*)\.sc}) do |m|
sclang(m[1])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment