<commit_before>BaseReporter = require './reporters/base-reporter'
XUnitReporter = require './reporters/x-unit-reporter'
CliReporter = require './reporters/cli-reporter'
DotReporter = require './reporters/dot-reporter'
NyanCatReporter = require './reporters/nyan-reporter'
HtmlReporter = require './reporters/html-reporter'
MarkdownReporter = require './reporters/markdown-reporter'
ApiaryReporter = require './reporters/apiary-reporter'

logger = require './logger'

fileReporters = ['junit', 'html', 'markdown', 'apiary']
cliReporters = ['dot', 'nyan']

intersection = (a, b) ->
  [a, b] = [b, a] if a.length > b.length
  value for value in a when value in b

configureReporters = (config, stats, tests) ->
  baseReporter = new BaseReporter(config.emitter, stats, tests)
  reporters = config.options.reporter
  outputs = config.options.output

  addCli = (reporters) ->
    if reporters.length > 0
      usedCliReporters = intersection reporters, cliReporters
      if usedCliReporters.length is 0
        cliReporter = new CliReporter(config.emitter, stats, tests, config.options['inline-errors'], config.options.details)
      else
        addReporter(usedCliReporters[0], config.emitter, stats, tests)
    else
      cliReporter = new CliReporter(config.emitter, stats, tests, config.options['inline-errors'], config.options.details)

  addReporter = (reporter, emitter, stats, tests, path) ->
    switch reporter
      when 'junit'
        xUnitReporter = new XUnitReporter(emitter, stats, tests, path, config.options.details)
      when 'dot'
        dotReporter = new DotReporter(emitter, stats, tests)
      when 'nyan'
        nyanCatReporter = new NyanCatReporter(emitter, stats, tests)
      when 'html'
        htmlReporter = new HtmlReporter(emitter, stats, tests, path, config.options.details)
      when 'markdown'
        mdReporter = new MarkdownReporter(emitter, stats, tests, path, config.options.details)
      when 'apiary'
        apiaryReporter = new ApiaryReporter(emitter, stats, tests)        
      else
        logger.warn 'Invalid reporter #{reporter} selected, ignoring.'


  addCli(reporters) if not config.options.silent

  usedFileReporters = intersection reporters, fileReporters

  stats.fileBasedReporters = usedFileReporters.length

  if usedFileReporters.length > 0
    usedFileReportersLength = usedFileReporters.length
    if reporters.indexOf('apiary') != -1
      usedFileReportersLength = usedFileReportersLength - 1
      if process.env['DREDD_REST_TOKEN'] == undefined or process.env['DREDD_REST_SUITE'] == undefined
        logger.warn "Apiary reporter environment variable DREDD_REST_TOKEN or DREDD_REST_SUITE not defined."

    if usedFileReportersLength > outputs.length<commit_msg>Fix trailing whitespace to pass coffeelint check<commit_after>BaseReporter = require './reporters/base-reporter'
XUnitReporter = require './reporters/x-unit-reporter'
CliReporter = require './reporters/cli-reporter'
DotReporter = require './reporters/dot-reporter'
NyanCatReporter = require './reporters/nyan-reporter'
HtmlReporter = require './reporters/html-reporter'
MarkdownReporter = require './reporters/markdown-reporter'
ApiaryReporter = require './reporters/apiary-reporter'

logger = require './logger'

fileReporters = ['junit', 'html', 'markdown', 'apiary']
cliReporters = ['dot', 'nyan']

intersection = (a, b) ->
  [a, b] = [b, a] if a.length > b.length
  value for value in a when value in b

configureReporters = (config, stats, tests) ->
  baseReporter = new BaseReporter(config.emitter, stats, tests)
  reporters = config.options.reporter
  outputs = config.options.output

  addCli = (reporters) ->
    if reporters.length > 0
      usedCliReporters = intersection reporters, cliReporters
      if usedCliReporters.length is 0
        cliReporter = new CliReporter(config.emitter, stats, tests, config.options['inline-errors'], config.options.details)
      else
        addReporter(usedCliReporters[0], config.emitter, stats, tests)
    else
      cliReporter = new CliReporter(config.emitter, stats, tests, config.options['inline-errors'], config.options.details)

  addReporter = (reporter, emitter, stats, tests, path) ->
    switch reporter
      when 'junit'
        xUnitReporter = new XUnitReporter(emitter, stats, tests, path, config.options.details)
      when 'dot'
        dotReporter = new DotReporter(emitter, stats, tests)
      when 'nyan'
        nyanCatReporter = new NyanCatReporter(emitter, stats, tests)
      when 'html'
        htmlReporter = new HtmlReporter(emitter, stats, tests, path, config.options.details)
      when 'markdown'
        mdReporter = new MarkdownReporter(emitter, stats, tests, path, config.options.details)
      when 'apiary'
        apiaryReporter = new ApiaryReporter(emitter, stats, tests)
      else
        logger.warn 'Invalid reporter #{reporter} selected, ignoring.'


  addCli(reporters) if not config.options.silent

  usedFileReporters = intersection reporters, fileReporters

  stats.fileBasedReporters = usedFileReporters.length

  if usedFileReporters.length > 0
    usedFileReportersLength = usedFileReporters.length
    if reporters.indexOf('apiary') != -1
      usedFileReportersLength = usedFileReportersLength - 1
      if process.env['DREDD_REST_TOKEN'] == undefined or process.env['DREDD_REST_SUITE'] == undefined
        logger.warn "Apiary reporter environment variable DREDD_REST_TOKEN or DREDD_REST_SUITE not defined."

    if usedFileReportersLength > outputs.length
{'fraction_non_alphanumeric': 0.10420841683366733, 'fraction_numerical': 0.00218619056294407, 'mean_word_length': 3.9863760217983653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '3688798', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1606, 'n_words': 411}