Skip to content

Commit

Permalink
Ensure unlink in #spawn_io
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1eef committed May 17, 2024
1 parent cc22858 commit de269bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ p cmd("ruby", "test.rb").stdout # => "foo\nbar\n"
## Documentation

A complete API reference is available at
[0x1eef.github.io/x/test-cmd.rb](https://0x1eef.github.io/x/test-cmd.rb).
[0x1eef.github.io/x/test-cmd.rb](https://0x1eef.github.io/x/test-cmd.rb)

## Install

Expand All @@ -115,6 +115,6 @@ test-cmd.rb can be installed via rubygems.org:

## License

[BSD Zero Clause](https://choosealicense.com/licenses/0bsd/).
[BSD Zero Clause](https://choosealicense.com/licenses/0bsd/)
<br>
See [LICENSE](./LICENSE).
See [LICENSE](./LICENSE)
12 changes: 7 additions & 5 deletions lib/test/cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ def spawn_io
[
[".testcmd.stdout.#{ns}.", SecureRandom.alphanumeric(3)],
[".testcmd.stderr.#{ns}.", SecureRandom.alphanumeric(3)]
].map {
file = Tempfile.new(_1)
File.chmod(0, file.path)
file.tap(&:unlink)
}
].map do
Tempfile.new(_1).tap do |file|
File.chmod(0, file.path)
ensure
file.unlink
end
end
end

def ns
Expand Down

0 comments on commit de269bf

Please sign in to comment.