<commit_before>require 'fileutils'

BP_BIN_PATH = File.join(File.dirname(__FILE__), '..', 'bin', 'bitpocket')
RSYNC_STUB_BIN_PATH = File.join(File.dirname(__FILE__), 'bin')
PATH = "#{RSYNC_STUB_BIN_PATH}:#{ENV['PATH']}"

def sync(opts={})
  system "CALLBACK=#{opts[:callback]} PATH=#{PATH} sh #{BP_BIN_PATH} >/dev/null"
  $?.exitstatus
end

def local_path(fname)
  "#{@local_dir}/#{fname}"
end

def remote_path(fname)
  "#{@remote_dir}/#{fname}"
end

def touch(path)
  FileUtils.mkdir_p(File.dirname(path))
  FileUtils.touch(path)
end

def cat(content, path)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w') { |f| f.write content }
end

def rm(path)
  FileUtils.rm(path)
end

RSpec::Matchers.define :exist do
  match do |filename|
    File.exist?(filename)
  end
end

RSpec::Matchers.define :succeed do
  match do |status|
    status == 0
  end
end

RSpec::Matchers.define :exit_with do |expected|
  match do |status|
    status == expected
  end
end

shared_context 'setup' do
  before(:all) do
    @tmp_dir = "/tmp/bitpocket-test-#{Time.now.to_i}"
    @test_case = { :num => 0 }
  end

  before do
    @test_case[:num] += 1
    test_case_dir = File.join(@tmp_dir, @test_case[:num].to_s)
    @local_dir = File.join(test_case_dir, 'local')
    @remote_dir = File.join(test_case_dir, 'remote')
    FileUtils.mkdir_p(@local_dir)
    FileUtils.mkdir_p(@remote_dir)
    Dir.chdir(@local_dir)
    FileUtils.mkdir_p("#{@local_dir}/.bitpocket")
    cat "REMOTE_PATH=#{@remote_dir}", local_path('.bitpocket/config')
  end

  let(:content) { 'foo' }
end<commit_msg>Fix sync() helper in specs<commit_after>require 'fileutils'

BP_BIN_PATH = File.join(File.dirname(__FILE__), '..', 'bin', 'bitpocket')
RSYNC_STUB_BIN_PATH = File.join(File.dirname(__FILE__), 'bin')
PATH = "#{RSYNC_STUB_BIN_PATH}:#{ENV['PATH']}"

def sync(opts={})
  system "bash -c 'CALLBACK=#{opts[:callback]} PATH=#{PATH} sh #{BP_BIN_PATH}' >/dev/null"
  $?.exitstatus
end

def local_path(fname)
  "#{@local_dir}/#{fname}"
end

def remote_path(fname)
  "#{@remote_dir}/#{fname}"
end

def touch(path)
  FileUtils.mkdir_p(File.dirname(path))
  FileUtils.touch(path)
end

def cat(content, path)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w') { |f| f.write content }
end

def rm(path)
  FileUtils.rm(path)
end

RSpec::Matchers.define :exist do
  match do |filename|
    File.exist?(filename)
  end
end

RSpec::Matchers.define :succeed do
  match do |status|
    status == 0
  end
end

RSpec::Matchers.define :exit_with do |expected|
  match do |status|
    status == expected
  end
end

TEST_CASE = { :num => 0 }

shared_context 'setup' do
  before(:all) do
    @tmp_dir = "/tmp/bitpocket-test-#{Time.now.to_i}"
  end

  before do
    TEST_CASE[:num] += 1
    test_case_dir = File.join(@tmp_dir, TEST_CASE[:num].to_s)
    @local_dir = File.join(test_case_dir, 'local')
    @remote_dir = File.join(test_case_dir, 'remote')
    FileUtils.mkdir_p(@local_dir)
    FileUtils.mkdir_p(@remote_dir)
    Dir.chdir(@local_dir)
    FileUtils.mkdir_p("#{@local_dir}/.bitpocket")
    cat "REMOTE_PATH=#{@remote_dir}", local_path('.bitpocket/config')
  end

  let(:content) { 'foo' }
end
{'fraction_non_alphanumeric': 0.16788089958821667, 'fraction_numerical': 0.0019005384859043396, 'mean_word_length': 4.569664902998237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2054482', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1248, 'n_words': 231}