-
Notifications
You must be signed in to change notification settings - Fork 1
/
Guardfile
45 lines (40 loc) · 1.2 KB
/
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
42
43
44
45
YELLOW='[93m'
RESET='[0m'
ignore %r!^out/!, %r!^testdata/gen/.*/HAVE!, %r!^tmp/!
def run(cmdline)
puts "#{YELLOW}+#{cmdline}#{RESET}"
system cmdline
end
def run_tests(file, flags='')
parent = File.dirname file
sources = Dir["#{parent}/*.go"].reject{|p| p.end_with? '_test.go' }.uniq.join ' '
sources = "common_test.go #{sources}" if file != 'common_test.go'
# Assume that https://github.com/rhysd/gotest is installed
run "gotest #{flags} #{file} #{sources}"
end
guard :shell do
watch /\.go$/ do |m|
puts "#{Time.now}: #{m[0]}"
case m[0]
when /_test\.go$/
run_tests m[0]
when %r{^testdata/gen/}
run_tests 'generate_test.go'
when %r{^testdata/trans/ok/([^/]+)/}
run_tests 'translate_test.go', "-run TestTranslationOK/#{$1}"
when %r{^testdata/trans/error/([^/]+)/}
run_tests 'translate_test.go', "-run TestTranslationError/#{$1}"
when %r{^[^/]+\.go$}
run 'go build ./cmd/trygo'
run "golint #{m[0]}"
run 'go vet'
end
end
watch /\.txt$/ do |m|
puts "#{Time.now}: #{m[0]}"
case m[0]
when %r{^testdata/trans/error/([^/]+)/message\.txt$}
run_tests 'translate_test.go', "-run TestTranslationError/#{$1}"
end
end
end