<commit_before>class Spork::TestFramework::MiniTest < Spork::TestFramework
  DEFAULT_PORT = 8988
  UNIT_HELPER = File.join(Dir.pwd, "test/minitest_helper.rb")
  SPEC_HELPER = File.join(Dir.pwd, "spec/minitest_helper.rb")

  if File.exists?(SPEC_HELPER)
    HELPER_FILE = SPEC_HELPER
    TEST_PATH = "spec"
  else
    HELPER_FILE = UNIT_HELPER
    TEST_PATH = "test"
  end
  # HELPER_FILE = HELPER_FILES.detect {|f| File.exists?(f) }

  def run_tests(argv, stderr, stdout)
    ::MiniTest::Unit.output = stdout
    $LOAD_PATH << "." << TEST_PATH

    paths, opts = parse_options(argv)

    paths.each do |path|
      require path
    end

    ::MiniTest::Unit.new.run(opts)
  end

  def parse_options(argv)
    test_path = File.dirname(HELPER_FILE).split("/").last
    paths = argv.select {|arg|
      # break if arg =~ /^--/
      arg =~ /(^|\.\/)#{test_path}\//
    }
    opts = handle_flags(argv)

    [paths, opts]
  end

  protected

  # parses flags and handles them
  # * -I - adds to load path
  # * -r - requires file
  # * -e - evaluates string
  #
  # @param [Array] list of ARGV
  # @return [Array] args without known flags
  def handle_flags(args)
    unknown = []
    args.each_with_index do |item, index|
      case item
      when /^-I(.*)/
        path = $1
        path = path != "" ? path : args[index+1]
        $LOAD_PATH << path
      when /^-r(.*)/
        path = $1
        path = path != "" ? path : args[index+1]
        require path
      when /^-e(.*)/
        command = $1
        command = command != "" ? command : args[index+1]<commit_msg>better search for help file<commit_after>class Spork::TestFramework::MiniTest < Spork::TestFramework
  DEFAULT_PORT = 8988
  TEST_PATH = ["test", "spec"].detect {|dir| File.exists?(File.join(Dir.pwd, dir)) }
  HELPER_FILE = ["minitest_helper.rb", "test_helper.rb", "spec_helper.rb"].detect {|file|
    File.exists?(File.join(Dir.pwd, TEST_PATH, file))
  }

  def run_tests(argv, stderr, stdout)
    ::MiniTest::Unit.output = stdout
    $LOAD_PATH << "." << TEST_PATH

    paths, opts = parse_options(argv)

    paths.each do |path|
      require path
    end

    ::MiniTest::Unit.new.run(opts)
  end

  def parse_options(argv)
    paths = argv.select {|arg|
      # break if arg =~ /^--/
      arg =~ /(^|\.\/)#{TEST_PATH}\//
    }
    opts = handle_flags(argv)

    [paths, opts]
  end

  protected

  # parses flags and handles them
  # * -I - adds to load path
  # * -r - requires file
  # * -e - evaluates string
  #
  # @param [Array] list of ARGV
  # @return [Array] args without known flags
  def handle_flags(args)
    unknown = []
    args.each_with_index do |item, index|
      case item
      when /^-I(.*)/
        path = $1
        path = path != "" ? path : args[index+1]
        $LOAD_PATH << path
      when /^-r(.*)/
        path = $1
        path = path != "" ? path : args[index+1]
        require path
      when /^-e(.*)/
        command = $1
        command = command != "" ? command : args[index+1]
{'fraction_non_alphanumeric': 0.1534603811434303, 'fraction_numerical': 0.006686726847208292, 'mean_word_length': 2.3922902494331066, 'pattern_counts': {'":': 0, '<': 17, '<?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': '4874962', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1049, 'n_words': 249}