lino 3.2.0.pre.7 → 3.2.0.pre.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 316b2b5ecae6178261c4b76fedfe0c5797ae50355a94a939f02c115507ba2a37
4
- data.tar.gz: 7ee4b662f7c3b1b5fa7ca3b6aca9d1e2597c5804d12732822bf766cfad2d228f
3
+ metadata.gz: beea9421552cd298e9e5cd1147018e9f441d4d1125a4f0a62b92153d73977420
4
+ data.tar.gz: 041531edbe469e0e33bd2c4f2c88bc725dd9562dbbc3718dba9ee645f7afdd45
5
5
  SHA512:
6
- metadata.gz: 152d8164ab1b7b00deaae2538d18559d872a5fb8800231728d238a34fa0393658134fc41244134288e7b2a6cff8b8962bb48bb5c151104a24aadb798da9149cd
7
- data.tar.gz: b2549104ac5496bb688b3cb61c8b4229bc99af00be5071871dbabd018007603734940f610658f20a8c62a9bd0638d1923e0f3b8631dc873819c812de54084deb
6
+ metadata.gz: a30f3228f4a66df89fb8e9d0f55e7dbfa02aaf81cd5f241103130ca27d2c26463618b95dda82cb13c53c6c7b71312afff7ef0940c6a98a31d4f330aee34a7f3e
7
+ data.tar.gz: 6bcf014ce80d9a2e302978be707f33b1f493d37bef77e360fd30928681dbacce8cb1c19948d759265a920440a6c5bb240fd3f30d2ba3c556ecf37d44bbae22ff
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lino (3.2.0.pre.7)
4
+ lino (3.2.0.pre.9)
5
5
  childprocess (~> 5.0.0)
6
6
  hamster (~> 3.0)
7
7
  open4 (~> 1.3)
@@ -39,7 +39,8 @@ module Lino
39
39
  def start_process(process, opts)
40
40
  process.duplex = true if opts[:stdin]
41
41
  process.start
42
- process.io.stdin.write(opts[:stdin]) if opts[:stdin]
42
+ process.io.stdin.write(opts[:stdin].read) if opts[:stdin]
43
+ process.io.stdin.close if opts[:stdin]
43
44
  end
44
45
 
45
46
  def set_output_streams(process, opts)
@@ -3,7 +3,7 @@
3
3
  module Lino
4
4
  module Executors
5
5
  class Mock
6
- attr_reader :calls
6
+ attr_reader :executions, :stdout_contents, :stderr_contents
7
7
  attr_accessor :exit_code
8
8
 
9
9
  def initialize
@@ -11,7 +11,10 @@ module Lino
11
11
  end
12
12
 
13
13
  def execute(command_line, opts = {})
14
- @calls << { command_line:, opts:, exit_code: @exit_code }
14
+ execution = Execution.new(command_line:, opts:, exit_code: @exit_code)
15
+ execution = process_streams(execution, opts)
16
+
17
+ @executions << execution
15
18
 
16
19
  return if @exit_code.zero?
17
20
 
@@ -20,9 +23,120 @@ module Lino
20
23
  )
21
24
  end
22
25
 
26
+ def fail_all_executions
27
+ self.exit_code = 1
28
+ end
29
+
30
+ def write_to_stdout(contents)
31
+ @stdout_contents = contents
32
+ end
33
+
34
+ def write_to_stderr(contents)
35
+ @stderr_contents = contents
36
+ end
37
+
23
38
  def reset
24
- @calls = []
39
+ @executions = []
25
40
  @exit_code = 0
41
+ @stdout_contents = nil
42
+ @stderr_contents = nil
43
+ end
44
+
45
+ private
46
+
47
+ def process_streams(execution, opts)
48
+ execution = process_stdout(execution, opts[:stdout])
49
+ execution = process_stderr(execution, opts[:stderr])
50
+ process_stdin(execution, opts[:stdin])
51
+ end
52
+
53
+ def process_stdout(execution, stdout)
54
+ if stdout && stdout_contents
55
+ stdout.write(stdout_contents)
56
+ return execution.with_stdout_contents(stdout_contents)
57
+ end
58
+
59
+ execution
60
+ end
61
+
62
+ def process_stderr(execution, stderr)
63
+ if stderr && stderr_contents
64
+ stderr.write(stderr_contents)
65
+ return execution.with_stderr_contents(stderr_contents)
66
+ end
67
+
68
+ execution
69
+ end
70
+
71
+ def process_stdin(execution, stdin)
72
+ return execution.with_stdin_contents(stdin.read) if stdin
73
+
74
+ execution
75
+ end
76
+
77
+ class Execution
78
+ attr_reader :command_line,
79
+ :opts,
80
+ :exit_code,
81
+ :stdin_contents,
82
+ :stdout_contents,
83
+ :stderr_contents
84
+
85
+ def initialize(state)
86
+ @command_line = state[:command_line]
87
+ @opts = state[:opts]
88
+ @exit_code = state[:exit_code]
89
+ @stdin_contents = state[:stdin_contents]
90
+ @stdout_contents = state[:stdout_contents]
91
+ @stderr_contents = state[:stderr_contents]
92
+ end
93
+
94
+ def with_stdin_contents(contents)
95
+ Execution.new(state_hash.merge(stdin_contents: contents))
96
+ end
97
+
98
+ def with_stdout_contents(contents)
99
+ Execution.new(state_hash.merge(stdout_contents: contents))
100
+ end
101
+
102
+ def with_stderr_contents(contents)
103
+ Execution.new(state_hash.merge(stderr_contents: contents))
104
+ end
105
+
106
+ def ==(other)
107
+ self.class == other.class &&
108
+ state_array == other.state_array
109
+ end
110
+
111
+ alias eql? ==
112
+
113
+ def hash
114
+ [self.class, state_array].hash
115
+ end
116
+
117
+ protected
118
+
119
+ def state_array
120
+ [
121
+ @command_line,
122
+ @opts,
123
+ @exit_code,
124
+ @stdin_contents,
125
+ @stdout_contents,
126
+ @stderr_contents
127
+ ]
128
+ end
129
+
130
+ def state_hash
131
+ {
132
+ command_line: @command_line,
133
+ opts: @opts,
134
+ exit_code: @exit_code,
135
+ stdin_contents: @stdin_contents,
136
+ stdout_contents: @stdout_contents,
137
+ stderr_contents: @stderr_contents
138
+ }
139
+ end
26
140
  end
27
141
  end
28
142
  end
data/lib/lino/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lino
4
- VERSION = '3.2.0.pre.7'
4
+ VERSION = '3.2.0.pre.9'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lino
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0.pre.7
4
+ version: 3.2.0.pre.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfraBlocks Maintainers