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

binaryDir = ENV["BINARY_DIR"]

# arguments are a string that must match the test name
substrpat = ARGV.length ? ARGV[0] : ""

thisDir = File.dirname(__FILE__)
casesDir = File.join(thisDir, "validator")
verifyBin = File.join(binaryDir,  "validator",  "orderly_verify")
if !File.executable? verifyBin
  throw "Can't find validator test binary: #{verifyBin}"
end
passed = 0
total = 0

puts "Running validator tests: "
puts "(containing '#{substrpat}' in name)" if substrpat && substrpat.length > 0

Dir.glob(File.join(casesDir, "*.orderly")).each { |f| 
  next if substrpat && substrpat.length > 0 && !f.include?(substrpat)
  [
    [ "Invalid case", f.sub(/orderly$/, "fail"), verifyBin, 1 ],
    [ "Valid case", f.sub(/orderly$/, "pass"),   verifyBin, 0 ]
  ].each { |testType|
    what, textfile, program, exitCode = *testType
    gotFile = textfile + ".got"
    got = ""
    puts "#{what} for #{textfile}" ;
    ENV['ORDERLY_SCHEMA'] = IO.readlines(f,'').to_s
    IO.popen(program, "w+") { |lb|
      File.open(textfile, "r").each {|l| lb.write(l)}
      lb.close_write
      got = lb.read
    }
    if ($?.exitstatus != exitCode) 
      puts "FAIL";
      puts "got wrong exit code #{$?.exitstatus}, expected #{exitCode}"
    else
      puts "ok"
      passed += 1
    end
    total += 1
  }
}
<commit_msg>o allow for '.got' files, fix formatting<commit_after>#!/usr/bin/env ruby

binaryDir = ENV["BINARY_DIR"]

# arguments are a string that must match the test name
substrpat = ARGV.length ? ARGV[0] : ""

thisDir = File.dirname(__FILE__)
casesDir = File.join(thisDir, "validator")
verifyBin = File.join(binaryDir,  "validator",  "orderly_verify")
if !File.executable? verifyBin
  throw "Can't find validator test binary: #{verifyBin}"
end
passed = 0
total = 0

puts "Running validator tests: "
puts "(containing '#{substrpat}' in name)" if substrpat && substrpat.length > 0

Dir.glob(File.join(casesDir, "*.orderly")).each { |f| 
  next if substrpat && substrpat.length > 0 && !f.include?(substrpat)
  [
    [ "Invalid case", f.sub(/orderly$/, "fail"), verifyBin, 1 ],
    [ "Valid case", f.sub(/orderly$/, "pass"),   verifyBin, 0 ]
  ].each { |testType|
    what, textfile, program, exitCode = *testType
    wantFile = textfile + ".want"
    gotFile = textfile + ".got"
    got = ""
    print "#{what} for #{textfile}:\t" ;
    ENV['ORDERLY_SCHEMA'] = IO.readlines(f,'').to_s
    IO.popen(program, "w+") { |lb|
      File.open(textfile, "r").each {|l| lb.write(l)}
      lb.close_write
      got = lb.read
    }
    if ($?.exitstatus != exitCode) 
      puts "FAIL";
      puts "got bad exit code '#{$?.exitstatus}', expected '#{exitCode}'"
    else
      if File.exist? wantFile
        want = IO.read(wantFile)
        if (got == want)
          puts "ok"
          passed += 1
        else
          puts "FAIL"
          puts "<<<want<<<"
          puts want
          puts "========"
          puts got
          puts ">>got>>"
        end
      else
        puts "ok"
        passed += 1
      end
    end
    total += 1
  }
}

{'fraction_non_alphanumeric': 0.1662870159453303, 'fraction_numerical': 0.006182883176049463, 'mean_word_length': 2.8138957816377173, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4188703', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1071, 'n_words': 282}