<commit_before>require 'test/unit'
require 'stringio'
require File.dirname(__FILE__) + '/../lib/active_support/clean_logger'

class CleanLoggerTest < Test::Unit::TestCase
  def setup
    @out = StringIO.new
    @logger = Logger.new(@out)
  end

  def test_format_message
    @logger.error 'error'
    assert_equal "error\n", @out.string
  end

  def test_silence
    # Without yielding self.
    @logger.silence do
      @logger.debug  'debug'
      @logger.info   'info'
      @logger.warn   'warn'
      @logger.error  'error'
      @logger.fatal  'fatal'
    end

    # Yielding self.
    @logger.silence do |logger|
      logger.debug  'debug'
      logger.info   'info'
      logger.warn   'warn'
      logger.error  'error'
      logger.fatal  'fatal'
    end

    assert_equal "error\nfatal\nerror\nfatal\n", @out.string
  end
end

class CleanLogger_182_to_183_Test < Test::Unit::TestCase
  def setup
    if Logger.method_defined?(:formatter=)
      Logger.send(:alias_method, :hide_formatter=, :formatter=)
    else
      Logger.send(:define_method, :formatter=) { }
    end
    load File.dirname(__FILE__) + '/../lib/active_support/clean_logger.rb'

    @out = StringIO.new
    @logger = Logger.new(@out)
    @logger.progname = 'CLEAN LOGGER TEST'
  end

  def teardown
    if Logger.method_defined?(:hide_formatter=)
      Logger.send(:alias_method, :formatter=, :hide_formatter=)
    else
      Logger.send(:undef_method, :formatter=)
    end
    load File.dirname(__FILE__) + '/../lib/active_support/clean_logger.rb'
  end

  # Since we've fooled Logger into thinking we're on 1.8.2 if we're on 1.8.3<commit_msg>Fix Logger compatibility test<commit_after>require 'test/unit'
require 'stringio'
require File.dirname(__FILE__) + '/../lib/active_support/clean_logger'

class CleanLoggerTest < Test::Unit::TestCase
  def setup
    @out = StringIO.new
    @logger = Logger.new(@out)
  end

  def test_format_message
    @logger.error 'error'
    assert_equal "error\n", @out.string
  end

  def test_silence
    # Without yielding self.
    @logger.silence do
      @logger.debug  'debug'
      @logger.info   'info'
      @logger.warn   'warn'
      @logger.error  'error'
      @logger.fatal  'fatal'
    end

    # Yielding self.
    @logger.silence do |logger|
      logger.debug  'debug'
      logger.info   'info'
      logger.warn   'warn'
      logger.error  'error'
      logger.fatal  'fatal'
    end

    assert_equal "error\nfatal\nerror\nfatal\n", @out.string
  end
end

class CleanLogger_182_to_183_Test < Test::Unit::TestCase
  def setup
    if Logger.method_defined?(:formatter=)
      Logger.send(:alias_method, :hide_formatter=, :formatter=)
      Logger.send(:undef_method, :formatter=)
    else
      Logger.send(:define_method, :formatter=) { }
    end
    load File.dirname(__FILE__) + '/../lib/active_support/clean_logger.rb'

    @out = StringIO.new
    @logger = Logger.new(@out)
    @logger.progname = 'CLEAN LOGGER TEST'
  end

  def teardown
    if Logger.method_defined?(:hide_formatter=)
      Logger.send(:alias_method, :formatter=, :hide_formatter=)
    else
      Logger.send(:undef_method, :formatter=)
    end
    load File.dirname(__FILE__) + '/../lib/active_support/clean_logger.rb'
  end

  # Since we've fooled Logger into thinking we're on 1.8.2 if we're on 1.8.3
{'fraction_non_alphanumeric': 0.12235649546827794, 'fraction_numerical': 0.0072507552870090634, 'mean_word_length': 2.9747899159663866, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6525932', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1103, 'n_words': 240}