<commit_before>def growl(title, msg, img)
  %x{growlnotify -m #{ msg.inspect} -t #{title.inspect} --image ~/.watchr/#{img}.png}
end

def form_growl_message(str)
  msg = str.split("\n").last
  if msg =~ /(\d)\sfailure/
    img = $1.to_i > 0 ? 'fail' : 'pass'
  end
  growl 'Results', msg, img
end

def run(cmd)
  puts cmd
  output = ""
  IO.popen(cmd) do |com|
    com.each_char do |c|
      print c
      output << c
      $stdout.flush
    end
  end
  form_growl_message output
end

def run_spec(path)
  path.gsub!('lib/', 'spec/')
  path.gsub!('_spec', '')
  file_name = File.basename(path, '.rb')
  path.gsub!(file_name, file_name + "_spec")
  run %Q(spec #{path})
end

watch('test/lint_test.rb') {     system('clear'); run 'rake test' }
watch('spec/helper\.rb')   {     system('clear'); run 'rake'      }
watch('lib/.*\.rb')        { |m| system('clear'); run_spec m[0]   }
watch('spec/.*_spec\.rb')  { |m| system('clear'); run_spec m[0]   }

# Ctrl-\
Signal.trap('QUIT') do
  puts " --- Running all tests ---\n\n"
  run('rake')
end<commit_msg>Only run spec if file exists.<commit_after>def growl(title, msg, img)
  %x{growlnotify -m #{ msg.inspect} -t #{title.inspect} --image ~/.watchr/#{img}.png}
end

def form_growl_message(str)
  msg = str.split("\n").last
  if msg =~ /(\d)\sfailure/
    img = $1.to_i > 0 ? 'fail' : 'pass'
  end
  growl 'Results', msg, img
end

def run(cmd)
  puts cmd
  output = ""
  IO.popen(cmd) do |com|
    com.each_char do |c|
      print c
      output << c
      $stdout.flush
    end
  end
  form_growl_message output
end

def run_spec(path)
  path.gsub!('lib/', 'spec/')
  path.gsub!('_spec', '')
  file_name = File.basename(path, '.rb')
  path.gsub!(file_name, file_name + "_spec")
  run %Q(spec #{path}) if File.exists?(path)
end

watch('test/lint_test.rb') {     system('clear'); run 'rake test' }
watch('spec/helper\.rb')   {     system('clear'); run 'rake'      }
watch('lib/.*\.rb')        { |m| system('clear'); run_spec m[0]   }
watch('spec/.*_spec\.rb')  { |m| system('clear'); run_spec m[0]   }

# Ctrl-\
Signal.trap('QUIT') do
  puts " --- Running all tests ---\n\n"
  run('rake')
end
{'fraction_non_alphanumeric': 0.2049718574108818, 'fraction_numerical': 0.00375234521575985, 'mean_word_length': 2.9354243542435423, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '2300343', 'n_tokens_mistral': 865, 'n_tokens_neox': 857, 'n_words': 196}