<commit_before>#
# This file is responsible for loading/executing any code that exists outside of
# the step definitions. You can also define hooks either here or in another file
# in this directory (e.g. hooks.rb). For more info on hooks, see
# https://github.com/cucumber/cucumber/wiki/Hooks
#
require 'fileutils'
require "capybara"
require "capybara/cucumber"
require "capybara/rspec"
require 'capybara/poltergeist'
require 'selenium-webdriver'
require 'capybara-screenshot/cucumber'

def combineAllDataFiles(dir)
    data = "{"
    Dir.foreach(dir) do |file|
        next if file == '.' || file == '..'
        begin
            original = File.read(File.join(dir, file))
        rescue => err
            printf "ERROR: Dataset file %s could not be read: %s\n", file, err.message
            exit 1
        end
        data << removeWhitespaceAndOuterBrackets(original)
        data << ",\n\n"
    end
    data = data.rstrip.chop
    data << "\n}"
    return data
end

def removeWhitespaceAndOuterBrackets(text)
    text = text.strip
    text = (text[1..-2]).rstrip
    return text
end

def parseJson(data)
    begin
        data = JSON.parse(data)
    rescue => err
        printf "ERROR: Dataset file could not be parsed: %s\n", err.message
        exit 1
    end
    return data
end

#
# Set defaults
Capybara.default_wait_time = 10
Capybara.default_driver = :selenium
Capybara::Screenshot.prune_strategy = :keep_last_run

Capybara.app_host = ENV["APPLICATION_URL"]
if Capybara.app_host.empty?
    #
    # replace with our own default application as necessary
    Capybara.app_host = "http://localhost"
end
printf "Using app_host=%s\n", Capybara.app_host

#
# NOTE: Cucumber does not provide an API to override the output directory
#       for the various foramatters, so we don't use the OUTPUT_DIR env var
#       as an override like the other environment variables. Instead, we
#       use it to set Capybara.save_and_open_page_path assuming that the value
#       of OUTPUT_DIR and the value specified for the --out argument for the
#       HTML formatter are the same.
#
output_dir = ENV["OUTPUT_DIR"]
if output_dir.nil? || output_dir.empty?
    printf "ERROR: OUTPUT_DIR is not defined; check cucumber.yml"
    exit 1
end

if Dir.exists?(output_dir)
    FileUtils.rm_rf(output_dir)
end
Capybara.save_and_open_page_path = output_dir + "/screenshots"
FileUtils.mkdir_p(Capybara.save_and_open_page_path)
printf "Using output directory=%s\n", output_dir

dataset_dir = File.join(ENV["DATASET_DIR"], ENV["DATASET"])<commit_msg>Log the userid used for acceptance tests<commit_after>#
# This file is responsible for loading/executing any code that exists outside of
# the step definitions. You can also define hooks either here or in another file
# in this directory (e.g. hooks.rb). For more info on hooks, see
# https://github.com/cucumber/cucumber/wiki/Hooks
#
require 'fileutils'
require "capybara"
require "capybara/cucumber"
require "capybara/rspec"
require 'capybara/poltergeist'
require 'selenium-webdriver'
require 'capybara-screenshot/cucumber'

def combineAllDataFiles(dir)
    data = "{"
    Dir.foreach(dir) do |file|
        next if file == '.' || file == '..'
        begin
            original = File.read(File.join(dir, file))
        rescue => err
            printf "ERROR: Dataset file %s could not be read: %s\n", file, err.message
            exit 1
        end
        data << removeWhitespaceAndOuterBrackets(original)
        data << ",\n\n"
    end
    data = data.rstrip.chop
    data << "\n}"
    return data
end

def removeWhitespaceAndOuterBrackets(text)
    text = text.strip
    text = (text[1..-2]).rstrip
    return text
end

def parseJson(data)
    begin
        data = JSON.parse(data)
    rescue => err
        printf "ERROR: Dataset file could not be parsed: %s\n", err.message
        exit 1
    end
    return data
end

#
# Set defaults
Capybara.default_wait_time = 10
Capybara.default_driver = :selenium
Capybara::Screenshot.prune_strategy = :keep_last_run

Capybara.app_host = ENV["APPLICATION_URL"]
if Capybara.app_host.empty?
    #
    # replace with our own default application as necessary
    Capybara.app_host = "http://localhost"
end
printf "Using app_host=%s\n", Capybara.app_host
printf "Using userid=%s\n", ENV["APPLICATION_USERID"]

#
# NOTE: Cucumber does not provide an API to override the output directory
#       for the various foramatters, so we don't use the OUTPUT_DIR env var
#       as an override like the other environment variables. Instead, we
#       use it to set Capybara.save_and_open_page_path assuming that the value
#       of OUTPUT_DIR and the value specified for the --out argument for the
#       HTML formatter are the same.
#
output_dir = ENV["OUTPUT_DIR"]
if output_dir.nil? || output_dir.empty?
    printf "ERROR: OUTPUT_DIR is not defined; check cucumber.yml"
    exit 1
end

if Dir.exists?(output_dir)
    FileUtils.rm_rf(output_dir)
end
Capybara.save_and_open_page_path = output_dir + "/screenshots"
FileUtils.mkdir_p(Capybara.save_and_open_page_path)
printf "Using output directory=%s\n", output_dir

dataset_dir = File.join(ENV["DATASET_DIR"], ENV["DATASET"])
{'fraction_non_alphanumeric': 0.09703085581214826, 'fraction_numerical': 0.0027168639627401514, 'mean_word_length': 3.405128205128205, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '2348639', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1673, 'n_words': 503}