<commit_before>#!/usr/bin/env ruby
require 'yaml'

def generate_index_html(files)
  File::open("index.html", "w") do |f|
    f.write <<EOF
# <!DOCTYPE html>
<html>
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type">
  <title>QUnit Test Suite</title>
  <script>
    var AsakusaSatellite = {
      current : {
        user : "user",
        room : "000000000000000000000000"
      }
    };
  </script>
  <link rel="stylesheet" href="./lib/qunit/qunit.css" type="text/css" media="screen">
  <script type="text/javascript" src="./lib/qunit/qunit.js"></script>
  <script type="text/javascript" src="./lib/qunit-tap.js"></script>
  <script>
    qunitTap(QUnit, function() { console.log.apply(console, arguments); }, {noPlan: true});
  </script>
#{files.map{|f| "<script type='text/javascript' src='#{f}'></script>"}.join"\n"}
</head>
<body>
  <h1 id="qunit-header">QUnit Test Suite</h1>
  <h2 id="qunit-banner"></h2>
  <div id="qunit-testrunner-toolbar"></div>
  <h2 id="qunit-userAgent"></h2>
  <ol id="qunit-tests"></ol>
</body>
</html>
EOF
  end
end

result = (["qunit_setting.yml"]+Dir::glob("../plugins/*/qunit/qunit_setting.yml")).all? do |yaml|
  path = File.dirname yaml
  setting = YAML.load_file yaml
  generate_index_html(setting['files'].map{|f| File::expand_path(f, path)})
  File::open("#{setting['name']}.tap", "w") do |f|
    f.write %x(phantomjs run_qunit.js file://#{Dir::pwd+"/index.html"})
  end
  $?.exitstatus == 0
end

exit result<commit_msg>output test results to each .tap files refs #1434<commit_after>#!/usr/bin/env ruby
require 'yaml'

def generate_index_html(prefix, files)
  File::open("#{prefix}_index.html", "w") do |f|
    f.write <<EOF
# <!DOCTYPE html>
<html>
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type">
  <title>QUnit Test Suite</title>
  <script>
    var AsakusaSatellite = {
      current : {
        user : "user",
        room : "000000000000000000000000"
      }
    };
  </script>
  <link rel="stylesheet" href="./lib/qunit/qunit.css" type="text/css" media="screen">
  <script type="text/javascript" src="./lib/qunit/qunit.js"></script>
  <script type="text/javascript" src="./lib/qunit-tap.js"></script>
  <script>
    qunitTap(QUnit, function() { console.log.apply(console, arguments); }, {noPlan: true});
  </script>
#{files.map{|f| "<script type='text/javascript' src='#{f}'></script>"}.join"\n"}
</head>
<body>
  <h1 id="qunit-header">QUnit Test Suite</h1>
  <h2 id="qunit-banner"></h2>
  <div id="qunit-testrunner-toolbar"></div>
  <h2 id="qunit-userAgent"></h2>
  <ol id="qunit-tests"></ol>
</body>
</html>
EOF
  end
end

def execute_test(name)
  File::open("#{name}.tap", "w") do |f|
    output = %x(phantomjs run_qunit.js file://#{Dir::pwd}/#{name}_index.html)
    f.write output
    puts output
  end
  $?.exitstatus == 0
end

(Dir::glob("*.html")+Dir::glob("*.tap")).each{|f| File.unlink f}

result = (["qunit_setting.yml"]+Dir::glob("../plugins/*/qunit/qunit_setting.yml")).map do |yaml|
  setting = YAML.load_file yaml
  name    = setting['name']
  files   = setting['files']

  if ARGV.empty? or ARGV.member? name
    path = File.dirname yaml
    generate_index_html(name, files.map{|f| File::expand_path(f, path)})
    execute_test(name)
  else
    false
  end
end.all?

exit result
{'fraction_non_alphanumeric': 0.21087815253722272, 'fraction_numerical': 0.020662412640534793, 'mean_word_length': 4.072419106317412, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5181545', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1237, 'n_words': 234}