-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.watchr
65 lines (50 loc) · 1.85 KB
/
.watchr
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
require "open3"
watch("application/(models|controllers)/(.*).php") do |match|
test_changed_application(match[0])
end
watch("tests/(.*/.*)\.php") do |match|
phpunit match[0]
end
def test_changed_application(file)
type = file.split('/')[1]
name = file.split('/')[2].split('.')[0]
#system "phpunit --verbose --colors application/tests/#{type}/test#{name.capitalize}"
phpunit "tests/#{type}/#{name.capitalize}Test.php"
#phpunit "tests/#{type}/test#{name.capitalize}.php"
end
def say what
puts "\n[#{Time.now.strftime('%H:%M:%S')}] #{what}\n"
end
def phpunit file
if File.exists? file
cmd = "phpunit #{file}" # redirect stderr to stdout
say "About to run '#{cmd}'"
previous = last = nil
status = Open3::popen3(cmd) do |stdin,stdout,stderr|
stdout.each do |line|
previous = last
puts last = line
end
say stdout.gets
end
# status = Open3::popen3('phpunit application/tests/controllers/testWelcome.php 2>&1') do |stdin,stdout,stderr|
# stdout.each { |line| puts "stdout:"+line }
# say stdout.gets
# end
file_name = File.basename(file)
image, summary, message = case
when last =~ /\AOK/ # PHPUnit is green
['dialog-ok', file_name, last.gsub('OK (', '').gsub(')', '')]
when previous =~ /\AOK, but incomplete or skipped tests/ # PHPUnit is yellow
['dialog-question', file_name, last]
when last =~ /\APHP/ # PHP Fatal error, PHPUnit process crashed
['dialog-error', 'Fatal error!', last]
else # PHPUnit is red
['dialog-warning', previous, last]
end
say message
# `--hint=string:x-canonical-private-synchronous:` is a workaround for `-t`
system "notify-send --hint=string:x-canonical-private-synchronous: -i '#{image}' '#{summary}' '#{message}'"
say "waiting..."
end
end