<commit_before>#!/usr/bin/env ruby

TEST_CASE = ARGV[0]
APPLICATION = ARGV[1]

tests = Dir.glob("#{TEST_CASE}/*.in").collect do |input_file|
  name = input_file[/(?<=#{TEST_CASE}\/).*(?=\.in)/]
  input = IO.read(input_file).strip

  output_files = Dir.glob "#{TEST_CASE}/#{name}.out*"
  potential_outputs = output_files.collect do |output_file|
    IO.read(output_file).strip
  end

  [name, input, potential_outputs]
end

def succeeded message
  puts "\033[32m#{message}\033[0m"
end

@failures = 0
def failed message
  puts "\033[31m#{message}\033[0m"
  @failures += 1
end

tests.each do |name, input, potential_outputs|
  failed "#{name}: no outputs provided" if potential_outputs.length == 0

  output = IO.popen APPLICATION, 'r+' do |io|
    io.write input
    io.read.strip
  end

  unless potential_outputs.include? output
    next failed "#{name}:\n  output: #{output.inspect}\n  expected: #{potential_outputs[0].inspect}" if potential_outputs.length == 1
    next failed "#{name}:\n  output: #{output.inspect}\n  expected: #{potential_outputs[0...potential_outputs.length - 1].join(', ')} or #{potential_outputs[-1]}"
  end

  succeeded name
end

puts
if @failures > 0
  failed "#{tests.length} tests, #{@failures} failures"
else
  succeeded "#{tests.length} tests, #{@failures} failures"
end<commit_msg>Reworked the success/fail handling.<commit_after>#!/usr/bin/env ruby

TEST_CASE = ARGV[0]
APPLICATION = ARGV[1]

GREEN = "\033[31m"
RED = "\033[32m"
RESET = "\033[0m"

tests = Dir.glob("#{TEST_CASE}/*.in").collect do |input_file|
  name = input_file[/(?<=#{TEST_CASE}\/).*(?=\.in)/]
  input = IO.read(input_file).strip

  output_files = Dir.glob "#{TEST_CASE}/#{name}.out*"
  potential_outputs = output_files.collect do |output_file|
    IO.read(output_file).strip.inspect
  end

  [name, input, potential_outputs]
end

def green string
  "#{GREEN}#{string}#{RESET}"
end

def red string
  "#{RED}#{string}#{RESET}"
end

def succeeded *messages
  puts green messages.collect { |message| '  ' + message }.join "\n"
end

@failures = 0
def failed *messages
  puts red messages.collect { |message| '  ' + message }.join "\n"
  @failures += 1
end

tests.each do |name, input, potential_outputs|
  puts name
  failed "no outputs provided" if potential_outputs.length == 0

  output = IO.popen APPLICATION, 'r+' do |io|
    io.write input
    io.read.strip.inspect
  end

  unless potential_outputs.include? output
    if potential_outputs.length == 1
      next failed "output: #{output}", "expected: #{potential_outputs[0]}" 
    end

    next failed "output: #{output}", "expected: #{potential_outputs[0...potential_outputs.length - 1].join(', ')} or #{potential_outputs[-1]}"
  end

  succeeded 'succeeded'
end

puts
if @failures > 0
  puts red "#{tests.length} tests, #{@failures} failures"
else
  puts green "#{tests.length} tests, #{@failures} failures"
end
{'fraction_non_alphanumeric': 0.16317991631799164, 'fraction_numerical': 0.01882845188284519, 'mean_word_length': 4.235401459854015, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5536376', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1012, 'n_words': 248}