<commit_before>require 'test_helper'

class JobBuildTest < Test::Unit::TestCase
  include Travis::Worker

  Job::Build.send :public, *Job::Build.protected_instance_methods
  Job::Build.base_dir = '/tmp/travis/test'

  attr_reader :payload, :build

  def setup
    super

    Config.any_instance.stubs(:read).returns({})

    @payload = INCOMING_PAYLOADS['build:test-project-1']
    @build = Job::Build.new(payload)

    FileUtils.mkdir_p(build.build_dir)
  end

  def teardown
    super
    FileUtils.rm_rf(Job::Build.base_dir)
  end

  test 'perform: builds and sets status and log' do
    build.expects(:build!).returns(true)

    build.notify(:update, :log => 'log')

    build.perform

    assert_equal "log\nDone. Build script exited with: 0\n", build.log
    assert_equal 0, build.status
  end

  test 'build!: sets rvm, env vars, checks the repository out, installs the bundle and runs the scripts' do
    expect_shell [
      'mkdir -p /tmp/travis/test/travis-ci/test-project-1; cd /tmp/travis/test/travis-ci/test-project-1',
      'test -d .git',
      'git clean -fdx',
      'git fetch',
      'git checkout -qf 1234567',
      'test -f Gemfile.rails-3.1',
      'rvm use 1.9.2',
      { :command => 'pwd', :method => :evaluate, :returns => '/path/to' },
      'export BUNDLE_GEMFILE=/path/to/Gemfile.rails-3.1',
      'export FOO=bar',
      'export BAR=baz',
      'bundle install bundler_arg=1',
      'bundle exec rake ci:before',
      'bundle exec rake',
      'bundle exec rake ci:after'
    ]

    build.build!
  end

  test 'build_dir: the path from the github url local to the base builds dir' do
    assert_equal '/tmp/travis/test/travis-ci/test-project-1', build.build_dir.to_s
  end

  test 'on_update: appends the log data' do
    build.notify(:update, :log => 'log and ')
    build.notify(:update, :log => 'more log')
    assert_equal 'log and more log', build.log
  end

  # test 'run_scripts: iterates over keys and executes appropriate script' do
  #   build.expects(:exec).with('bundle exec rake ci:before', :timeout => 'before_script').returns(true)
  #   build.expects(:exec).with('bundle exec rake', :timeout => 'script').returns(true)
  #   build.expects(:exec).with('bundle exec rake ci:after', :timeout => 'after_script').returns(true)
  #   build.run_scripts
  # end
  #
  # test 'run_scripts: returns as soon as a script fails' do
  #   build.expects(:exec).with('bundle exec rake ci:before', :timeout => 'before_script').returns(false)
  #   build.expects(:exec).with('bundle exec rake', :timeout => 'script').never
  #   build.expects(:exec).with('bundle exec rake ci:after', :timeout => 'after_script').never
  #   assert_equal false, build.run_scripts
  # end
  #
  # test 'run_script when passed a String' do
  #   options = { :timeout => 'before_script' }
  #   build.expects(:exec).with('./before_script', options).returns(true)
  #   build.run_script('./before_script', options)
  # end
  #
  # test 'run_script when passed a multiline String' do
  #   options = { :timeout => 'before_script' }
  #   build.expects(:exec).with('./before_script_1', options).returns(true)
  #   build.expects(:exec).with('./before_script_2', options).returns(true)
  #   build.run_script("./before_script_1\n./before_script_2", options)
  # end
  #
  # test 'run_script when passed an Array' do
  #   options = { :timeout => 'before_script' }
  #   build.expects(:exec).with('./before_script_1', options).returns(true)
  #   build.expects(:exec).with('./before_script_2', options).returns(true)
  #   build.run_script(['./before_script_1', './before_script_2'], options)
  # end
  #
  # test 'setup_env sets up the environment with the default rvm and multiple env vars' do
  #   build.config.stubs(:gemfile?)
  #   build.config.stubs(:rvm).returns(nil)
  #   build.config.stubs(:env).returns(['FOO=true', 'BAR=true'])
  #
  #   expect_shell [
  #     'rvm use default',
  #     'export FOO=true',
  #     'export BAR=true'
  #   ]
  #   build.setup_env
  # end
  #
  # test 'setup_env sets up the environment with 1.9.2, a Gemfile and an empty env var (which is skipped)' do
  #   build.config.stubs(:gemfile?).returns(true)
  #   build.config.stubs(:gemfile).returns('path/to/Gemfile')
  #   build.config.stubs(:rvm).returns('1.9.2')
  #   build.config.stubs(:env).returns('')
  #
  #   expect_shell [
  #     'rvm use 1.9.2',
  #     'export BUNDLE_GEMFILE=path/to/Gemfile'
  #   ]
  #   build.setup_env
  # end
end<commit_msg>these tests are no longer needed as they are covered by the base builder tests<commit_after>require 'test_helper'

class JobBuildTest < Test::Unit::TestCase
  include Travis::Worker

  Job::Build.send :public, *Job::Build.protected_instance_methods
  Job::Build.base_dir = '/tmp/travis/test'

  attr_reader :payload, :build

  def setup
    super

    Config.any_instance.stubs(:read).returns({})

    @payload = INCOMING_PAYLOADS['build:test-project-1']
    @build = Job::Build.new(payload)

    FileUtils.mkdir_p(build.build_dir)
  end

  def teardown
    super
    FileUtils.rm_rf(Job::Build.base_dir)
  end

  test 'perform: builds and sets status and log' do
    build.expects(:build!).returns(true)

    build.notify(:update, :log => 'log')

    build.perform

    assert_equal "log\nDone. Build script exited with: 0\n", build.log
    assert_equal 0, build.status
  end

  test 'build!: sets rvm, env vars, checks the repository out, installs the bundle and runs the scripts' do
    expect_shell [
      'mkdir -p /tmp/travis/test/travis-ci/test-project-1; cd /tmp/travis/test/travis-ci/test-project-1',
      'test -d .git',
      'git clean -fdx',
      'git fetch',
      'git checkout -qf 1234567',
      'test -f Gemfile.rails-3.1',
      'rvm use 1.9.2',
      { :command => 'pwd', :method => :evaluate, :returns => '/path/to' },
      'export BUNDLE_GEMFILE=/path/to/Gemfile.rails-3.1',
      'export FOO=bar',
      'export BAR=baz',
      'bundle install bundler_arg=1',
      'bundle exec rake ci:before',
      'bundle exec rake',
      'bundle exec rake ci:after'
    ]

    build.build!
  end

  test 'build_dir: the path from the github url local to the base builds dir' do
    assert_equal '/tmp/travis/test/travis-ci/test-project-1', build.build_dir.to_s
  end

  test 'on_update: appends the log data' do
    build.notify(:update, :log => 'log and ')
    build.notify(:update, :log => 'more log')
    assert_equal 'log and more log', build.log
  end
end
{'fraction_non_alphanumeric': 0.14576534576534578, 'fraction_numerical': 0.00916860916860917, 'mean_word_length': 3.2878081279147233, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '4855983', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2223, 'n_words': 520}