<commit_before># Copyright (c) 2015 AppNeta, Inc.
# All rights reserved.

require 'rubygems'
require 'bundler/setup'
require "minitest/spec"
require "minitest/autorun"
require "minitest/reporters"
require "minitest/debugger" if ENV['DEBUG']
require "sinatra"

require "minitest/hell"
class Minitest::Test
  # parallelize_me!
end

ENV["RACK_ENV"] = "test"
ENV["TRACEVIEW_GEM_TEST"] = "true"
ENV["TRACEVIEW_GEM_VERBOSE"] = "true"

# FIXME: Temp hack to fix padrino-core calling RUBY_ENGINE when it's
# not defined under Ruby 1.8.7 and 1.9.3
RUBY_ENGINE = "ruby" unless defined?(RUBY_ENGINE)

Minitest::Spec.new 'pry'

unless RUBY_VERSION =~ /^1.8/
  MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
end

if defined?(JRUBY_VERSION)
  ENV['JAVA_OPTS'] = "-J-javaagent:/usr/local/tracelytics/tracelyticsagent.jar"
end

@trace_dir = "/tmp/"
$trace_file = @trace_dir + "trace_output.bson"

Bundler.require(:default, :test)

# Configure TraceView
TraceView::Config[:verbose] = true
TraceView::Config[:tracing_mode] = "always"
TraceView::Config[:sample_rate] = 1000000
TraceView.logger.level = Logger::DEBUG

# Pre-create test databases (see also .travis.yml)
# puts "Pre-creating test databases"
# puts %x{mysql -u root -e 'create database travis_ci_test;'}
# puts %x{psql -c 'create database travis_ci_test;' -U postgres}

# Our background Rack-app for http client testing
require './test/servers/rackapp_8101'

# Conditionally load other background servers
# depending on what we're testing
#
case File.basename(ENV['BUNDLE_GEMFILE'])
when /rails4/
  require "./test/servers/rails4x_8140"
  require './test/servers/delayed_job'
when /rails3/
  require "./test/servers/rails3x_8140"
  require './test/servers/delayed_job'
when /frameworks/
when /libraries/
  if RUBY_VERSION >= '2.0'
    # Load Sidekiq if TEST isn't defined or if it is, it calls
    # out the sidekiq tests
    if !ENV.key?('TEST') || ENV['TEST'] =~ /sidekiq/
      # Background Sidekiq thread
      require './test/servers/sidekiq.rb'
    end
  end
end

##
# clear_all_traces
#
# Truncates the trace output file to zero
#
def clear_all_traces
  if TraceView.loaded
    TraceView::Reporter.clear_all_traces
  end
end

##
# get_all_traces
#
# Retrieves all traces written to the trace file<commit_msg>Fix quoting style<commit_after># Copyright (c) 2015 AppNeta, Inc.
# All rights reserved.

require 'rubygems'
require 'bundler/setup'
require "minitest/spec"
require "minitest/autorun"
require "minitest/reporters"
require "minitest/debugger" if ENV['DEBUG']
require "sinatra"

require "minitest/hell"
class Minitest::Test
  # parallelize_me!
end

ENV["RACK_ENV"] = "test"
ENV["TRACEVIEW_GEM_TEST"] = "true"
ENV["TRACEVIEW_GEM_VERBOSE"] = "true"

# FIXME: Temp hack to fix padrino-core calling RUBY_ENGINE when it's
# not defined under Ruby 1.8.7 and 1.9.3
RUBY_ENGINE = "ruby" unless defined?(RUBY_ENGINE)

Minitest::Spec.new 'pry'

unless RUBY_VERSION =~ /^1.8/
  MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
end

if defined?(JRUBY_VERSION)
  ENV['JAVA_OPTS'] = "-J-javaagent:/usr/local/tracelytics/tracelyticsagent.jar"
end

@trace_dir = "/tmp/"
$trace_file = @trace_dir + "trace_output.bson"

Bundler.require(:default, :test)

# Configure TraceView
TraceView::Config[:verbose] = true
TraceView::Config[:tracing_mode] = "always"
TraceView::Config[:sample_rate] = 1000000
TraceView.logger.level = Logger::DEBUG

# Pre-create test databases (see also .travis.yml)
# puts "Pre-creating test databases"
# puts %x{mysql -u root -e 'create database travis_ci_test;'}
# puts %x{psql -c 'create database travis_ci_test;' -U postgres}

# Our background Rack-app for http client testing
require './test/servers/rackapp_8101'

# Conditionally load other background servers
# depending on what we're testing
#
case File.basename(ENV['BUNDLE_GEMFILE'])
when /rails4/
  require './test/servers/rails4x_8140'
  require './test/servers/delayed_job'
when /rails3/
  require './test/servers/rails3x_8140'
  require './test/servers/delayed_job'
when /frameworks/
when /libraries/
  if RUBY_VERSION >= '2.0'
    # Load Sidekiq if TEST isn't defined or if it is, it calls
    # out the sidekiq tests
    if !ENV.key?('TEST') || ENV['TEST'] =~ /sidekiq/
      # Background Sidekiq thread
      require './test/servers/sidekiq.rb'
    end
  end
end

##
# clear_all_traces
#
# Truncates the trace output file to zero
#
def clear_all_traces
  if TraceView.loaded
    TraceView::Reporter.clear_all_traces
  end
end

##
# get_all_traces
#
# Retrieves all traces written to the trace file
{'fraction_non_alphanumeric': 0.12604303908651734, 'fraction_numerical': 0.016249451032059728, 'mean_word_length': 4.729559748427673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2848299', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1672, 'n_words': 413}