<commit_before>require 'spec'
require 'pathname'

all_dir = Pathname.new("#{File.dirname __FILE__}/scenarios")
Dir.glob "#{all_dir}/**/*/" do |this_dir|
  relative_path = Pathname.new(this_dir).relative_path_from(all_dir).to_s
  context_name = relative_path.split('/').join(' ').gsub('_', ' ')
  describe context_name do
    define_method :content do |filename|
      path = "#{this_dir}/#{filename}"
      return nil unless File.file?(path)
      content = File.read(path)
      return nil if content.empty?
      content
    end

    define_method :run_and_capture do |options={}|
      stdin_filename = "#{this_dir}/stdin"
      htty_filename = "#{File.dirname __FILE__}/../../bin/htty"
      stderr_target = options[:combine_stdout_and_stderr] ?
                      '&1'                                :
                      "#{this_dir}/actual_stderr"
      arguments = "#{content 'arguments'} 2>#{stderr_target}"
      stdout_filename = "#{this_dir}/actual_stdout"
      system "cat #{stdin_filename} | "         +
             "#{htty_filename} #{arguments} > " +
             "#{this_dir}/actual_stdout"
    end

    it 'should produce the expected stdout' do
      run_and_capture
      content('actual_stdout').should == content('expected_stdout')
    end

    it 'should produce the expected stderr' do<commit_msg>Don't use Ruby v1.9-only syntax<commit_after>require 'spec'
require 'pathname'

all_dir = Pathname.new("#{File.dirname __FILE__}/scenarios")
Dir.glob "#{all_dir}/**/*/" do |this_dir|
  relative_path = Pathname.new(this_dir).relative_path_from(all_dir).to_s
  context_name = relative_path.split('/').join(' ').gsub('_', ' ')
  describe context_name do
    define_method :content do |filename|
      path = "#{this_dir}/#{filename}"
      return nil unless File.file?(path)
      content = File.read(path)
      return nil if content.empty?
      content
    end

    define_method :run_and_capture do |*args|
      options = args.first || {}
      stdin_filename = "#{this_dir}/stdin"
      htty_filename = "#{File.dirname __FILE__}/../../bin/htty"
      stderr_target = options[:combine_stdout_and_stderr] ?
                      '&1'                                :
                      "#{this_dir}/actual_stderr"
      arguments = "#{content 'arguments'} 2>#{stderr_target}"
      stdout_filename = "#{this_dir}/actual_stdout"
      system "cat #{stdin_filename} | "         +
             "#{htty_filename} #{arguments} > " +
             "#{this_dir}/actual_stdout"
    end

    it 'should produce the expected stdout' do
      run_and_capture
      content('actual_stdout').should == content('expected_stdout')
    end

    it 'should produce the expected stderr' do
{'fraction_non_alphanumeric': 0.13804589193190228, 'fraction_numerical': 0.0022205773501110288, 'mean_word_length': 2.6775510204081634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5911966', 'n_tokens_mistral': 841, 'n_tokens_neox': 831, 'n_words': 167}