Ruby environment variables do not always appear as Java environment variables 
to new processes
----------------------------------------------------------------------------------------------

                 Key: JRUBY-1579
                 URL: http://jira.codehaus.org/browse/JRUBY-1579
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.1b1, JRuby 1.0.2, JRuby 1.0.0
         Environment: OS X 10.4.11 with Java 1.5
            Reporter: Matt Fletcher
            Priority: Minor
         Attachments: other_program, other_program.rb, 
test_backquotes_pass_environment.rb

Here's another bug related to spawning new processes with backquotes. This 
time, if you set some variables in your Ruby program's ENV, new JRuby processes 
will not always see them as Java environment variables.

Attached is a test case demonstrating this behavior. The test case uses 
backquotes to start up a new JRuby program in a variety of ways; the new 
environment variables will show up in the new program in some cases, but not 
others.

Paste of test case:
{noformat}
require "test/unit"

class BackquotesEnvironmentTest < Test::Unit::TestCase
  def test_backquotes_pass_environment_variables_from_ruby_environment
    ENV["ONE"] = nil
    ENV["TWO"] = nil
    assert_equal "ONE:  TWO: ", `./other_program`, "variables should have been 
unset"

    ENV["ONE"] = "aaa"
    ENV["TWO"] = "bbb"
    results_with_variables_set = "ONE: aaa TWO: bbb"
    assert_equal results_with_variables_set, `./other_program`, "wrong 
variables when run straight up"
    assert_equal results_with_variables_set, `THREE=four jruby 
./other_program`, "wrong variables when tricking backquotes"
    assert_equal results_with_variables_set, `jruby ./other_program`, "wrong 
variables when run with jruby"
    assert_equal results_with_variables_set, `./other_program.rb`, "wrong 
variables when run with rb suffix"
  end
end
{noformat}

Paste of result:
{noformat}
Loaded suite test_backquotes_pass_environment
Started
F
Finished in 3.363 seconds.

  1) Failure:
test_backquotes_pass_environment_variables_from_ruby_environment(BackquotesEnvironmentTest)
 [test_backquotes_pass_environment.rb:14]:
wrong variables when run with jruby.
<"ONE: aaa TWO: bbb"> expected but was
<"ONE:  TWO: ">.

1 tests, 4 assertions, 1 failures, 0 errors
{noformat}

Note that in the test failed on the line spawning the new application when it 
has a 'jruby' prefix. This is because that prefix causes JRuby to not actually 
spawn a new process. The previous two assertions demonstrate that when a new 
process is created, the variables do show up correctly. (See how I tricked 
JRuby into creating a new process on line 13?)

I ran into this problem because I, unfortunately, need to use a Java library 
that digs into environment variables to get some of its configuration data. My 
system tests were setting up the environment for my application and then firing 
it up with backqoutes, but since that Java library is using Java's accessors to 
the environment, it wasn't seeing my configuration. Bummer. (To get by for now 
I'm using the trick shown on line 13 of the above test case.)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to