<commit_before>require File.dirname(__FILE__) + '/helper'

class CliTest < Test::Unit::TestCase
  TEMP_DIR = File.expand_path(File.dirname(__FILE__) + "/tmp")
  BIN_P = File.expand_path(File.dirname(__FILE__) + "/../bin/tracksperanto")
  
  def setup
    Dir.mkdir(TEMP_DIR)
    FileUtils.cp(File.dirname(__FILE__) + "/import/samples/flame_stabilizer/fromCombustion_fromMidClip_wSnap.stabilizer", TEMP_DIR + "/flm.stabilizer")
  end
  
  def teardown
    FileUtils.rm_rf(TEMP_DIR)
  end
  
  # Run the tracksperanto binary with passed options, and return [exit_code, stdout_content, stderr_content]
  def cli(commandline_arguments)
    old_stdout, old_stderr, old_argv = $stdout, $stderr, ARGV.dup
    os, es = StringIO.new, StringIO.new
    begin
      $stdout, $stderr, verbosity = os, es, $VERBOSE
      ARGV.replace(commandline_arguments.split)
      $VERBOSE = false
      load(BIN_P)
      return [0, os.string, es.string]
    rescue Exception => boom # The binary uses exit(), we use that to preserve the output code
      return [boom.status, os.string, es.string] if boom.is_a?(SystemExit)
      raise boom
    ensure
      $VERBOSE = verbosity
      ARGV.replace(old_argv)
      $stdout, $stderr = old_stdout, old_stderr
    end
  end
  
  def test_cli_with_no_args_produces_usage
    status, o, e = cli('')
    assert_equal -1, status
    assert_match /Also use the --help option/, e
  end
  <commit_msg>Change the CLI test to only rescue from SystemExit, as anything else has to go upwards anyway<commit_after>require File.dirname(__FILE__) + '/helper'

class CliTest < Test::Unit::TestCase
  TEMP_DIR = File.expand_path(File.dirname(__FILE__) + "/tmp")
  BIN_P = File.expand_path(File.dirname(__FILE__) + "/../bin/tracksperanto")
  
  def setup
    Dir.mkdir(TEMP_DIR)
    FileUtils.cp(File.dirname(__FILE__) + "/import/samples/flame_stabilizer/fromCombustion_fromMidClip_wSnap.stabilizer", TEMP_DIR + "/flm.stabilizer")
  end
  
  def teardown
    FileUtils.rm_rf(TEMP_DIR)
  end
  
  # Run the tracksperanto binary with passed options, and return [exit_code, stdout_content, stderr_content]
  def cli(commandline_arguments)
    old_stdout, old_stderr, old_argv = $stdout, $stderr, ARGV.dup
    os, es = StringIO.new, StringIO.new
    begin
      $stdout, $stderr, verbosity = os, es, $VERBOSE
      ARGV.replace(commandline_arguments.split)
      $VERBOSE = false
      load(BIN_P)
      return [0, os.string, es.string]
    rescue SystemExit => boom # The binary uses exit(), we use that to preserve the output code
      return [boom.status, os.string, es.string]
    ensure
      $VERBOSE = verbosity
      ARGV.replace(old_argv)
      $stdout, $stderr = old_stdout, old_stderr
    end
  end
  
  def test_cli_with_no_args_produces_usage
    status, o, e = cli('')
    assert_equal -1, status
    assert_match /Also use the --help option/, e
  end
  
{'fraction_non_alphanumeric': 0.10425383542538354, 'fraction_numerical': 0.001394700139470014, 'mean_word_length': 3.4968652037617556, 'pattern_counts': {'":': 0, '<': 5, '<?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': '717706', 'n_tokens_mistral': 988, 'n_tokens_neox': 974, 'n_words': 238}