grntest 1.1.3 → 1.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c677198eaacb9883f7cd6ca46f7b7cf0ee6d5aea
4
- data.tar.gz: 8b50e54a05791eaf15370b1951eac4b831a52e31
3
+ metadata.gz: a2e33b36b6199c83bc97b514f7d2942cba652840
4
+ data.tar.gz: b2110017d594ff0b64639d003b3456b7c027abce
5
5
  SHA512:
6
- metadata.gz: d8d191e4fd6029fedfa9a4b346514f280ad133266e8acb236a0c0f46ee9b35a6e8cff38e7b84c3f8d13c894ab82c20a610ed4d9c7ab1d62d2fe18552c50efa69
7
- data.tar.gz: 0421f9e8c25fce0adbcaa43c6503737c71c8bcd2c49f167ef57c3333eabc00a7172314599c2dcb945cf0deaf56ba80e6fa8c2fc11db02253f22cf8e1991c560a
6
+ metadata.gz: d5c763cd7853c9a47bea09db3af4a6dd60d16f4836cbea6bfe7dff232b1cc06a28f04b0b69096ed5155966f2c0bfafb99cef091fb46b51f8edc6ef7490fdfa38
7
+ data.tar.gz: 7f36ce4674303db798adecb3c1d62dcd89d9a93b4fd948045f6a3c3ea8bf4797fb089f7e117bb0977703349d715af272e065f5df99879442e5339a7212105afe
data/doc/text/news.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # News
2
2
 
3
+ ## 1.1.4: 2016-04-26
4
+
5
+ ### Improvements
6
+
7
+ * Supported Windows.
8
+
3
9
  ## 1.1.3: 2016-03-20
4
10
 
5
11
  ### Improvements
data/grntest.gemspec CHANGED
@@ -45,6 +45,7 @@ Gem::Specification.new do |spec|
45
45
 
46
46
  spec.add_runtime_dependency("json")
47
47
  spec.add_runtime_dependency("msgpack")
48
+ spec.add_runtime_dependency("diff-lcs")
48
49
  spec.add_runtime_dependency("groonga-command-parser")
49
50
 
50
51
  spec.add_development_dependency("bundler")
@@ -0,0 +1,78 @@
1
+ # Copyright (C) 2016 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 "diff/lcs"
17
+ require "diff/lcs/hunk"
18
+
19
+ module Grntest
20
+ class DiffReporter
21
+ def initialize(expected, actual)
22
+ @expected = expected
23
+ @actual = actual
24
+ end
25
+
26
+ def report
27
+ expected_lines = @expected.lines.collect(&:chomp)
28
+ actual_lines = @actual.lines.collect(&:chomp)
29
+ diffs = Diff::LCS.diff(expected_lines,
30
+ actual_lines)
31
+ return if diffs.empty?
32
+
33
+ report_expected_label("(expected)")
34
+ report_actual_label("(actual)")
35
+
36
+ context_n_lines = 3
37
+ previous_hunk = nil
38
+ file_length_diff = 0
39
+ diffs.each do |diff|
40
+ begin
41
+ hunk = Diff::LCS::Hunk.new(expected_lines,
42
+ actual_lines,
43
+ diff,
44
+ context_n_lines,
45
+ file_length_diff)
46
+ next if previous_hunk.nil?
47
+ next if hunk.merge(previous_hunk)
48
+
49
+ report_hunk(previous_hunk)
50
+ ensure
51
+ previous_hunk = hunk
52
+ end
53
+ end
54
+ report_hunk(previous_hunk)
55
+ end
56
+
57
+ private
58
+ def expected_mark
59
+ "-"
60
+ end
61
+
62
+ def actual_mark
63
+ "+"
64
+ end
65
+
66
+ def report_expected_label(content)
67
+ puts("#{expected_mark * 3} #{content}")
68
+ end
69
+
70
+ def report_actual_label(content)
71
+ puts("#{actual_mark * 3} #{content}")
72
+ end
73
+
74
+ def report_hunk(hunk)
75
+ puts(hunk.diff(:unified))
76
+ end
77
+ end
78
+ end
@@ -35,6 +35,7 @@ module Grntest
35
35
  @result = []
36
36
  @output_type = "json"
37
37
  @log = nil
38
+ @query_log = nil
38
39
  @on_error = :default
39
40
  @abort_tag = nil
40
41
  @omitted = false
@@ -99,5 +100,17 @@ module Grntest
99
100
  def abort
100
101
  throw @abort_tag
101
102
  end
103
+
104
+ def close_logs
105
+ if @log
106
+ @log.close
107
+ @log = nil
108
+ end
109
+
110
+ if @query_log
111
+ @query_log.close
112
+ @query_log = nil
113
+ end
114
+ end
102
115
  end
103
116
  end
@@ -226,6 +226,10 @@ module Grntest
226
226
 
227
227
  def execute_directive_omit(line, content, options)
228
228
  reason, = options
229
+ omit(reason)
230
+ end
231
+
232
+ def omit(reason)
229
233
  @output_type = "raw"
230
234
  log_output("omit: #{reason}")
231
235
  @context.omit
@@ -292,9 +296,15 @@ module Grntest
292
296
  end
293
297
 
294
298
  def execute_suggest_create_dataset(dataset_name)
295
- command_line = [@context.groonga_suggest_create_dataset,
296
- @context.db_path.to_s,
297
- dataset_name]
299
+ if @context.groonga_suggest_create_dataset.nil?
300
+ omit("groonga-suggest-create-dataset isn't specified")
301
+ end
302
+
303
+ command_line = [
304
+ @context.groonga_suggest_create_dataset,
305
+ @context.db_path.to_s,
306
+ dataset_name,
307
+ ]
298
308
  packed_command_line = command_line.join(" ")
299
309
  log_input("#{packed_command_line}\n")
300
310
  begin
@@ -384,6 +394,8 @@ module Grntest
384
394
  case message
385
395
  when /\A\//
386
396
  true
397
+ when /\[a-zA-Z]:\//
398
+ true
387
399
  when /\Agroonga\(\) \[0x[\da-f]+\]\z/
388
400
  true
389
401
  when /\A\d+\s+(?:lib\S+\.dylib|\S+\.so|groonga|nginx|\?\?\?)\s+
@@ -0,0 +1,24 @@
1
+ # Copyright (C) 2016 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
+ module Grntest
17
+ module Platform
18
+ class << self
19
+ def windows?
20
+ /mswin|mingw|cygwin/ === RUBY_PLATFORM
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012-2015 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2012-2016 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify
4
4
  # it under the terms of the GNU General Public License as published by
@@ -13,6 +13,8 @@
13
13
  # You should have received a copy of the GNU General Public License
14
14
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
 
16
+ require "grntest/diff-reporter"
17
+
16
18
  module Grntest
17
19
  module Reporters
18
20
  class BaseReporter
@@ -93,16 +95,31 @@ module Grntest
93
95
  end
94
96
 
95
97
  def report_diff(expected, actual)
98
+ if @tester.diff == "internal"
99
+ run_diff_reporter(expected, actual)
100
+ else
101
+ run_diff_command(expected, actual)
102
+ end
103
+ end
104
+
105
+ def run_diff_command(expected, actual)
96
106
  create_temporary_file("expected", expected) do |expected_file|
97
107
  create_temporary_file("actual", actual) do |actual_file|
98
108
  diff_options = @tester.diff_options.dup
99
- diff_options.concat(["--label", "(expected)", expected_file.path,
100
- "--label", "(actual)", actual_file.path])
109
+ diff_options += [
110
+ "--label", "(expected)", expected_file.path,
111
+ "--label", "(actual)", actual_file.path,
112
+ ]
101
113
  system(@tester.diff, *diff_options)
102
114
  end
103
115
  end
104
116
  end
105
117
 
118
+ def run_diff_reporter(expected, actual)
119
+ reporter = DiffReporter.new(expected, actual)
120
+ reporter.report
121
+ end
122
+
106
123
  def report_test(worker, result)
107
124
  report_marker(result)
108
125
  print("[#{worker.id}] ") if @tester.n_workers > 1
@@ -19,6 +19,7 @@ require "tempfile"
19
19
 
20
20
  require "json"
21
21
 
22
+ require "grntest/platform"
22
23
  require "grntest/error"
23
24
  require "grntest/log-parser"
24
25
  require "grntest/executors"
@@ -139,6 +140,7 @@ module Grntest
139
140
  check_memory_leak(context)
140
141
  result.omitted = context.omitted?
141
142
  result.actual = context.result
143
+ context.close_logs
142
144
  end
143
145
  end
144
146
 
@@ -186,17 +188,23 @@ module Grntest
186
188
  groonga_input = input_write
187
189
  groonga_output = output_read
188
190
 
189
- input_fd = input_read.to_i
190
- output_fd = output_write.to_i
191
191
  env = {}
192
- spawn_options = {
193
- input_fd => input_fd,
194
- output_fd => output_fd
195
- }
192
+ spawn_options = {}
196
193
  command_line = groonga_command_line(context, spawn_options)
194
+ if Platform.windows?
195
+ spawn_options[:in] = input_read
196
+ spawn_options[:out] = output_write
197
+ else
198
+ input_fd = input_read.to_i
199
+ output_fd = output_write.to_i
200
+ spawn_options[input_fd] = input_fd
201
+ spawn_options[output_fd] = output_fd
202
+ command_line += [
203
+ "--input-fd", input_fd.to_s,
204
+ "--output-fd", output_fd.to_s,
205
+ ]
206
+ end
197
207
  command_line += [
198
- "--input-fd", input_fd.to_s,
199
- "--output-fd", output_fd.to_s,
200
208
  context.relative_db_path.to_s,
201
209
  ]
202
210
  pid = Process.spawn(env, *command_line, spawn_options)
@@ -466,21 +474,26 @@ http {
466
474
  end
467
475
 
468
476
  def create_empty_database(db_path)
469
- output_fd = Tempfile.new("create-empty-database")
477
+ output_file = Tempfile.new("create-empty-database")
470
478
  env = {
471
479
  "GRN_FMALLOC_PROB" => nil,
472
480
  }
473
- create_database_command = [
474
- @tester.groonga,
475
- "--output-fd", output_fd.to_i.to_s,
481
+ options = {}
482
+ create_database_command = [@tester.groonga]
483
+ if Platform.windows?
484
+ options[:out] = output_file
485
+ else
486
+ options[output_file.fileno] = output_file.fileno
487
+ create_database_command += [
488
+ "--output-fd", output_file.fileno.to_s,
489
+ ]
490
+ end
491
+ create_database_command += [
476
492
  "-n", db_path,
477
- "shutdown"
493
+ "shutdown",
478
494
  ]
479
- options = {
480
- output_fd.to_i => output_fd.to_i
481
- }
482
495
  system(env, *create_database_command, options)
483
- output_fd.close(true)
496
+ output_file.close(true)
484
497
  end
485
498
 
486
499
  def normalize_actual_result(result)
@@ -502,7 +515,12 @@ http {
502
515
  result.actual = normalized_result
503
516
  end
504
517
 
518
+ def normalize_new_line(content)
519
+ content.gsub(/\r\n/, "\n")
520
+ end
521
+
505
522
  def normalize_raw_content(content)
523
+ content = normalize_new_line(content)
506
524
  "#{content}\n".force_encoding("ASCII-8BIT")
507
525
  end
508
526
 
@@ -13,6 +13,7 @@
13
13
  # You should have received a copy of the GNU General Public License
14
14
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
 
16
+ require "rbconfig"
16
17
  require "optparse"
17
18
  require "pathname"
18
19
 
@@ -40,25 +41,25 @@ module Grntest
40
41
  parser.on("--groonga=COMMAND",
41
42
  "Use COMMAND as groonga command",
42
43
  "(#{tester.groonga})") do |command|
43
- tester.groonga = command
44
+ tester.groonga = normalize_command(command)
44
45
  end
45
46
 
46
47
  parser.on("--groonga-httpd=COMMAND",
47
48
  "Use COMMAND as groonga-httpd command for groonga-httpd tests",
48
49
  "(#{tester.groonga_httpd})") do |command|
49
- tester.groonga_httpd = command
50
+ tester.groonga_httpd = normalize_command(command)
50
51
  end
51
52
 
52
53
  parser.on("--groonga-suggest-create-dataset=COMMAND",
53
54
  "Use COMMAND as groonga_suggest_create_dataset command",
54
55
  "(#{tester.groonga_suggest_create_dataset})") do |command|
55
- tester.groonga_suggest_create_dataset = command
56
+ tester.groonga_suggest_create_dataset = normalize_command(command)
56
57
  end
57
58
 
58
59
  available_interfaces = [:stdio, :http]
59
60
  available_interface_labels = available_interfaces.join(", ")
60
61
  parser.on("--interface=INTERFACE", available_interfaces,
61
- "Use INTERFACE for communicating groonga",
62
+ "Use INTERFACE for communicating Groonga",
62
63
  "[#{available_interface_labels}]",
63
64
  "(#{tester.interface})") do |interface|
64
65
  tester.interface = interface
@@ -100,6 +101,7 @@ module Grntest
100
101
 
101
102
  parser.on("--diff=DIFF",
102
103
  "Use DIFF as diff command",
104
+ "Use --diff=internal to use internal differ",
103
105
  "(#{tester.diff})") do |diff|
104
106
  tester.diff = diff
105
107
  tester.diff_options.clear
@@ -157,13 +159,13 @@ module Grntest
157
159
  end
158
160
 
159
161
  parser.on("--gdb[=COMMAND]",
160
- "Run groonga on gdb and use COMMAND as gdb",
162
+ "Run Groonga on gdb and use COMMAND as gdb",
161
163
  "(#{tester.default_gdb})") do |command|
162
164
  tester.gdb = command || tester.default_gdb
163
165
  end
164
166
 
165
167
  parser.on("--valgrind[=COMMAND]",
166
- "Run groonga on valgrind and use COMMAND as valgrind",
168
+ "Run Groonga on valgrind and use COMMAND as valgrind",
167
169
  "(#{tester.default_valgrind})") do |command|
168
170
  tester.valgrind = command || tester.default_valgrind
169
171
  end
@@ -213,6 +215,22 @@ module Grntest
213
215
  parser
214
216
  end
215
217
 
218
+ def normalize_command(command)
219
+ if File.executable?(command)
220
+ return File.expand_path(command)
221
+ end
222
+
223
+ exeext = RbConfig::CONFIG["EXEEXT"]
224
+ unless exeext.empty?
225
+ command_exe = "#{command}#{exeext}"
226
+ if File.executable?(command_exe)
227
+ return File.expand_path(command_exe)
228
+ end
229
+ end
230
+
231
+ command
232
+ end
233
+
216
234
  def parse_name_or_pattern(name)
217
235
  if /\A\/(.+)\/\z/ =~ name
218
236
  Regexp.new($1, Regexp::IGNORECASE)
@@ -239,6 +257,9 @@ module Grntest
239
257
  @groonga = "groonga"
240
258
  @groonga_httpd = "groonga-httpd"
241
259
  @groonga_suggest_create_dataset = "groonga-suggest-create-dataset"
260
+ unless command_exist?(@groonga_suggest_create_dataset)
261
+ @groonga_suggest_create_dataset = nil
262
+ end
242
263
  @interface = :stdio
243
264
  @output_type = "json"
244
265
  @testee = "groonga"
@@ -345,6 +366,7 @@ module Grntest
345
366
  targets.each do |target|
346
367
  target_path = Pathname(target)
347
368
  next unless target_path.exist?
369
+ target_path = target_path.cleanpath
348
370
  if target_path.directory?
349
371
  load_tests_under_directory(tests, target_path)
350
372
  else
@@ -373,9 +395,12 @@ module Grntest
373
395
  if command_exist?("cut-diff")
374
396
  @diff = "cut-diff"
375
397
  @diff_options = ["--context-lines", "10"]
376
- else
398
+ elsif command_exist?("diff")
377
399
  @diff = "diff"
378
400
  @diff_options = ["-u"]
401
+ else
402
+ @diff = "internal"
403
+ @diff_options = []
379
404
  end
380
405
  end
381
406
 
@@ -391,9 +416,16 @@ module Grntest
391
416
  end
392
417
 
393
418
  def command_exist?(name)
419
+ exeext = RbConfig::CONFIG["EXEEXT"]
394
420
  ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
395
- absolute_path = File.join(path, name)
396
- return true if File.executable?(absolute_path)
421
+ raw_candidate = File.join(path, name)
422
+ candidates = [
423
+ raw_candidate,
424
+ "#{raw_candidate}#{exeext}",
425
+ ]
426
+ candidates.each do |candidate|
427
+ return true if File.executable?(candidate)
428
+ end
397
429
  end
398
430
  false
399
431
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012-2015 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2012-2016 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify
4
4
  # it under the terms of the GNU General Public License as published by
@@ -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.1.3"
17
+ VERSION = "1.1.4"
18
18
  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.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-20 00:00:00.000000000 Z
12
+ date: 2016-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: diff-lcs
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: groonga-command-parser
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -155,6 +169,7 @@ files:
155
169
  - doc/text/news.md
156
170
  - grntest.gemspec
157
171
  - lib/grntest/base-result.rb
172
+ - lib/grntest/diff-reporter.rb
158
173
  - lib/grntest/error.rb
159
174
  - lib/grntest/execution-context.rb
160
175
  - lib/grntest/executors.rb
@@ -163,6 +178,7 @@ files:
163
178
  - lib/grntest/executors/standard-io-executor.rb
164
179
  - lib/grntest/log-entry.rb
165
180
  - lib/grntest/log-parser.rb
181
+ - lib/grntest/platform.rb
166
182
  - lib/grntest/query-log-entry.rb
167
183
  - lib/grntest/query-log-parser.rb
168
184
  - lib/grntest/reporters.rb