test-parser 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,12 @@
1
+ == 0.0.1 2007-07-01
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
5
+
6
+ == 0.8.0 2007-08-01
7
+
8
+ * 4 major enhancements:
9
+ * Support for rspec
10
+ * Support for rubyunit
11
+ * Support for pyunit
12
+ * Support for quickCheck
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 FIXME full name
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,29 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/test_parser
7
+ lib/test-parser.rb
8
+ lib/test-parser/version.rb
9
+ lib/test-parser/parsers/pyunit.rb
10
+ lib/test-parser/parsers/rspec.rb
11
+ lib/test-parser/parsers/rubyunit.rb
12
+ lib/test-parser/parsers/junit4.rb
13
+ lib/test-parser/parsers/quickCheck.rb
14
+ lib/test-parser/parsers/base.rb
15
+ scripts/txt2html
16
+ setup.rb
17
+ spec/spec_helper.rb
18
+ spec/test_parsers_spec.rb
19
+ spec/example_data/pyunit.rb
20
+ spec/example_data/rspec.rb
21
+ spec/example_data/junit4.rb
22
+ spec/example_data/rubyunit.rb
23
+ spec/example_data/quickCheck.rb
24
+ website/index.html
25
+ website/index.txt
26
+ website/parser_output.txt
27
+ website/javascripts/rounded_corners_lite.inc.js
28
+ website/stylesheets/screen.css
29
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,3 @@
1
+ README for test-parser
2
+ ======================
3
+
data/Rakefile ADDED
@@ -0,0 +1,147 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'hoe'
11
+ begin
12
+ require 'spec/rake/spectask'
13
+ rescue LoadError
14
+ puts 'To use rspec for testing you must install rspec gem:'
15
+ puts '$ sudo gem install rspec'
16
+ exit
17
+ end
18
+
19
+ include FileUtils
20
+ require File.join(File.dirname(__FILE__), 'lib', 'test-parser', 'version')
21
+
22
+ AUTHOR = 'Peter Burns' # can also be an array of Authors
23
+ EMAIL = "rictic@gmail.com"
24
+ DESCRIPTION = "A collection of parsers for parsing the output of various testing suites."
25
+ GEM_NAME = 'test-parser' # what ppl will type to install your gem
26
+
27
+ @config_file = "~/.rubyforge/user-config.yml"
28
+ @config = nil
29
+ def rubyforge_username
30
+ unless @config
31
+ begin
32
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
33
+ rescue
34
+ puts <<-EOS
35
+ ERROR: No rubyforge config file found: #{@config_file}"
36
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
37
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
38
+ EOS
39
+ exit
40
+ end
41
+ end
42
+ @rubyforge_username ||= @config["username"]
43
+ end
44
+
45
+ RUBYFORGE_PROJECT = 'test-parser' # The unix name for your project
46
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
47
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
48
+
49
+ NAME = "test-parser"
50
+ REV = nil
51
+ # UNCOMMENT IF REQUIRED:
52
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
53
+ VERS = TestParser::VERSION.to_s + (REV ? ".#{REV}" : "")
54
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
55
+ RDOC_OPTS = ['--quiet', '--title', 'test-parser documentation',
56
+ "--opname", "index.html",
57
+ "--line-numbers",
58
+ "--main", "README",
59
+ "--inline-source"]
60
+
61
+ class Hoe
62
+ def extra_deps
63
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
64
+ end
65
+ end
66
+
67
+ # Generate all the Rake tasks
68
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
69
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
70
+ p.author = AUTHOR
71
+ p.description = DESCRIPTION
72
+ p.email = EMAIL
73
+ p.summary = DESCRIPTION
74
+ p.url = HOMEPATH
75
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
76
+ p.test_globs = ["test/**/test_*.rb"]
77
+ p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
78
+ p.extra_deps << "rake"
79
+ p.extra_deps << "rspec"
80
+
81
+ # == Optional
82
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
83
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
84
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
85
+ end
86
+
87
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
88
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
89
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
90
+
91
+ desc 'Generate website files'
92
+ task :website_generate do
93
+ Dir['website/**/*.txt'].each do |txt|
94
+ sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
95
+ end
96
+ end
97
+
98
+ desc 'Upload website files to rubyforge'
99
+ task :website_upload do
100
+ host = "#{rubyforge_username}@rubyforge.org"
101
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
102
+ local_dir = 'website'
103
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
104
+ end
105
+
106
+ desc 'Generate and upload website files'
107
+ task :website => [:website_generate, :website_upload, :publish_docs]
108
+
109
+ desc 'Release the website and new gem version'
110
+ task :deploy => [:check_version, :website, :release] do
111
+ puts "Remember to create SVN tag:"
112
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
113
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
114
+ puts "Suggested comment:"
115
+ puts "Tagging release #{CHANGES}"
116
+ end
117
+
118
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
119
+ task :local_deploy => [:website_generate, :install_gem]
120
+
121
+ task :check_version do
122
+ unless ENV['VERSION']
123
+ puts 'Must pass a VERSION=x.y.z release version'
124
+ exit
125
+ end
126
+ unless ENV['VERSION'] == VERS
127
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
128
+ exit
129
+ end
130
+ end
131
+
132
+ desc "Run the specs under spec/models"
133
+ Spec::Rake::SpecTask.new do |t|
134
+ t.spec_opts = ['--options', "spec/spec.opts"]
135
+ t.spec_files = FileList['spec/*_spec.rb']
136
+ end
137
+
138
+ desc "Default task is to run specs"
139
+ task :default => :spec
140
+
141
+ desc "Uninstall the current version of the library"
142
+ task :uninstall do
143
+ sh "yes | gem uninstall #{RUBYFORGE_PROJECT}"
144
+ end
145
+
146
+ desc "Uninstall the current version and deploy locally again"
147
+ task :reinstall => [:uninstall, :local_deploy]
data/bin/test_parser ADDED
@@ -0,0 +1,16 @@
1
+ require 'test-parser'
2
+ require 'yaml'
3
+ def usage
4
+ puts "usage: test_parser <test_framework>"
5
+ puts " frameworks:"
6
+ TestParser.parsers.each {|p,_| puts " #{p}"}
7
+ exit 1
8
+ end
9
+
10
+ usage if !ARGV[0]
11
+ parser = TestParser.parsers[ARGV[0].to_sym]
12
+ usage if !parser
13
+
14
+
15
+
16
+ puts YAML.dump(parser.parse(STDIN.read))
@@ -0,0 +1,14 @@
1
+ require 'test-parser/version'
2
+ require 'rake'
3
+ require File.dirname(__FILE__) + '/test-parser/parsers/base.rb'
4
+ FileList[File.dirname(__FILE__) + '/test-parser/parsers/*.rb'].each {|parser| require parser}
5
+
6
+ module TestParser
7
+ def self.parsers
8
+ {:rspec => TestParser::RSpec,
9
+ :pyunit => TestParser::PyUnit,
10
+ # :junit4 => TestParser::JUnit4,
11
+ :rubyunit => TestParser::RubyUnit,
12
+ :quickCheck => TestParser::QuickCheck}
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module TestParser
2
+ class Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module TestParser
2
+ class JUnit4 < Base
3
+ def self.parse test_results
4
+ test_info = Hash.new(0)
5
+ test_info[:failures] = []
6
+
7
+ "Tests run: 2, Failures: 1, Errors: 0"
8
+ test_results.scan(/Tests? run: (\d+), Failures: (\d+), Errors: (\d+)/).each do |(tests,failures,errors)|
9
+ test_info[:failure_count] += failures.to_i + errors.to_i
10
+ test_info[:test_count] += tests.to_i
11
+ end
12
+
13
+ test_info[:success_count] = test_info[:test_count] - test_info[:failure_count]
14
+ test_info.default = nil
15
+ test_info
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ module TestParser
2
+ class PyUnit < Base
3
+ def self.parse test_results
4
+ test_info = Hash.new(0)
5
+ test_info[:failure_count] = 0
6
+ test_info[:failures] = []
7
+
8
+ failure_regex = /^(ERROR|FAIL): (.*?)\n-+\nTraceback \(most recent call last\):\n(\s*File \"(.*?)\", line (\d+),( in (.*?))?\n.*?\n(.*?)([A-Za-z]*?): (.*?))\n+(---------|=======)/m
9
+ failed_tests = test_results.scan(failure_regex).each do |_1,test,_stack_trace,file,line,_2,method,_rest_of_stack,error_class,message,_3|
10
+ failure_info = {:file => file,
11
+ :line => line.to_i,
12
+ :error_type => error_class,
13
+ :message => message,
14
+ :test => test}
15
+ failure_info[:method] = method if method
16
+ test_info[:failures] << failure_info
17
+ end
18
+ test_info[:failure_count] += failed_tests.size
19
+
20
+
21
+ # critical_errors = test_results.scan(/^$/m)
22
+ # critical_errors.each do |file,line,stack,error_class,message|
23
+ # test_info[:failure_count] += 1
24
+ # test_info[:failures] << {:file => file,
25
+ # :line => line,
26
+ # :stack_trace => stack,
27
+ # :type => error_class,
28
+ # :message => message}
29
+ # end
30
+
31
+ test_results.scan(/Ran (\d+) tests? in/).each do |successes|
32
+ test_info[:success_count] += successes.first.to_i
33
+ end
34
+ test_info[:success_count] -= test_info[:failure_count]
35
+
36
+ test_info.default = nil
37
+ test_info
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,34 @@
1
+ module TestParser
2
+ class QuickCheck < Base
3
+ def self.parse test_results
4
+ test_info = Hash.new
5
+ test_info[:failures] = []
6
+ test_info[:failure_count] = 0
7
+ test_info[:success_count] = 0
8
+ test_info[:test_count] = 0
9
+
10
+ # you should really use the +names option with quickCheck here,
11
+ # quickCheck doesn't give you much info on the command line, and
12
+ # every little bit helps
13
+
14
+ #known bug: need to deal with the characters used to rewrite the number of tests written
15
+ # i.e. the ascii control characters that quickCheck uses to increment the current number of tests ran
16
+
17
+ test_results.scan(/((^\s*?): )?OK, passed (\d+) tests./).each do |(_1,test,tests_passed,)|
18
+ test_info[:success_count] += 1
19
+ test_info[:test_count] += 1
20
+ end
21
+
22
+ #this assumes that the counterexample can be shown on a single line
23
+ test_results.scan(/(([^\s]*?): )?(Falsifiable, after (\d+) tests:\n.*?)\n/) do |_1,test,message,successes|
24
+ test_info[:failure_count] += 1
25
+ test_info[:test_count] += 1
26
+ failure_info = {:message => message}
27
+ failure_info[:test] = test if test
28
+ test_info[:failures] << failure_info
29
+ end
30
+
31
+ test_info
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,61 @@
1
+ module TestParser
2
+ class RSpec < Base
3
+ def self.parse test_results
4
+ test_info = Hash.new(0)
5
+ test_info[:failures] = []
6
+
7
+ #count them
8
+ test_results.scan(/(\d+) (specification|example)s?, (\d+) failures?/) do |(examples,_,failures)|
9
+ test_info[:failure_count] += failures.to_i
10
+ test_info[:success_count] += examples.to_i - failures.to_i
11
+ test_info[:test_count] += examples.to_i
12
+ end
13
+
14
+ #look for errors
15
+ # ../../test-parser//pkg/test-parser-0.5.0/setup.rb:440: undefined method `set' for class `ConfigTable::ExecItem' (NameError)
16
+ #/opt/[.......]/rake.rb:2028:in `const_missing': uninitialized constant TestRunner (NameError)
17
+ error_regex1 = /\s*(.*?)\:(\d+)\:(in `(.*?)':)? (.*?) \((.*?)\)/
18
+ test_results.scan(error_regex1) do |(file,line,_,method,message,type)|
19
+ error_info = {:file => file,
20
+ :line => line.to_i,
21
+ :message => message,
22
+ :error_type => type,}
23
+ error_info[:method] = method if method
24
+ test_info[:failures] << error_info
25
+ end
26
+
27
+ #1)
28
+ #NameError in 'the PyUnitParser should be able to count successes and failures in some examples'
29
+ #undefined local variable or method `results' for PyUnitParser:Module
30
+ #./spec/../lib/test-parser/parsers/pyunit.rb:8:in `parse'
31
+ error_regex2 = /\s+(.*?) in '(.*?)'\s+(.*?)\s+(.*?):(\d+):(in `(.*?)')?/
32
+ test_results.scan(error_regex2) do |(type,test,message,file,line,_,method)|
33
+ error_info = {:error_type => type,
34
+ :test => test,
35
+ :message => message,
36
+ :file => file,
37
+ :line => line.to_i,
38
+ }
39
+ error_info[:method] = method if method
40
+ test_info[:failures] << error_info
41
+ end
42
+
43
+ #look for failures
44
+ #1)
45
+ #'RSpecParser should agree with the listed examples' FAILED
46
+ #expected 1, got 2 (using ==)
47
+ #./spec/test_rspec_parser_spec.rb:15:
48
+ #
49
+ failure_regex = /\d+\)\s+'(.*?)' FAILED\s+(.*?)\n\s*(.*?):(\d+):/
50
+ test_results.scan(failure_regex) do |(test,message,file,line)|
51
+ test_info[:failures] << {:test => test,
52
+ :message => message,
53
+ :file => file,
54
+ :line => line.to_i,}
55
+ end
56
+
57
+ test_info.default = nil
58
+ test_info
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,42 @@
1
+ module TestParser
2
+ class RubyUnit < Base
3
+ def self.parse test_results
4
+ test_info = Hash.new(0)
5
+ test_info[:failures] = []
6
+
7
+ #1 tests, 1 assertions, 0 failures, 0 errors
8
+ test_results.scan(/(\d+) tests?, \d+ assertions?, (\d+) failures?, (\d+) errors/).each do |(tests,failures,errors)|
9
+ test_info[:failure_count] += failures.to_i + errors.to_i
10
+ test_info[:test_count] += tests.to_i
11
+ end
12
+
13
+ # 1) Failure:
14
+ #test_truth(TestGtest) [test/test_gtest.rb:9]:
15
+ #<false> is not true.
16
+ test_results.scan(/\s+\d+\) Failure:\n(.*?) \[(.*?):(\d+)\]:\n(.*?)\n/).each do |(test,file,line,message)|
17
+ test_info[:failures] << {:test => test,
18
+ :file => file,
19
+ :line => line.to_i,
20
+ :message => message}
21
+ end
22
+
23
+ # 1) Error:
24
+ #test_truth(TestGtest):
25
+ #RuntimeError: What
26
+ # test/test_gtest.rb:9:in `test_truth'
27
+ test_results.scan(/\s+\d+\) Error:\n(.+?):\n(.+?): (.+?)\n\s*(.+?):(\d+):in `(.+?)'/).each do |(test,error_type,message,file,line,method)|
28
+ test_info[:failures] << {:test => test,
29
+ :error_type => error_type,
30
+ :message => message,
31
+ :file => file,
32
+ :line => line.to_i,
33
+ :method => method}
34
+ end
35
+
36
+
37
+ test_info[:success_count] = test_info[:test_count] - test_info[:failure_count]
38
+ test_info.default = nil
39
+ test_info
40
+ end
41
+ end
42
+ end