Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
8604cdb1
Unverified
Commit
8604cdb1
authored
4 years ago
by
Mike McQuaid
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #8541 from claui/fix-patch-stdout
Return standard output in `popen_write`
parents
64eaa80c
09d7889e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Library/Homebrew/test/utils/popen_spec.rb
+40
-2
40 additions, 2 deletions
Library/Homebrew/test/utils/popen_spec.rb
Library/Homebrew/utils/popen.rb
+22
-2
22 additions, 2 deletions
Library/Homebrew/utils/popen.rb
with
62 additions
and
4 deletions
Library/Homebrew/test/utils/popen_spec.rb
+
40
−
2
View file @
8604cdb1
...
...
@@ -26,11 +26,49 @@ describe Utils do
end
describe
"::popen_write"
do
it
"with supports writing to a command's standard input"
do
let
(
:foo
)
{
mktmpdir
/
"foo"
}
before
{
foo
.
write
"Foo
\n
"
}
it
"supports writing to a command's standard input"
do
subject
.
popen_write
(
"grep"
,
"-q"
,
"success"
)
do
|
pipe
|
pipe
.
write
(
"success
\n
"
)
pipe
.
write
"success
\n
"
end
expect
(
$CHILD_STATUS
).
to
be_a_success
end
it
"returns the command's standard output before writing"
do
child_stdout
=
subject
.
popen_write
(
"cat"
,
foo
,
"-"
)
do
|
pipe
|
pipe
.
write
"Bar
\n
"
end
expect
(
$CHILD_STATUS
).
to
be_a_success
expect
(
child_stdout
).
to
eq
<<~
EOS
Foo
Bar
EOS
end
it
"returns the command's standard output after writing"
do
child_stdout
=
subject
.
popen_write
(
"cat"
,
"-"
,
foo
)
do
|
pipe
|
pipe
.
write
"Bar
\n
"
end
expect
(
$CHILD_STATUS
).
to
be_a_success
expect
(
child_stdout
).
to
eq
<<~
EOS
Bar
Foo
EOS
end
it
"supports interleaved writing between two reads"
do
child_stdout
=
subject
.
popen_write
(
"cat"
,
foo
,
"-"
,
foo
)
do
|
pipe
|
pipe
.
write
"Bar
\n
"
end
expect
(
$CHILD_STATUS
).
to
be_a_success
expect
(
child_stdout
).
to
eq
<<~
EOS
Foo
Bar
Foo
EOS
end
end
end
This diff is collapsed.
Click to expand it.
Library/Homebrew/utils/popen.rb
+
22
−
2
View file @
8604cdb1
# frozen_string_literal: true
module
Utils
IO_DEFAULT_BUFFER_SIZE
=
4096
private_constant
:IO_DEFAULT_BUFFER_SIZE
def
self
.
popen_read
(
*
args
,
**
options
,
&
block
)
popen
(
args
,
"rb"
,
options
,
&
block
)
end
...
...
@@ -12,8 +15,25 @@ module Utils
raise
ErrorDuringExecution
.
new
(
args
,
status:
$CHILD_STATUS
,
output:
[[
:stdout
,
output
]])
end
def
self
.
popen_write
(
*
args
,
**
options
,
&
block
)
popen
(
args
,
"wb"
,
options
,
&
block
)
def
self
.
popen_write
(
*
args
,
**
options
)
popen
(
args
,
"w+b"
,
options
)
do
|
pipe
|
output
=
""
# Before we yield to the block, capture as much output as we can
loop
do
output
+=
pipe
.
read_nonblock
(
IO_DEFAULT_BUFFER_SIZE
)
rescue
IO
::
WaitReadable
,
EOFError
break
end
yield
pipe
pipe
.
close_write
IO
.
select
([
pipe
])
# Capture the rest of the output
output
+=
pipe
.
read
output
.
freeze
end
end
def
self
.
safe_popen_write
(
*
args
,
**
options
,
&
block
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment