<commit_before>require "unindent"
require 'open3'

describe "CLI" do
  before :all do
    # use local scripts
    ENV["PATH"] = "#{File.join(File.dirname(__FILE__),"..","bin")}:#{ENV["PATH"]}"
  end

  def run(cmd, options={})
    Open3.popen2e(cmd) do |stdin, stdout_and_stderr, wait_thr|
      unless wait_thr.value.success?
        message = "Unable to run #{cmd.inspect} in #{Dir.pwd}.\n#{stdout_and_stderr.read}"
        warn "ERROR: #{message}"
        raise message unless options[:fail]
      end
      stdout_and_stderr.read
    end
  end

  def write(file, content)
    File.open(file, 'w'){|f| f.write content }
  end

  around do |example|
    dir = "spec/tmp"
    run "rm -rf #{dir}"
    run "mkdir #{dir}"

    # use fake home for .ssh hacks
    run "mkdir #{dir}/home"
    ENV["HOME"] = File.expand_path("#{dir}/home")

    Dir.chdir dir do
      run "touch a && git init && git add . && git commit -am 'initial'"
      example.run
    end
  end

  describe "about" do
    it "lists the user" do
      run "git config user.name NAME"
      run("git about").should =~ /git user:\s+NAME/
    end

    it "lists the user as NONE if there is none" do
      run "git config user.name ''"
      run("git about").should =~ /git user:\s+NONE/
    end

    it "lists the email" do
      run "git config user.email EMAIL"
      run("git about").should =~ /git email:\s+EMAIL/<commit_msg>Git will not commit without a user name and email<commit_after>require "unindent"
require 'open3'

describe "CLI" do
  before :all do
    # use local scripts
    ENV["PATH"] = "#{File.join(File.dirname(__FILE__),"..","bin")}:#{ENV["PATH"]}"
  end

  def run(cmd, options={})
    Open3.popen2e(cmd) do |stdin, stdout_and_stderr, wait_thr|
      unless wait_thr.value.success?
        message = "Unable to run #{cmd.inspect} in #{Dir.pwd}.\n#{stdout_and_stderr.read}"
        warn "ERROR: #{message}"
        raise message unless options[:fail]
      end
      stdout_and_stderr.read
    end
  end

  def write(file, content)
    File.open(file, 'w'){|f| f.write content }
  end

  around do |example|
    dir = "spec/tmp"
    run "rm -rf #{dir}"
    run "mkdir #{dir}"

    # use fake home for .ssh hacks
    run "mkdir #{dir}/home"
    ENV["HOME"] = File.expand_path("#{dir}/home")

    Dir.chdir dir do
      run "touch a"
      run "git init"
      run "git add ."
      run "git config user.email '<EMAIL>'"
      run "git config user.name 'rspec test suite'"
      run "git commit -am 'initial'"
      run "git config --unset user.email"
      run "git config --unset user.name"
      example.run
    end
  end

  describe "about" do
    it "lists the user" do
      run "git config user.name NAME"
      run("git about").should =~ /git user:\s+NAME/
    end

    it "lists the user as NONE if there is none" do
      run "git config user.name ''"
      run("git about").should =~ /git user:\s+NONE/
    end

    it "lists the email" do
      run "git config user.email EMAIL"
      run("git about").should =~ /git email:\s+EMAIL/
{'fraction_non_alphanumeric': 0.14474553866490417, 'fraction_numerical': 0.0019828155981493722, 'mean_word_length': 2.536214953271028, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '3257370', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1025, 'n_words': 321}