Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Process tests and documents #10148

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,12 @@ static rb_io_t *flush_before_seek(rb_io_t *fptr);

extern ID ruby_static_id_signo;

NORETURN(static void raise_on_write(rb_io_t *fptr, int e, VALUE errinfo));
NORETURN(static void rb_sys_fail_on_write(rb_io_t *fptr));
static void
raise_on_write(rb_io_t *fptr, int e, VALUE errinfo)
rb_sys_fail_on_write(rb_io_t *fptr)
{
int e = errno;
VALUE errinfo = rb_syserr_new_path(e, (fptr)->pathv);
#if defined EPIPE
if (fptr_signal_on_epipe(fptr) && (e == EPIPE)) {
const VALUE sig =
Expand All @@ -550,12 +552,6 @@ raise_on_write(rb_io_t *fptr, int e, VALUE errinfo)
rb_exc_raise(errinfo);
}

#define rb_sys_fail_on_write(fptr) \
do { \
int e = errno; \
raise_on_write(fptr, e, rb_syserr_new_path(e, (fptr)->pathv)); \
} while (0)

#define NEED_NEWLINE_DECORATOR_ON_READ(fptr) ((fptr)->mode & FMODE_TEXTMODE)
#define NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) ((fptr)->mode & FMODE_TEXTMODE)
#if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
Expand Down
15 changes: 14 additions & 1 deletion process.c
Original file line number Diff line number Diff line change
Expand Up @@ -8865,7 +8865,7 @@ proc_warmup(VALUE _)
*
* Argument +exe_path+ is one of the following:
*
* - The string path to an executable to be called:
* - The string path to an executable file to be called:
*
* Example:
*
Expand All @@ -8881,6 +8881,19 @@ proc_warmup(VALUE _)
* escape the entire command name using a shell in platform
* dependent manner, or use the array form below.
*
* If +exe_path+ does not contain any path separator, an executable
* file is searched from directories specified with the +PATH+
* environment variable. What the word "executable" means here is
* depending on platforms.
*
* Even if the file considered "executable", its content may not be
* in proper executable format. In that case, Ruby tries to run it
* by using <tt>/bin/sh</tt> on a Unix-like system, like system(3)
* does.
*
* File.write('shell_command', 'echo $SHELL', perm: 0o755)
* system('./shell_command') # prints "/bin/sh" or something.
*
* - A 2-element array containing the path to an executable
* and the string to be used as the name of the executing process:
*
Expand Down
17 changes: 17 additions & 0 deletions spec/ruby/core/kernel/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@
end
end

platform_is_not :windows do
before :each do
require 'tmpdir'
@shell_command = File.join(Dir.mktmpdir, "noshebang.cmd")
File.write(@shell_command, %[echo "$PATH"\n], perm: 0o700)
end

after :each do
File.unlink(@shell_command)
Dir.rmdir(File.dirname(@shell_command))
end

it "executes with `sh` if the command is executable but not binary and there is no shebang" do
-> { @object.system(@shell_command) }.should output_to_fd(ENV['PATH'] + "\n")
end
end

before :each do
ENV['TEST_SH_EXPANSION'] = 'foo'
@shell_var = '$TEST_SH_EXPANSION'
Expand Down