<commit_before>var assert = require("assert")

function test_local(swf) {
  var stdin_line = "hello"
  var exit_code = 123

  require("child_process").exec([
    "echo", stdin_line, "|",
    "bin/flashplayer-stdio", swf, exit_code
  ].join(" "), function (error, stdout, stderr) {
    test(swf, function () {
      assert.equal(stdout, stdin_line + "\n")
      assert.equal(stderr, stdin_line.toUpperCase() + "\n")
      assert.equal(error.code, exit_code)
    })
  })
}

function test_web(swf, port) {
  var flashplayer, timeout

  require("http").createServer(function () {
    test_passed(swf)
    flashplayer.kill()
    clearTimeout(timeout)
    this.close()
  }).listen(port, function () {
    flashplayer = start_flashplayer(swf, { port: port })    
    timeout = setTimeout(function () {
      test(swf, function () {
        assert.fail("timeout")
      })
    }, 5000)
  })
}

function start_flashplayer(swf, parameters) {
  var executable = "/Applications/Flash Player Debugger.app/" +
    "Contents/MacOS/Flash Player Debugger"

  return require("child_process").spawn(executable, [
    swf + "?" + stringify_query_parameters(parameters || {})
  ])
}

function stringify_query_parameters(parameters) {
  return Object.keys(parameters || {}).map(function (name) {
    return name + "=" + parameters[name]
  }).join("&")
}

//----------------------------------------------------------

function test(name, callback) {
  try {
    callback()
    test_passed(name)
  } catch (error) {
    test_failed(name)
    throw error
  }
}

function test_passed(name) {
  console.log("OK " + name)
}

function test_failed(name) {
  console.log("FAIL " + name)
}

//----------------------------------------------------------

test_web("test_web_flash.swf", 56788)
test_web("test_web_flex.swf", 56789)

test_local("test_local_flash.swf")
test_local("test_local_flex.swf")
<commit_msg>Use TAP for test output.<commit_after>var assert = require("assert")

console.log("1..4")

function test_local(swf) {
  var stdin_line = "hello"
  var exit_code = 123

  require("child_process").exec([
    "echo", stdin_line, "|",
    "bin/flashplayer-stdio", swf, exit_code
  ].join(" "), function (error, stdout, stderr) {
    test(swf, function () {
      assert.equal(stdout, stdin_line + "\n")
      assert.equal(stderr, stdin_line.toUpperCase() + "\n")
      assert.equal(error.code, exit_code)
    })
  })
}

function test_web(swf, port) {
  var flashplayer, timeout

  require("http").createServer(function () {
    test_passed(swf)
    flashplayer.kill()
    clearTimeout(timeout)
    this.close()
  }).listen(port, function () {
    flashplayer = start_flashplayer(swf, { port: port })    
    timeout = setTimeout(function () {
      test(swf, function () {
        assert.fail("timeout")
      })
    }, 5000)
  })
}

function start_flashplayer(swf, parameters) {
  var executable = "/Applications/Flash Player Debugger.app/" +
    "Contents/MacOS/Flash Player Debugger"

  return require("child_process").spawn(executable, [
    swf + "?" + stringify_query_parameters(parameters || {})
  ])
}

function stringify_query_parameters(parameters) {
  return Object.keys(parameters || {}).map(function (name) {
    return name + "=" + parameters[name]
  }).join("&")
}

//----------------------------------------------------------

function test(name, callback) {
  try {
    callback()
    test_passed(name)
  } catch (error) {
    test_failed(name)
    throw error
  }
}

function test_passed(name) {
  console.log("ok - " + name)
}

function test_failed(name) {
  console.log("not ok - " + name)
}

//----------------------------------------------------------

test_web("test_web_flash.swf", 56788)
test_web("test_web_flex.swf", 56789)

test_local("test_local_flash.swf")
test_local("test_local_flex.swf")

{'fraction_non_alphanumeric': 0.20927780706378493, 'fraction_numerical': 0.009488666315234581, 'mean_word_length': 2.8256048387096775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3531080', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1232, 'n_words': 216}