module SimpleCov::CommandGuesser

def from_command_line_options

def from_command_line_options
  case original_run_command
    when /test\/functional\//, /test\/{.*?functional.*?}\//
      "Functional Tests"
    when /test\/integration\//
      "Integration Tests"
    when /test\//
      "Unit Tests"
    when /spec/
      "RSpec"
    when /cucumber/, /features/
      "Cucumber Features"
    else
      nil
  end
end

def from_defined_constants

def from_defined_constants
  # If the command regexps fail, let's try checking defined constants.
  if defined?(RSpec)
    "RSpec"
  elsif defined?(Test::Unit)
    "Unit Tests"
  elsif defined?(MiniTest)
    "MiniTest"
  else
    # TODO: Provide link to docs/wiki article
    warn "SimpleCov failed to recognize the test framework and/or suite used. Please specify manually using SimpleCov.command_name 'Unit Tests'."
    'Unknown Test Framework'
  end
end

def from_env

def from_env
  # If being run from inside parallel_tests set the command name according to the process number
  if ENV['PARALLEL_TEST_GROUPS'] && ENV['TEST_ENV_NUMBER']
    number = ENV['TEST_ENV_NUMBER']
    number = '1' if number == ''
    "(#{number}/#{ENV['PARALLEL_TEST_GROUPS']})"
  end
end

def guess

def guess
  from_env || from_command_line_options || from_defined_constants
end