<commit_before>var fs, naught_bin, path, naught_main, assert, async, exec, spawn, steps, root, test_root;

fs = require('fs');
spawn = require('child_process').spawn;
path = require("path");
assert = require("assert");
async = require("async");

root = path.join(__dirname, "..");
test_root = path.join(root, "test");
naught_main = path.join(root, "lib", "main.js");

function assertEqual(actual, expected) {
  assert(actual === expected, "actual:\n" + actual + "\nexpected:\n" + expected);
}

function exec(cmd, args, opts, cb){
  var bin, stdout, stderr;
  if (args == null) args = []
  if (opts == null) opts = {}
  if (cb == null) cb = function(){};
  bin = spawn(cmd, args, opts);
  stdout = ""
  bin.stdout.on('data', function(data) {
    stdout += data;
  });
  stderr = ""
  bin.stderr.on('data', function(data) {
    stderr += data;
  });
  bin.on('exit', function(code, signal) {
    cb(stdout, stderr, code, signal);
  });
}

function naught_exec(args, cb) {
  exec("node", [naught_main].concat(args), {
    cwd: __dirname
  }, function(stdout, stderr, code, signal) {
    cb(stdout, stderr, code);
  });
}

steps = [
  // ability to start a server
  function (cb) {
    naught_exec(["start", "server.js"], function(stdout, stderr, code) {
      assertEqual(stderr, "event: Bootup, old: 0, new: 0, dying: 0\n")
      assertEqual(stdout, "server is running\nworkers online: 1\n")
      assertEqual(code, 0)
      cb();
    });
  },
  // starting a server twice prints the status of the running server
  function (cb) {
    naught_exec(["start", "server.js"], function(stdout, stderr, code) {
      assertEqual(stderr, "");
      assertEqual(stdout, "server is running\nworkers online: 1\n");
      assertEqual(code, 1)
      cb();
    });
  },
  function (cb) {
    naught_exec(["status"], function(stdout, stderr, code) {
      assertEqual(stderr, "");
      assertEqual(stdout, "server is running\nworkers online: 1\n");
      assertEqual(code, 0)
      cb();
    });
  },
  function (cb) {
    naught_exec(["stop"], function(stdout, stderr, code) {
      assertEqual(stderr, "event: ShutdownOld, old: 1, new: 0, dying: 0\nevent: OldExit, old: 0, new: 0, dying: 1\n");
      assertEqual(stdout, "");
      assertEqual(code, 0)
      cb();
    });
  },
  function (cb) {
    naught_exec(["stop"], function(stdout, stderr, code) {
      assertEqual(stdout, "");
      assertEqual(stderr, "server not running\n");
      assertEqual(code, 1)
      cb();
    });
  },
  function (cb) {
    async.parallel([
      function (cb) {
        fs.unlink(path.join(test_root, "naught.log"), cb);
      },
      function (cb) {
        fs.unlink(path.join(test_root, "stderr.log"), cb);
      },
      function (cb) {
        fs.unlink(path.join(test_root, "stdout.log"), cb);
      },
    ], cb);
  },
];

async.series(steps, function(err) {
  assert.ifError(err);
  console.error("pass");
});<commit_msg>document tests<commit_after>var fs, naught_bin, path, naught_main, assert, async, exec, spawn, steps, root, test_root;

fs = require('fs');
spawn = require('child_process').spawn;
path = require("path");
assert = require("assert");
async = require("async");

root = path.join(__dirname, "..");
test_root = path.join(root, "test");
naught_main = path.join(root, "lib", "main.js");

function assertEqual(actual, expected) {
  assert(actual === expected, "actual:\n" + actual + "\nexpected:\n" + expected);
}

function exec(cmd, args, opts, cb){
  var bin, stdout, stderr;
  if (args == null) args = []
  if (opts == null) opts = {}
  if (cb == null) cb = function(){};
  bin = spawn(cmd, args, opts);
  stdout = ""
  bin.stdout.on('data', function(data) {
    stdout += data;
  });
  stderr = ""
  bin.stderr.on('data', function(data) {
    stderr += data;
  });
  bin.on('exit', function(code, signal) {
    cb(stdout, stderr, code, signal);
  });
}

function naught_exec(args, cb) {
  exec("node", [naught_main].concat(args), {
    cwd: __dirname
  }, function(stdout, stderr, code, signal) {
    cb(stdout, stderr, code);
  });
}

steps = [
  // ability to start a server
  function (cb) {
    naught_exec(["start", "server.js"], function(stdout, stderr, code) {
      assertEqual(stderr, "event: Bootup, old: 0, new: 0, dying: 0\n")
      assertEqual(stdout, "server is running\nworkers online: 1\n")
      assertEqual(code, 0)
      cb();
    });
  },
  // starting a server twice prints the status of the running server
  function (cb) {
    naught_exec(["start", "server.js"], function(stdout, stderr, code) {
      assertEqual(stderr, "");
      assertEqual(stdout, "server is running\nworkers online: 1\n");
      assertEqual(code, 1)
      cb();
    });
  },
  // ability to query status of a running server
  function (cb) {
    naught_exec(["status"], function(stdout, stderr, code) {
      assertEqual(stderr, "");
      assertEqual(stdout, "server is running\nworkers online: 1\n");
      assertEqual(code, 0)
      cb();
    });
  },
  // ability to stop a running server
  function (cb) {
    naught_exec(["stop"], function(stdout, stderr, code) {
      assertEqual(stderr, "event: ShutdownOld, old: 1, new: 0, dying: 0\nevent: OldExit, old: 0, new: 0, dying: 1\n");
      assertEqual(stdout, "");
      assertEqual(code, 0)
      cb();
    });
  },
  // stopping a server twice prints helpful output
  function (cb) {
    naught_exec(["stop"], function(stdout, stderr, code) {
      assertEqual(stdout, "");
      assertEqual(stderr, "server not running\n");
      assertEqual(code, 1)
      cb();
    });
  },
  // server writes to default log files
  function (cb) {
    async.parallel([
      function (cb) {
        fs.unlink(path.join(test_root, "naught.log"), cb);
      },
      function (cb) {
        fs.unlink(path.join(test_root, "stderr.log"), cb);
      },
      function (cb) {
        fs.unlink(path.join(test_root, "stdout.log"), cb);
      },
    ], cb);
  },
];

async.series(steps, function(err) {
  assert.ifError(err);
  console.error("pass");
});
{'fraction_non_alphanumeric': 0.18206113245364958, 'fraction_numerical': 0.005678971104058794, 'mean_word_length': 3.2318021201413427, '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': '3654396', 'n_tokens_mistral': 2071, 'n_tokens_neox': 1996, 'n_words': 498}