ghaki-report 2011.11.30.1
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.
- data/LICENSE +19 -0
- data/README +23 -0
- data/VERSION +1 -0
- data/lib/ghaki/report/base.rb +68 -0
- data/lib/ghaki/report/errors.rb +6 -0
- data/lib/ghaki/report/mixin/linear_parser.rb +135 -0
- data/lib/ghaki/report/output_file.rb +41 -0
- data/spec/ghaki/report/base_spec.rb +70 -0
- data/spec/ghaki/report/mixin/linear_parser_spec.rb +289 -0
- data/spec/ghaki/report/output_file_spec.rb +32 -0
- data/spec/spec_helper.rb +6 -0
- metadata +148 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2010 Gerald Kalafut
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
data/README
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
= Ghaki Report - Basic reporting helpers
|
|
2
|
+
|
|
3
|
+
Ghaki Report is a collection of extensions for basic reporting.
|
|
4
|
+
|
|
5
|
+
== Download
|
|
6
|
+
|
|
7
|
+
The latest version of Ghaki Report can be found at
|
|
8
|
+
|
|
9
|
+
* git@github.com:ghaki/ghaki-report.git
|
|
10
|
+
|
|
11
|
+
== Installation
|
|
12
|
+
|
|
13
|
+
The preferred method of installing Ghaki Report is through its GEM file.
|
|
14
|
+
|
|
15
|
+
% [sudo] gem install ghaki-report-1.0.0.gem
|
|
16
|
+
|
|
17
|
+
== License
|
|
18
|
+
|
|
19
|
+
Ghaki Report is released under the MIT license.
|
|
20
|
+
|
|
21
|
+
== Support
|
|
22
|
+
|
|
23
|
+
Contact mailto:gerald@kalafut.org
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2011.11.30.1
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'ghaki/logger/mixin'
|
|
2
|
+
require 'ghaki/stats/mixin'
|
|
3
|
+
|
|
4
|
+
module Ghaki #:nodoc:
|
|
5
|
+
module Report #:nodoc:
|
|
6
|
+
|
|
7
|
+
class Base
|
|
8
|
+
include Ghaki::Logger::Mixin
|
|
9
|
+
include Ghaki::Stats::Mixin
|
|
10
|
+
|
|
11
|
+
######################################################################
|
|
12
|
+
class << self
|
|
13
|
+
attr_accessor :report_name
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
######################################################################
|
|
17
|
+
def initialize opts={}
|
|
18
|
+
self.report_name = opts[:report_name] unless opts[:report_name].nil?
|
|
19
|
+
@stats = opts[:stats]
|
|
20
|
+
if not opts[:logger].nil?
|
|
21
|
+
@logger = opts[:logger]
|
|
22
|
+
elsif not opts[:log_file_name].nil?
|
|
23
|
+
@logger = Ghaki::Logger::Base.new( :file_name => opts[:log_file_name] )
|
|
24
|
+
elsif not opts[:log_file_handle].nil?
|
|
25
|
+
@logger = Ghaki::Logger::Base.new( :file_handle => opts[:log_file_handle] )
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
######################################################################
|
|
30
|
+
def report_name= title
|
|
31
|
+
self.class.report_name = title
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
######################################################################
|
|
35
|
+
def report_name title=nil
|
|
36
|
+
if title.nil?
|
|
37
|
+
self.class.report_name
|
|
38
|
+
elsif title[0,1] == '.'
|
|
39
|
+
self.class.report_name + title
|
|
40
|
+
else
|
|
41
|
+
title
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
######################################################################
|
|
46
|
+
def minor_report_wrap title=nil, &block
|
|
47
|
+
logger.minor.wrap( report_name(title) ) do
|
|
48
|
+
begin
|
|
49
|
+
block.call
|
|
50
|
+
ensure
|
|
51
|
+
stats.flush self.logger
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
######################################################################
|
|
57
|
+
def major_report_wrap title=nil, &block
|
|
58
|
+
logger.major.wrap( report_name(title) ) do
|
|
59
|
+
begin
|
|
60
|
+
block.call
|
|
61
|
+
ensure
|
|
62
|
+
stats.flush self.logger
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
68
|
+
end end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require 'ghaki/report/errors'
|
|
2
|
+
|
|
3
|
+
module Ghaki #:nodoc:
|
|
4
|
+
module Report #:nodoc:
|
|
5
|
+
module Mixin #:nodoc:
|
|
6
|
+
|
|
7
|
+
module LinearParser
|
|
8
|
+
|
|
9
|
+
PARSER_UNKNOWN_UNLIMITED = 0
|
|
10
|
+
PARSER_UNKNOWN_MAX_DEF = PARSER_UNKNOWN_UNLIMITED
|
|
11
|
+
|
|
12
|
+
PARSER_WARN_UNLIMITED = 0
|
|
13
|
+
PARSER_WARN_MAX_DEF = 10
|
|
14
|
+
|
|
15
|
+
PARSER_ERROR_UNLIMITED = 0
|
|
16
|
+
PARSER_ERROR_MAX_DEF = 1
|
|
17
|
+
|
|
18
|
+
attr_reader :parser_curr_line, :parser_curr_lcnt
|
|
19
|
+
attr_accessor :parser_unknown_max,
|
|
20
|
+
:parser_error_max, :parser_warn_max
|
|
21
|
+
|
|
22
|
+
def parser_startup
|
|
23
|
+
@parser_unknown_max ||= PARSER_UNKNOWN_MAX_DEF
|
|
24
|
+
@parser_warn_max ||= PARSER_WARN_MAX_DEF
|
|
25
|
+
@parser_error_max ||= PARSER_ERROR_MAX_DEF
|
|
26
|
+
parser_reset_stats
|
|
27
|
+
parser_reset_state
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def parser_reset_state
|
|
31
|
+
@parser_curr_lcnt = 0
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def parser_reset_stats
|
|
35
|
+
stats.clear
|
|
36
|
+
stats.def_zero 'Input Lines', 'Read'
|
|
37
|
+
stats.def_zero 'Input Lines', 'Skipped'
|
|
38
|
+
stats.def_zero 'Input Lines', 'Matched'
|
|
39
|
+
stats.def_zero 'Input Lines', 'Invalid'
|
|
40
|
+
stats.def_zero 'Input Lines', 'Unknown'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def parser_cleanup
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def parser_advance line
|
|
47
|
+
@parser_curr_lcnt += 1
|
|
48
|
+
@parser_curr_line = line
|
|
49
|
+
stats.incr 'Input Lines', 'Read'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def parser_engine text, &block
|
|
53
|
+
parser_startup
|
|
54
|
+
text.each_line do |line|
|
|
55
|
+
parser_advance line
|
|
56
|
+
block.call( line )
|
|
57
|
+
end
|
|
58
|
+
parser_cleanup
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
#
|
|
62
|
+
# PARSING STATUS
|
|
63
|
+
#
|
|
64
|
+
|
|
65
|
+
def parser_matched msg=''
|
|
66
|
+
stats.incr 'Input Lines', 'Matched'
|
|
67
|
+
stats.incr 'Matched Lines', msg unless msg.empty?
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def parser_skipped msg='Expected'
|
|
71
|
+
stats.incr 'Input Lines', 'Skipped'
|
|
72
|
+
stats.incr 'Skipped Lines', msg
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def parser_unknown msg='Unknown Input'
|
|
76
|
+
logger.warn "#{msg} At Line #{@parser_curr_lcnt}"
|
|
77
|
+
logger.puts @parser_curr_line
|
|
78
|
+
_parser_unknown_check msg
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def parser_invalid msg='Invalid Line'
|
|
82
|
+
stats.incr 'Input Lines', 'Invalid'
|
|
83
|
+
parser_error msg
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def parser_error msg='Parser Error'
|
|
87
|
+
logger.error "#{msg} At Line #{@parser_curr_lcnt}"
|
|
88
|
+
logger.puts @parser_curr_line
|
|
89
|
+
_parser_error_check msg
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def parser_warn msg='Parser Warning'
|
|
93
|
+
logger.warn "#{msg} At Line #{@parser_curr_lcnt}"
|
|
94
|
+
logger.puts @parser_curr_line
|
|
95
|
+
_parser_warn_check msg
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
#
|
|
100
|
+
# PARSER STATE CHECKS
|
|
101
|
+
#
|
|
102
|
+
|
|
103
|
+
def _parser_basic_check msg, max, unl, maj, min, exc
|
|
104
|
+
stats.incr maj, min
|
|
105
|
+
return if max == unl
|
|
106
|
+
raise ReportContentError, msg if max == 1
|
|
107
|
+
cnt = stats.get( maj, min )
|
|
108
|
+
if cnt >= max
|
|
109
|
+
raise ReportContentError, exc + ' Maximum Exceeded: ' + cnt.to_s
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def _parser_error_check msg
|
|
114
|
+
_parser_basic_check( msg,
|
|
115
|
+
@parser_error_max, PARSER_ERROR_UNLIMITED,
|
|
116
|
+
'Parser State', 'Errors',
|
|
117
|
+
'Parser Error' )
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def _parser_warn_check msg
|
|
121
|
+
_parser_basic_check( msg,
|
|
122
|
+
@parser_warn_max, PARSER_WARN_UNLIMITED,
|
|
123
|
+
'Parser State', 'Warnings',
|
|
124
|
+
'Parser Warning' )
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def _parser_unknown_check msg
|
|
128
|
+
_parser_basic_check( msg,
|
|
129
|
+
@parser_unknown_max, PARSER_UNKNOWN_UNLIMITED,
|
|
130
|
+
'Input Lines', 'Unknown',
|
|
131
|
+
'Unknown Line' )
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
end
|
|
135
|
+
end end end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'ghaki/core_ext/file/with_temp'
|
|
2
|
+
require 'ghaki/report/base'
|
|
3
|
+
|
|
4
|
+
module Ghaki #:nodoc:
|
|
5
|
+
module Report #:nodoc:
|
|
6
|
+
|
|
7
|
+
class OutputFile < Base
|
|
8
|
+
|
|
9
|
+
######################################################################
|
|
10
|
+
attr_accessor :output_file
|
|
11
|
+
|
|
12
|
+
######################################################################
|
|
13
|
+
def initialize opts={} ; super opts
|
|
14
|
+
self.class.report_name ||= 'WRITING REPORT'
|
|
15
|
+
@output_file = opts[:output_file]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
######################################################################
|
|
19
|
+
def output_report
|
|
20
|
+
output_prepare
|
|
21
|
+
logger.info 'output file: ' + @output_file
|
|
22
|
+
File.with_opened_temp @output_file do |tmp_file|
|
|
23
|
+
output_to_format tmp_file
|
|
24
|
+
end
|
|
25
|
+
output_finish
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
######################################################################
|
|
29
|
+
def output_finish
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
######################################################################
|
|
33
|
+
def output_prepare
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
######################################################################
|
|
37
|
+
def output_to_format out_file
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'ghaki/report/base'
|
|
2
|
+
|
|
3
|
+
module Ghaki module Report module BaseTesting
|
|
4
|
+
describe Base do
|
|
5
|
+
|
|
6
|
+
before(:all) do
|
|
7
|
+
@log = stub_everything()
|
|
8
|
+
@maj = stub_everything()
|
|
9
|
+
@min = stub_everything()
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class MyReport < Base
|
|
13
|
+
self.report_name = 'my_report'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context 'eigen class' do
|
|
17
|
+
subject { MyReport }
|
|
18
|
+
it { should respond_to :report_name }
|
|
19
|
+
describe '#report_name' do
|
|
20
|
+
it 'specifies report name' do
|
|
21
|
+
MyReport.report_name.should == 'my_report'
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
subject do MyReport.new( :logger => @log ) end
|
|
27
|
+
|
|
28
|
+
context 'object instance' do
|
|
29
|
+
it { should respond_to :logger }
|
|
30
|
+
it { should respond_to :logger= }
|
|
31
|
+
it { should respond_to :stats }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '#report_name' do
|
|
35
|
+
it 'defaults to eigen report name' do
|
|
36
|
+
subject.report_name == 'my_report'
|
|
37
|
+
end
|
|
38
|
+
it 'accepts normal report name' do
|
|
39
|
+
subject.report_name('quack').should == 'quack'
|
|
40
|
+
end
|
|
41
|
+
it 'accepts period leading report nmae' do
|
|
42
|
+
subject.report_name('.moo').should == 'my_report.moo'
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe '#report_name=' do
|
|
47
|
+
it 'assigns report name' do
|
|
48
|
+
subject.report_name = 'zap'
|
|
49
|
+
subject.report_name.should == 'zap'
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe '#minor_report_wrap' do
|
|
54
|
+
it 'calls logger minor mode' do
|
|
55
|
+
@log.expects(:minor).returns(@min).once
|
|
56
|
+
@min.expects(:wrap).with('my_report').once
|
|
57
|
+
subject.minor_report_wrap do end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe '#major_report_wrap' do
|
|
62
|
+
it 'calls logger major mode' do
|
|
63
|
+
@log.expects(:major).returns(@maj).once
|
|
64
|
+
@maj.expects(:wrap).with('my_report').once
|
|
65
|
+
subject.major_report_wrap do end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
end end end
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
require 'ghaki/logger/spec_helper'
|
|
2
|
+
require 'ghaki/stats/spec_helper'
|
|
3
|
+
require 'ghaki/report/base'
|
|
4
|
+
require 'ghaki/report/mixin/linear_parser'
|
|
5
|
+
|
|
6
|
+
module Ghaki module Report module Mixin module LinearParser_Testing
|
|
7
|
+
describe LinearParser do
|
|
8
|
+
include Ghaki::Logger::SpecHelper
|
|
9
|
+
include Ghaki::Stats::SpecHelper
|
|
10
|
+
|
|
11
|
+
class MyParser < Base
|
|
12
|
+
include LinearParser
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
before(:each) do
|
|
16
|
+
setup_safe_stats
|
|
17
|
+
setup_safe_logger
|
|
18
|
+
@parser = MyParser.new({
|
|
19
|
+
:logger => @logger,
|
|
20
|
+
:stats => @stats,
|
|
21
|
+
})
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
subject do @parser end
|
|
25
|
+
|
|
26
|
+
it { should respond_to :parser_curr_line }
|
|
27
|
+
it { should respond_to :parser_curr_lcnt }
|
|
28
|
+
it { should respond_to :parser_unknown_max }
|
|
29
|
+
it { should respond_to :parser_unknown_max= }
|
|
30
|
+
it { should respond_to :parser_error_max }
|
|
31
|
+
it { should respond_to :parser_error_max= }
|
|
32
|
+
it { should respond_to :parser_warn_max }
|
|
33
|
+
it { should respond_to :parser_warn_max= }
|
|
34
|
+
|
|
35
|
+
before(:each) do
|
|
36
|
+
@stats.clear
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '#parser_startup' do
|
|
40
|
+
it 'defaults parser unknown max' do
|
|
41
|
+
subject.parser_unknown_max = nil
|
|
42
|
+
subject.parser_startup
|
|
43
|
+
subject.parser_unknown_max.should == LinearParser::PARSER_UNKNOWN_MAX_DEF
|
|
44
|
+
end
|
|
45
|
+
it 'defaults parser warning max' do
|
|
46
|
+
subject.parser_warn_max = nil
|
|
47
|
+
subject.parser_startup
|
|
48
|
+
subject.parser_warn_max.should == LinearParser::PARSER_WARN_MAX_DEF
|
|
49
|
+
end
|
|
50
|
+
it 'defaults parser error max' do
|
|
51
|
+
subject.parser_error_max = nil
|
|
52
|
+
subject.parser_startup
|
|
53
|
+
subject.parser_error_max.should == LinearParser::PARSER_ERROR_MAX_DEF
|
|
54
|
+
end
|
|
55
|
+
it 'zeroes parser stats' do
|
|
56
|
+
subject.expects(:parser_reset_stats).once
|
|
57
|
+
subject.parser_startup
|
|
58
|
+
end
|
|
59
|
+
it 'resets parser state' do
|
|
60
|
+
subject.expects(:parser_reset_state).once
|
|
61
|
+
subject.parser_startup
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe '#parser_cleanup' do
|
|
66
|
+
it { should respond_to :parser_cleanup }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe '#parser_advance' do
|
|
70
|
+
before(:each) do
|
|
71
|
+
subject.parser_startup
|
|
72
|
+
end
|
|
73
|
+
it 'increments line count' do
|
|
74
|
+
subject.parser_advance 'junk'
|
|
75
|
+
subject.parser_curr_lcnt.should == 1
|
|
76
|
+
end
|
|
77
|
+
it 'sets current line' do
|
|
78
|
+
subject.parser_advance 'junk'
|
|
79
|
+
subject.parser_curr_line.should == 'junk'
|
|
80
|
+
end
|
|
81
|
+
it 'increments input lines read' do
|
|
82
|
+
subject.parser_advance 'junk'
|
|
83
|
+
@stats.get('Input Lines','Read').should == 1
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe '#parser_engine' do
|
|
88
|
+
it 'calls parser startup' do
|
|
89
|
+
subject.parser_startup # do actual init
|
|
90
|
+
subject.expects(:parser_startup).once # test for init
|
|
91
|
+
subject.parser_engine "\njunk\njunk\n" do
|
|
92
|
+
# do nothing
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
it 'calls parser advance for each line' do
|
|
96
|
+
subject.expects(:parser_advance).times(3)
|
|
97
|
+
subject.parser_engine "\njunk\njunk\n" do
|
|
98
|
+
# do nothing
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
it 'yields for each line' do
|
|
102
|
+
cnt = 0
|
|
103
|
+
subject.parser_engine "\njunk\njunk\n" do
|
|
104
|
+
cnt += 1
|
|
105
|
+
end
|
|
106
|
+
cnt.should == 3
|
|
107
|
+
end
|
|
108
|
+
it 'calls parser cleanup' do
|
|
109
|
+
subject.expects(:parser_cleanup)
|
|
110
|
+
subject.parser_engine "\njunk\njunk\n" do
|
|
111
|
+
# do nothing
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe '#parser_reset_stats' do
|
|
117
|
+
it 'clears existing stats' do
|
|
118
|
+
@stats.expects(:clear).once
|
|
119
|
+
subject.parser_reset_stats
|
|
120
|
+
end
|
|
121
|
+
it 'zeroes input lines read' do
|
|
122
|
+
@stats.put( 'Input Lines', 'Read', 20 )
|
|
123
|
+
subject.parser_reset_stats
|
|
124
|
+
@stats.get('Input Lines','Read').should == 0
|
|
125
|
+
end
|
|
126
|
+
it 'zeroes input lines skipped' do
|
|
127
|
+
@stats.put( 'Input Lines', 'Skipped', 20 )
|
|
128
|
+
subject.parser_reset_stats
|
|
129
|
+
@stats.get('Input Lines','Skipped').should == 0
|
|
130
|
+
end
|
|
131
|
+
it 'zeroes input lines matched' do
|
|
132
|
+
@stats.put( 'Input Lines', 'Matched', 20 )
|
|
133
|
+
subject.parser_reset_stats
|
|
134
|
+
@stats.get('Input Lines','Matched').should == 0
|
|
135
|
+
end
|
|
136
|
+
it 'zeroes input lines invalid' do
|
|
137
|
+
@stats.put( 'Input Lines', 'Invalid', 20 )
|
|
138
|
+
subject.parser_reset_stats
|
|
139
|
+
@stats.get('Input Lines','Invalid').should == 0
|
|
140
|
+
end
|
|
141
|
+
it 'zeroes input lines unknown' do
|
|
142
|
+
@stats.put( 'Input Lines', 'Unknown', 20 )
|
|
143
|
+
subject.parser_reset_stats
|
|
144
|
+
@stats.get('Input Lines','Unknown').should == 0
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
describe '#parser_matched' do
|
|
149
|
+
it 'increments counters' do
|
|
150
|
+
subject.parser_matched 'Zap'
|
|
151
|
+
subject.stats.get('Input Lines','Matched').should == 1
|
|
152
|
+
subject.stats.get('Matched Lines','Zap').should == 1
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
describe '#parser_skipped' do
|
|
157
|
+
it 'increments counters' do
|
|
158
|
+
subject.parser_skipped 'Whitespace'
|
|
159
|
+
subject.stats.get('Input Lines','Skipped').should == 1
|
|
160
|
+
subject.stats.get('Skipped Lines','Whitespace').should == 1
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
describe '#parser_unknown' do
|
|
165
|
+
before(:each) do
|
|
166
|
+
@logger.expects(:warn).once
|
|
167
|
+
@logger.expects(:puts).once
|
|
168
|
+
end
|
|
169
|
+
it 'increments counters' do
|
|
170
|
+
subject.parser_unknown_max = 10
|
|
171
|
+
subject.parser_engine 'junk' do
|
|
172
|
+
subject.parser_unknown
|
|
173
|
+
end
|
|
174
|
+
subject.stats.get('Input Lines','Unknown').should == 1
|
|
175
|
+
end
|
|
176
|
+
it 'alarms at threshold at one' do
|
|
177
|
+
subject.parser_unknown_max = 1
|
|
178
|
+
lambda do
|
|
179
|
+
subject.parser_engine 'junk' do
|
|
180
|
+
subject.parser_unknown
|
|
181
|
+
end
|
|
182
|
+
end.should raise_error(ReportContentError,%r{Unknown\sInput})
|
|
183
|
+
end
|
|
184
|
+
it 'alarms at threshold at many' do
|
|
185
|
+
subject.parser_unknown_max = 10
|
|
186
|
+
lambda do
|
|
187
|
+
subject.parser_engine 'junk' do
|
|
188
|
+
subject.stats.put('Input Lines','Unknown',10)
|
|
189
|
+
subject.parser_unknown
|
|
190
|
+
end
|
|
191
|
+
end.should raise_error(ReportContentError,%r{Unknown\sLine\sMaximum})
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
describe '#parser_warn' do
|
|
196
|
+
before(:each) do
|
|
197
|
+
@logger.expects(:warn).once
|
|
198
|
+
@logger.expects(:puts).once
|
|
199
|
+
end
|
|
200
|
+
it 'increments counters' do
|
|
201
|
+
subject.parser_warn_max = 10
|
|
202
|
+
subject.parser_engine 'junk' do
|
|
203
|
+
subject.parser_warn
|
|
204
|
+
end
|
|
205
|
+
subject.stats.get('Parser State','Warnings').should == 1
|
|
206
|
+
end
|
|
207
|
+
it 'alarms at threshold of one' do
|
|
208
|
+
subject.parser_warn_max = 1
|
|
209
|
+
lambda do
|
|
210
|
+
subject.parser_engine 'junk' do
|
|
211
|
+
subject.parser_warn
|
|
212
|
+
end
|
|
213
|
+
end.should raise_error(ReportContentError,%r{Parser\sWarning})
|
|
214
|
+
end
|
|
215
|
+
it 'alarms at threshold of many' do
|
|
216
|
+
subject.parser_warn_max = 10
|
|
217
|
+
lambda do
|
|
218
|
+
subject.parser_engine 'junk' do
|
|
219
|
+
subject.stats.put('Parser State','Warnings',10)
|
|
220
|
+
subject.parser_warn
|
|
221
|
+
end
|
|
222
|
+
end.should raise_error(ReportContentError,%r{Parser\sWarning\sMaximum})
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
describe '#parser_error' do
|
|
227
|
+
before(:each) do
|
|
228
|
+
@logger.expects(:error).once
|
|
229
|
+
@logger.expects(:puts).once
|
|
230
|
+
end
|
|
231
|
+
it 'increments counters' do
|
|
232
|
+
subject.parser_error_max = 10
|
|
233
|
+
subject.parser_engine 'junk' do
|
|
234
|
+
subject.parser_error
|
|
235
|
+
end
|
|
236
|
+
subject.stats.get('Parser State','Errors').should == 1
|
|
237
|
+
end
|
|
238
|
+
it 'alarms at threshold of one' do
|
|
239
|
+
subject.parser_error_max = 1
|
|
240
|
+
lambda do
|
|
241
|
+
subject.parser_engine 'junk' do
|
|
242
|
+
subject.parser_error
|
|
243
|
+
end
|
|
244
|
+
end.should raise_error(ReportContentError,%r{Parser\sError})
|
|
245
|
+
end
|
|
246
|
+
it 'alarms at threshold of many' do
|
|
247
|
+
subject.parser_error_max = 10
|
|
248
|
+
lambda do
|
|
249
|
+
subject.parser_engine 'junk' do
|
|
250
|
+
subject.stats.put('Parser State','Errors',10)
|
|
251
|
+
subject.parser_error
|
|
252
|
+
end
|
|
253
|
+
end.should raise_error(ReportContentError,%r{Parser\sError\sMaximum})
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
describe '#parser_invalid' do
|
|
258
|
+
before(:each) do
|
|
259
|
+
@logger.expects(:error).once
|
|
260
|
+
@logger.expects(:puts).once
|
|
261
|
+
end
|
|
262
|
+
it 'increments counters' do
|
|
263
|
+
subject.parser_error_max = 10
|
|
264
|
+
subject.parser_engine 'junk' do
|
|
265
|
+
subject.parser_invalid
|
|
266
|
+
end
|
|
267
|
+
subject.stats.get('Input Lines','Invalid').should == 1
|
|
268
|
+
end
|
|
269
|
+
it 'alarms at threshold of one' do
|
|
270
|
+
subject.parser_error_max = 1
|
|
271
|
+
lambda do
|
|
272
|
+
subject.parser_engine 'junk' do
|
|
273
|
+
subject.parser_invalid
|
|
274
|
+
end
|
|
275
|
+
end.should raise_error(ReportContentError,%r{Invalid\sLine})
|
|
276
|
+
end
|
|
277
|
+
it 'alarms at threshold of many' do
|
|
278
|
+
subject.parser_error_max = 10
|
|
279
|
+
lambda do
|
|
280
|
+
subject.parser_engine 'junk' do
|
|
281
|
+
subject.stats.put('Parser State','Errors',10)
|
|
282
|
+
subject.parser_invalid
|
|
283
|
+
end
|
|
284
|
+
end.should raise_error(ReportContentError,%r{Parser\sError\sMaximum})
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
end
|
|
289
|
+
end end end end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'ghaki/report/output_file'
|
|
2
|
+
|
|
3
|
+
module Ghaki module Report module OutputFileTesting
|
|
4
|
+
describe OutputFile do
|
|
5
|
+
|
|
6
|
+
before(:all) do
|
|
7
|
+
@log = stub_everything()
|
|
8
|
+
@out = '/tmp/myfile.txt'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
subject do OutputFile.new( :logger => @log, :output_file => @out ) end
|
|
12
|
+
|
|
13
|
+
it { should respond_to :output_file }
|
|
14
|
+
it { should respond_to :output_file= }
|
|
15
|
+
it { should respond_to :output_report }
|
|
16
|
+
it { should respond_to :output_finish }
|
|
17
|
+
it { should respond_to :output_prepare }
|
|
18
|
+
it { should respond_to :output_to_format }
|
|
19
|
+
|
|
20
|
+
describe '#output_report' do
|
|
21
|
+
it 'should create file' do
|
|
22
|
+
abc = sequence('reporting')
|
|
23
|
+
subject.expects(:output_prepare).once.in_sequence(abc)
|
|
24
|
+
::File.expects(:with_opened_temp).with(@out).yields(@out).once.in_sequence(abc)
|
|
25
|
+
subject.expects(:output_to_format).with(@out).once.in_sequence(abc)
|
|
26
|
+
subject.expects(:output_finish).once.in_sequence(abc)
|
|
27
|
+
subject.output_report
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end end end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ghaki-report
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2011.11.30.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Gerald Kalafut
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2011-11-30 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: ghaki-app
|
|
16
|
+
requirement: &80031340 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 2011.11.29.1
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *80031340
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: ghaki-ext-file
|
|
27
|
+
requirement: &80031120 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 2011.11.29.1
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *80031120
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
37
|
+
name: ghaki-logger
|
|
38
|
+
requirement: &80030900 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>='
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 2011.11.29.1
|
|
44
|
+
type: :runtime
|
|
45
|
+
prerelease: false
|
|
46
|
+
version_requirements: *80030900
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: ghaki-match
|
|
49
|
+
requirement: &80030680 !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 2011.11.30.1
|
|
55
|
+
type: :runtime
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: *80030680
|
|
58
|
+
- !ruby/object:Gem::Dependency
|
|
59
|
+
name: ghaki-stats
|
|
60
|
+
requirement: &80030460 !ruby/object:Gem::Requirement
|
|
61
|
+
none: false
|
|
62
|
+
requirements:
|
|
63
|
+
- - ! '>='
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: 2011.11.29.1
|
|
66
|
+
type: :runtime
|
|
67
|
+
prerelease: false
|
|
68
|
+
version_requirements: *80030460
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: &80030240 !ruby/object:Gem::Requirement
|
|
72
|
+
none: false
|
|
73
|
+
requirements:
|
|
74
|
+
- - ! '>='
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: 2.4.0
|
|
77
|
+
type: :development
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: *80030240
|
|
80
|
+
- !ruby/object:Gem::Dependency
|
|
81
|
+
name: mocha
|
|
82
|
+
requirement: &80030010 !ruby/object:Gem::Requirement
|
|
83
|
+
none: false
|
|
84
|
+
requirements:
|
|
85
|
+
- - ! '>='
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: 0.9.12
|
|
88
|
+
type: :development
|
|
89
|
+
prerelease: false
|
|
90
|
+
version_requirements: *80030010
|
|
91
|
+
- !ruby/object:Gem::Dependency
|
|
92
|
+
name: rdoc
|
|
93
|
+
requirement: &80029780 !ruby/object:Gem::Requirement
|
|
94
|
+
none: false
|
|
95
|
+
requirements:
|
|
96
|
+
- - ! '>='
|
|
97
|
+
- !ruby/object:Gem::Version
|
|
98
|
+
version: 3.9.4
|
|
99
|
+
type: :development
|
|
100
|
+
prerelease: false
|
|
101
|
+
version_requirements: *80029780
|
|
102
|
+
description: Collection of extensions for basic reporting.
|
|
103
|
+
email: gerald@kalafut.org
|
|
104
|
+
executables: []
|
|
105
|
+
extensions: []
|
|
106
|
+
extra_rdoc_files:
|
|
107
|
+
- README
|
|
108
|
+
files:
|
|
109
|
+
- lib/ghaki/report/mixin/linear_parser.rb
|
|
110
|
+
- lib/ghaki/report/output_file.rb
|
|
111
|
+
- lib/ghaki/report/errors.rb
|
|
112
|
+
- lib/ghaki/report/base.rb
|
|
113
|
+
- README
|
|
114
|
+
- LICENSE
|
|
115
|
+
- VERSION
|
|
116
|
+
- spec/ghaki/report/base_spec.rb
|
|
117
|
+
- spec/ghaki/report/mixin/linear_parser_spec.rb
|
|
118
|
+
- spec/ghaki/report/output_file_spec.rb
|
|
119
|
+
- spec/spec_helper.rb
|
|
120
|
+
homepage: http://github.com/ghaki
|
|
121
|
+
licenses: []
|
|
122
|
+
post_install_message:
|
|
123
|
+
rdoc_options: []
|
|
124
|
+
require_paths:
|
|
125
|
+
- lib
|
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
|
+
none: false
|
|
128
|
+
requirements:
|
|
129
|
+
- - ! '>='
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
|
+
none: false
|
|
134
|
+
requirements:
|
|
135
|
+
- - ! '>='
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: 1.3.6
|
|
138
|
+
requirements: []
|
|
139
|
+
rubyforge_project: ghaki-report
|
|
140
|
+
rubygems_version: 1.8.10
|
|
141
|
+
signing_key:
|
|
142
|
+
specification_version: 3
|
|
143
|
+
summary: Basic reporting helpers
|
|
144
|
+
test_files:
|
|
145
|
+
- spec/ghaki/report/base_spec.rb
|
|
146
|
+
- spec/ghaki/report/mixin/linear_parser_spec.rb
|
|
147
|
+
- spec/ghaki/report/output_file_spec.rb
|
|
148
|
+
- spec/spec_helper.rb
|