<commit_before>var fs = require('fs')
var chalk = require('chalk')
var success = require('success-symbol')
var error = require('error-symbol')
var warning = require('warning-symbol')

var getSongArtistTitle = require('./')

function stringifyTitle (o) {
  return o ? '"' + o[0] + '" - "' + o[1] + '"' : 'nothing'
}

function testFailed (test, result) {
  console.error(chalk.red('   ' + error + ' expected ' + stringifyTitle(test.expected)))
  console.error(chalk.red('     but got  ' + stringifyTitle(result)))
}
function optionalTestFailed (test, result) {
  console.error(chalk.yellow('   ' + warning + ' expected ' + stringifyTitle(test.expected)))
  console.error(chalk.yellow('     but got  ' + stringifyTitle(result)))
}
function testSucceeded (test, result) {
  console.log(chalk.green('   ' + success + ' got ' + stringifyTitle(result)))
}

function runTest (plugins, test) {
  console.log('  ' + test.input)
  var result = getSongArtistTitle(test.input, plugins)
  if (!result || result[0] !== test.expected[0] || result[1] !== test.expected[1]) {
    if (test.optional) {
      optionalTestFailed(test, result)
      return 'optionalFail'
    } else {
      testFailed(test, result)
      return 'fail'
    }
  }
  testSucceeded(test, result)
  return 'success'
}

function runSuite (suite) {
  var score = { fail: 0, optionalFail: 0, success: 0 }
  suite.tests
    .map(runTest.bind(null, suite.plugins))
    .forEach(function (result) {
      score[result]++
    })
  return score
}

function readSuite (suiteName) {
  var suite = require('./test/' + suiteName)
  return {
    name: suiteName,
    plugins: suite.plugins,
    tests: suite.tests
  }
}

var suites = fs.readdirSync('test')
var total = { fail: 0, success: 0 }
suites.forEach(function (suiteName) {
  var suite = readSuite(suiteName)

  var title = suiteName.replace(/\.txt$/, '')
  console.log(title)
  console.log(title.replace(/./g, '-'))

  var result = runSuite(suite)
  console.log(
    chalk.red(' ' + error + ' ' + result.fail) + '  ' +
    chalk.yellow(' ' + warning + ' ' + result.optionalFail) + ' ' +
    chalk.green(' ' + success + ' ' + result.success)
  )
  total.fail += result.fail
  total.success += result.success
})

if (total.fail > 0) {
  process.exit(1)
}<commit_msg>test: show error/warning/success summary at end<commit_after>var fs = require('fs')
var chalk = require('chalk')
var success = require('success-symbol')
var error = require('error-symbol')
var warning = require('warning-symbol')

var getSongArtistTitle = require('./')

function stringifyTitle (o) {
  return o ? '"' + o[0] + '" - "' + o[1] + '"' : 'nothing'
}

function testFailed (test, result) {
  console.error(chalk.red('   ' + error + ' expected ' + stringifyTitle(test.expected)))
  console.error(chalk.red('     but got  ' + stringifyTitle(result)))
}
function optionalTestFailed (test, result) {
  console.error(chalk.yellow('   ' + warning + ' expected ' + stringifyTitle(test.expected)))
  console.error(chalk.yellow('     but got  ' + stringifyTitle(result)))
}
function testSucceeded (test, result) {
  console.log(chalk.green('   ' + success + ' got ' + stringifyTitle(result)))
}

function runTest (plugins, test) {
  console.log('  ' + test.input)
  var result = getSongArtistTitle(test.input, plugins)
  if (!result || result[0] !== test.expected[0] || result[1] !== test.expected[1]) {
    if (test.optional) {
      optionalTestFailed(test, result)
      return 'optionalFail'
    } else {
      testFailed(test, result)
      return 'fail'
    }
  }
  testSucceeded(test, result)
  return 'success'
}

function runSuite (suite) {
  var score = { fail: 0, optionalFail: 0, success: 0 }
  suite.tests
    .map(runTest.bind(null, suite.plugins))
    .forEach(function (result) {
      score[result]++
    })
  return score
}

function readSuite (suiteName) {
  var suite = require('./test/' + suiteName)
  return {
    name: suiteName,
    plugins: suite.plugins,
    tests: suite.tests
  }
}

var suites = fs.readdirSync('test')
var total = { fail: 0, optionalFail: 0, success: 0 }
suites.forEach(function (suiteName) {
  var suite = readSuite(suiteName)

  var title = suiteName.replace(/\.txt$/, '')
  console.log(title)
  console.log(title.replace(/./g, '-'))

  var result = runSuite(suite)
  console.log(
    chalk.red(' ' + error + ' ' + result.fail) + '  ' +
    chalk.yellow(' ' + warning + ' ' + result.optionalFail) + ' ' +
    chalk.green(' ' + success + ' ' + result.success)
  )
  total.fail += result.fail
  total.optionalFail += result.optionalFail
  total.success += result.success
})

console.log('')
console.log('summary')
console.log('-------')
console.log(
  chalk.red(' ' + error + ' ' + total.fail) + '  ' +
  chalk.yellow(' ' + warning + ' ' + total.optionalFail) + ' ' +
  chalk.green(' ' + success + ' ' + total.success)
)

if (total.fail > 0) {
  process.exit(1)
}
{'fraction_non_alphanumeric': 0.17172753385309808, 'fraction_numerical': 0.00553959786622897, 'mean_word_length': 3.4889502762430937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '385263', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1631, 'n_words': 346}