Sha256: e6a67c2519e4caec031b0179692061fd13bdf40ecbb054ce5f0b84b6b6dde645

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

require_relative 'program/pausable'

module Retest
  class Program
    include Pausable

    attr_accessor :runner, :repository, :command
    def initialize(runner: nil, repository: nil, command: nil, clear_window: true)
      @runner = runner
      @repository = repository
      @command = command
      @clear_window = clear_window
      initialize_pause(false)
    end

    def run(modified, added, removed)
      repository.sync(added: added, removed: removed)
      runner.sync(added: added, removed: removed)

      return if paused?

      clear_terminal
      runner.run (modified + added).first, repository: repository
      yield if block_given?
    end

    def diff(branch)
      raise "Git not installed" unless VersionControl::Git.installed?
      test_files = repository.find_tests VersionControl::Git.diff_files(branch)

      puts "Tests found:"
      test_files.each { |test_file| puts "  - #{test_file}" }

      puts "Running tests..."
      runner.run_all_tests command.format_batch(*test_files)
    end

    def run_synchronously(runner: @runner, prompt: @repository.prompt)
      raise ArgumentError, 'need a block' unless block_given?

      begin
        pause
        old_command_stdin = runner.command_stdin
        old_prompt_stdin = prompt.input
        prompt.input = $stdin
        runner.command_stdin = $stdin
        yield
      ensure
        resume
        runner.command_stdin = old_command_stdin
        prompt.input = old_prompt_stdin
      end
    end

    private

    def clear_terminal
      return unless @clear_window

      system('clear 2>/dev/null') || system('cls 2>/dev/null')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
retest-2.0.0.pre2 lib/retest/program.rb