<commit_before>require 'abstract_unit'

if defined?(MiniTest) || defined?(Test::Unit::TestResultFailureSupport)
  $stderr.puts "Isolation tests can test test-unit 1 only"

# Does awesome
elsif ENV['CHILD']
  class ChildIsolationTest < ActiveSupport::TestCase
    include ActiveSupport::Testing::Isolation

    def self.setup
      File.open(File.join(File.dirname(__FILE__), "fixtures", "isolation_test"), "a") do |f|
        f.puts "hello"
      end
    end

    def setup
      @instance = "HELLO"
    end

    def teardown
      raise if @boom
    end

    test "runs the test" do
      assert true
    end

    test "captures errors" do
      raise
    end

    test "captures failures" do
      assert false
    end

    test "first runs in isolation" do
      assert_nil $x
      $x = 1
    end

    test "second runs in isolation" do
      assert_nil $x
      $x = 2
    end

    test "runs with slow tests" do
      sleep 0.3
      assert true
      sleep 0.2
    end

    test "runs setup" do
      assert "HELLO", @instance
    end

    test "runs teardown" do
      @boom = true
    end

    test "resets requires one" do
      assert !defined?(OmgOmg)
      assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/omgomg/).size
      require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "omgomg"))
    end

    test "resets requires two" do
      assert !defined?(OmgOmg)
      assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/omgomg/).size
      require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "omgomg"))
    end
  end
else
  class ParentIsolationTest < ActiveSupport::TestCase

    File.open(File.join(File.dirname(__FILE__), "fixtures", "isolation_test"), "w") {}

    ENV["CHILD"] = "1"
    OUTPUT = `#{Gem.ruby} -I#{File.dirname(__FILE__)} "#{File.expand_path(__FILE__)}" -v`
    ENV.delete("CHILD")

    def setup
      # Extract the results<commit_msg>Avoid referencing rubygems<commit_after>require 'abstract_unit'

if defined?(MiniTest) || defined?(Test::Unit::TestResultFailureSupport)
  $stderr.puts "Isolation tests can test test-unit 1 only"

# Does awesome
elsif ENV['CHILD']
  class ChildIsolationTest < ActiveSupport::TestCase
    include ActiveSupport::Testing::Isolation

    def self.setup
      File.open(File.join(File.dirname(__FILE__), "fixtures", "isolation_test"), "a") do |f|
        f.puts "hello"
      end
    end

    def setup
      @instance = "HELLO"
    end

    def teardown
      raise if @boom
    end

    test "runs the test" do
      assert true
    end

    test "captures errors" do
      raise
    end

    test "captures failures" do
      assert false
    end

    test "first runs in isolation" do
      assert_nil $x
      $x = 1
    end

    test "second runs in isolation" do
      assert_nil $x
      $x = 2
    end

    test "runs with slow tests" do
      sleep 0.3
      assert true
      sleep 0.2
    end

    test "runs setup" do
      assert "HELLO", @instance
    end

    test "runs teardown" do
      @boom = true
    end

    test "resets requires one" do
      assert !defined?(OmgOmg)
      assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/omgomg/).size
      require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "omgomg"))
    end

    test "resets requires two" do
      assert !defined?(OmgOmg)
      assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/omgomg/).size
      require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "omgomg"))
    end
  end
else
  class ParentIsolationTest < ActiveSupport::TestCase

    File.open(File.join(File.dirname(__FILE__), "fixtures", "isolation_test"), "w") {}

    ENV["CHILD"] = "1"
    OUTPUT = `ruby -I#{File.dirname(__FILE__)} "#{File.expand_path(__FILE__)}" -v`
    ENV.delete("CHILD")

    def setup
      # Extract the results
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.005241090146750524, 'mean_word_length': 2.6986434108527133, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7041246', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1261, 'n_words': 337}