<commit_before>var t = require('../')
var spawn = require('child_process').spawn
var node = process.execPath
var run = require.resolve('../bin/run.js')
var ok = require.resolve('./test/ok.js')
var notok = require.resolve('./test/not-ok.js')
var colorRe = new RegExp('\u001b\\[[0-9;]+m')
var bailRe = new RegExp('^Bail out! # this is not ok$', 'm')
var okre = new RegExp('test[\\\\/]test[/\\\\]ok\\.js \\.+ 10/10$', 'm')
var notokre = new RegExp('test[\\\\/]test[/\\\\]not-ok\\.js \\.+ 0/1$', 'm')
var fs = require('fs')

t.test('colors', function (t) {
  function colorTest(args, env, hasColor) { return function (t) {
    var out = ''
    env = env || {}
    env.TAP = 0
    args = [run, ok].concat(args || [])
    var child = spawn(node, args, { env: env })
    child.stdout.on('data', function (o) {
      out += o
    })
    child.on('close', function (code) {
      t.equal(code, 0, 'code should be 0')
      if (hasColor)
        t.match(out, colorRe)
      else
        t.notMatch(out, colorRe)
      t.end()
    })
  }}

  t.test('no colors by default for non-TTY',
         colorTest([], {}, false))

  t.test('force colors with -c or --color', function (t) {
    ;[ '-c', '--color' ].forEach(function (c) {
      t.test(c, colorTest([c], {}, true))
    })
    t.end()
  })<commit_msg>handle slow ok.js test run in test/runner.js<commit_after>var t = require('../')
var spawn = require('child_process').spawn
var node = process.execPath
var run = require.resolve('../bin/run.js')
var ok = require.resolve('./test/ok.js')
var notok = require.resolve('./test/not-ok.js')
var colorRe = new RegExp('\u001b\\[[0-9;]+m')
var bailRe = new RegExp('^Bail out! # this is not ok$', 'm')
var okre = new RegExp('test[\\\\/]test[/\\\\]ok\\.js \\.+ 10/10( [0-9\.]+ms)?$', 'm')
var notokre = new RegExp('test[\\\\/]test[/\\\\]not-ok\\.js \\.+ 0/1( [0-9\.]+ms)?$', 'm')
var fs = require('fs')

t.test('colors', function (t) {
  function colorTest(args, env, hasColor) { return function (t) {
    var out = ''
    env = env || {}
    env.TAP = 0
    args = [run, ok].concat(args || [])
    var child = spawn(node, args, { env: env })
    child.stdout.on('data', function (o) {
      out += o
    })
    child.on('close', function (code) {
      t.equal(code, 0, 'code should be 0')
      if (hasColor)
        t.match(out, colorRe)
      else
        t.notMatch(out, colorRe)
      t.end()
    })
  }}

  t.test('no colors by default for non-TTY',
         colorTest([], {}, false))

  t.test('force colors with -c or --color', function (t) {
    ;[ '-c', '--color' ].forEach(function (c) {
      t.test(c, colorTest([c], {}, true))
    })
    t.end()
  })
{'fraction_non_alphanumeric': 0.2315829240649792, 'fraction_numerical': 0.012089157536834151, 'mean_word_length': 2.549597855227882, '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': '7436720', 'n_tokens_mistral': 1023, 'n_tokens_neox': 988, 'n_words': 244}