grntest 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,5 +14,5 @@
14
14
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
 
16
16
  module Grntest
17
- VERSION = "1.0.2"
17
+ VERSION = "1.0.3"
18
18
  end
@@ -0,0 +1,164 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "grntest/base-result"
19
+ require "grntest/test-runner"
20
+
21
+ module Grntest
22
+ class WorkerResult < BaseResult
23
+ attr_reader :n_tests, :n_passed_tests, :n_leaked_tests
24
+ attr_reader :n_omitted_tests, :n_not_checked_tests
25
+ attr_reader :failed_tests
26
+ def initialize
27
+ super
28
+ @n_tests = 0
29
+ @n_passed_tests = 0
30
+ @n_leaked_tests = 0
31
+ @n_omitted_tests = 0
32
+ @n_not_checked_tests = 0
33
+ @failed_tests = []
34
+ end
35
+
36
+ def n_failed_tests
37
+ @failed_tests.size
38
+ end
39
+
40
+ def on_test_finish
41
+ @n_tests += 1
42
+ end
43
+
44
+ def on_test_success
45
+ @n_passed_tests += 1
46
+ end
47
+
48
+ def on_test_failure(name)
49
+ @failed_tests << name
50
+ end
51
+
52
+ def on_test_leak(name)
53
+ @n_leaked_tests += 1
54
+ end
55
+
56
+ def on_test_omission
57
+ @n_omitted_tests += 1
58
+ end
59
+
60
+ def on_test_no_check
61
+ @n_not_checked_tests += 1
62
+ end
63
+ end
64
+
65
+ class Worker
66
+ attr_reader :id, :tester, :test_suites_rusult, :reporter
67
+ attr_reader :suite_name, :test_script_path, :test_name, :status, :result
68
+ def initialize(id, tester, test_suites_result, reporter)
69
+ @id = id
70
+ @tester = tester
71
+ @test_suites_result = test_suites_result
72
+ @reporter = reporter
73
+ @suite_name = nil
74
+ @test_script_path = nil
75
+ @test_name = nil
76
+ @interruptted = false
77
+ @status = "not running"
78
+ @result = WorkerResult.new
79
+ end
80
+
81
+ def interrupt
82
+ @interruptted = true
83
+ end
84
+
85
+ def interruptted?
86
+ @interruptted
87
+ end
88
+
89
+ def run(queue)
90
+ succeeded = true
91
+
92
+ @result.measure do
93
+ @reporter.on_worker_start(self)
94
+ catch do |tag|
95
+ loop do
96
+ suite_name, test_script_path, test_name = queue.pop
97
+ break if test_script_path.nil?
98
+
99
+ unless @suite_name == suite_name
100
+ @reporter.on_suite_finish(self) if @suite_name
101
+ @suite_name = suite_name
102
+ @reporter.on_suite_start(self)
103
+ end
104
+ @test_script_path = test_script_path
105
+ @test_name = test_name
106
+ runner = TestRunner.new(@tester, self)
107
+ succeeded = false unless runner.run
108
+
109
+ break if interruptted?
110
+ end
111
+ @status = "finished"
112
+ @reporter.on_suite_finish(@suite_name) if @suite_name
113
+ @suite_name = nil
114
+ end
115
+ end
116
+ @reporter.on_worker_finish(self)
117
+
118
+ succeeded
119
+ end
120
+
121
+ def on_test_start
122
+ @status = "running"
123
+ @test_result = nil
124
+ @reporter.on_test_start(self)
125
+ end
126
+
127
+ def on_test_success(result)
128
+ @status = "passed"
129
+ @result.on_test_success
130
+ @reporter.on_test_success(self, result)
131
+ end
132
+
133
+ def on_test_failure(result)
134
+ @status = "failed"
135
+ @result.on_test_failure(test_name)
136
+ @reporter.on_test_failure(self, result)
137
+ end
138
+
139
+ def on_test_leak(result)
140
+ @status = "leaked(#{result.n_leaked_objects})"
141
+ @result.on_test_leak(test_name)
142
+ @reporter.on_test_leak(self, result)
143
+ end
144
+
145
+ def on_test_omission(result)
146
+ @status = "omitted"
147
+ @result.on_test_omission
148
+ @reporter.on_test_omission(self, result)
149
+ end
150
+
151
+ def on_test_no_check(result)
152
+ @status = "not checked"
153
+ @result.on_test_no_check
154
+ @reporter.on_test_no_check(self, result)
155
+ end
156
+
157
+ def on_test_finish(result)
158
+ @result.on_test_finish
159
+ @reporter.on_test_finish(self, result)
160
+ @test_script_path = nil
161
+ @test_name = nil
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,42 @@
1
+ # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require "grntest/executors/base-executor"
17
+
18
+ class TestBaseExecutor < Test::Unit::TestCase
19
+ def setup
20
+ @executor = Grntest::Executors::BaseExecutor.new
21
+ @context = @executor.context
22
+ end
23
+
24
+ class TestErrorLog < self
25
+ data("emergency" => "E",
26
+ "alert" => "A",
27
+ "critical" => "C",
28
+ "error" => "e",
29
+ "warning" => "w")
30
+ def test_important_log_level(level)
31
+ assert_true(@executor.send(:important_log_level?, level))
32
+ end
33
+
34
+ data("notice" => "n",
35
+ "info" => "i",
36
+ "debug" => "d",
37
+ "dump" => "-")
38
+ def test_not_important_log_level(level)
39
+ assert_false(@executor.send(:important_log_level?, level))
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,61 @@
1
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require "stringio"
17
+ require "tempfile"
18
+ require "grntest/executors/standard-io-executor"
19
+
20
+ class TestStandardIOExecutor < Test::Unit::TestCase
21
+ def setup
22
+ input = StringIO.new
23
+ output = StringIO.new
24
+ @executor = Grntest::Executors::StandardIOExecutor.new(input, output)
25
+ @context = @executor.context
26
+ @script = Tempfile.new("test-executor")
27
+ end
28
+
29
+ private
30
+ def execute(command)
31
+ @script.puts(command)
32
+ @script.close
33
+ @executor.execute(Pathname(@script.path))
34
+ end
35
+
36
+ class TestComment < self
37
+ def test_disable_logging
38
+ assert_predicate(@context, :logging?)
39
+ execute("\#@disable-logging")
40
+ assert_not_predicate(@context, :logging?)
41
+ end
42
+
43
+ def test_enable_logging
44
+ @context.logging = false
45
+ assert_not_predicate(@context, :logging?)
46
+ execute("\#@enable-logging")
47
+ assert_predicate(@context, :logging?)
48
+ end
49
+
50
+ def test_suggest_create_dataset
51
+ mock(@executor).execute_suggest_create_dataset("shop")
52
+ execute("\#@suggest-create-dataset shop")
53
+ end
54
+
55
+ def test_enable_ignore_feature_on_error
56
+ assert_not_equal(:omit, @context.on_error)
57
+ execute("\#@on-error omit")
58
+ assert_equal(:omit, @context.on_error)
59
+ end
60
+ end
61
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grntest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-11 00:00:00.000000000 Z
13
+ date: 2013-08-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -170,12 +170,29 @@ files:
170
170
  - Gemfile
171
171
  - grntest.gemspec
172
172
  - .yardopts
173
+ - lib/grntest/test-runner.rb
173
174
  - lib/grntest/tester.rb
175
+ - lib/grntest/worker.rb
176
+ - lib/grntest/response-parser.rb
177
+ - lib/grntest/error.rb
178
+ - lib/grntest/base-result.rb
174
179
  - lib/grntest/version.rb
180
+ - lib/grntest/test-suites-runner.rb
181
+ - lib/grntest/executors/http-executor.rb
182
+ - lib/grntest/executors/base-executor.rb
183
+ - lib/grntest/executors/standard-io-executor.rb
184
+ - lib/grntest/executors.rb
185
+ - lib/grntest/execution-context.rb
186
+ - lib/grntest/reporters.rb
187
+ - lib/grntest/reporters/inplace-reporter.rb
188
+ - lib/grntest/reporters/stream-reporter.rb
189
+ - lib/grntest/reporters/base-reporter.rb
190
+ - lib/grntest/reporters/mark-reporter.rb
175
191
  - doc/text/news.md
176
192
  - doc/text/gpl-3.0.txt
177
193
  - test/run-test.rb
178
- - test/test-executor.rb
194
+ - test/executors/test-base-executor.rb
195
+ - test/executors/test-standard-io-executor.rb
179
196
  - bin/grntest
180
197
  homepage: https://github.com/groonga/grntest
181
198
  licenses:
@@ -190,18 +207,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
207
  - - ! '>='
191
208
  - !ruby/object:Gem::Version
192
209
  version: '0'
193
- segments:
194
- - 0
195
- hash: -173336567552475669
196
210
  required_rubygems_version: !ruby/object:Gem::Requirement
197
211
  none: false
198
212
  requirements:
199
213
  - - ! '>='
200
214
  - !ruby/object:Gem::Version
201
215
  version: '0'
202
- segments:
203
- - 0
204
- hash: -173336567552475669
205
216
  requirements: []
206
217
  rubyforge_project:
207
218
  rubygems_version: 1.8.23
@@ -211,5 +222,6 @@ summary: Grntest is a testing framework for groonga. You can write a test for gr
211
222
  by writing groonga commands and expected result.
212
223
  test_files:
213
224
  - test/run-test.rb
214
- - test/test-executor.rb
225
+ - test/executors/test-base-executor.rb
226
+ - test/executors/test-standard-io-executor.rb
215
227
  has_rdoc:
@@ -1,207 +0,0 @@
1
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # This program is free software: you can redistribute it and/or modify
4
- # it under the terms of the GNU General Public License as published by
5
- # the Free Software Foundation, either version 3 of the License, or
6
- # (at your option) any later version.
7
- #
8
- # This program is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- # GNU General Public License for more details.
12
- #
13
- # You should have received a copy of the GNU General Public License
14
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
-
16
- require "stringio"
17
- require "cgi/util"
18
- require "grntest/tester"
19
-
20
- class TestExecutor < Test::Unit::TestCase
21
- def setup
22
- input = StringIO.new
23
- output = StringIO.new
24
- @executor = Grntest::Tester::StandardIOExecutor.new(input, output)
25
- @context = @executor.context
26
- @script = Tempfile.new("test-executor")
27
- end
28
-
29
- private
30
- def execute(command)
31
- @script.puts(command)
32
- @script.close
33
- @executor.execute(Pathname(@script.path))
34
- end
35
-
36
- class TestComment < self
37
- def test_disable_logging
38
- assert_predicate(@context, :logging?)
39
- execute("\#@disable-logging")
40
- assert_not_predicate(@context, :logging?)
41
- end
42
-
43
- def test_enable_logging
44
- @context.logging = false
45
- assert_not_predicate(@context, :logging?)
46
- execute("\#@enable-logging")
47
- assert_predicate(@context, :logging?)
48
- end
49
-
50
- def test_suggest_create_dataset
51
- mock(@executor).execute_suggest_create_dataset("shop")
52
- execute("\#@suggest-create-dataset shop")
53
- end
54
-
55
- def test_enable_ignore_feature_on_error
56
- assert_not_equal(:omit, @context.on_error)
57
- execute("\#@on-error omit")
58
- assert_equal(:omit, @context.on_error)
59
- end
60
- end
61
-
62
- class TestCommandFormatConveter < self
63
- def test_without_argument_name
64
- command = "table_create Site TABLE_HASH_KEY ShortText"
65
- arguments = {
66
- "name" => "Site",
67
- "flags" => "TABLE_HASH_KEY",
68
- "key_type" => "ShortText",
69
- }
70
- actual_url = convert(command)
71
- expected_url = build_url("table_create", arguments)
72
-
73
- assert_equal(expected_url, actual_url)
74
- end
75
-
76
- def test_with_argument_name
77
- command = "select --table Sites"
78
- actual_url = convert(command)
79
- expected_url = build_url("select", "table" => "Sites")
80
-
81
- assert_equal(expected_url, actual_url)
82
- end
83
-
84
- def test_non_named_argument_after_named_arguement
85
- command = "table_create --flags TABLE_HASH_KEY --key_type ShortText Site"
86
- arguments = {
87
- "flags" => "TABLE_HASH_KEY",
88
- "key_type" => "ShortText",
89
- "name" => "Site",
90
- }
91
- actual_url = convert(command)
92
- expected_url = build_url("table_create", arguments)
93
-
94
- assert_equal(expected_url, actual_url)
95
- end
96
-
97
- def test_without_arguments
98
- command = "dump"
99
- actual_url = convert(command)
100
- expected_url = build_url(command, {})
101
-
102
- assert_equal(expected_url, actual_url)
103
- end
104
-
105
- def test_load_json_array
106
- load_command = "load --table Sites"
107
- load_values = <<EOF
108
- [
109
- ["_key","uri"],
110
- ["groonga","http://groonga.org/"],
111
- ["razil","http://razil.jp/"]
112
- ]
113
- EOF
114
- command = "#{load_command}\n#{load_values}"
115
- actual_url = convert(command)
116
-
117
- load_values_without_columns =
118
- '[["groonga","http://groonga.org/"],["razil","http://razil.jp/"]]'
119
- arguments = {
120
- "table" => "Sites",
121
- "columns" => "_key,uri",
122
- "values" => load_values_without_columns
123
- }
124
- expected_url = build_url("load", arguments)
125
-
126
- assert_equal(expected_url, actual_url)
127
- end
128
-
129
- def test_load_json_object
130
- load_command = "load --table Sites"
131
- load_values = <<EOF
132
- [
133
- {"_key": "ruby", "uri": "http://ruby-lang.org/"}
134
- ]
135
- EOF
136
- command = "#{load_command}\n#{load_values}"
137
- actual_url = convert(command)
138
-
139
- arguments = {
140
- "table" => "Sites",
141
- "values" => '[{"_key":"ruby","uri":"http://ruby-lang.org/"}]'
142
- }
143
- expected_url = build_url("load", arguments)
144
-
145
- assert_equal(expected_url, actual_url)
146
- end
147
-
148
- def test_value_single_quote
149
- command = "select Sites --output_columns '_key, uri'"
150
- arguments = {
151
- "table" => "Sites",
152
- "output_columns" => "_key, uri",
153
- }
154
- actual_url = convert(command)
155
- expected_url = build_url("select", arguments)
156
-
157
- assert_equal(expected_url, actual_url)
158
- end
159
-
160
- def test_value_double_quote_in_single_quote
161
- command = "select Sites --filter 'uri @ \"ruby\"'"
162
- arguments = {
163
- "table" => "Sites",
164
- "filter" => "uri @ \"ruby\"",
165
- }
166
- actual_url = convert(command)
167
- expected_url = build_url("select", arguments)
168
-
169
- assert_equal(expected_url, actual_url)
170
- end
171
-
172
- def test_value_double_quote
173
- command = "select Sites --output_columns \"_key, uri\""
174
- arguments = {
175
- "table" => "Sites",
176
- "output_columns" => "_key, uri",
177
- }
178
- actual_url = convert(command)
179
- expected_url = build_url("select", arguments)
180
-
181
- assert_equal(expected_url, actual_url)
182
- end
183
-
184
- private
185
- def convert(command)
186
- converter = Grntest::Tester::CommandFormatConverter.new(command)
187
- converter.to_url
188
- end
189
-
190
- def build_url(command, named_arguments)
191
- url = "/d/#{command}"
192
- query_parameters = []
193
-
194
- sorted_arguments = named_arguments.sort_by do |name, _|
195
- name
196
- end
197
- sorted_arguments.each do |name, argument|
198
- query_parameters << "#{CGI.escape(name)}=#{CGI.escape(argument)}"
199
- end
200
- unless query_parameters.empty?
201
- url << "?"
202
- url << query_parameters.join("&")
203
- end
204
- url
205
- end
206
- end
207
- end