Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
9620191c
Commit
9620191c
authored
Jun 04, 2015
by
Boris Bügling
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3626 from CocoaPods/seg-executable-readpartial
[Executable] Use readpartial instead of gets
parents
a1a6919b
0fad2b4f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
9 deletions
+81
-9
executable.rb
lib/cocoapods/executable.rb
+26
-9
executable_spec.rb
spec/unit/executable_spec.rb
+55
-0
No files found.
lib/cocoapods/executable.rb
View file @
9620191c
...
@@ -64,7 +64,7 @@ module Pod
...
@@ -64,7 +64,7 @@ module Pod
end
end
status
=
popen3
(
bin
,
command
,
stdout
,
stderr
)
status
=
popen3
(
bin
,
command
,
stdout
,
stderr
)
output
=
stdout
.
join
(
"
\n
"
)
+
stderr
.
join
(
"
\n
"
)
output
=
stdout
.
join
+
stderr
.
join
unless
status
.
success?
unless
status
.
success?
if
raise_on_failure
if
raise_on_failure
raise
Informative
,
"
#{
full_command
}
\n\n
#{
output
}
"
raise
Informative
,
"
#{
full_command
}
\n\n
#{
output
}
"
...
@@ -80,19 +80,37 @@ module Pod
...
@@ -80,19 +80,37 @@ module Pod
def
self
.
popen3
(
bin
,
command
,
stdout
,
stderr
)
def
self
.
popen3
(
bin
,
command
,
stdout
,
stderr
)
require
'open3'
require
'open3'
Open3
.
popen3
(
bin
,
*
command
)
do
|
i
,
o
,
e
,
t
|
Open3
.
popen3
(
bin
,
*
command
)
do
|
i
,
o
,
e
,
t
|
Thread
.
new
{
while
s
=
o
.
gets
;
stdout
<<
s
;
end
}
reader
(
o
,
stdout
)
Thread
.
new
{
while
s
=
e
.
gets
;
stderr
<<
s
;
end
}
reader
(
e
,
stderr
)
i
.
close
i
.
close
status
=
t
.
value
status
=
t
.
value
o
.
flush
e
.
flush
sleep
(
0.1
)
status
status
end
end
end
end
def
self
.
reader
(
input
,
output
)
Thread
.
new
do
buf
=
''
begin
loop
do
buf
<<
input
.
readpartial
(
4096
)
loop
do
string
,
separator
,
buf
=
buf
.
partition
(
/[\r\n]/
)
if
separator
.
empty?
buf
=
string
break
end
output
<<
(
string
<<
separator
)
end
end
rescue
EOFError
output
<<
(
buf
<<
$/
)
unless
buf
.
empty?
end
end
end
#-------------------------------------------------------------------------#
#-------------------------------------------------------------------------#
# Helper class that allows to write to an {IO} instance taking into account
# Helper class that allows to write to an {IO} instance taking into account
...
@@ -125,8 +143,7 @@ module Pod
...
@@ -125,8 +143,7 @@ module Pod
#
#
def
<<
(
value
)
def
<<
(
value
)
super
super
ensure
io
<<
"
#{
indent
}#{
value
}
"
if
io
@io
<<
"
#{
indent
}#{
value
}
"
if
@io
end
end
end
end
end
end
...
...
spec/unit/executable_spec.rb
View file @
9620191c
...
@@ -29,5 +29,60 @@ module Pod
...
@@ -29,5 +29,60 @@ module Pod
Executable
.
execute_command
(
'ruby'
,
cmd
,
true
).
should
==
"out
\n
"
Executable
.
execute_command
(
'ruby'
,
cmd
,
true
).
should
==
"out
\n
"
end
end
end
end
it
'returns the right output'
do
cmd
=
[
'-e'
,
<<-
RB
]
puts 'foo'
puts 'bar'
RB
Executable
.
execute_command
(
'ruby'
,
cmd
,
true
).
should
==
"foo
\n
bar
\n
"
end
it
'handles an EOFError'
do
cmd
=
[
'-e'
,
<<-
RB
]
puts 'foo'
print 'bar'
RB
Executable
.
execute_command
(
'ruby'
,
cmd
,
true
).
should
==
"foo
\n
bar
#{
$/
}
"
end
it
'handles a large amount of output'
do
cmd
=
[
'-e'
,
<<-
RB
]
puts File.read(
#{
__FILE__
.
inspect
}
)
RB
Executable
.
execute_command
(
'ruby'
,
cmd
,
true
).
should
==
File
.
read
(
__FILE__
)
end
it
'handles carriage returns'
do
cmd
=
[
'-e'
,
<<-
RB
]
print "foo
\\
rbar
\\
nbaz
\\
r"
RB
Executable
.
execute_command
(
'ruby'
,
cmd
,
true
).
should
==
"foo
\r
bar
\n
baz
\r
"
end
it
'prints the correct output to the console'
do
io
=
''
UI
.
indentation_level
=
1
config
.
verbose
=
true
Executable
::
Indenter
.
any_instance
.
stubs
(
:io
).
returns
(
io
)
cmd
=
[
'-e'
,
<<-
RB
]
3.times { |i| puts i }
RB
Executable
.
execute_command
(
'ruby'
,
cmd
,
true
)
io
.
should
==
" 0
\n
1
\n
2
\n
"
end
describe
Executable
::
Indenter
do
it
'indents any appended strings'
do
UI
.
indentation_level
=
4
io
=
StringIO
.
new
indenter
=
Executable
::
Indenter
.
new
(
io
)
indenter
<<
'hello'
io
.
string
.
should
==
' hello'
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment