<commit_before>require 'io/wait'
require 'open3'

class ::Guard::Haskell::Repl
  attr_reader :stdin, :reader, :thread, :success

  def start ghci_options
    cmd = ["ghci"]
    Dir["*"].each { |x| cmd << "-i#{x}" }
    sandbox = ::Dir[".cabal-sandbox/*packages.conf.d"].first
    cmd << "-package-db=#{sandbox}" if sandbox
    cmd.concat(ghci_options)

    @stdin, stdout, @thread = ::Open3.popen2e(*cmd)
    @reader = ::Thread.new do
      loop do
        n = stdout.nread
        if n > 0
          out = stdout.read(n)
          print out
          case out
          when /\d+ examples?, 0 failures/
            @success = true
            @running = false
          when /\d+ examples?, \d+ failures?/, /Failed, modules loaded:/, /\*{3} Exception:/
            @success = false
            @running = false
          end
        else
          sleep(0.1)
        end
      end<commit_msg>Do not hang up on preprocessor failures<commit_after>require 'io/wait'
require 'open3'

class ::Guard::Haskell::Repl
  attr_reader :stdin, :reader, :thread, :success

  def start ghci_options
    cmd = ["ghci"]
    Dir["*"].each { |x| cmd << "-i#{x}" }
    sandbox = ::Dir[".cabal-sandbox/*packages.conf.d"].first
    cmd << "-package-db=#{sandbox}" if sandbox
    cmd.concat(ghci_options)

    @stdin, stdout, @thread = ::Open3.popen2e(*cmd)
    @reader = ::Thread.new do
      loop do
        n = stdout.nread
        if n > 0
          out = stdout.read(n)
          print out
          case out
          when /\d+ examples?, 0 failures/
            @success = true
            @running = false
          when /\d+ examples?, \d+ failures?/,
               /Failed, modules loaded:/,
               /\*{3} Exception:/,
               /phase `C preprocessor' failed/
            @success = false
            @running = false
          end
        else
          sleep(0.1)
        end
      end
{'fraction_non_alphanumeric': 0.1433862433862434, 'fraction_numerical': 0.008465608465608466, 'mean_word_length': 1.748546511627907, 'pattern_counts': {'":': 0, '<': 11, '<?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': '1327912', 'n_tokens_mistral': 617, 'n_tokens_neox': 599, 'n_words': 159}