<commit_before>fs = require "fs"
glob = require "glob"

assert = require "assert"
Testify = require "testify"

module.exports = class SuiteRunner

  constructor: (@version, {@ignore}) ->
    @suites = {}
    @read()

  read: ->
    files = glob.sync "test/JSON-Schema-Test-Suite/tests/#{@version}/**/*.json"
    l = "test/JSON-Schema-Test-Suite/tests/#{@version}/".length
    for file in files
      # drop the .json
      key = file.slice(l, -5)

      continue if @ignore?[key] == true
      string = fs.readFileSync(file, "utf8")
      @suites[key] = JSON.parse string

  test: ({constructor, attribute, test_number}) ->

    Testify.test "JSON Schema: #{@version}", (context) =>
      if attribute
        attribute_suite = @suites[attribute]
        if !attribute_suite
          throw new Error "No such attribute to test: '#{attribute}'"
        else
          @run_attribute({constructor, context, attribute, attribute_suite, test_number})
        if @ignore?[attribute]
          process.on "exit", =>
            console.log "Ignored these tests:", @ignore[attribute]
      else
        for attribute, attribute_suite of @suites
          @run_attribute({constructor, context, attribute, attribute_suite, test_number})
        if @ignore
          process.on "exit", =>
            console.log "Ignored these tests:"
            for attribute, val of @ignore
              if val == true
                console.log attribute
              else
                console.log "#{attribute}:", val

  run_attribute: ({constructor, context, attribute, attribute_suite, test_number}) ->
    context.test attribute, (context) =>
      if test_number
        if suite = attribute_suite[parseInt(test_number)]
          @run_subsuite({constructor, context, suite})
        else<commit_msg>improved reporting on ignored tests<commit_after>fs = require "fs"
glob = require "glob"

assert = require "assert"
Testify = require "testify"

module.exports = class SuiteRunner

  constructor: (@version, {@ignore}) ->
    @suites = {}
    @read()

  read: ->
    files = glob.sync "test/JSON-Schema-Test-Suite/tests/#{@version}/**/*.json"
    l = "test/JSON-Schema-Test-Suite/tests/#{@version}/".length
    for file in files
      # drop the .json
      key = file.slice(l, -5)

      continue if @ignore?[key] == true
      string = fs.readFileSync(file, "utf8")
      @suites[key] = JSON.parse string

  test: ({constructor, attribute, test_number}) ->

    Testify.test "JSON Schema: #{@version}", (context) =>
      if attribute
        attribute_suite = @suites[attribute]
        if !attribute_suite
          throw new Error "No such attribute to test: '#{attribute}'"
        else
          @run_attribute({constructor, context, attribute, attribute_suite, test_number})
        if @ignore?[attribute]
          process.on "exit", =>
            console.log "Ignored these tests for #{@version}:", @ignore[attribute]
      else
        for attribute, attribute_suite of @suites
          @run_attribute({constructor, context, attribute, attribute_suite, test_number})
        if @ignore
          process.on "exit", =>
            console.log "Ignored these tests for #{@version}:"
            for attribute, val of @ignore
              if val == true
                console.log "\t", attribute
              else
                console.log "\t", "#{attribute}:", val

  run_attribute: ({constructor, context, attribute, attribute_suite, test_number}) ->
    context.test attribute, (context) =>
      if test_number
        if suite = attribute_suite[parseInt(test_number)]
          @run_subsuite({constructor, context, suite})
        else
{'fraction_non_alphanumeric': 0.1272627537026879, 'fraction_numerical': 0.0010970927043335162, 'mean_word_length': 2.54421768707483, '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': '6478424', 'n_tokens_mistral': 1021, 'n_tokens_neox': 1005, 'n_words': 281}