<commit_before>#:  * `test` [`--devel`|`--HEAD`] [`--debug`] [`--keep-tmp`] <formula>:
#:    Most formulae provide a test method. `brew test` <formula> runs this
#:    test method. There is no standard output or return code, but it should
#:    generally indicate to the user if something is wrong with the installed
#:    formula.
#:
#:    To test the development or head version of a formula, use `--devel` or
#:    `--HEAD`.
#:
#:    If `--debug` (or `-d`) is passed and the test fails, an interactive debugger will be
#:    launched with access to IRB or a shell inside the temporary test directory.
#:
#:    If `--keep-tmp` is passed, the temporary files created for the test are
#:    not deleted.
#:
#:    Example: `brew install jruby && brew test jruby`

require "extend/ENV"
require "formula_assertions"
require "sandbox"
require "timeout"

module Homebrew
  module_function

  def test
    raise FormulaUnspecifiedError if ARGV.named.empty?

    ARGV.resolved_formulae.each do |f|
      # Cannot test uninstalled formulae
      unless f.installed?
        ofail "Testing requires the latest version of #{f.full_name}"
        next
      end

      # Cannot test formulae without a test method
      unless f.test_defined?
        ofail "#{f.full_name} defines no test"
        next
      end

      # Don't test unlinked formulae
      if !ARGV.force? && !f.keg_only? && !f.linked?
        ofail "#{f.full_name} is not linked"
        next
      end

      puts "Testing #{f.full_name}"

      env = ENV.to_hash

      begin
        args = %W[
          #{RUBY_PATH}
          -W0
          -I #{HOMEBREW_LOAD_PATH}
          --
          #{HOMEBREW_LIBRARY_PATH}/test.rb
          #{f.path}
        ].concat(ARGV.options_only)

        if f.head?
          args << "--HEAD"
        elsif f.devel?
          args << "--devel"
        end

        Sandbox.print_sandbox_message if Sandbox.test?

        Utils.safe_fork do
          if Sandbox.test?
            sandbox = Sandbox.new
            f.logs.mkpath
            sandbox.record_log(f.logs/"test.sandbox.log")
            sandbox.allow_write_temp_and_cache
            sandbox.allow_write_log(f)
            sandbox.allow_write_xcode
            sandbox.allow_write_path(HOMEBREW_PREFIX/"var/cache")
            sandbox.allow_write_path(HOMEBREW_PREFIX/"var/log")
            sandbox.allow_write_path(HOMEBREW_PREFIX/"var/run")
            sandbox.exec(*args)
          else
            exec(*args)
          end
        end
      rescue Homebrew::Assertions::AssertionFailed => e<commit_msg>test: use Test::Unit class.<commit_after>#:  * `test` [`--devel`|`--HEAD`] [`--debug`] [`--keep-tmp`] <formula>:
#:    Most formulae provide a test method. `brew test` <formula> runs this
#:    test method. There is no standard output or return code, but it should
#:    generally indicate to the user if something is wrong with the installed
#:    formula.
#:
#:    To test the development or head version of a formula, use `--devel` or
#:    `--HEAD`.
#:
#:    If `--debug` (or `-d`) is passed and the test fails, an interactive debugger will be
#:    launched with access to IRB or a shell inside the temporary test directory.
#:
#:    If `--keep-tmp` is passed, the temporary files created for the test are
#:    not deleted.
#:
#:    Example: `brew install jruby && brew test jruby`

require "extend/ENV"
require "formula_assertions"
require "sandbox"
require "timeout"

module Homebrew
  module_function

  def test
    raise FormulaUnspecifiedError if ARGV.named.empty?

    ARGV.resolved_formulae.each do |f|
      # Cannot test uninstalled formulae
      unless f.installed?
        ofail "Testing requires the latest version of #{f.full_name}"
        next
      end

      # Cannot test formulae without a test method
      unless f.test_defined?
        ofail "#{f.full_name} defines no test"
        next
      end

      # Don't test unlinked formulae
      if !ARGV.force? && !f.keg_only? && !f.linked?
        ofail "#{f.full_name} is not linked"
        next
      end

      puts "Testing #{f.full_name}"

      env = ENV.to_hash

      begin
        args = %W[
          #{RUBY_PATH}
          -W0
          -I #{HOMEBREW_LOAD_PATH}
          --
          #{HOMEBREW_LIBRARY_PATH}/test.rb
          #{f.path}
        ].concat(ARGV.options_only)

        if f.head?
          args << "--HEAD"
        elsif f.devel?
          args << "--devel"
        end

        Sandbox.print_sandbox_message if Sandbox.test?

        Utils.safe_fork do
          if Sandbox.test?
            sandbox = Sandbox.new
            f.logs.mkpath
            sandbox.record_log(f.logs/"test.sandbox.log")
            sandbox.allow_write_temp_and_cache
            sandbox.allow_write_log(f)
            sandbox.allow_write_xcode
            sandbox.allow_write_path(HOMEBREW_PREFIX/"var/cache")
            sandbox.allow_write_path(HOMEBREW_PREFIX/"var/log")
            sandbox.allow_write_path(HOMEBREW_PREFIX/"var/run")
            sandbox.exec(*args)
          else
            exec(*args)
          end
        end
      rescue ::Test::Unit::AssertionFailedError => e
{'fraction_non_alphanumeric': 0.10645349970754533, 'fraction_numerical': 0.0003899395593682979, 'mean_word_length': 2.1185410334346506, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, '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': '3929299', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1544, 'n_words': 450}