ciat 0.4.9 → 0.4.10

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 (50) hide show
  1. data/lib/ciat.rb +1 -2
  2. data/lib/ciat/{test_file.rb → ciat_file.rb} +21 -9
  3. data/lib/ciat/erb_helpers.rb +6 -1
  4. data/lib/ciat/feedback/feedback_counter.rb +11 -19
  5. data/lib/ciat/feedback/return_status.rb +6 -2
  6. data/lib/ciat/feedback/standard_output.rb +7 -2
  7. data/lib/ciat/processors/compilation_interpreter.rb +20 -7
  8. data/lib/ciat/processors/compiler.rb +38 -15
  9. data/lib/ciat/processors/interpreter.rb +28 -7
  10. data/lib/ciat/processors/java.rb +2 -8
  11. data/lib/ciat/processors/parrot.rb +0 -3
  12. data/lib/ciat/subresult.rb +14 -4
  13. data/lib/ciat/subtest.rb +83 -0
  14. data/lib/ciat/suite.rb +9 -9
  15. data/lib/ciat/suite_builder.rb +5 -5
  16. data/lib/ciat/test.rb +36 -28
  17. data/lib/ciat/test_result.rb +2 -2
  18. data/lib/ciat/traffic_light.rb +5 -14
  19. data/lib/data/ciat.css +14 -2
  20. data/lib/data/elements.yml +8 -2
  21. data/lib/templates/detail_row.html.erb +10 -4
  22. data/lib/templates/report.html.erb +5 -5
  23. data/lib/templates/summary_row.html.erb +5 -3
  24. data/spec/ciat/{test_file_spec.rb → ciat_file_spec.rb} +51 -19
  25. data/spec/ciat/erb_helpers_spec.rb +8 -13
  26. data/spec/ciat/feedback/feedback_counter_spec.rb +37 -57
  27. data/spec/ciat/feedback/return_status_spec.rb +67 -61
  28. data/spec/ciat/feedback/standard_output_spec.rb +21 -15
  29. data/spec/ciat/processors/compilation_interpreter_spec.rb +12 -0
  30. data/spec/ciat/processors/compiler_spec.rb +12 -0
  31. data/spec/ciat/processors/interpreter_spec.rb +12 -0
  32. data/spec/ciat/processors/java_spec.rb +0 -10
  33. data/spec/ciat/processors/parrot_spec.rb +0 -10
  34. data/spec/ciat/processors/shared_examples_for_element_names.rb +27 -0
  35. data/spec/ciat/rake_task_spec.rb +65 -0
  36. data/spec/ciat/subresult_spec.rb +13 -12
  37. data/spec/ciat/subtest_spec.rb +199 -0
  38. data/spec/ciat/suite_builder_spec.rb +17 -17
  39. data/spec/ciat/suite_spec.rb +13 -13
  40. data/spec/ciat/test_result_spec.rb +36 -0
  41. data/spec/ciat/test_spec.rb +73 -83
  42. data/spec/ciat/traffic_light_spec.rb +21 -31
  43. data/spec/spec_helper.rb +16 -53
  44. data/spec/templates/detail_row/elements_html_erb_spec.rb +3 -4
  45. data/spec/templates/detail_row_html_erb_spec.rb +84 -23
  46. data/spec/templates/elements/diff_html_erb_spec.rb +5 -3
  47. data/spec/templates/summary_row_html_erb_spec.rb +21 -14
  48. metadata +13 -7
  49. data/lib/ciat/processors/basic_processing.rb +0 -55
  50. data/spec/ciat/processors/basic_processing_spec.rb +0 -146
@@ -58,7 +58,7 @@ class CIAT::Suite
58
58
 
59
59
  attr_reader :processors
60
60
  attr_reader :output_folder
61
- attr_reader :test_files
61
+ attr_reader :ciat_files
62
62
  attr_reader :results
63
63
 
64
64
  # Builds a suite of CIAT tests. See the instructions above for possible
@@ -68,34 +68,34 @@ class CIAT::Suite
68
68
  CIAT::Suite.new(
69
69
  builder.build_processors,
70
70
  builder.build_output_folder,
71
- builder.build_test_files,
71
+ builder.build_ciat_files,
72
72
  builder.build_feedback)
73
73
  end
74
74
 
75
- def initialize(processors, output_folder, test_files, feedback)
75
+ def initialize(processors, output_folder, ciat_files, feedback)
76
76
  @processors = processors
77
77
  @output_folder = output_folder
78
- @test_files = test_files
78
+ @ciat_files = ciat_files
79
79
  @feedback = feedback
80
80
  end
81
81
 
82
82
  # Returns the number of tests in the suite.
83
83
  def size
84
- test_files.size
84
+ ciat_files.size
85
85
  end
86
86
 
87
87
  # Runs all of the tests in the suite, and returns the results. The results
88
88
  # are also available through #results.
89
89
  def run
90
90
  @feedback.pre_tests(self)
91
- @results = test_files.
92
- map { |test_file| create_test(test_file) }.
91
+ @results = ciat_files.
92
+ map { |ciat_file| create_test(ciat_file) }.
93
93
  map { |test| test.run }
94
94
  @feedback.post_tests(self)
95
95
  @results
96
96
  end
97
97
 
98
- def create_test(test_file)
99
- CIAT::Test.new(test_file, @processors, @feedback)
98
+ def create_test(ciat_file)
99
+ CIAT::Test.new(ciat_file, @processors, @feedback)
100
100
  end
101
101
  end
@@ -17,22 +17,22 @@ class CIAT::SuiteBuilder
17
17
  options[:output_folder] || OUTPUT_FOLDER
18
18
  end
19
19
 
20
- def build_test_files
20
+ def build_ciat_files
21
21
  if options[:files]
22
- make_test_files(options[:files])
22
+ make_ciat_files(options[:files])
23
23
  else
24
24
  folder = options[:folder] || "ciat"
25
25
  pattern = options[:pattern] || "*.ciat"
26
- make_test_files(Dir[File.join(folder, "**", pattern)])
26
+ make_ciat_files(Dir[File.join(folder, "**", pattern)])
27
27
  end
28
28
  end
29
29
 
30
- def make_test_files(filenames)
30
+ def make_ciat_files(filenames)
31
31
  if filenames.empty?
32
32
  raise IOError.new("no test files specified")
33
33
  end
34
34
  filenames.map do |filename|
35
- CIAT::TestFile.new(filename, build_output_folder)
35
+ CIAT::CiatFile.new(filename, build_output_folder)
36
36
  end
37
37
  end
38
38
 
@@ -1,55 +1,63 @@
1
1
  require 'set'
2
2
  require 'ciat/test_result'
3
+ require 'ciat/subtest'
3
4
  require 'ciat/subresult'
4
5
 
5
6
  class CIAT::Test
6
7
  attr_reader :processors
7
8
 
8
- def initialize(test_file, processors, feedback) #:nodoc:
9
- @test_file = test_file
9
+ def initialize(ciat_file, processors, feedback) #:nodoc:
10
+ @ciat_file = ciat_file
10
11
  @processors = processors
11
12
  @feedback = feedback
12
13
  end
14
+
15
+ def run
16
+ CIAT::TestResult.new(@ciat_file, run_subtests)
17
+ end
13
18
 
14
- def elements
15
- @elements ||= @test_file.process
19
+ def grouping
20
+ @ciat_file.grouping
16
21
  end
17
22
 
18
- def filename
19
- @test_file.filename(:ciat)
23
+ def run_subtests #:nodoc:
24
+ subtests = make_subtests
25
+ subresults = []
26
+ until subtests.empty?
27
+ subtest = subtests.shift
28
+ subresults << subresult(subtest, subtest.process)
29
+ if subtest.sad_path?
30
+ return subresults + remaining_subtests(subtests, unneeded)
31
+ end
32
+ unless subresults.last.light.green?
33
+ return subresults + remaining_subtests(subtests, unset)
34
+ end
35
+ end
36
+ subresults
37
+ end
38
+
39
+ def remaining_subtests(subtests, light)
40
+ subtests.map { |subtest| subresult(subtest, light) }
20
41
  end
21
42
 
22
- def run
23
- CIAT::TestResult.new(self, run_processors)
43
+ def unneeded
44
+ CIAT::TrafficLight::UNNEEDED
24
45
  end
25
46
 
26
- def grouping
27
- @test_file.grouping
47
+ def unset
48
+ CIAT::TrafficLight::UNSET
28
49
  end
29
50
 
30
- def run_processors #:nodoc:
31
- light = CIAT::TrafficLight::GREEN
51
+ def make_subtests
32
52
  processors.map do |processor|
33
- if light.green?
34
- light = processor.process(self)
35
- subresult(processor, light)
36
- else
37
- subresult(processor)
38
- end
53
+ CIAT::Subtest.new(@ciat_file, processor)
39
54
  end
40
55
  end
41
56
 
42
- def subresult(processor, light = CIAT::TrafficLight::UNSET)
43
- subresult = CIAT::Subresult.new(self, light, processor)
57
+ def subresult(subtest, light)
58
+ subresult = CIAT::Subresult.new(@ciat_file,
59
+ subtest.path_kind, light, subtest)
44
60
  @feedback.report_subresult(subresult)
45
61
  subresult
46
62
  end
47
-
48
- def element(*names)
49
- elements[names.compact.join("_").to_sym]
50
- end
51
-
52
- def element?(*names)
53
- elements.has_key?(names.compact.join("_").to_sym)
54
- end
55
63
  end
@@ -11,11 +11,11 @@ class CIAT::TestResult
11
11
  end
12
12
 
13
13
  def processors
14
- @test.processors
14
+ @subresults.map { |subresult| subresult.processor }
15
15
  end
16
16
 
17
17
  def filename
18
- @test.filename
18
+ @test.filename(:ciat)
19
19
  end
20
20
 
21
21
  def element(*args)
@@ -1,8 +1,6 @@
1
1
  class CIAT::TrafficLight
2
2
 
3
- attr_reader :setting
4
-
5
- def initialize(setting = :unset) #:nodoc:
3
+ def initialize(setting) #:nodoc:
6
4
  @setting = setting
7
5
  end
8
6
 
@@ -10,6 +8,7 @@ class CIAT::TrafficLight
10
8
  RED = CIAT::TrafficLight.new(:red)
11
9
  YELLOW = CIAT::TrafficLight.new(:yellow)
12
10
  UNSET = CIAT::TrafficLight.new(:unset)
11
+ UNNEEDED = CIAT::TrafficLight.new(:unneeded)
13
12
 
14
13
  def unset?
15
14
  @setting == :unset
@@ -19,24 +18,16 @@ class CIAT::TrafficLight
19
18
  @setting == :green
20
19
  end
21
20
 
22
- def green! #:nodoc:
23
- @setting = :green unless yellow?
24
- end
25
-
26
21
  def yellow?
27
22
  @setting == :yellow
28
23
  end
29
24
 
30
- def yellow! #:nodoc:
31
- @setting = :yellow
32
- end
33
-
34
25
  def red?
35
26
  @setting == :red
36
27
  end
37
-
38
- def red! #:nodoc:
39
- @setting = :red unless yellow?
28
+
29
+ def unneeded?
30
+ @setting == :unneeded
40
31
  end
41
32
 
42
33
  def color
@@ -35,6 +35,18 @@
35
35
  margin: 0;
36
36
  }
37
37
 
38
- .details h4, .details h3 {
39
- margin: 0;
38
+ .details table, .details p {
39
+ margin-left: 10px;
40
+ }
41
+
42
+ tr.details td {
43
+ padding-bottom: 10px;
44
+ }
45
+
46
+ .details h3 {
47
+ margin: 20px 10px 10px 10px;
48
+ }
49
+
50
+ .details h4 {
51
+ margin: 10px;
40
52
  }
@@ -7,9 +7,12 @@ compilation:
7
7
  compilation_generated:
8
8
  description: compilation
9
9
  template: plain
10
- compilation_error:
10
+ compilation_error_generated:
11
11
  description: error from compilation
12
12
  template: plain
13
+ compilation_error_diff:
14
+ description: diff of error output
15
+ template: diff
13
16
  compilation_diff:
14
17
  description: compilation diff
15
18
  template: diff
@@ -19,12 +22,15 @@ execution:
19
22
  execution_generated:
20
23
  description: execution
21
24
  template: plain
22
- execution_error:
25
+ execution_error_generated:
23
26
  description: error from execution
24
27
  template: plain
25
28
  execution_diff:
26
29
  description: execution diff
27
30
  template: diff
31
+ execution_error_diff:
32
+ description: execution error diff
33
+ template: diff
28
34
  command_line:
29
35
  description: command-line arguments
30
36
  template: plain
@@ -1,10 +1,16 @@
1
- <tr class="details" style="display:none">
1
+ <tr id="details_<%= filename_to_id(result.filename) %>"
2
+ class="details" style="display:none">
2
3
  <td colspan="<%= result.subresults.size + 1 %>">
3
4
 
4
5
  <% result.subresults.each do |subresult| %>
5
- <h3>Results from <%= subresult.processor.describe %></h3>
6
- <%= render "detail_row/elements",
7
- :elements => subresult.relevant_elements %>
6
+ <h3>Results from <%= subresult.processor.describe %> (<%= subresult.path_kind %> path)</h3>
7
+
8
+ <% if subresult.light.unset? || subresult.light.unneeded? %>
9
+ <p>Not executed.</p>
10
+ <% else %>
11
+ <%= render "detail_row/elements",
12
+ :elements => subresult.relevant_elements %>
13
+ <% end %>
8
14
  <% end %>
9
15
 
10
16
  </tr>
@@ -27,11 +27,11 @@
27
27
  </tr>
28
28
 
29
29
  <% results.each do |result| %>
30
- <% if new_grouping?(result) %>
31
- <%= render "group_header", :result => result %>
32
- <% end %>
33
- <%= render "summary_row", :result => result %>
34
- <%= render "detail_row", :result => result %>
30
+ <% if new_grouping?(result) %>
31
+ <%= render "group_header", :result => result %>
32
+ <% end %>
33
+ <%= render "summary_row", :result => result %>
34
+ <%= render "detail_row", :result => result %>
35
35
  <% end %>
36
36
  </table>
37
37
  </body>
@@ -1,11 +1,13 @@
1
- <tr class="summary">
1
+ <tr id="summary_<%= filename_to_id(result.filename) %>" class="summary">
2
2
  <td>
3
- <a href="#" onclick="$(this).up('tr').next().toggle(); return false;" title="<%= result.filename %>">
3
+ <a href="#"
4
+ onclick="$(this).up('tr').next().toggle(); return false;"
5
+ title="<%= result.filename %>">
4
6
  <%= result.element(:description).content %>
5
7
  </a>
6
8
  </td>
7
9
  <% result.subresults.each do |subresult| %>
8
- <td class="<%= subresult.light.setting %>">
10
+ <td class="<%= subresult.light.color %>">
9
11
  <%= light_to_word(subresult.light) %>
10
12
  </td>
11
13
  <% end %>
@@ -1,10 +1,10 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper.rb'
2
2
 
3
- describe CIAT::TestFile do
3
+ describe CIAT::CiatFile do
4
4
  before(:each) do
5
5
  File.should_receive(:exists?).with(anything).
6
6
  any_number_of_times.and_return(true)
7
- @test_file = CIAT::TestFile.new(mock("filename"), mock("output folder"))
7
+ @ciat_file = CIAT::CiatFile.new(mock("filename"), mock("output folder"))
8
8
  end
9
9
 
10
10
  describe "processing test file" do
@@ -17,10 +17,10 @@ describe CIAT::TestFile do
17
17
  :e0 => mock("element 0"), :e1 => mock("element 1"),
18
18
  :e2 => mock("element 2") }
19
19
 
20
- @test_file.should_receive(:split).and_return(raw_elements)
21
- @test_file.should_receive(:filename).with(:e0).and_return(filenames[0])
22
- @test_file.should_receive(:filename).with(:e1).and_return(filenames[1])
23
- @test_file.should_receive(:filename).with(:e2).and_return(filenames[2])
20
+ @ciat_file.should_receive(:split).and_return(raw_elements)
21
+ @ciat_file.should_receive(:filename).with(:e0).and_return(filenames[0])
22
+ @ciat_file.should_receive(:filename).with(:e1).and_return(filenames[1])
23
+ @ciat_file.should_receive(:filename).with(:e2).and_return(filenames[2])
24
24
  CIAT::TestElement.should_receive(:new).
25
25
  with(:e0, filenames[0], raw_elements[:e0]).and_return(elements[:e0])
26
26
  CIAT::TestElement.should_receive(:new).
@@ -28,69 +28,101 @@ describe CIAT::TestFile do
28
28
  CIAT::TestElement.should_receive(:new).
29
29
  with(:e2, filenames[2], raw_elements[:e2]).and_return(elements[:e2])
30
30
 
31
- @test_file.process.should == elements
31
+ @ciat_file.process.should == elements
32
32
  end
33
33
  end
34
34
 
35
35
  describe "splitting a test file" do
36
36
  it "should split just a description" do
37
37
  expect_file_content("description only\n")
38
- @test_file.split.should == { :description => "description only\n" }
38
+ @ciat_file.split.should == { :description => "description only\n" }
39
39
  end
40
40
 
41
41
  it "should split description and something else" do
42
42
  expect_file_content("description\n", "==== tag\n", "content\n")
43
- @test_file.split.should == { :description => "description\n", :tag => "content\n" }
43
+ @ciat_file.split.should == { :description => "description\n", :tag => "content\n" }
44
44
  end
45
45
 
46
46
  it "should split the test file" do
47
47
  expect_file_content("d\n", "==== source\n", "s\n",
48
48
  "==== compilation_expected \n", "p\n",
49
49
  "==== output_expected\n", "o\n")
50
- @test_file.split.should == { :description => "d\n",
50
+ @ciat_file.split.should == { :description => "d\n",
51
51
  :source => "s\n", :compilation_expected => "p\n", :output_expected => "o\n" }
52
52
  end
53
53
 
54
54
  it "should allow spaces in element name" do
55
55
  expect_file_content("description\n" , "==== element name\n", "content\n")
56
- @test_file.split.should == {
56
+ @ciat_file.split.should == {
57
57
  :description => "description\n", :element_name => "content\n" }
58
58
  end
59
59
 
60
60
  def expect_file_content(*content)
61
- @test_file.should_receive(:read).and_return(content)
61
+ @ciat_file.should_receive(:read).and_return(content)
62
+ end
63
+ end
64
+
65
+ describe "processing elements" do
66
+ before(:each) do
67
+ @elements = mock("elements")
68
+ @ciat_file.should_receive(:elements).and_return(@elements)
69
+ end
70
+
71
+ it "should return specified element" do
72
+ element = mock("element")
73
+
74
+ @elements.should_receive(:[]).with(:foo).and_return(element)
75
+
76
+ @ciat_file.element(:foo).should == element
77
+ end
78
+
79
+ it "should return specified element with multi-word name" do
80
+ element = mock("element")
81
+
82
+ @elements.should_receive(:[]).with(:foo_bar_joe).and_return(element)
83
+
84
+ @ciat_file.element(:foo, :bar, :joe).should == element
85
+ end
86
+
87
+ it "should check to see if element exists" do
88
+ exists = mock("a boolean")
89
+
90
+ @elements.should_receive(:has_key?).
91
+ with(:foo_bar_joe).and_return(exists)
92
+
93
+ @ciat_file.element?(:foo, :bar, :joe).should == exists
62
94
  end
63
95
  end
64
96
  end
65
97
 
66
- describe CIAT::TestFile, "generating actual file names" do
98
+ describe CIAT::CiatFile, "generating actual file names" do
67
99
  before(:each) do
68
100
  File.should_receive(:exists?).with(anything).
69
101
  any_number_of_times.and_return(true)
70
102
  @output_folder = "outie"
71
- @test_file = CIAT::TestFile.new("ciat/phile.ciat", @output_folder)
103
+ @ciat_file = CIAT::CiatFile.new("ciat/phile.ciat", @output_folder)
72
104
  end
73
105
 
74
106
  it "should return the original filename" do
75
- @test_file.filename(:ciat).should == "ciat/phile.ciat"
107
+ @ciat_file.filename(:ciat).should == "ciat/phile.ciat"
76
108
  end
77
109
 
78
110
  it "should work with no modifiers" do
79
- @test_file.filename().should == "outie/ciat/phile"
111
+ @ciat_file.filename().should == "outie/ciat/phile"
80
112
  end
81
113
 
82
114
  it "should work with multiple modifiers" do
83
- @test_file.filename("one", "two", "three").should == "outie/ciat/phile_one_two_three"
115
+ @ciat_file.filename("one", "two", "three").should == "outie/ciat/phile_one_two_three"
84
116
  end
85
117
  end
86
118
 
87
- describe CIAT::TestFile, "constructor errors" do
119
+ describe CIAT::CiatFile, "constructor errors" do
88
120
  it "should complain about a missing file" do
89
121
  File.should_receive(:exists?).
90
122
  with("does-not-exist.ciat").and_return(false)
91
123
 
92
124
  lambda {
93
- CIAT::TestFile.new("does-not-exist.ciat", nil)
125
+ CIAT::CiatFile.new("does-not-exist.ciat", nil)
94
126
  }.should raise_error(IOError)
95
127
  end
96
128
  end