Class: CIAT::Subtest
Instance Attribute Summary collapse
Instance Method Summary
collapse
#diff_options, #html_diff
Constructor Details
#initialize(ciat_file, processor) ⇒ Subtest
Returns a new instance of Subtest.
9
10
11
12
|
# File 'lib/ciat/subtest.rb', line 9
def initialize(ciat_file, processor)
@ciat_file = ciat_file
@processor = processor
end
|
Instance Attribute Details
#processor ⇒ Object
Returns the value of attribute processor.
7
8
9
|
# File 'lib/ciat/subtest.rb', line 7
def processor
@processor
end
|
Instance Method Details
#command_line ⇒ Object
51
52
53
|
# File 'lib/ciat/subtest.rb', line 51
def command_line
"#{@processor.executable} '#{input_file}' #{command_line_args} > '#{output_file}' 2> '#{error_file}'"
end
|
#command_line_args ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/ciat/subtest.rb', line 55
def command_line_args
if @ciat_file.element?(:command_line)
@ciat_file.element(:command_line).content.strip
else
''
end
end
|
#describe ⇒ Object
14
15
16
|
# File 'lib/ciat/subtest.rb', line 14
def describe
@processor.describe
end
|
#diff ⇒ Object
Compares the expected and generated executions.
76
77
78
79
80
81
82
|
# File 'lib/ciat/subtest.rb', line 76
def diff
element_name = happy_path? ? @processor.kind.output_name : @processor.kind.error_name
html_diff(
@ciat_file.element(element_name).as_file,
@ciat_file.element(element_name, :generated).as_file,
@ciat_file.element(element_name, :diff).as_file)
end
|
#error_file ⇒ Object
71
72
73
|
# File 'lib/ciat/subtest.rb', line 71
def error_file
@ciat_file.element(@processor.kind.error_name, :generated).as_file
end
|
#execute ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/ciat/subtest.rb', line 31
def execute
RakeFileUtils.verbose(false) do
sh(command_line) do |ok, result|
return happy_path? == ok
end
end
end
|
#happy_path? ⇒ Boolean
39
40
41
|
# File 'lib/ciat/subtest.rb', line 39
def happy_path?
@ciat_file.element?(@processor.kind.happy_path_element)
end
|
63
64
65
|
# File 'lib/ciat/subtest.rb', line 63
def input_file
@ciat_file.element(@processor.kind.input_name).as_file
end
|
#output_file ⇒ Object
67
68
69
|
# File 'lib/ciat/subtest.rb', line 67
def output_file
@ciat_file.element(@processor.kind.output_name, :generated).as_file
end
|
#path_kind ⇒ Object
47
48
49
|
# File 'lib/ciat/subtest.rb', line 47
def path_kind
happy_path? ? :happy : :sad
end
|
#process ⇒ Object
Executes the program, and diffs the output.
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/ciat/subtest.rb', line 19
def process
if execute
if diff
CIAT::TrafficLight::GREEN
else
CIAT::TrafficLight::RED
end
else
CIAT::TrafficLight::YELLOW
end
end
|
#sad_path? ⇒ Boolean
43
44
45
|
# File 'lib/ciat/subtest.rb', line 43
def sad_path?
not happy_path?
end
|