test-parser 0.8.0

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.
@@ -0,0 +1,17 @@
1
+ #not sure if this is junit4
2
+ #stolen from http://www.samspublishing.com/articles/article.asp?p=32052&seqNum=6&rl=1
3
+ [
4
+ ["% java com.networksByteDesign.eMarket.inventory.salesItemTest
5
+ .F.
6
+ Time: 0.033
7
+ There was 1 failure:
8
+ 1) testConstructor(com.networksByteDesign.eMarket.inventory.salesItemTest)
9
+ \"Expected exception was not thrown\"
10
+
11
+ FAILURES!!!
12
+ Tests run: 2, Failures: 1, Errors: 0",
13
+ {:failure_count => 1, :success_count => 1, :test_count => 2,
14
+ # :failures => [{:test => 'testConstructor',
15
+ # :message => "Expected exception was not thrown"}]
16
+ }],
17
+ ]
@@ -0,0 +1,143 @@
1
+ [
2
+ #baseline
3
+ [
4
+ "...................
5
+ ----------------------------------------------------------------------
6
+ Ran 19 tests in 2.181s
7
+
8
+ OK
9
+ ",
10
+ {:success_count => 19, :failure_count => 0}
11
+ ],
12
+
13
+ #verbose mode...
14
+ [
15
+ "Should perform the same as reading, then parsing the header ... ok
16
+ testHeaderParsing (__main__.TestHTTPProtocol) ... ok
17
+ Attempting to parse a header that doesn't end in \\r\\n\\r\\n should raise a ValueError ... ok
18
+ A valid buffer read in shouldn't cause parse_header to complain ... ok
19
+ Grabbing the next header should leave all other data after the header ... ok
20
+ If two headers are in the buffer reading twice in a row should produce one header, then the next. ... ok
21
+
22
+ ----------------------------------------------------------------------
23
+ Ran 6 tests in 0.003s
24
+
25
+ OK",
26
+ {:failure_count => 0, :success_count => 6,
27
+
28
+ #YAGNI has stripped this functionality right out...
29
+ # :test_names => ["Should perform the same as reading, then parsing the header",
30
+ # "testHeaderParsing (__main__.TestHTTPProtocol)",
31
+ # "Attempting to parse a header that doesn't end in \\r\\n\\r\\n should raise a ValueError",
32
+ # "A valid buffer read in shouldn't cause parse_header to complain",
33
+ # "Grabbing the next header should leave all other data after the header",
34
+ # "If two headers are in the buffer reading twice in a row should produce one header, then the next."]}
35
+ }],
36
+ #testing for an ERROR
37
+ [
38
+ "...E..
39
+ ======================================================================
40
+ ERROR: A valid buffer read in shouldn't cause parse_header to complain
41
+ ----------------------------------------------------------------------
42
+ Traceback (most recent call last):
43
+ File \"test_http.py\", line 24, in testReadHeader
44
+ header = self.http.read_header()
45
+ File \"/Users/peter/Documents/Class Notes/2007s/Networking/labs/software/2/http/http.py\", line 124, in read_header
46
+ match = find_header.match(self.buffer)
47
+ TypeError: expected string or buffer
48
+
49
+ ----------------------------------------------------------------------
50
+ Ran 6 tests in 0.022s
51
+
52
+ FAILED (errors=1)",
53
+ {
54
+ :failure_count => 1,
55
+ :success_count => 5,
56
+ :failures => [{
57
+ :file => "test_http.py",
58
+ :line => 24,
59
+ :error_type => "TypeError",
60
+ :message => "expected string or buffer",
61
+ :method => "testReadHeader",
62
+ :test => "A valid buffer read in shouldn't cause parse_header to complain",
63
+ }],
64
+ }],
65
+ #testing for FAIL
66
+ [
67
+ "....F.
68
+ ======================================================================
69
+ FAIL: Grabbing the next header should leave all other data after the header
70
+ ----------------------------------------------------------------------
71
+ Traceback (most recent call last):
72
+ File \"test_http.py\", line 32, in testReadHeadersHandlesExtraDataProperly
73
+ self.assertEqual(self.http.buffer,3)#data)
74
+ AssertionError: 'Lieutenant Commander' != 3
75
+
76
+ ----------------------------------------------------------------------
77
+ Ran 6 tests in 0.003s
78
+
79
+ FAILED (failures=1)
80
+ ",
81
+ {
82
+ :failure_count => 1,
83
+ :success_count => 5,
84
+ :failures => [{
85
+ :file => "test_http.py",
86
+ :line => 32,
87
+ :error_type => "AssertionError",
88
+ :message => "'Lieutenant Commander' != 3",
89
+ :test => "Grabbing the next header should leave all other data after the header",
90
+ :method => "testReadHeadersHandlesExtraDataProperly",
91
+ }],
92
+ },
93
+ ],
94
+
95
+ #test multiple failures
96
+ [
97
+ "...EF.
98
+ ======================================================================
99
+ ERROR: A valid buffer read in shouldn't cause parse_header to complain
100
+ ----------------------------------------------------------------------
101
+ Traceback (most recent call last):
102
+ File \"test_http.py\", line 24, in testReadHeader
103
+ header = self.http.read_header()
104
+ File \"/Users/peter/Documents/Class Notes/2007s/Networking/labs/software/2/http/http.py\", line 124, in read_header
105
+ match = find_header.match(self.buffer)
106
+ TypeError: expected string or buffer
107
+
108
+ ======================================================================
109
+ FAIL: Grabbing the next header should leave all other data after the header
110
+ ----------------------------------------------------------------------
111
+ Traceback (most recent call last):
112
+ File \"test_http.py\", line 32, in testReadHeadersHandlesExtraDataProperly
113
+ self.assertEqual(self.http.buffer,3)#data)
114
+ AssertionError: 'Lieutenant Commander' != 3
115
+
116
+ ----------------------------------------------------------------------
117
+ Ran 6 tests in 0.003s
118
+
119
+ FAILED (failures=1, errors=1)",
120
+ {
121
+ :success_count => 4,
122
+ :failure_count => 2,
123
+ :failures => [
124
+ {
125
+ :file => "test_http.py",
126
+ :line => 32,
127
+ :error_type => "AssertionError",
128
+ :message => "'Lieutenant Commander' != 3",
129
+ :test => "Grabbing the next header should leave all other data after the header",
130
+ :method => "testReadHeadersHandlesExtraDataProperly",
131
+ },
132
+ {
133
+ :file => "test_http.py",
134
+ :line => 24,
135
+ :error_type => "TypeError",
136
+ :message => "expected string or buffer",
137
+ :method => "testReadHeader",
138
+ :test => "A valid buffer read in shouldn't cause parse_header to complain",
139
+ }
140
+ ]
141
+ }
142
+ ]
143
+ ]
@@ -0,0 +1,61 @@
1
+ [
2
+ [
3
+ ' ___ ___ _
4
+ / _ \ /\ /\/ __(_)
5
+ / /_\// /_/ / / | | GHC Interactive, version 6.5.20060608, for Haskell 98.
6
+ / /_\\\\/ __ / /___| | http://www.haskell.org/ghc/
7
+ \____/\/ /_/\____/|_| Type :? for help.
8
+
9
+ Loading package base-1.0 ... linking ... done.
10
+ Prelude> [1 of 2] Compiling QuickCheck ( QuickCheck.hs, interpreted )
11
+ [2 of 2] Compiling Main ( primes.hs, interpreted )
12
+ Ok, modules loaded: QuickCheck, Main.
13
+ *Main> Loading package haskell98-1.0 ... linking ... done.
14
+ OK, passed 100 tests.
15
+ *Main> Leaving GHCi.
16
+ ',
17
+ {:failure_count => 0, :success_count => 1, :test_count => 1}
18
+ ],
19
+ [
20
+ ' ___ ___ _
21
+ / _ \ /\ /\/ __(_)
22
+ / /_\// /_/ / / | | GHC Interactive, version 6.5.20060608, for Haskell 98.
23
+ / /_\\/ __ / /___| | http://www.haskell.org/ghc/
24
+ \____/\/ /_/\____/|_| Type :? for help.
25
+
26
+ Loading package base-1.0 ... linking ... done.
27
+ Prelude> [1 of 2] Compiling QuickCheck ( QuickCheck.hs, interpreted )
28
+ [2 of 2] Compiling Main ( primes.hs, interpreted )
29
+ Ok, modules loaded: QuickCheck, Main.
30
+ *Main> Loading package haskell98-1.0 ... linking ... done.
31
+ prop_PrimesArePrime: Falsifiable, after 0 tests:
32
+ 5696
33
+ *Main> Leaving GHCi.
34
+ ',
35
+ {:failure_count => 1, :success_count => 0, :test_count => 1,
36
+ :failures => [{:test => "prop_PrimesArePrime", :message => "Falsifiable, after 0 tests:\n5696"}]
37
+ }
38
+ ],
39
+
40
+ [" ___ ___ _
41
+ / _ \\ /\\ /\\/ __(_)
42
+ / /_\\// /_/ / / | | GHC Interactive, version 6.5.20060608, for Haskell 98.
43
+ / /_\\\\/ __ / /___| | http://www.haskell.org/ghc/
44
+ \\____/\\/ /_/\\____/|_| Type :? for help.
45
+
46
+ Loading package base-1.0 ... linking ... done.
47
+ Prelude> [1 of 2] Compiling QuickCheck ( QuickCheck.hs, interpreted )
48
+ [2 of 2] Compiling Main ( primes.hs, interpreted )
49
+ Ok, modules loaded: QuickCheck, Main.
50
+ *Main> Loading package haskell98-1.0 ... linking ... done.
51
+ prop_PrimesArePrime: OK, passed 100 tests.
52
+ *Main> prop_PrimesAreOdd: Falsifiable, after 65 tests:
53
+ 2
54
+ *Main> Leaving GHCi.
55
+ ",
56
+ {:failure_count => 1, :success_count => 1, :test_count => 2,
57
+ :failures => [{:test => "prop_PrimesAreOdd", :message => "Falsifiable, after 65 tests:\n2"}]}
58
+ ],
59
+
60
+
61
+ ]
@@ -0,0 +1,105 @@
1
+ #This is a big array of example data.
2
+
3
+ #It consists of pairs of values.
4
+ #The first is the output to parse
5
+ #The second is a hash of values that should be extracted by the parser.
6
+ [
7
+ ["
8
+
9
+ Finished in 0.007427 seconds
10
+
11
+ 1 example, 0 failures",
12
+ {:success_count => 1, :failure_count => 0, :test_count => 1 }],
13
+
14
+ ["This is a bunch of text.
15
+ - perhaps we can throw off the parser...
16
+
17
+ Finished in 0.007427 seconds
18
+
19
+ 2 examples, 0 failures",
20
+ {:success_count => 2, :failure_count => 0, :test_count => 2}],
21
+
22
+ ["[17, 18, 18, 17]
23
+ \"The 'internet'\"
24
+
25
+ Finished in 0.007427 seconds
26
+
27
+ 2 specifications, 0 failures",
28
+ {:success_count => 2, :failure_count => 0, :test_count => 2}],
29
+
30
+
31
+ ["the PyUnitParser
32
+ - should be able to count successes and failures in some examples (ERROR - 1)
33
+
34
+ the rspec parser
35
+ - should agree with the listed examples
36
+ - should be able to pick out a stack trace of an error
37
+
38
+ 1)
39
+ NameError in 'the PyUnitParser should be able to count successes and failures in some examples'
40
+ undefined local variable or method `results' for PyUnitParser:Module
41
+ ./spec/../lib/test-parser/parsers/pyunit.rb:8:in `parse'
42
+ ./spec/test_pyunit_parser_spec.rb:13:
43
+ ./spec/test_pyunit_parser_spec.rb:12:
44
+
45
+ Finished in 0.01853 seconds
46
+
47
+ 3 examples, 1 failure
48
+ ",
49
+ {:success_count => 2, :failure_count => 1, :test_count => 3,
50
+ :failures => [{:error_type => "NameError",
51
+ :file => './spec/../lib/test-parser/parsers/pyunit.rb',
52
+ :test => 'the PyUnitParser should be able to count successes and failures in some examples',
53
+ :line => 8,
54
+ :method => 'parse',
55
+ :message => "undefined local variable or method `results' for PyUnitParser:Module" }]
56
+ }
57
+ ],
58
+ ["1)
59
+ 'RSpecParser should agree with the listed examples' FAILED
60
+ expected 1, got 2 (using ==)
61
+ ./spec/test_rspec_parser_spec.rb:15:
62
+
63
+ Finished in 0.08832 seconds
64
+
65
+ 1 examples, 1 failure
66
+ ",{:failure_count => 1,
67
+ :failures => [{:test => 'RSpecParser should agree with the listed examples',
68
+ :message => 'expected 1, got 2 (using ==)',
69
+ :file => './spec/test_rspec_parser_spec.rb',
70
+ :line => 15
71
+ }]}],
72
+ ["RSpecParser
73
+ - should agree with the listed examples
74
+
75
+ PyUnitParser
76
+ - should agree with the listed examples (ERROR - 1)
77
+
78
+ 1)
79
+ SyntaxError in 'PyUnitParser should agree with the listed examples'
80
+ (eval):30: compile error
81
+ (eval):25: parse error, unexpected '=', expecting tASSOC
82
+ :test_names = [\"Should perform the same as reading, then parsing the header\",
83
+ ^
84
+ (eval):30: parse error, unexpected '}', expecting $
85
+ ./spec/test_parsers.rb:21:
86
+ ./spec/test_parsers.rb:21:
87
+
88
+ Finished in 0.01552 seconds
89
+
90
+ 2 examples, 1 failure
91
+ ",
92
+ {:failure_count => 1, :success_count => 1,
93
+ :failures => [
94
+ {:file => "(eval)",
95
+ :line => 25,
96
+ :test => "PyUnitParser should agree with the listed examples",
97
+ :error_type => "SyntaxError",
98
+ :message => "(eval):30: compile error",
99
+ }
100
+ ]
101
+ }
102
+ ],
103
+
104
+
105
+ ]
@@ -0,0 +1,77 @@
1
+ [
2
+
3
+ ["Loaded suite -e
4
+ Started
5
+ .
6
+ Finished in 0.00045 seconds.
7
+
8
+ 1 tests, 1 assertions, 0 failures, 0 errors
9
+ ",
10
+ {:failure_count => 0, :success_count => 1, :test_count => 1}
11
+ ],
12
+
13
+ ["Loaded suite test/test_gtest
14
+ Started
15
+ F
16
+ Finished in 0.049108 seconds.
17
+
18
+ 1) Failure:
19
+ test_truth(TestGtest) [test/test_gtest.rb:9]:
20
+ <false> is not true.
21
+
22
+ 1 tests, 1 assertions, 1 failures, 0 errors
23
+
24
+ ",
25
+ {:failure_count => 1, :success_count => 0, :test_count => 1,
26
+ :failures => [{:test => "test_truth(TestGtest)",
27
+ :file => "test/test_gtest.rb",
28
+ :line => 9,
29
+ :message => "<false> is not true."}]}
30
+
31
+ ],
32
+
33
+ ["Started
34
+ E
35
+ Finished in 0.00042 seconds.
36
+
37
+ 1) Error:
38
+ test_truth(TestGtest):
39
+ RuntimeError: What
40
+ test/test_gtest.rb:9:in `test_truth'
41
+
42
+ 1 tests, 0 assertions, 0 failures, 1 errors
43
+ ",
44
+ {:failure_count => 1, :success_count => 0, :test_count => 1,
45
+ :failures => [{:test => "test_truth(TestGtest)",
46
+ :error_type => "RuntimeError",
47
+ :message => "What",
48
+ :file => "test/test_gtest.rb",
49
+ :line => 9,
50
+ :method => "test_truth"}]}
51
+ ],
52
+
53
+ ["snarl_notifier is not available
54
+ Loaded suite test/popup_notifier_test
55
+ Started
56
+ E
57
+ Finished in 0.010711 seconds.
58
+
59
+ 1) Error:
60
+ test_growl(PopupNotifierTest):
61
+ NoMethodError: undefined method `LoadError' for #<PopupNotifier:0x112210c>
62
+ ./test/../lib/popup_notifier.rb:10:in `initialize'
63
+ test/popup_notifier_test.rb:14:in `test_growl'
64
+ /opt/local/lib/ruby/gems/1.8/gems/mocha-0.5.1/lib/mocha/test_case_adapter.rb:19:in `run'
65
+
66
+ 1 tests, 0 assertions, 0 failures, 1 errors
67
+ ",
68
+ {:failure_count => 1, :success_count => 0, :test_count => 1,
69
+ :failures => [{:test => "test_growl(PopupNotifierTest)",
70
+ :error_type => "NoMethodError",
71
+ :message => "undefined method `LoadError' for #<PopupNotifier:0x112210c>",
72
+ :file => "./test/../lib/popup_notifier.rb",
73
+ :line => 10,
74
+ :method => "initialize"}]}
75
+ ],
76
+
77
+ ]
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ $: << File.dirname(__FILE__) + '/../lib/'
4
+ require 'test-parser'
@@ -0,0 +1,101 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ def have_key? ex, keys
4
+ keys = [keys] if !keys.respond_to?(:each)
5
+ ex.any? {|(_,c,_)|
6
+ keys.all? {|key| c[key]}
7
+ }
8
+ end
9
+
10
+ def hash_match ex, key
11
+ ex.each do |test_results, correct_info, parsed_info|
12
+ next if !correct_info[key] # don't test things that aren't in the data file
13
+ parsed_info[key].should == correct_info[key]
14
+ end
15
+ end
16
+
17
+
18
+
19
+ TestParser.parsers.each_value do |parser|
20
+
21
+ begin
22
+ data_filename = File.dirname(__FILE__) + "/example_data/" + parser.name.downcase.sub("testparser::","") + ".rb"
23
+ examples = eval(File.read(data_filename))
24
+ rescue Exception => err
25
+ STDERR.puts "Syntax error in #{data_filename}:\n\n"
26
+ raise err
27
+ end
28
+
29
+
30
+ describe parser do
31
+
32
+ before :all do
33
+ examples.each do |example|
34
+ test_results, correct_info = example
35
+ example << parser.parse(test_results)
36
+ end
37
+ end
38
+
39
+ #if there are any examples at all, they should...
40
+ if !examples.empty?
41
+ it "should give accurate failure_counts" do
42
+ hash_match examples, :failure_count
43
+ end
44
+ end
45
+
46
+ #if any of the examples include info on any of these properties, ensure that the
47
+ #parser aligns with that property
48
+ [:success_count, :test_count].each do |property|
49
+ if have_key? examples, property
50
+ it "should give accurate #{property}s" do
51
+ hash_match examples, property
52
+ end
53
+ end
54
+ end
55
+
56
+ #if any of the examples include detailed info on failures...
57
+ if have_key? examples, :failures
58
+
59
+ it "should give details on failures" do
60
+ examples.each do |test_results, correct_info, parsed_info|
61
+
62
+ next if !correct_info[:failures]
63
+
64
+ correct_info[:failures].each do |correct_hash|
65
+
66
+ #find the relevent failure in the parsed_info by the filename/line number this may not work for some systems...
67
+
68
+ parsed_hash = parsed_info[:failures].find {|p_h| p_h[:file] == correct_hash[:file] && p_h[:line] == correct_hash[:line] }
69
+
70
+ if !parsed_hash
71
+ fail "didn't find the error in '#{correct_hash[:file]}' line #{correct_hash[:line]}"
72
+ else
73
+ #anything in the correct_info needs to match what was parsed
74
+ #this enables the parsed data to include more info than we're testing for
75
+ correct_hash.each do |(key,val)|
76
+ parsed_hash[key].should == val
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ #the number of detailed failure accounts should match the number of reported failures
84
+ it "should give the same number of failure details as there were failures" do
85
+ examples.each do |test_results, correct_info, parsed_info|
86
+ parsed_info[:failures].length.should == parsed_info[:failure_count]
87
+ end
88
+ end
89
+ end
90
+
91
+ if have_key? examples, [:test_count,:success_count]
92
+ it "should give a test_count that's equal to the sum of failure_count and success_count" do
93
+ examples.each do |_tr,_ci, parsed_info|
94
+ next if (!parsed_info[:test_count]) || (!parsed_info[:success_count])
95
+ parsed_info[:test_count].should == parsed_info[:failure_count] + parsed_info[:success_count]
96
+ end
97
+ end
98
+ end
99
+
100
+ end
101
+ end