<commit_before>require_relative './storer_test_base'
require_relative './spy_logger'

class ExternalGitterTest < StorerTestBase

  def self.hex_prefix; 'C89'; end

  def hex_setup
    @log = SpyLogger.new(self)
  end

  # - - - - - - - - - - - - - - - - -

  test 'DC3',
  'git.setup' do
    Dir.mktmpdir(ENV['CYBER_DOJO_TEST_HEX_ID']) do |path|
      git.setup(path, user_name, user_email)
      cd_exec(path, 'git status')
      assert_status 0
      assert_stdout_include  'On branch master'
      assert_stdout_include  'Initial commit'
      assert_stderr ''
      assert_log []
      cd_exec(path, 'git config user.name')
      assert_success 'lion' + "\n"
      cd_exec(path, 'git config user.email')
      assert_success '<EMAIL>' + "\n"
    end
  end

  # - - - - - - - - - - - - - - - - -

  test 'F2F',
  'git.add' do
    Dir.mktmpdir(ENV['CYBER_DOJO_TEST_HEX_ID']) do |path|
      git.setup(path, user_name, user_email)
      filename = 'limerick.txt'
      content = 'the boy stood on the burning deck'
      disk.write(path + '/' + filename, content)
      git.add(path, filename)
      cd_exec(path, 'git status')
      assert_status 0
      assert_stdout_include 'new file:   limerick.txt'
      assert_stderr ''
      assert_log []
    end
  end

  # - - - - - - - - - - - - - - - - -

  test 'F72',
  'git.commit' do
    Dir.mktmpdir(ENV['CYBER_DOJO_TEST_HEX_ID']) do |path|
      git.setup(path, user_name, user_email)
      filename = 'limerick.txt'
      content = 'the boy stood on the burning deck'
      disk.write(path + '/' + filename, content)
      git.add(path, filename)
      git.commit(path, tag=0)
      cd_exec(path, 'git log')
      assert_status 0
      assert_match /commit (\h*)/, @stdout
      assert_match /Author: lion <<EMAIL>>/, @stdout
      assert_match /Date:\s\s\s(.*)/, @stdout
      assert_match /\s\s\s0/, @stdout
      assert_stderr ''
      assert_log []
    end
  end

  # - - - - - - - - - - - - - - - - -

  test '6F8',
  'git.show' do
    Dir.mktmpdir(ENV['CYBER_DOJO_TEST_HEX_ID']) do |path|
      git.setup(path, user_name, user_email)
      filename = 'limerick.txt'
      content = 'the boy stood on the burning deck'
      disk.write(path + '/' + filename, content)
      git.add(path, filename)
      git.commit(path, tag=0)
      assert_equal content, git.show(path, "#{tag}:#{filename}")
    end
  end

  # - - - - - - - - - - - - - - - - -

  private

  def user_name
    'lion'
  end

  def user_email
    '<EMAIL>'
  end<commit_msg>refactor duplication<commit_after>require_relative './storer_test_base'
require_relative './spy_logger'

class ExternalGitterTest < StorerTestBase

  def self.hex_prefix; 'C89'; end

  def hex_setup
    @log = SpyLogger.new(self)
  end

  # - - - - - - - - - - - - - - - - -

  test 'DC3',
  'git.setup' do
    hex_tmp_dir do |path|
      git.setup(path, user_name, user_email)
      cd_exec(path, 'git status')
      assert_status 0
      assert_stdout_include  'On branch master'
      assert_stdout_include  'Initial commit'
      assert_stderr ''
      assert_log []
      cd_exec(path, 'git config user.name')
      assert_success 'lion' + "\n"
      cd_exec(path, 'git config user.email')
      assert_success '<EMAIL>' + "\n"
    end
  end

  # - - - - - - - - - - - - - - - - -

  test 'F2F',
  'git.add' do
    hex_tmp_dir do |path|
      git.setup(path, user_name, user_email)
      filename = 'limerick.txt'
      content = 'the boy stood on the burning deck'
      disk.write(path + '/' + filename, content)
      git.add(path, filename)
      cd_exec(path, 'git status')
      assert_status 0
      assert_stdout_include 'new file:   limerick.txt'
      assert_stderr ''
      assert_log []
    end
  end

  # - - - - - - - - - - - - - - - - -

  test 'F72',
  'git.commit' do
    hex_tmp_dir do |path|
      git.setup(path, user_name, user_email)
      filename = 'limerick.txt'
      content = 'the boy stood on the burning deck'
      disk.write(path + '/' + filename, content)
      git.add(path, filename)
      git.commit(path, tag=0)
      cd_exec(path, 'git log')
      assert_status 0
      assert_match /commit (\h*)/, @stdout
      assert_match /Author: lion <<EMAIL>>/, @stdout
      assert_match /Date:\s\s\s(.*)/, @stdout
      assert_match /\s\s\s0/, @stdout
      assert_stderr ''
      assert_log []
    end
  end

  # - - - - - - - - - - - - - - - - -

  test '6F8',
  'git.show' do
    hex_tmp_dir do |path|
      git.setup(path, user_name, user_email)
      filename = 'limerick.txt'
      content = 'the boy stood on the burning deck'
      disk.write(path + '/' + filename, content)
      git.add(path, filename)
      git.commit(path, tag=0)
      assert_equal content, git.show(path, "#{tag}:#{filename}")
    end
  end

  # - - - - - - - - - - - - - - - - -

  private

  def hex_tmp_dir
    Dir.mktmpdir(ENV['CYBER_DOJO_TEST_HEX_ID']) do |path|
      yield path
    end
  end

  def user_name
    'lion'
  end

  def user_email
    '<EMAIL>'
  end
{'fraction_non_alphanumeric': 0.14824473420260784, 'fraction_numerical': 0.005616850551654965, 'mean_word_length': 2.0458155161881493, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1773893', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1812, 'n_words': 383}