From 76c3ac29921bc9e2f76edc32fd04583b9363645f Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Mon, 14 Mar 2016 14:33:58 +0900 Subject: [PATCH] Suppress a lot of warnings * Do not shadow local variables test/plugin/test_in_dummy.rb:91: warning: assigned but unused variable - time lib/fluent/plugin/in_dummy.rb:45: warning: shadowing outer local variable - e test/test_event.rb:94: warning: shadowing outer local variable - time test/test_event.rb:142: warning: shadowing outer local variable - time test/plugin/test_in_stream.rb:20: warning: shadowing outer local variable - time test/plugin/test_in_stream.rb:35: warning: shadowing outer local variable - time test/plugin/test_in_stream.rb:51: warning: shadowing outer local variable - time test/plugin/test_in_stream.rb:68: warning: shadowing outer local variable - time test/plugin/test_in_stream.rb:84: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:43: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:59: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:75: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:113: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:150: warning: shadowing outer local variable - tag test/plugin/test_in_http.rb:163: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:184: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:200: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:238: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:262: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:280: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:43: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:59: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:75: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:113: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:150: warning: shadowing outer local variable - tag test/plugin/test_in_http.rb:163: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:184: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:200: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:238: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:262: warning: shadowing outer local variable - time test/plugin/test_in_http.rb:280: warning: shadowing outer local variable - time * Initialize uninitialized instance variables lib/fluent/test/base.rb:31: warning: instance variable @now not initialized lib/fluent/test/input_test.rb:121: warning: instance variable @run_post_conditions not initialized lib/fluent/log.rb:324: warning: instance variable @suppress_repeated_stacktrace not initialized lib/fluent/config/configure_proxy.rb:183: warning: instance variable @current_description not initialized lib/fluent/plugin/buf_file.rb:147: warning: instance variable @symlink_path not initialized lib/fluent/output.rb:212: warning: instance variable @secondary not initialized lib/fluent/output.rb:220: warning: instance variable @secondary not initialized lib/fluent/mixin.rb:201: warning: instance variable @localtime not initialized lib/fluent/mixin.rb:201: warning: instance variable @timezone not initialized lib/fluent/mixin.rb:149: warning: instance variable @remove_tag_prefix not initialized lib/fluent/mixin.rb:150: warning: instance variable @remove_tag_suffix not initialized test/config/test_system_config.rb:81: warning: instance variable @emit_error_log_interval not initialized lib/fluent/plugin/in_syslog.rb:111: warning: instance variable @use_default not initialized lib/fluent/root_agent.rb:89: warning: instance variable @without_source not initialized lib/fluent/process.rb:488: warning: instance variable @detach_process not initialized * Define assert_equal_event_time once lib/fluent/test/base.rb:35: warning: method redefined; discarding old assert_equal_event_time lib/fluent/test/base.rb:35: warning: previous definition of assert_equal_event_time was here * Add '_' prefix to unused variables test/test_parser.rb:1046: warning: assigned but unused variable - time lib/fluent/test/output_test.rb:91: warning: assigned but unused variable - record lib/fluent/config/element.rb:138: warning: assigned but unused variable - block * Remove unused variables test/test_parser.rb:453: warning: assigned but unused variable - format test/test_mixin.rb:211: warning: assigned but unused variable - d test/test_formatter.rb:55: warning: assigned but unused variable - formatter test/test_buffer.rb:581: warning: assigned but unused variable - e test/config/test_dsl.rb:164: warning: assigned but unused variable - root lib/fluent/parser.rb:619: warning: assigned but unused variable - e lib/fluent/plugin/in_exec.rb:56: warning: assigned but unused variable - localtime lib/fluent/plugin/in_exec.rb:58: warning: assigned but unused variable - utc lib/fluent/event_router.rb:105: warning: assigned but unused variable - c * Rename block parameter lib/fluent/config/v1_parser.rb:159: warning: shadowing outer local variable - path lib/fluent/config/parser.rb:84: warning: shadowing outer local variable - path lib/fluent/plugin/buf_file.rb:175: warning: assigned but unused variable - chunk lib/fluent/plugin/buf_file.rb:177: warning: assigned but unused variable - timestamp lib/fluent/plugin/buf_file.rb:181: warning: assigned but unused variable - chunk lib/fluent/plugin/buf_file.rb:183: warning: assigned but unused variable - timestamp * Use defined global variable lib/fluent/plugin.rb:129: warning: global variable `$log' not initialized * Remove redundant condition lib/fluent/log.rb:255: warning: instance variable @suppress_repeated_stacktrace not initialized lib/fluent/log.rb:261: warning: instance variable @suppress_repeated_stacktrace not initialized * Define instance method once lib/fluent/plugin/in_tail.rb:457: warning: method redefined; discarding old swap_state lib/fluent/plugin/in_tail.rb:457: warning: previous definition of swap_state was here --- lib/fluent/config/configure_proxy.rb | 1 + lib/fluent/config/element.rb | 2 +- lib/fluent/config/parser.rb | 8 ++-- lib/fluent/config/v1_parser.rb | 8 ++-- lib/fluent/event_router.rb | 2 +- lib/fluent/log.rb | 8 ++-- lib/fluent/mixin.rb | 20 +++++++--- lib/fluent/output.rb | 1 + lib/fluent/parser.rb | 2 +- lib/fluent/plugin.rb | 2 +- lib/fluent/plugin/buf_file.rb | 9 +++-- lib/fluent/plugin/in_dummy.rb | 4 +- lib/fluent/plugin/in_exec.rb | 4 +- lib/fluent/plugin/in_syslog.rb | 2 + lib/fluent/plugin/in_tail.rb | 16 ++++---- lib/fluent/process.rb | 4 ++ lib/fluent/root_agent.rb | 1 + lib/fluent/test/base.rb | 16 ++++---- lib/fluent/test/input_test.rb | 2 +- lib/fluent/test/output_test.rb | 2 +- test/config/test_dsl.rb | 2 +- test/config/test_system_config.rb | 1 + test/plugin/test_filter_record_transformer.rb | 32 ++++++++-------- test/plugin/test_in_dummy.rb | 2 +- test/plugin/test_in_http.rb | 38 +++++++++---------- test/plugin/test_in_stream.rb | 16 ++++---- test/test_buffer.rb | 2 +- test/test_event.rb | 8 ++-- test/test_formatter.rb | 2 +- test/test_mixin.rb | 2 +- test/test_parser.rb | 4 +- 31 files changed, 121 insertions(+), 102 deletions(-) diff --git a/lib/fluent/config/configure_proxy.rb b/lib/fluent/config/configure_proxy.rb index af9be8d135..2e5e0fe169 100644 --- a/lib/fluent/config/configure_proxy.rb +++ b/lib/fluent/config/configure_proxy.rb @@ -52,6 +52,7 @@ def initialize(name, opts = {}) @defaults = {} @descriptions = {} @sections = {} + @current_description = nil end def required? diff --git a/lib/fluent/config/element.rb b/lib/fluent/config/element.rb index 5d47824646..6daff414c2 100644 --- a/lib/fluent/config/element.rb +++ b/lib/fluent/config/element.rb @@ -135,7 +135,7 @@ def secret_param?(key) param_key = key.to_sym @corresponding_proxies.each { |proxy| - block, opts = proxy.params[param_key] + _block, opts = proxy.params[param_key] if opts && opts.has_key?(:secret) return opts[:secret] end diff --git a/lib/fluent/config/parser.rb b/lib/fluent/config/parser.rb index 98e8cbfbec..3a17539b8b 100644 --- a/lib/fluent/config/parser.rb +++ b/lib/fluent/config/parser.rb @@ -81,10 +81,10 @@ def process_include(attrs, elems, uri, allow_include = true) pattern = path end - Dir.glob(pattern).sort.each { |path| - basepath = File.dirname(path) - fname = File.basename(path) - File.open(path) { |f| + Dir.glob(pattern).sort.each { |entry| + basepath = File.dirname(entry) + fname = File.basename(entry) + File.open(entry) { |f| Parser.new(basepath, f.each_line, fname).parse!(allow_include, nil, attrs, elems) } } diff --git a/lib/fluent/config/v1_parser.rb b/lib/fluent/config/v1_parser.rb index 4eceaedc3c..9f6a73aed9 100644 --- a/lib/fluent/config/v1_parser.rb +++ b/lib/fluent/config/v1_parser.rb @@ -156,10 +156,10 @@ def eval_include(attrs, elems, uri) pattern = path end - Dir.glob(pattern).sort.each { |path| - basepath = File.dirname(path) - fname = File.basename(path) - data = File.read(path) + Dir.glob(pattern).sort.each { |entry| + basepath = File.dirname(entry) + fname = File.basename(entry) + data = File.read(entry) data.force_encoding('UTF-8') ss = StringScanner.new(data) V1Parser.new(ss, basepath, fname, @eval_context).parse_element(true, nil, attrs, elems) diff --git a/lib/fluent/event_router.rb b/lib/fluent/event_router.rb index 7ff4828606..feb0e6b5a7 100644 --- a/lib/fluent/event_router.rb +++ b/lib/fluent/event_router.rb @@ -102,7 +102,7 @@ def match?(tag) def match(tag) collector = @match_cache.get(tag) { - c = find(tag) || @default_collector + find(tag) || @default_collector } collector end diff --git a/lib/fluent/log.rb b/lib/fluent/log.rb index e0340497c0..40cea47cd2 100644 --- a/lib/fluent/log.rb +++ b/lib/fluent/log.rb @@ -68,9 +68,7 @@ def initialize(out=STDERR, level=LEVEL_TRACE, opts={}) # Fluent::Engine requires Fluent::Log, so we must take that object lazily @engine = Fluent.const_get('Engine') - if opts.has_key?(:suppress_repeated_stacktrace) - @suppress_repeated_stacktrace = opts[:suppress_repeated_stacktrace] - end + @suppress_repeated_stacktrace = opts[:suppress_repeated_stacktrace] end attr_accessor :out @@ -320,7 +318,9 @@ def initialize(logger) @logger = logger @level = @logger.level @depth_offset = 2 - @suppress_repeated_stacktrace = logger.instance_variable_get(:@suppress_repeated_stacktrace) + if logger.instance_variable_defined?(:@suppress_repeated_stacktrace) + @suppress_repeated_stacktrace = logger.instance_variable_get(:@suppress_repeated_stacktrace) + end enable_color @logger.enable_color? end diff --git a/lib/fluent/mixin.rb b/lib/fluent/mixin.rb index 610528ebd6..5fd6a6d77b 100644 --- a/lib/fluent/mixin.rb +++ b/lib/fluent/mixin.rb @@ -133,13 +133,18 @@ module HandleTagNameMixin attr_accessor :remove_tag_prefix, :remove_tag_suffix, :add_tag_prefix, :add_tag_suffix def configure(conf) super - if remove_tag_prefix = conf['remove_tag_prefix'] - @remove_tag_prefix = Regexp.new('^' + Regexp.escape(remove_tag_prefix)) - end - if remove_tag_suffix = conf['remove_tag_suffix'] - @remove_tag_suffix = Regexp.new(Regexp.escape(remove_tag_suffix) + '$') - end + @remove_tag_prefix = if conf.has_key?('remove_tag_prefix') + Regexp.new('^' + Regexp.escape(conf['remove_tag_prefix'])) + else + nil + end + + @remove_tag_suffix = if conf.has_key?('remove_tag_suffix') + Regexp.new(Regexp.escape(conf['remove_tag_suffix']) + '$') + else + nil + end @add_tag_prefix = conf['add_tag_prefix'] @add_tag_suffix = conf['add_tag_suffix'] @@ -162,6 +167,8 @@ module SetTimeKeyMixin def configure(conf) @include_time_key = false + @localtime = false + @timezone = nil super @@ -257,6 +264,7 @@ def self.included(klass) def configure(conf) super + @type_converters = nil @type_converters = parse_types_parameter unless @types.nil? end diff --git a/lib/fluent/output.rb b/lib/fluent/output.rb index 203531c685..18cfb5e27a 100644 --- a/lib/fluent/output.rb +++ b/lib/fluent/output.rb @@ -146,6 +146,7 @@ def initialize @next_retry_time = 0 @num_errors = 0 @num_errors_lock = Mutex.new + @secondary = nil @secondary_limit = 8 @emit_count = 0 end diff --git a/lib/fluent/parser.rb b/lib/fluent/parser.rb index 08d1f4a8b7..d04c82f6c9 100644 --- a/lib/fluent/parser.rb +++ b/lib/fluent/parser.rb @@ -616,7 +616,7 @@ def self.lookup(format) # built-in template begin Fluent::Plugin.new_parser(format) - rescue ConfigError => e # keep same error message + rescue ConfigError # keep same error message raise ConfigError, "Unknown format template '#{format}'" end end diff --git a/lib/fluent/plugin.rb b/lib/fluent/plugin.rb index 5cf106646f..03ea20439c 100644 --- a/lib/fluent/plugin.rb +++ b/lib/fluent/plugin.rb @@ -126,7 +126,7 @@ def self.register_impl(kind, registry, type, value) raise Fluent::ConfigError, "Invalid implementation as #{kind} plugin: '#{type}'. It must be a Class, or callable." end registry.register(type, value) - $log.trace "registered #{kind} plugin '#{type}'" if $log + $log.trace "registered #{kind} plugin '#{type}'" if defined?($log) nil end diff --git a/lib/fluent/plugin/buf_file.rb b/lib/fluent/plugin/buf_file.rb index 58d6b10722..0d3fb4a4aa 100644 --- a/lib/fluent/plugin/buf_file.rb +++ b/lib/fluent/plugin/buf_file.rb @@ -100,6 +100,7 @@ def initialize super @uri_parser = URI::Parser.new + @symlink_path = nil end desc 'The path where buffer chunks are stored.' @@ -171,15 +172,15 @@ def resume } map = {} - maps.sort_by {|(timestamp,chunk)| + maps.sort_by {|(timestamp,_chunk)| timestamp - }.each {|(timestamp,chunk)| + }.each {|(_timestamp,chunk)| map[chunk.key] = chunk } - queue = queues.sort_by {|(timestamp,chunk)| + queue = queues.sort_by {|(timestamp,_chunk)| timestamp - }.map {|(timestamp,chunk)| + }.map {|(_timestamp,chunk)| chunk } diff --git a/lib/fluent/plugin/in_dummy.rb b/lib/fluent/plugin/in_dummy.rb index 365eb975f4..576b6df466 100644 --- a/lib/fluent/plugin/in_dummy.rb +++ b/lib/fluent/plugin/in_dummy.rb @@ -35,11 +35,11 @@ class DummyInput < Input config_param :dummy, default: [{"message"=>"dummy"}] do |val| begin parsed = JSON.parse(val) - rescue JSON::ParserError => e + rescue JSON::ParserError => ex # Fluent::ConfigParseError, "got incomplete JSON" will be raised # at literal_parser.rb with --use-v1-config, but I had to # take care at here for the case of --use-v0-config. - raise Fluent::ConfigError, "#{e.class}: #{e.message}" + raise Fluent::ConfigError, "#{ex.class}: #{ex.message}" end dummy = parsed.is_a?(Array) ? parsed : [parsed] dummy.each_with_index do |e, i| diff --git a/lib/fluent/plugin/in_exec.rb b/lib/fluent/plugin/in_exec.rb index 9aa57d4735..98585fb87c 100644 --- a/lib/fluent/plugin/in_exec.rb +++ b/lib/fluent/plugin/in_exec.rb @@ -53,9 +53,9 @@ def initialize def configure(conf) super - if localtime = conf['localtime'] + if conf['localtime'] @localtime = true - elsif utc = conf['utc'] + elsif conf['utc'] @localtime = false end diff --git a/lib/fluent/plugin/in_syslog.rb b/lib/fluent/plugin/in_syslog.rb index 0f4291fe65..60990049ab 100644 --- a/lib/fluent/plugin/in_syslog.rb +++ b/lib/fluent/plugin/in_syslog.rb @@ -96,6 +96,8 @@ def initialize def configure(conf) super + @use_default = false + if conf.has_key?('format') @parser = Plugin.new_parser(conf['format']) @parser.configure(conf) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index 5764d7dc0b..7957a6051d 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -453,16 +453,16 @@ def on_rotate(io) @update_watcher.call(@path, swap_state(@pe)) end end + end - def swap_state(pe) - # Use MemoryPositionEntry for rotated file temporary - mpe = MemoryPositionEntry.new - mpe.update(pe.read_inode, pe.read_pos) - @pe = mpe - @io_handler.pe = mpe # Don't re-create IOHandler because IOHandler has an internal buffer. + def swap_state(pe) + # Use MemoryPositionEntry for rotated file temporary + mpe = MemoryPositionEntry.new + mpe.update(pe.read_inode, pe.read_pos) + @pe = mpe + @io_handler.pe = mpe # Don't re-create IOHandler because IOHandler has an internal buffer. - pe # This pe will be updated in on_rotate after TailWatcher is initialized - end + pe # This pe will be updated in on_rotate after TailWatcher is initialized end class TimerWatcher < Coolio::TimerWatcher diff --git a/lib/fluent/process.rb b/lib/fluent/process.rb index 87151f8a48..1fc2b1d51c 100644 --- a/lib/fluent/process.rb +++ b/lib/fluent/process.rb @@ -418,6 +418,8 @@ module DetachProcessMixin def configure(conf) super + @detach_process = nil + if detach_process = conf['detach_process'] b3v = Config.bool_value(detach_process) case b3v @@ -461,6 +463,8 @@ def initialize def configure(conf) super + @detach_process = nil + if detach_process = conf['detach_process'] b3v = Config.bool_value(detach_process) case b3v diff --git a/lib/fluent/root_agent.rb b/lib/fluent/root_agent.rb index b38682cc59..4814e20551 100644 --- a/lib/fluent/root_agent.rb +++ b/lib/fluent/root_agent.rb @@ -55,6 +55,7 @@ def initialize(system_config = SystemConfig.new) @started_inputs = [] @suppress_emit_error_log_interval = 0 @next_emit_error_log_time = nil + @without_source = false suppress_interval(system_config.emit_error_log_interval) unless system_config.emit_error_log_interval.nil? @without_source = system_config.without_source unless system_config.without_source.nil? diff --git a/lib/fluent/test/base.rb b/lib/fluent/test/base.rb index 089005f15d..f98143be9d 100644 --- a/lib/fluent/test/base.rb +++ b/lib/fluent/test/base.rb @@ -28,14 +28,7 @@ def self.setup @now = n } engine.define_singleton_method(:now) { - @now || super() - } - - ::Test::Unit::Assertions.module_eval { - def assert_equal_event_time(a, b) - assert_equal(a.sec, b.sec) - assert_equal(a.nsec, b.nsec) - end + @now ||= super() } nil @@ -131,3 +124,10 @@ def logs end end end + +Test::Unit::Assertions.module_eval do + def assert_equal_event_time(a, b) + assert_equal(a.sec, b.sec) + assert_equal(a.nsec, b.nsec) + end +end diff --git a/lib/fluent/test/input_test.rb b/lib/fluent/test/input_test.rb index 02c8d3da8d..ecbccc6f9f 100644 --- a/lib/fluent/test/input_test.rb +++ b/lib/fluent/test/input_test.rb @@ -36,6 +36,7 @@ def initialize(klass, &block) # for checking only the number of emitted records during run @expected_emits_length = nil @run_timeout = 5 + @run_post_conditions = [] end def expect_emit(tag, time, record) @@ -81,7 +82,6 @@ def records def register_run_post_condition(&block) if block - @run_post_conditions ||= [] @run_post_conditions << block end end diff --git a/lib/fluent/test/output_test.rb b/lib/fluent/test/output_test.rb index 4aeb8ed89e..617ee8dc74 100644 --- a/lib/fluent/test/output_test.rb +++ b/lib/fluent/test/output_test.rb @@ -88,7 +88,7 @@ def run(num_waits = 10, &block) key = '' if @instance.respond_to?(:time_slicer) # this block is only for test_out_file - time, record = @entries.first + time, _record = @entries.first key = @instance.time_slicer.call(time) end chunk = @instance.buffer.new_chunk(key) diff --git a/test/config/test_dsl.rb b/test/config/test_dsl.rb index f81b97756d..d957386b4e 100644 --- a/test/config/test_dsl.rb +++ b/test/config/test_dsl.rb @@ -161,7 +161,7 @@ def setup sub_test_case 'with configuration that returns non element on top' do sub_test_case '.parse' do test 'does not crash' do - root = Fluent::Config::DSL::Parser.parse(DSL_CONFIG_RETURNS_NON_ELEMENT, 'dsl_config_returns_non_element.rb') + Fluent::Config::DSL::Parser.parse(DSL_CONFIG_RETURNS_NON_ELEMENT, 'dsl_config_returns_non_element.rb') end end end diff --git a/test/config/test_system_config.rb b/test/config/test_system_config.rb index e4cfb13f01..8a9eaef484 100644 --- a/test/config/test_system_config.rb +++ b/test/config/test_system_config.rb @@ -20,6 +20,7 @@ def initialize @suppress_config_dump = nil @suppress_repeated_stacktrace = nil @without_source = nil + @emit_error_log_interval = nil end end diff --git a/test/plugin/test_filter_record_transformer.rb b/test/plugin/test_filter_record_transformer.rb index 43a8b51713..76e82c4e50 100644 --- a/test/plugin/test_filter_record_transformer.rb +++ b/test/plugin/test_filter_record_transformer.rb @@ -58,7 +58,7 @@ def emit(config, msgs = ['']) test 'typical usage' do msgs = ['1', '2'] es = emit(CONFIG, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_equal('bar', r['foo']) assert_equal(@hostname, r['hostname']) assert_equal(@tag, r['tag']) @@ -70,7 +70,7 @@ def emit(config, msgs = ['']) test 'remove_keys' do config = CONFIG + %[remove_keys foo,message] es = emit(config) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_not_include(r, 'foo') assert_equal(@hostname, r['hostname']) assert_equal(@tag, r['tag']) @@ -83,7 +83,7 @@ def emit(config, msgs = ['']) config = CONFIG + %[renew_record true] msgs = ['1', '2'] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_not_include(r, 'foo') assert_equal(@hostname, r['hostname']) assert_equal(@tag, r['tag']) @@ -97,7 +97,7 @@ def emit(config, msgs = ['']) times = [ Time.local(2,2,3,4,5,2010,nil,nil,nil,nil), Time.local(3,2,3,4,5,2010,nil,nil,nil,nil) ] msgs = times.map{|t| t.to_f.to_s } es = emit(config, msgs) - es.each_with_index do |(time, record), i| + es.each_with_index do |(time, _record), i| assert_equal(times[i].to_i, time) assert(time.is_a?(Fluent::EventTime)) end @@ -107,7 +107,7 @@ def emit(config, msgs = ['']) config = %[renew_record true\nkeep_keys foo,message] msgs = ['1', '2'] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_equal('bar', r['foo']) assert_equal(msgs[i], r['message']) end @@ -122,7 +122,7 @@ def emit(config, msgs = ['']) ] msgs = ['1', '2'] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_equal("#{@hostname} #{@tag_parts[-1]} #{msgs[i]}", r['message']) end end @@ -135,7 +135,7 @@ def emit(config, msgs = ['']) %] msgs = ['1', '2'] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_equal({"k1"=>100, "k2"=>"foobar"}, r['hash_field']) end end @@ -148,7 +148,7 @@ def emit(config, msgs = ['']) %] msgs = ['1', '2'] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_equal([1,2,3], r['array_field']) end end @@ -161,7 +161,7 @@ def emit(config, msgs = ['']) %] msgs = ['1', '2'] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_equal({"hello"=>[1,2,3], "world"=>{"foo"=>"bar"}}, r['mixed_field']) end end @@ -263,7 +263,7 @@ def emit(config, msgs = ['']) ] msgs = ['1', '2'] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_not_include(r, 'eventType0') assert_equal("bar", r['eventtype']) assert_equal("bar #{msgs[i]}", r['message']) @@ -283,7 +283,7 @@ def emit(config, msgs = ['']) ] msgs = ['1', '2'] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_equal({"hostname" => @hostname, "tag" => @tag, "#{@tag}" => 100}, r['hash_field']) end end @@ -297,7 +297,7 @@ def emit(config, msgs = ['']) ] msgs = ['1', '2'] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_equal([@hostname, @tag], r['array_field']) end end @@ -311,7 +311,7 @@ def emit(config, msgs = ['']) ] msgs = ['1', '2'] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_equal([{"tag" => @tag}], r['mixed_field']) end end @@ -327,7 +327,7 @@ def emit(config, msgs = ['']) ] msgs = ['1', '2'] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| assert_equal({@hostname=>'hostname',"foo.#{@tag}"=>'tag'}, r) end end @@ -380,7 +380,7 @@ def emit(config, msgs = ['']) ] actual_results = [] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| actual_results << { single: r["single"], multiple: r["multiple"], @@ -434,7 +434,7 @@ def emit(config, msgs = ['']) ] actual_results = [] es = emit(config, msgs) - es.each_with_index do |(t, r), i| + es.each_with_index do |(_t, r), i| actual_results << { single: r["single"], multiple: r["multiple"], diff --git a/test/plugin/test_in_dummy.rb b/test/plugin/test_in_dummy.rb index bea015c35c..4fc4f405d4 100644 --- a/test/plugin/test_in_dummy.rb +++ b/test/plugin/test_in_dummy.rb @@ -88,7 +88,7 @@ def create_driver(conf) # d.run sleeps 0.5 sec } emits = d.emits - emits.each_with_index do |(tag, time, record), i| + emits.each_with_index do |(tag, _time, record), i| assert_equal("dummy", tag) assert_equal({"foo"=>"bar", "id"=>i}, record) end diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb index d49da12d0e..406f435eab 100644 --- a/test/plugin/test_in_http.rb +++ b/test/plugin/test_in_http.rb @@ -40,7 +40,7 @@ def test_time d.expect_emit "tag2", time, {"a"=>2} d.run do - d.expected_emits.each {|tag,time,record| + d.expected_emits.each {|tag,_time,record| res = post("/#{tag}", {"json"=>record.to_json}) assert_equal "200", res.code } @@ -56,7 +56,7 @@ def test_time_as_float d.expect_emit "tag1", time, {"a"=>1} d.run do - d.expected_emits.each {|tag,time,record| + d.expected_emits.each {|tag,_time,record| res = post("/#{tag}", {"json"=>record.to_json, "time"=>float_time.to_s}) assert_equal "200", res.code } @@ -72,8 +72,8 @@ def test_json d.expect_emit "tag2", time, {"a"=>2} d.run do - d.expected_emits.each {|tag,time,record| - res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s}) + d.expected_emits.each {|tag,_time,record| + res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}) assert_equal "200", res.code } end @@ -110,8 +110,8 @@ def test_json_with_add_remote_addr d.expect_emit "tag2", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2} d.run do - d.expected_emits.each {|tag,time,record| - res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s}) + d.expected_emits.each {|tag,_time,record| + res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}) assert_equal "200", res.code } end @@ -147,7 +147,7 @@ def test_multi_json_with_add_http_headers assert_equal "200", res.code end - d.emit_streams.each { |tag, es| + d.emit_streams.each { |_tag, es| assert include_http_header?(es.first[1]) } end @@ -160,8 +160,8 @@ def test_json_with_add_http_headers records = [["tag1", time, {"a"=>1}], ["tag2", time, {"a"=>2}]] d.run do - records.each {|tag,time,record| - res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s}) + records.each {|tag,_time,record| + res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}) assert_equal "200", res.code } @@ -181,8 +181,8 @@ def test_application_json d.expect_emit "tag2", time, {"a"=>2} d.run do - d.expected_emits.each {|tag,time,record| - res = post("/#{tag}?time=#{time.to_s}", record.to_json, {"Content-Type"=>"application/json; charset=utf-8"}) + d.expected_emits.each {|tag,_time,record| + res = post("/#{tag}?time=#{_time.to_s}", record.to_json, {"Content-Type"=>"application/json; charset=utf-8"}) assert_equal "200", res.code } end @@ -197,8 +197,8 @@ def test_msgpack d.expect_emit "tag2", time, {"a"=>2} d.run do - d.expected_emits.each {|tag,time,record| - res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>time.to_s}) + d.expected_emits.each {|tag,_time,record| + res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>_time.to_s}) assert_equal "200", res.code } end @@ -235,11 +235,11 @@ def test_with_regexp d.expect_emit "tag2", time, {"field_1" => 2, "field_2" => 'str'} d.run do - d.expected_emits.each { |tag, time, record| + d.expected_emits.each { |tag, _time, record| body = record.map { |k, v| v.to_s }.join(':') - res = post("/#{tag}?time=#{time.to_s}", body) + res = post("/#{tag}?time=#{_time.to_s}", body) assert_equal "200", res.code } end @@ -259,9 +259,9 @@ def test_with_csv d.expect_emit "tag2", time, {"foo" => "2", "bar" => 'str'} d.run do - d.expected_emits.each { |tag, time, record| + d.expected_emits.each { |tag, _time, record| body = record.map { |k, v| v }.to_csv - res = post("/#{tag}?time=#{time.to_s}", body) + res = post("/#{tag}?time=#{_time.to_s}", body) assert_equal "200", res.code } end @@ -277,8 +277,8 @@ def test_resonse_with_empty_img d.expect_emit "tag2", time, {"a"=>2} d.run do - d.expected_emits.each {|tag,time,record| - res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s}) + d.expected_emits.each {|tag,_time,record| + res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}) assert_equal "200", res.code # Ruby returns ASCII-8 encoded string for GIF. assert_equal Fluent::HttpInput::EMPTY_GIF_IMAGE, res.body.force_encoding("UTF-8") diff --git a/test/plugin/test_in_stream.rb b/test/plugin/test_in_stream.rb index 462eb24308..e1560c1f88 100644 --- a/test/plugin/test_in_stream.rb +++ b/test/plugin/test_in_stream.rb @@ -17,7 +17,7 @@ def test_time d.expect_emit "tag2", time, {"a"=>2} d.run do - d.expected_emits.each {|tag,time,record| + d.expected_emits.each {|tag,_time,record| send_data Fluent::Engine.msgpack_factory.packer.write([tag, 0, record]).to_s } end @@ -32,8 +32,8 @@ def test_message d.expect_emit "tag2", time, {"a"=>2} d.run do - d.expected_emits.each {|tag,time,record| - send_data Fluent::Engine.msgpack_factory.packer.write([tag, time, record]).to_s + d.expected_emits.each {|tag,_time,record| + send_data Fluent::Engine.msgpack_factory.packer.write([tag, _time, record]).to_s } end end @@ -48,8 +48,8 @@ def test_forward d.run do entries = [] - d.expected_emits.each {|tag,time,record| - entries << [time, record] + d.expected_emits.each {|tag,_time,record| + entries << [_time, record] } send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s end @@ -65,8 +65,8 @@ def test_packed_forward d.run do entries = '' - d.expected_emits.each {|tag,time,record| - Fluent::Engine.msgpack_factory.packer(entries).write([time, record]).flush + d.expected_emits.each {|tag,_time,record| + Fluent::Engine.msgpack_factory.packer(entries).write([_time, record]).flush } send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s end @@ -81,7 +81,7 @@ def test_message_json d.expect_emit "tag2", time, {"a"=>2} d.run do - d.expected_emits.each {|tag,time,record| + d.expected_emits.each {|tag,_time,record| send_data [tag, time, record].to_json } end diff --git a/test/test_buffer.rb b/test/test_buffer.rb index dcb9436a79..8d3bdbf5c3 100644 --- a/test/test_buffer.rb +++ b/test/test_buffer.rb @@ -578,7 +578,7 @@ def test_emit_with_block assert db.emit('key', data, chain) } flunk("timeout must happen") - rescue Timeout::Error => e + rescue Timeout::Error end assert db.queue.size == 1 diff --git a/test/test_event.rb b/test/test_event.rb index e7489c2d4d..488db46196 100644 --- a/test/test_event.rb +++ b/test/test_event.rb @@ -91,8 +91,8 @@ def setup @times = [Fluent::EventTime.new(time.sec), Fluent::EventTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] @es = MultiEventStream.new - @times.zip(@records).each { |time, record| - @es.add(time, record) + @times.zip(@records).each { |_time, record| + @es.add(_time, record) } end @@ -139,8 +139,8 @@ def setup time = Engine.now @times = [Fluent::EventTime.new(time.sec), Fluent::EventTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] - @times.zip(@records).each { |time, record| - pk.write([time, record]) + @times.zip(@records).each { |_time, record| + pk.write([_time, record]) } @es = MessagePackEventStream.new(pk.to_s) end diff --git a/test/test_formatter.rb b/test/test_formatter.rb index 49e7f6c23c..54540ac2f9 100644 --- a/test/test_formatter.rb +++ b/test/test_formatter.rb @@ -52,7 +52,7 @@ class BaseFormatterTestWithTestDriver < ::Test::Unit::TestCase include FormatterTest def create_driver(conf={}) - formatter = Fluent::Test::FormatterTestDriver.new(Formatter).configure(conf) + Fluent::Test::FormatterTestDriver.new(Formatter).configure(conf) end def test_call diff --git a/test/test_mixin.rb b/test/test_mixin.rb index a3d36c0d14..b515108afe 100644 --- a/test/test_mixin.rb +++ b/test/test_mixin.rb @@ -208,7 +208,7 @@ def test_timezone_2 def test_timezone_invalid assert_raise(Fluent::ConfigError) do - d = create_driver(Fluent::SetTimeKeyMixin, %[ + create_driver(Fluent::SetTimeKeyMixin, %[ include_time_key true timezone Invalid/Invalid ]) diff --git a/test/test_parser.rb b/test/test_parser.rb index 96f8faf4fe..d8ece59fd2 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -253,6 +253,7 @@ class ApacheErrorParserTest < ::Test::Unit::TestCase def setup @parser = Fluent::Plugin.new_parser('apache_error') + @parser.configure({}) @expected = { 'level' => 'error', 'client' => '127.0.0.1', @@ -450,7 +451,6 @@ def test_parse_with_invalid_time(data) def test_parse_float_time(data) parser = TextParser::JSONParser.new parser.configure('json_parser' => data) - format = "%d/%b/%Y:%H:%M:%S %z" text = "100.1" parser.parse("{\"time\":\"#{text}\"}") do |time, record| assert_equal Time.at(text.to_f).to_i, time.sec @@ -1043,7 +1043,7 @@ def test_lookup_known_parser(data) def test_parse_with_return parser = TextParser.new parser.configure('format' => 'none') - time, record = parser.parse('log message!') + _time, record = parser.parse('log message!') assert_equal({'message' => 'log message!'}, record) end