<commit_before>require 'fileutils'

module Exercism
  @languages = {
    "ruby" => ["ruby", "test.rb"],
    "elixir" => ["elixir", "test.exs"],
    "ecmascript" => ["npm test", "spec.js"]
  }

  def self.run_tests
    bold, red, blue, reset = `tput bold`, `tput setaf 1`, `tput setaf 4`, `tput sgr0`
    
    @languages.each do |language, tool|
      script, ending_file = tool
      test_files = Dir.glob "#{language}/*/*#{ending_file}"

      unless test_files.empty?
        test_files.map do |file|
          path, test_file = self.project_path file

          FileUtils.cd(path) do
            system "npm i" if language == "ecmascript" && !self.node_modules?(path)

            name = self.project_name(file, ending_file)
            language = language.capitalize

            system "#{script} #{test_file}"
            if $?.exitstatus > 0
              system "printf '#{bold}#{red}#{language}: #{name} tests failed\n'"
              return exit(1) # Exits with "failure" code
            end
            system "printf '#{bold}#{blue}#{language}: #{name} tests finished without error#{reset}\n\n'"
          end
        end
      end
    end
  end

  def self.project_name(file, ending_file)
    file
      .split("/")
      .last
      .chomp(ending_file)
      .scan(/([A-Za-z0-9]+)/)
      .map { |word| word.join.capitalize }
      .join(" ")
  end

  def self.project_path(file)
    f = file.split("/")
    test_file = f.delete_at(2)
    [f.join("/"), test_file]<commit_msg>fix travis fix checking language name<commit_after>require 'fileutils'

module Exercism
  @languages = {
    "ruby" => ["ruby", "test.rb"],
    "elixir" => ["elixir", "test.exs"],
    "ecmascript" => ["npm test", "spec.js"]
  }

  def self.run_tests
    bold, red, blue, reset = `tput bold`, `tput setaf 1`, `tput setaf 4`, `tput sgr0`
    
    @languages.each do |language, tool|
      script, ending_file = tool
      test_files = Dir.glob "#{language}/*/*#{ending_file}"

      unless test_files.empty?
        test_files.map do |file|
          path, test_file = self.project_path file

          FileUtils.cd(path) do
            system "npm i" if language == "ecmascript" && !self.node_modules?(path)

            name = self.project_name(file, ending_file)

            system "#{script} #{test_file}"
            if $?.exitstatus > 0
              system "printf '#{bold}#{red}#{language.capitalize}: #{name} tests failed\n'"
              return exit(1) # Exits with "failure" code
            end
            system "printf '#{bold}#{blue}#{language.capitalize}: #{name} tests finished without error#{reset}\n\n'"
          end
        end
      end
    end
  end

  def self.project_name(file, ending_file)
    file
      .split("/")
      .last
      .chomp(ending_file)
      .scan(/([A-Za-z0-9]+)/)
      .map { |word| word.join.capitalize }
      .join(" ")
  end

  def self.project_path(file)
    f = file.split("/")
    test_file = f.delete_at(2)
    [f.join("/"), test_file]
{'fraction_non_alphanumeric': 0.15688903788132752, 'fraction_numerical': 0.0053637277908146165, 'mean_word_length': 2.2576419213973797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7091848', 'n_tokens_mistral': 1021, 'n_tokens_neox': 1001, 'n_words': 236}