Class: TestBench::Executable

Inherits:
Object
  • Object
show all
Defined in:
lib/test_bench/executable/defaults.rb,
lib/test_bench/executable/executable.rb,
lib/test_bench/executable/controls/run.rb,
lib/test_bench/executable/controls/path.rb,
lib/test_bench/executable/controls/random.rb,
lib/test_bench/executable/parse_arguments.rb,
lib/test_bench/executable/controls/standard_input.rb

Defined Under Namespace

Modules: Controls, Defaults Classes: ParseArguments

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsObject



8
9
10
# File 'lib/test_bench/executable/executable.rb', line 8

def arguments
  @arguments ||= []
end

#runObject



3
4
5
# File 'lib/test_bench/executable/executable.rb', line 3

def run
  @run ||= Run::Substitute.build
end

#stdinObject



13
14
15
# File 'lib/test_bench/executable/executable.rb', line 13

def stdin
  @stdin ||= STDIN
end

Class Method Details

.build(arguments = nil, env: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/test_bench/executable/executable.rb', line 18

def self.build(arguments=nil, env: nil)
  instance = new

  arguments = ParseArguments.(arguments, env:)
  instance.arguments = arguments

  Run.configure(instance)

  instance
end

.call(arguments = nil, env: nil) ⇒ Object



29
30
31
32
# File 'lib/test_bench/executable/executable.rb', line 29

def self.call(arguments=nil, env: nil)
  instance = build(arguments, env:)
  instance.()
end

Instance Method Details

#callObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/test_bench/executable/executable.rb', line 34

def call
  result = run.() do
    if not stdin.tty?
      until stdin.eof?
        path = stdin.gets(chomp: true)

        next if path.empty?

        run << path
      end
    end

    arguments.each do |path|
      run << path
    end

    if not run.ran?
      run << Defaults.path
    end
  end

  exit_code = result ? 0 : 1
  exit_code
end