<commit_before>var util = require('util');

/**
 * Check result exit code against expectated exit code.
 *
 * @param {Object} result: command execution result (exitcode, output)
 * @param {Object} test: test expectation (exitcode, output)
 * @return {Object} error if actual exit code doesn't equal expected exit code
 */
function _checkExitCode(result, test) {

  var actual = result.exitcode;
  var expect = test.exitcode;
  var error;

  if (typeof expect === 'string') {
    expect = parseInt(expect, 10);
  }

  if (expect && expect !== actual) {
    error = util.format('Exit code %d does not match expected %d', actual, expect);
  }

  return error;
}

/**
 * Check result output against expectated output.
 *
 * @param {Object} result: command execution result (exitcode, output)
 * @param {Object} test: test expectation (exitcode, output)
 * @return {Object} error if actual exit code doesn't match expected regexp pattern
 */
function _checkOutput(result, test) {

  var actual = result.output;
  var expect = test.output;
  var error;

  if (expect && !actual.match(new RegExp(expect))) {
    error = util.format('Output does not match expected regexp \'%s\'', expect);
  }

  return error;
}

/**
 * Check command execution result with test expectation against a set of check functions.<commit_msg>Fix checkers to still check when expectation is falsey but defined.<commit_after>var util = require('util');

/**
 * Check result exit code against expectated exit code.
 *
 * @param {Object} result: command execution result (exitcode, output)
 * @param {Object} test: test expectation (exitcode, output)
 * @return {Object} error if actual exit code doesn't equal expected exit code
 */
function _checkExitCode(result, test) {

  var actual = result.exitcode;
  var expect = test.exitcode;
  var error;

  if (typeof expect === 'string') {
    expect = parseInt(expect, 10);
  }

  if (expect !== undefined && expect !== actual) {
    error = util.format('Exit code %d does not match expected %d', actual, expect);
  }

  return error;
}

/**
 * Check result output against expectated output.
 *
 * @param {Object} result: command execution result (exitcode, output)
 * @param {Object} test: test expectation (exitcode, output)
 * @return {Object} error if actual exit code doesn't match expected regexp pattern
 */
function _checkOutput(result, test) {

  var actual = result.output;
  var expect = test.output;
  var error;

  if (expect !== undefined && !actual.match(new RegExp(expect))) {
    error = util.format('Output does not match expected regexp \'%s\'', expect);
  }

  return error;
}

/**
 * Check command execution result with test expectation against a set of check functions.
{'fraction_non_alphanumeric': 0.11871301775147929, 'fraction_numerical': 0.0014792899408284023, 'mean_word_length': 4.0092592592592595, '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': '1493385', 'n_tokens_mistral': 772, 'n_tokens_neox': 749, 'n_words': 301}