ciat 0.4.8 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/README.rdoc +4 -4
  2. data/lib/ciat.rb +3 -5
  3. data/lib/ciat/differs/html_differ.rb +3 -4
  4. data/lib/ciat/erb_helpers.rb +6 -4
  5. data/lib/ciat/feedback/composite.rb +2 -2
  6. data/lib/ciat/feedback/feedback_counter.rb +2 -2
  7. data/lib/ciat/feedback/html_feedback.rb +25 -8
  8. data/lib/ciat/feedback/html_feedback_builder.rb +28 -0
  9. data/lib/ciat/feedback/return_status.rb +1 -1
  10. data/lib/ciat/feedback/standard_output.rb +1 -1
  11. data/lib/ciat/io.rb +17 -0
  12. data/lib/ciat/processors/basic_processing.rb +21 -30
  13. data/lib/ciat/{executors → processors}/java.rb +7 -8
  14. data/lib/ciat/{executors → processors}/parrot.rb +9 -10
  15. data/lib/ciat/rake_task.rb +1 -1
  16. data/lib/ciat/subresult.rb +20 -0
  17. data/lib/ciat/suite.rb +27 -38
  18. data/lib/ciat/suite_builder.rb +54 -0
  19. data/lib/ciat/test.rb +32 -18
  20. data/lib/ciat/test_element.rb +7 -2
  21. data/lib/ciat/{crate.rb → test_file.rb} +24 -16
  22. data/lib/ciat/test_result.rb +24 -0
  23. data/lib/ciat/traffic_light.rb +6 -0
  24. data/lib/templates/detail_row.html.erb +5 -4
  25. data/lib/templates/group_header.html.erb +2 -2
  26. data/lib/templates/report.html.erb +1 -1
  27. data/lib/templates/summary_row.html.erb +4 -4
  28. data/spec/ciat/erb_helpers_spec.rb +71 -0
  29. data/spec/ciat/feedback/composite_spec.rb +28 -0
  30. data/spec/ciat/feedback/feedback_counter_spec.rb +91 -0
  31. data/spec/ciat/feedback/html_feedback_spec.rb +48 -0
  32. data/spec/ciat/feedback/return_status_spec.rb +90 -0
  33. data/spec/ciat/feedback/standard_output_spec.rb +109 -0
  34. data/spec/ciat/processors/basic_processing_spec.rb +146 -0
  35. data/spec/ciat/processors/java_spec.rb +31 -0
  36. data/spec/ciat/processors/parrot_spec.rb +40 -0
  37. data/spec/ciat/subresult_spec.rb +40 -0
  38. data/spec/ciat/suite_builder_spec.rb +70 -0
  39. data/spec/ciat/suite_spec.rb +64 -0
  40. data/spec/ciat/test_element_spec.rb +78 -0
  41. data/spec/ciat/test_file_spec.rb +96 -0
  42. data/spec/ciat/test_spec.rb +127 -0
  43. data/spec/ciat/traffic_light_spec.rb +41 -0
  44. data/spec/ciat_spec.rb +2 -0
  45. data/spec/spec_helper.rb +134 -0
  46. data/spec/templates/detail_row/elements_html_erb_spec.rb +60 -0
  47. data/spec/templates/detail_row_html_erb_spec.rb +73 -0
  48. data/spec/templates/elements/diff_html_erb_spec.rb +28 -0
  49. data/spec/templates/elements/plain_element_html_erb_spec.rb +36 -0
  50. data/spec/templates/report_html_erb_spec.rb +85 -0
  51. data/spec/templates/summary_row_html_erb_spec.rb +93 -0
  52. data/spec/templates/test_numbers_html_erb_spec.rb +82 -0
  53. metadata +54 -32
  54. data/History.txt +0 -96
  55. data/Rakefile +0 -40
  56. data/ciat.gemspec +0 -53
  57. data/lib/ciat/cargo.rb +0 -55
  58. data/lib/ciat/compilers/java.rb +0 -54
  59. data/lib/ciat/processors/copy.rb +0 -37
  60. data/lib/ciat/version.rb +0 -7
@@ -0,0 +1,54 @@
1
+ require 'ciat/io'
2
+
3
+ class CIAT::SuiteBuilder
4
+ include CIAT::IO
5
+
6
+ attr_reader :options
7
+
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ def build_processors
13
+ options[:processors]
14
+ end
15
+
16
+ def build_output_folder
17
+ options[:output_folder] || OUTPUT_FOLDER
18
+ end
19
+
20
+ def build_test_files
21
+ if options[:files]
22
+ make_test_files(options[:files])
23
+ else
24
+ folder = options[:folder] || "ciat"
25
+ pattern = options[:pattern] || "*.ciat"
26
+ make_test_files(Dir[File.join(folder, "**", pattern)])
27
+ end
28
+ end
29
+
30
+ def make_test_files(filenames)
31
+ if filenames.empty?
32
+ raise IOError.new("no test files specified")
33
+ end
34
+ filenames.map do |filename|
35
+ CIAT::TestFile.new(filename, build_output_folder)
36
+ end
37
+ end
38
+
39
+ def build_feedback
40
+ CIAT::Feedback::Composite.new(
41
+ options[:feedback] || default_feedback,
42
+ CIAT::Feedback::ReturnStatus.new
43
+ )
44
+ end
45
+
46
+ def default_feedback
47
+ counter = CIAT::Feedback::FeedbackCounter.new
48
+ CIAT::Feedback::Composite.new(counter,
49
+ CIAT::Feedback::StandardOutput.new(counter),
50
+ CIAT::Feedback::HtmlFeedback.new(counter, options)
51
+ )
52
+ end
53
+
54
+ end
data/lib/ciat/test.rb CHANGED
@@ -1,36 +1,50 @@
1
1
  require 'set'
2
+ require 'ciat/test_result'
3
+ require 'ciat/subresult'
2
4
 
3
5
  class CIAT::Test
4
- attr_reader :filename
5
6
  attr_reader :processors
6
- attr_reader :elements
7
7
 
8
- def initialize(filename, elements, options={}) #:nodoc:
9
- @filename = filename
10
- @elements = elements
11
- @processors = options[:processors]
12
- @feedback = options[:feedback]
8
+ def initialize(test_file, processors, feedback) #:nodoc:
9
+ @test_file = test_file
10
+ @processors = processors
11
+ @feedback = feedback
12
+ end
13
+
14
+ def elements
15
+ @elements ||= @test_file.process
16
+ end
17
+
18
+ def filename
19
+ @test_file.filename(:ciat)
13
20
  end
14
21
 
15
22
  def run
16
- run_processors
17
- report_lights
18
- self
23
+ CIAT::TestResult.new(self, run_processors)
24
+ end
25
+
26
+ def grouping
27
+ @test_file.grouping
19
28
  end
20
29
 
21
30
  def run_processors #:nodoc:
22
- processors.each do |processor|
23
- processor.process(self)
24
- break unless processor.light.green?
31
+ light = CIAT::TrafficLight::GREEN
32
+ processors.map do |processor|
33
+ if light.green?
34
+ light = processor.process(self)
35
+ subresult(processor, light)
36
+ else
37
+ subresult(processor)
38
+ end
25
39
  end
26
40
  end
27
41
 
28
- def report_lights #:nodoc:
29
- processors.each do |processor|
30
- @feedback.processor_result(processor)
31
- end
42
+ def subresult(processor, light = CIAT::TrafficLight::UNSET)
43
+ subresult = CIAT::Subresult.new(self, light, processor)
44
+ @feedback.report_subresult(subresult)
45
+ subresult
32
46
  end
33
-
47
+
34
48
  def element(*names)
35
49
  elements[names.compact.join("_").to_sym]
36
50
  end
@@ -1,6 +1,10 @@
1
1
  require "yaml"
2
+ require 'ciat/io'
2
3
 
3
4
  class CIAT::TestElement
5
+
6
+ include CIAT::IO
7
+
4
8
  attr_reader :name
5
9
  attr_reader :filename
6
10
 
@@ -26,12 +30,12 @@ class CIAT::TestElement
26
30
  end
27
31
 
28
32
  def content
29
- @content ||= CIAT::Cargo.read_file(@filename)
33
+ @content ||= read_file(@filename)
30
34
  end
31
35
 
32
36
  def as_file
33
37
  if @content
34
- CIAT::Cargo.write_file(@filename, @content)
38
+ write_file(@filename, @content)
35
39
  end
36
40
  @filename
37
41
  end
@@ -41,4 +45,5 @@ class CIAT::TestElement
41
45
  def metadata
42
46
  @@metadata ||= YAML.load_file(File.join(File.dirname(__FILE__), "..", "data", "elements.yml"))
43
47
  end
48
+
44
49
  end
@@ -1,38 +1,38 @@
1
- class CIAT::Crate #:nodoc:all
2
- attr_reader :test_file
3
- attr_reader :stub
4
- attr_reader :output_folder
1
+ class CIAT::TestFile #:nodoc:all
5
2
 
6
3
  def initialize(test_file, output_folder)
4
+ unless File.exists?(test_file)
5
+ raise IOError.new(test_file + " does not exist")
6
+ end
7
7
  @test_file = test_file
8
8
  @output_folder = output_folder
9
9
  end
10
-
11
- def stub
12
- test_file.gsub(File.extname(test_file), "")
13
- end
14
10
 
15
11
  def filename(*modifiers)
16
- File.join(output_folder, [stub, *modifiers].compact.join("_"))
12
+ if modifiers == [:ciat]
13
+ @test_file
14
+ else
15
+ File.join(@output_folder, [stub, *modifiers].compact.join("_"))
16
+ end
17
17
  end
18
18
 
19
- def read_test_file
20
- File.readlines(test_file)
21
- end
19
+ def grouping
20
+ File.dirname(@test_file)
21
+ end
22
22
 
23
- def process_test_file #:nodoc:
23
+ def process #:nodoc:
24
24
  elements = empty_elements_hash
25
- split_test_file.each do |name, contents|
25
+ split.each do |name, contents|
26
26
  elements[name] = CIAT::TestElement.new(name, filename(name), contents)
27
27
  end
28
28
  elements
29
29
  end
30
30
 
31
- def split_test_file #:nodoc:
31
+ def split #:nodoc:
32
32
  tag = :description
33
33
  content = ""
34
34
  raw_elements = {}
35
- read_test_file.each do |line|
35
+ read.each do |line|
36
36
  if line =~ /^==== ((\w|\s)+?)\W*$/
37
37
  raw_elements[tag] = content
38
38
  tag = $1.gsub(" ", "_").to_sym
@@ -50,9 +50,17 @@ class CIAT::Crate #:nodoc:all
50
50
  #
51
51
  private
52
52
 
53
+ def read
54
+ File.readlines(@test_file)
55
+ end
56
+
53
57
  def empty_elements_hash
54
58
  Hash.new do |hash, name|
55
59
  hash[name] = CIAT::TestElement.new(name, filename(name), nil)
56
60
  end
57
61
  end
62
+
63
+ def stub
64
+ @test_file.gsub(File.extname(@test_file), "")
65
+ end
58
66
  end
@@ -0,0 +1,24 @@
1
+ class CIAT::TestResult
2
+ attr_reader :subresults
3
+
4
+ def initialize(test, subresults)
5
+ @test = test
6
+ @subresults = subresults
7
+ end
8
+
9
+ def grouping
10
+ @test.grouping
11
+ end
12
+
13
+ def processors
14
+ @test.processors
15
+ end
16
+
17
+ def filename
18
+ @test.filename
19
+ end
20
+
21
+ def element(*args)
22
+ @test.element(*args)
23
+ end
24
+ end
@@ -1,10 +1,16 @@
1
1
  class CIAT::TrafficLight
2
+
2
3
  attr_reader :setting
3
4
 
4
5
  def initialize(setting = :unset) #:nodoc:
5
6
  @setting = setting
6
7
  end
7
8
 
9
+ GREEN = CIAT::TrafficLight.new(:green)
10
+ RED = CIAT::TrafficLight.new(:red)
11
+ YELLOW = CIAT::TrafficLight.new(:yellow)
12
+ UNSET = CIAT::TrafficLight.new(:unset)
13
+
8
14
  def unset?
9
15
  @setting == :unset
10
16
  end
@@ -1,9 +1,10 @@
1
1
  <tr class="details" style="display:none">
2
- <td colspan="<%= result.processors.size + 1 %>">
2
+ <td colspan="<%= result.subresults.size + 1 %>">
3
3
 
4
- <% result.processors.each do |processor| %>
5
- <h3>Results from <%= processor.describe %></h3>
6
- <%= render "detail_row/elements", :elements => processor.relevant_elements(result) %>
4
+ <% result.subresults.each do |subresult| %>
5
+ <h3>Results from <%= subresult.processor.describe %></h3>
6
+ <%= render "detail_row/elements",
7
+ :elements => subresult.relevant_elements %>
7
8
  <% end %>
8
9
 
9
10
  </tr>
@@ -1,7 +1,7 @@
1
- <% if new_path?(result) %>
1
+ <% if new_grouping?(result) %>
2
2
  <tr>
3
3
  <td colspan="<%= result.processors.size + 1 %>">
4
- <strong><%= File.dirname(result.filename).gsub("/", " / ") %></strong>
4
+ <strong><%= result.grouping.gsub("/", " / ") %></strong>
5
5
  </td>
6
6
  </tr>
7
7
  <% end %>
@@ -27,7 +27,7 @@
27
27
  </tr>
28
28
 
29
29
  <% results.each do |result| %>
30
- <% if new_path?(result) %>
30
+ <% if new_grouping?(result) %>
31
31
  <%= render "group_header", :result => result %>
32
32
  <% end %>
33
33
  <%= render "summary_row", :result => result %>
@@ -4,9 +4,9 @@
4
4
  <%= result.element(:description).content %>
5
5
  </a>
6
6
  </td>
7
- <% result.processors.each do |processor| %>
8
- <td class="<%= processor.light.setting %>">
9
- <%= light_to_word(processor.light) %>
10
- </td>
7
+ <% result.subresults.each do |subresult| %>
8
+ <td class="<%= subresult.light.setting %>">
9
+ <%= light_to_word(subresult.light) %>
10
+ </td>
11
11
  <% end %>
12
12
  </tr>
@@ -0,0 +1,71 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe CIAT::ERBHelpers do
4
+ before(:each) do
5
+ @helper = Object.new
6
+ @helper.extend(CIAT::ERBHelpers)
7
+
8
+ @unset = CIAT::TrafficLight.new(:unset)
9
+ @green = CIAT::TrafficLight.new(:green)
10
+ @yellow = CIAT::TrafficLight.new(:yellow)
11
+ @red = CIAT::TrafficLight.new(:red)
12
+ end
13
+
14
+ describe "converting light to word" do
15
+ it "should handle unset light" do
16
+ @helper.light_to_word(@unset).should == "n/a"
17
+ end
18
+
19
+ it "should handle green light" do
20
+ @helper.light_to_word(@green).should == "passed"
21
+ end
22
+
23
+ it "should handle yellow light" do
24
+ @helper.light_to_word(@yellow).should == "ERROR"
25
+ end
26
+
27
+ it "should handle red light" do
28
+ @helper.light_to_word(@red).should == "FAILURE"
29
+ end
30
+ end
31
+
32
+ describe "converting light to sentence" do
33
+ it "should handle unset light" do
34
+ @helper.light_to_sentence("prefix", @unset).should ==
35
+ "<span class=\"unset\">prefix not run.</span>"
36
+ end
37
+
38
+ it "should handle green light" do
39
+ @helper.light_to_sentence("prefix", @green).should ==
40
+ "<span class=\"green\">prefix passed.</span>"
41
+ end
42
+
43
+ it "should handle yellow light" do
44
+ @helper.light_to_sentence("prefix", @yellow).should ==
45
+ "<span class=\"yellow\">prefix errored.</span>"
46
+ end
47
+
48
+ it "should handle red light" do
49
+ @helper.light_to_sentence("prefix", @red).should ==
50
+ "<span class=\"red\">prefix failed.</span>"
51
+ end
52
+ end
53
+
54
+ it "should render another template" do
55
+ template = mock("template")
56
+ locals = mock("locals")
57
+ binder = mock("binder")
58
+ bindings = mock("bindings")
59
+ erb = mock("erb")
60
+ result = mock("result")
61
+
62
+ @helper.should_receive(:read).with("phile.html.erb").and_return(template)
63
+ ERB.should_receive(:new).with(template).and_return(erb)
64
+ CIAT::TemplateBinder.should_receive(:new).with(locals).and_return(binder)
65
+ binder.should_receive(:get_binding).and_return(bindings)
66
+ erb.should_receive(:filename=).with("phile.html.erb")
67
+ erb.should_receive(:result).with(bindings).and_return(result)
68
+
69
+ @helper.render("phile.html.erb", locals).should == result
70
+ end
71
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ require 'ciat/feedback/composite'
4
+
5
+ describe CIAT::Feedback::Composite do
6
+ before(:each) do
7
+ @subfeedbacks = [mock("feedback 1"), mock("feedback 2"), mock("feedback 3")]
8
+ @feedback = CIAT::Feedback::Composite.new(*@subfeedbacks)
9
+ end
10
+
11
+ it "should report at the end" do
12
+ suite = mock("suite")
13
+
14
+ @subfeedbacks.each { |feedback| feedback.should_receive(:post_tests).with(suite) }
15
+
16
+ @feedback.post_tests(suite)
17
+ end
18
+
19
+ it "should report a light" do
20
+ subresult = mock("subresult")
21
+
22
+ @subfeedbacks.each do |feedback|
23
+ feedback.should_receive(:report_subresult).with(subresult)
24
+ end
25
+
26
+ @feedback.report_subresult(subresult)
27
+ end
28
+ end
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ require 'ciat/feedback/standard_output'
4
+
5
+ describe CIAT::Feedback::FeedbackCounter do
6
+ before(:each) do
7
+ @feedback = CIAT::Feedback::FeedbackCounter.new
8
+ end
9
+
10
+ describe "reporting on a processor" do
11
+ before(:each) do
12
+ @light = mock("light")
13
+ @subresult = mock("subresult")
14
+ @subresult.should_receive(:light).at_least(:once).and_return(@light)
15
+ end
16
+
17
+ it "should report a green light" do
18
+ expect_light(:green)
19
+
20
+ @feedback.report_subresult(@subresult)
21
+ end
22
+
23
+ it "should report a red light" do
24
+ expect_light(:red)
25
+ @feedback.should_receive(:increment_failure_count)
26
+
27
+ @feedback.report_subresult(@subresult)
28
+ end
29
+
30
+ it "should report a yellow light" do
31
+ expect_light(:yellow)
32
+ @feedback.should_receive(:increment_error_count)
33
+
34
+ @feedback.report_subresult(@subresult)
35
+ end
36
+
37
+ it "should report an unset light" do
38
+ expect_light(:unset)
39
+
40
+ @feedback.report_subresult(@subresult)
41
+ end
42
+
43
+ def expect_light(setting)
44
+ @light.should_receive(:setting).at_least(:once).and_return(setting)
45
+ end
46
+ end
47
+
48
+ describe "failure count" do
49
+ it "should be zero initially" do
50
+ @feedback.failure_count.should == 0
51
+ end
52
+
53
+ it "should increment" do
54
+ @feedback.increment_failure_count
55
+
56
+ @feedback.failure_count.should == 1
57
+ end
58
+
59
+ it "should increment lots" do
60
+ 1000.times { @feedback.increment_failure_count }
61
+
62
+ @feedback.failure_count.should == 1000
63
+ end
64
+ end
65
+
66
+ describe "error count" do
67
+ it "should be zero initially" do
68
+ @feedback.error_count.should == 0
69
+ end
70
+
71
+ it "should increment" do
72
+ @feedback.increment_error_count
73
+
74
+ @feedback.error_count.should == 1
75
+ end
76
+
77
+ it "should increment lots" do
78
+ 666.times { @feedback.increment_error_count }
79
+
80
+ @feedback.error_count.should == 666
81
+ end
82
+
83
+ it "should not interfere with failure count" do
84
+ 666.times { @feedback.increment_failure_count }
85
+ 777.times { @feedback.increment_error_count }
86
+
87
+ @feedback.failure_count.should == 666
88
+ @feedback.error_count.should == 777
89
+ end
90
+ end
91
+ end