<commit_before>require File.expand_path('../helper', __FILE__)

TESTING_REQUIRE = [ ]

class TestRakeApplicationOptions < Rake::TestCase

  def setup
    super

    clear_argv
    Rake::FileUtilsExt.verbose_flag = false
    Rake::FileUtilsExt.nowrite_flag = false
    TESTING_REQUIRE.clear
  end

  def teardown
    clear_argv
    Rake::FileUtilsExt.verbose_flag = false
    Rake::FileUtilsExt.nowrite_flag = false

    super
  end

  def clear_argv
    while ! ARGV.empty?
      ARGV.pop
    end
  end

  def test_default_options
    opts = command_line
    assert_nil opts.backtrace
    assert_nil opts.classic_namespace
    assert_nil opts.dryrun
    assert_nil opts.ignore_system
    assert_nil opts.load_system
    assert_nil opts.always_multitask
    assert_nil opts.nosearch
    assert_equal ['rakelib'], opts.rakelib
    assert_nil opts.show_prereqs
    assert_nil opts.show_task_pattern
    assert_nil opts.show_tasks
    assert_nil opts.silent
    assert_nil opts.trace
    assert_nil opts.thread_pool_size
    assert_equal ['rakelib'], opts.rakelib
    assert ! Rake::FileUtilsExt.verbose_flag
    assert ! Rake::FileUtilsExt.nowrite_flag
  end

  def test_dry_run
    flags('--dry-run', '-n') do |opts|
      assert opts.dryrun
      assert opts.trace
      assert Rake::FileUtilsExt.verbose_flag
      assert Rake::FileUtilsExt.nowrite_flag
    end
  end

  def test_describe
    flags('--describe') do |opts|
      assert_equal :describe, opts.show_tasks
      assert_equal(//.to_s, opts.show_task_pattern.to_s)
    end
  end

  def test_describe_with_pattern
    flags('--describe=X') do |opts|
      assert_equal :describe, opts.show_tasks
      assert_equal(/X/.to_s, opts.show_task_pattern.to_s)
    end
  end

  def test_execute
    $xyzzy = 0
    flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
      assert_equal 1, $xyzzy
      assert_equal :exit, @exit
      $xyzzy = 0
    end
  end

  def test_execute_and_continue
    $xyzzy = 0
    flags('--execute-continue=$xyzzy=1', '-E $xyzzy=1') do |opts|
      assert_equal 1, $xyzzy
      refute_equal :exit, @exit
      $xyzzy = 0
    end
  end

  def test_execute_and_print
    $xyzzy = 0
    out, = capture_io do
      flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do |opts|
        assert_equal 'pugh', $xyzzy
        assert_equal :exit, @exit
        $xyzzy = 0
      end
    end

    assert_match(/^pugh$/, out)
  end

  def test_help
    out, = capture_io do
      flags '--help', '-H', '-h'
    end

    assert_match(/\Arake/, out)
    assert_match(/\boptions\b/, out)
    assert_match(/\btargets\b/, out)
    assert_equal :exit, @exit
  end

  def test_jobs
    flags(['--jobs', '4'], ['-j', '4']) do |opts|
      assert_equal 4, opts.thread_pool_size
    end
    flags(['--jobs', 'asdas'], ['-j', 'asdas']) do |opts|
      assert_equal 2, opts.thread_pool_size
    end
    flags('--jobs', '-j') do |opts|
      assert_equal 2, opts.thread_pool_size
    end
  end

  def test_libdir
    flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
      $:.include?('xx')
    end
  ensure
    $:.delete('xx')
  end

  def test_multitask
    flags('--multitask', '-m') do |opts|
      assert_equal opts.always_multitask, true
    end
  end

  def test_rakefile
    flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
      assert_equal ['RF'], @app.instance_eval { @rakefiles }
    end
  end

  def test_rakelib
    flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
      assert_equal ['A', 'B', 'C'], opts.rakelib
    end
  end

  def test_require
    $LOAD_PATH.unshift @tempdir<commit_msg>Use proper system path separator in test.<commit_after>require File.expand_path('../helper', __FILE__)

TESTING_REQUIRE = [ ]

class TestRakeApplicationOptions < Rake::TestCase

  def setup
    super

    clear_argv
    Rake::FileUtilsExt.verbose_flag = false
    Rake::FileUtilsExt.nowrite_flag = false
    TESTING_REQUIRE.clear
  end

  def teardown
    clear_argv
    Rake::FileUtilsExt.verbose_flag = false
    Rake::FileUtilsExt.nowrite_flag = false

    super
  end

  def clear_argv
    while ! ARGV.empty?
      ARGV.pop
    end
  end

  def test_default_options
    opts = command_line
    assert_nil opts.backtrace
    assert_nil opts.classic_namespace
    assert_nil opts.dryrun
    assert_nil opts.ignore_system
    assert_nil opts.load_system
    assert_nil opts.always_multitask
    assert_nil opts.nosearch
    assert_equal ['rakelib'], opts.rakelib
    assert_nil opts.show_prereqs
    assert_nil opts.show_task_pattern
    assert_nil opts.show_tasks
    assert_nil opts.silent
    assert_nil opts.trace
    assert_nil opts.thread_pool_size
    assert_equal ['rakelib'], opts.rakelib
    assert ! Rake::FileUtilsExt.verbose_flag
    assert ! Rake::FileUtilsExt.nowrite_flag
  end

  def test_dry_run
    flags('--dry-run', '-n') do |opts|
      assert opts.dryrun
      assert opts.trace
      assert Rake::FileUtilsExt.verbose_flag
      assert Rake::FileUtilsExt.nowrite_flag
    end
  end

  def test_describe
    flags('--describe') do |opts|
      assert_equal :describe, opts.show_tasks
      assert_equal(//.to_s, opts.show_task_pattern.to_s)
    end
  end

  def test_describe_with_pattern
    flags('--describe=X') do |opts|
      assert_equal :describe, opts.show_tasks
      assert_equal(/X/.to_s, opts.show_task_pattern.to_s)
    end
  end

  def test_execute
    $xyzzy = 0
    flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
      assert_equal 1, $xyzzy
      assert_equal :exit, @exit
      $xyzzy = 0
    end
  end

  def test_execute_and_continue
    $xyzzy = 0
    flags('--execute-continue=$xyzzy=1', '-E $xyzzy=1') do |opts|
      assert_equal 1, $xyzzy
      refute_equal :exit, @exit
      $xyzzy = 0
    end
  end

  def test_execute_and_print
    $xyzzy = 0
    out, = capture_io do
      flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do |opts|
        assert_equal 'pugh', $xyzzy
        assert_equal :exit, @exit
        $xyzzy = 0
      end
    end

    assert_match(/^pugh$/, out)
  end

  def test_help
    out, = capture_io do
      flags '--help', '-H', '-h'
    end

    assert_match(/\Arake/, out)
    assert_match(/\boptions\b/, out)
    assert_match(/\btargets\b/, out)
    assert_equal :exit, @exit
  end

  def test_jobs
    flags(['--jobs', '4'], ['-j', '4']) do |opts|
      assert_equal 4, opts.thread_pool_size
    end
    flags(['--jobs', 'asdas'], ['-j', 'asdas']) do |opts|
      assert_equal 2, opts.thread_pool_size
    end
    flags('--jobs', '-j') do |opts|
      assert_equal 2, opts.thread_pool_size
    end
  end

  def test_libdir
    flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
      $:.include?('xx')
    end
  ensure
    $:.delete('xx')
  end

  def test_multitask
    flags('--multitask', '-m') do |opts|
      assert_equal opts.always_multitask, true
    end
  end

  def test_rakefile
    flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
      assert_equal ['RF'], @app.instance_eval { @rakefiles }
    end
  end

  def test_rakelib
    dirs = %w(A B C).join(File::PATH_SEPARATOR)
    flags(['--rakelibdir', dirs], ["--rakelibdir=#{dirs}"], ['-R', dirs], ["-R#{dirs}"]) do |opts|
      assert_equal ['A', 'B', 'C'], opts.rakelib
    end
  end

  def test_require
    $LOAD_PATH.unshift @tempdir
{'fraction_non_alphanumeric': 0.1328103868001082, 'fraction_numerical': 0.004598322964565864, 'mean_word_length': 2.8118556701030926, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7233487', 'n_tokens_mistral': 2783, 'n_tokens_neox': 2638, 'n_words': 589}