Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6fd0b57be658
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 54a925943889
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 25, 2016

  1. Copy the full SHA
    0adbeb6 View commit details
  2. Copy the full SHA
    54a9259 View commit details
Showing with 21 additions and 8 deletions.
  1. +7 −2 spec/ruby/core/kernel/backtick_spec.rb
  2. +14 −6 truffle/src/main/java/org/jruby/truffle/core/kernel/KernelNodes.java
9 changes: 7 additions & 2 deletions spec/ruby/core/kernel/backtick_spec.rb
Original file line number Diff line number Diff line change
@@ -19,6 +19,13 @@
`echo disc #{ip}`.should == "disc world\n"
end

it "lets the standard error stream pass through to the inherited stderr" do
cmd = ruby_cmd('STDERR.print "error stream"')
lambda {
`#{cmd}`.should == ""
}.should output_to_fd("error stream", STDERR)
end

it "produces a String in the default external encoding" do
Encoding.default_external = Encoding::SHIFT_JIS
`echo disc`.encoding.should equal(Encoding::SHIFT_JIS)
@@ -66,8 +73,6 @@
end

describe "Kernel.`" do
it "needs to be reviewed for spec completeness"

it "tries to convert the given argument to String using #to_str" do
(obj = mock('echo test')).should_receive(:to_str).and_return("echo test")
Kernel.`(obj).should == "test\n" #` fix vim syntax highlighting
Original file line number Diff line number Diff line change
@@ -36,7 +36,9 @@
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import jnr.constants.platform.Errno;

import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.common.IRubyWarnings;
@@ -137,15 +139,18 @@
import org.jruby.truffle.language.threadlocal.ThreadLocalObject;
import org.jruby.truffle.platform.UnsafeGroup;
import org.jruby.truffle.util.StringUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.ProcessBuilder.Redirect;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@CoreClass("Kernel")
public abstract class KernelNodes {
@@ -183,18 +188,21 @@ public DynamicObject backtick(VirtualFrame frame, DynamicObject command) {

@TruffleBoundary
private DynamicObject spawnAndCaptureOutput(DynamicObject command, final DynamicObject envAsHash) {
final List<String> envp = new ArrayList<>();
// We need to run via bash to get the variable and other expansion we expect
String[] cmdArray = new String[] { "bash", "-c", command.toString() };

// TODO(CS): cast
ProcessBuilder builder = new ProcessBuilder(cmdArray).redirectError(Redirect.INHERIT);

Map<String, String> env = builder.environment();
env.clear();
for (KeyValue keyValue : HashOperations.iterableKeyValues(envAsHash)) {
envp.add(keyValue.getKey().toString() + "=" + keyValue.getValue().toString());
// TODO(CS): toString
env.put(keyValue.getKey().toString(), keyValue.getValue().toString());
}

final Process process;

try {
// We need to run via bash to get the variable and other expansion we expect
process = Runtime.getRuntime().exec(new String[]{ "bash", "-c", command.toString() }, envp.toArray(new String[envp.size()]));
process = builder.start();
} catch (IOException e) {
throw new JavaException(e);
}