<commit_before>FRAMEWORKS = begin
  attempt1 = "/Applications/Xcode.app/Contents/Developer/Library/Frameworks"
  if File.directory? "#{attempt1}/XCTest.framework"
    attempt1
  else
    "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks"
  end
end

def bold(s); s; end
def red(s); "\e[31m#{s}\e[0m"; end
def green(s); "\e[32m#{s}\e[0m"; end
def tab(n, s); s.gsub(/^/, " " * n); end
def log(message); $stdout.puts(message); end

def each_test_line
  require "stringio"
  require "open3"

  Open3.popen3("/tmp/PromiseKitTests") do |stdin, stdout, stderr, wait_thr|
    while line = stderr.gets
      yield line, stderr
    end
    exit_status = wait_thr.value
  end
end

def test!
  test_method = nil
  each_test_line do |line, stderr|
    case line
    when /Test Suite '(.*)' started/
      log bold($1) unless $1 == 'tmp'
    when /Test Suite '.*' finished/
    when /\[(\w+) (\w+)\]' started.$/
      test_method = $2
    when /\s(passed|failed)\s\((.*)\)/
      result = if $1 == "passed"
        green("PASS") 
      else
        red("FAIL")
      end
      result = tab(2, result)
      time = $2.gsub(/\sseconds/, "s")
      log "#{result} #{test_method} (#{time})"
    when /^(Executed(.?)+)$/
      if stderr.eof?
        summary = $1
        if /(\d+) failures?/.match(summary)[1] == "0"
          summary.gsub!(/(\d+ failures?)/, green('\1'))
        else
          summary.gsub!(/(\d+ failures?)/, red('\1'))
        end
        log summary
      end
    else
      log line.strip
    end
  end
end

def clone! repo
  Dir.chdir "/tmp" do
    system "git clone #{repo}"
  end unless File.directory? "/tmp/#{File.basename(repo)}"
end

def prepare!
  clone! "https://github.com/mxcl/ChuzzleKit"
  clone! "https://github.com/mxcl/OMGHTTPURLRQ"

  File.open('/tmp/PromiseKitTests.m', 'w') do |f|<commit_msg>We don’t use chuzzlekit anymore<commit_after>FRAMEWORKS = begin
  attempt1 = "/Applications/Xcode.app/Contents/Developer/Library/Frameworks"
  if File.directory? "#{attempt1}/XCTest.framework"
    attempt1
  else
    "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks"
  end
end

def bold(s); s; end
def red(s); "\e[31m#{s}\e[0m"; end
def green(s); "\e[32m#{s}\e[0m"; end
def tab(n, s); s.gsub(/^/, " " * n); end
def log(message); $stdout.puts(message); end

def each_test_line
  require "stringio"
  require "open3"

  Open3.popen3("/tmp/PromiseKitTests") do |stdin, stdout, stderr, wait_thr|
    while line = stderr.gets
      yield line, stderr
    end
    exit_status = wait_thr.value
  end
end

def test!
  test_method = nil
  each_test_line do |line, stderr|
    case line
    when /Test Suite '(.*)' started/
      log bold($1) unless $1 == 'tmp'
    when /Test Suite '.*' finished/
    when /\[(\w+) (\w+)\]' started.$/
      test_method = $2
    when /\s(passed|failed)\s\((.*)\)/
      result = if $1 == "passed"
        green("PASS") 
      else
        red("FAIL")
      end
      result = tab(2, result)
      time = $2.gsub(/\sseconds/, "s")
      log "#{result} #{test_method} (#{time})"
    when /^(Executed(.?)+)$/
      if stderr.eof?
        summary = $1
        if /(\d+) failures?/.match(summary)[1] == "0"
          summary.gsub!(/(\d+ failures?)/, green('\1'))
        else
          summary.gsub!(/(\d+ failures?)/, red('\1'))
        end
        log summary
      end
    else
      log line.strip
    end
  end
end

def clone! repo
  Dir.chdir "/tmp" do
    system "git clone #{repo}"
  end unless File.directory? "/tmp/#{File.basename(repo)}"
end

def prepare!
  clone! "https://github.com/mxcl/OMGHTTPURLRQ"

  File.open('/tmp/PromiseKitTests.m', 'w') do |f|
{'fraction_non_alphanumeric': 0.17803030303030304, 'fraction_numerical': 0.012445887445887446, 'mean_word_length': 2.5963035019455254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5794443', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1351, 'n_words': 317}