Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 82 lines (66 sloc) 2.438 kb
685fa37 Michael Fellinger Brand new rake tasks, fine-grained with help of raku
manveru authored
1 desc 'Run all bacon specs with pretty output'
38430a9 Michael Fellinger Fix the bacon task dependency
manveru authored
2 task :bacon => :setup do
95a59e2 Michael Fellinger Improve tasks for spec/rcov
manveru authored
3 require 'open3'
979e75e Michael Fellinger Better spec task
manveru authored
4 require 'scanf'
a4c080f Michael Fellinger Improve bacon task
manveru authored
5 require 'matrix'
18bf4b5 Yorick Peterse rake bacon now shows the spec paths relative to the project root.
YorickPeterse authored
6 require 'pathname'
95a59e2 Michael Fellinger Improve tasks for spec/rcov
manveru authored
7
18bf4b5 Yorick Peterse rake bacon now shows the spec paths relative to the project root.
YorickPeterse authored
8 specs = PROJECT_SPECS
979e75e Michael Fellinger Better spec task
manveru authored
9 some_failed = false
18bf4b5 Yorick Peterse rake bacon now shows the spec paths relative to the project root.
YorickPeterse authored
10 root_path = Pathname.new(File.expand_path('../../', __FILE__))
11
12 # Generate a hash of relative and absolute paths for all the specs.
13 specs_relative = {}
14
15 specs.each do |spec|
16 specs_relative[spec] = Pathname.new(spec).relative_path_from(root_path).to_s
17 end
18
f511186 Yorick Peterse The changes in this commit are the first set of changes to make developi...
YorickPeterse authored
19 specs_size = specs.size
18bf4b5 Yorick Peterse rake bacon now shows the spec paths relative to the project root.
YorickPeterse authored
20 len = specs_relative.map { |abs, rel| rel.size }.sort.last
a4c080f Michael Fellinger Improve bacon task
manveru authored
21 total_tests = total_assertions = total_failures = total_errors = 0
f511186 Yorick Peterse The changes in this commit are the first set of changes to make developi...
YorickPeterse authored
22 totals = Vector[0, 0, 0, 0]
95a59e2 Michael Fellinger Improve tasks for spec/rcov
manveru authored
23
685fa37 Michael Fellinger Brand new rake tasks, fine-grained with help of raku
manveru authored
24 red, yellow, green = "\e[31m%s\e[0m", "\e[33m%s\e[0m", "\e[32m%s\e[0m"
979e75e Michael Fellinger Better spec task
manveru authored
25 left_format = "%4d/%d: %-#{len + 11}s"
26 spec_format = "%d specifications (%d requirements), %d failures, %d errors"
6e23112 Michael Fellinger run specs with total summary
manveru authored
27
552ae84 Michael Fellinger Add the ramaze/lib directory to -I on bacon task
manveru authored
28 load_path = File.expand_path('../../lib', __FILE__)
158ae0f Michael Fellinger Let the bacon task pass -I with the root directory
manveru authored
29
95a59e2 Michael Fellinger Improve tasks for spec/rcov
manveru authored
30 specs.each_with_index do |spec, idx|
18bf4b5 Yorick Peterse rake bacon now shows the spec paths relative to the project root.
YorickPeterse authored
31 print(left_format % [idx + 1, specs_size, specs_relative[spec]])
95a59e2 Michael Fellinger Improve tasks for spec/rcov
manveru authored
32
0d37c8e Yorick Peterse Platform checks and used FileUtils::RUBY directly.
YorickPeterse authored
33 Open3.popen3(FileUtils::RUBY, '-I', load_path, spec) do |sin, sout, serr|
02cd6ec Michael Fellinger Improve bacon task so specs can fail on dependencies without messing up ...
manveru authored
34 out = sout.read.strip
35 err = serr.read.strip
95a59e2 Michael Fellinger Improve tasks for spec/rcov
manveru authored
36
158ae0f Michael Fellinger Let the bacon task pass -I with the root directory
manveru authored
37 # this is conventional
02cd6ec Michael Fellinger Improve bacon task so specs can fail on dependencies without messing up ...
manveru authored
38 if out =~ /^Bacon::Error: (needed .*)/
39 puts(yellow % ("%6s %s" % ['', $1]))
eb63517 Michael Fellinger Recognize Spec precondition and Spec require in bacon task
manveru authored
40 elsif out =~ /^Spec (precondition: "[^"]*" failed)/
41 puts(yellow % ("%6s %s" % ['', $1]))
42 elsif out =~ /^Spec require: "require" failed: "(no such file to load -- [^"]*)"/
43 puts(yellow % ("%6s %s" % ['', $1]))
02cd6ec Michael Fellinger Improve bacon task so specs can fail on dependencies without messing up ...
manveru authored
44 else
45 total = nil
64033fc Clive Crous Failure feedback when specs completely fail to run
clivecrous authored
46
02cd6ec Michael Fellinger Improve bacon task so specs can fail on dependencies without messing up ...
manveru authored
47 out.each_line do |line|
48 scanned = line.scanf(spec_format)
49
50 next unless scanned.size == 4
a4c080f Michael Fellinger Improve bacon task
manveru authored
51
02cd6ec Michael Fellinger Improve bacon task so specs can fail on dependencies without messing up ...
manveru authored
52 total = Vector[*scanned]
53 break
54 end
55
56 if total
57 totals += total
58 tests, assertions, failures, errors = total_array = total.to_a
979e75e Michael Fellinger Better spec task
manveru authored
59
02cd6ec Michael Fellinger Improve bacon task so specs can fail on dependencies without messing up ...
manveru authored
60 if tests > 0 && failures + errors == 0
61 puts((green % "%6d passed") % tests)
62 else
63 some_failed = true
64 puts(red % " failed")
65 puts out unless out.empty?
66 puts err unless err.empty?
67 end
a4c080f Michael Fellinger Improve bacon task
manveru authored
68 else
69 some_failed = true
70 puts(red % " failed")
02cd6ec Michael Fellinger Improve bacon task so specs can fail on dependencies without messing up ...
manveru authored
71 puts out unless out.empty?
72 puts err unless err.empty?
979e75e Michael Fellinger Better spec task
manveru authored
73 end
95a59e2 Michael Fellinger Improve tasks for spec/rcov
manveru authored
74 end
36e461d Michael Fellinger Finally switch to bacon totally, enjoy :D
manveru authored
75 end
fd26838 Michael Fellinger restructure spec tasks, check `rake -T` for the new tasks
manveru authored
76 end
6e23112 Michael Fellinger run specs with total summary
manveru authored
77
a4c080f Michael Fellinger Improve bacon task
manveru authored
78 total_color = some_failed ? red : green
79 puts(total_color % (spec_format % totals.to_a))
979e75e Michael Fellinger Better spec task
manveru authored
80 exit 1 if some_failed
fd26838 Michael Fellinger restructure spec tasks, check `rake -T` for the new tasks
manveru authored
81 end
Something went wrong with that request. Please try again.