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

Test is failing with Rubinius #36

Closed
rogerleite opened this issue Aug 10, 2011 · 12 comments
Closed

Test is failing with Rubinius #36

rogerleite opened this issue Aug 10, 2011 · 12 comments

Comments

@rogerleite
Copy link
Contributor

$ruby -v
rubinius 1.2.5dev (1.8.7 9b88cd26 yyyy-mm-dd JI) [i686-pc-linux-gnu]

$uname -a
Linux HDU64511 2.6.38-10-generic-pae #46-Ubuntu SMP Tue Jun 28 16:54:49 UTC 2011 i686 i686 i386 GNU/Linux

$rake test

/home/roger/.rvm/rubies/rbx-master/bin/rbx -I"lib:spec" -I"/home/roger/.rvm/gems/rbx-master@global/gems/rake-0.9.2/lib" "/home/roger/.rvm/gems/rbx-master@global/gems/rake-0.9.2/lib/rake/rake_test_loader.rb" "spec/rack/webconsole_spec.rb" "spec/rack/webconsole/sandbox_spec.rb" "spec/rack/webconsole/asset_helpers_spec.rb" "spec/rack/webconsole/assets_spec.rb" "spec/rack/webconsole/repl_spec.rb"
Run options: --seed 37563

Running tests:

...encoding options not supported in 1.8
.encoding options not supported in 1.8
.encoding options not supported in 1.8
...encoding options not supported in 1.8
encoding options not supported in 1.8
encoding options not supported in 1.8
.encoding options not supported in 1.8
encoding options not supported in 1.8
encoding options not supported in 1.8
.encoding options not supported in 1.8
encoding options not supported in 1.8
encoding options not supported in 1.8
.....encoding options not supported in 1.8
encoding options not supported in 1.8
encoding options not supported in 1.8
...F.............

Finished tests in 0.562222s, 56.9170 tests/s, 124.5060 assertions/s.

  1. Failure:
    test_0002_maintains_local_state_in_subsequent_calls_thanks_to_an_evil_global_variable(Rack::Webconsole::Repl::#call) [/home/roger/dev/trivial/rack-webconsole/spec/rack/webconsole/repl_spec.rb:44]:
    --- expected
    +++ actual
    @@ -1 +1 @@
    -"32"
    +"Error: undefined local variable or method `a' on an instance of Rack::Webconsole::Sandbox."

32 tests, 70 assertions, 1 failures, 0 errors, 0 skips
rake aborted!
Command failed with status (1): [/home/roger/.rvm/rubies/rbx-master/bin/rbx...]

Tasks: TOP => test
(See full trace by running task with --trace)

@rogerleite
Copy link
Contributor Author

I lost some time debugging ... i think the problem is with local_variables.
At this line:
ls = (local_variables.map(&:to_sym) - [#{boilerplate.map(&:inspect).join(', ')}])

In Rubinius, "ls" is always empty and should not be, should return "new variables".
I don't know how to fix it.

@txus
Copy link
Member

txus commented Aug 10, 2011

Yes, I've rn into this too. I spent some time debugging too but couldn't found what the problem was.

A couple days ago I opened a similar issue in Rubinius but it happened only when using IRB (they might be related though):
rubinius/rubinius#1107

@rogerleite
Copy link
Contributor Author

$ruby -v
rubinius 1.2.5dev (1.8.7 9b88cd26 yyyy-mm-dd JI) [i686-pc-linux-gnu]

I did a test_rbx.rb in the project's root:

require 'rubygems'
require 'rack/webconsole'

begin
  $sandbox = Rack::Webconsole::Sandbox.new

  old_local_variables = local_variables.map(&:to_sym)
  puts "current local_variables:       #{old_local_variables.inspect}"

  params = "a = 4"
  result = $sandbox.instance_eval """
    result = (#{params})
    ls = local_variables.map(&:to_sym)
    puts 'instance eval local_variables: ' + ls.inspect
    ls = (ls - [#{old_local_variables.map(&:inspect).join(', ')}])
    puts 'ls: ' + ls.inspect
    result
  """

  puts "result: #{result}"
rescue=> e
  puts "error: #{e.message}"
end

When a execute ruby -I lib/ test_rbx.rb, i get right output.

current local_variables:       [:old_local_variables, :params, :result, :e]
instance eval local_variables: [:a, :ls, :old_local_variables, :params, :result, :e]
ls: [:a, :ls]
result: 4

I can't simulate the problem.

@rogerleite
Copy link
Contributor Author

Updating information ...
The problem is "evaluating the local variable" ... i improved the test_rbx.rb

require 'rubygems'
require 'rack/webconsole'

module Rack
  class Webconsole

    class Test

      class << self
        def go(query)
        params = {}
        params['query'] = query

        result = begin
          $sandbox ||= Sandbox.new

          # Force conversion to symbols due to issues with lovely 1.8.7
          boilerplate = local_variables.map(&:to_sym) + [:ls]

          result = $sandbox.instance_eval """
            result = (#{params['query']})
            ls = (local_variables.map(&:to_sym) - [#{boilerplate.map(&:inspect).join(', ')}])
            @locals ||= {}
            @locals.update(ls.inject({}) do |hash, value|
              puts 'local name: ' + value.inspect + ' value: ' + eval(value.to_s).inspect
              hash.update({value => eval(value.to_s)})
            end)
            result
          """
          puts "$sandbox: #{$sandbox.inspect}"

          result.inspect
        rescue=>e
          "Error: " + e.message
        end

        end

      end
    end

  end
end

puts 'result: ' + Rack::Webconsole::Test.go('a = 4').inspect
puts 'result: ' + Rack::Webconsole::Test.go('a * 8').inspect

With rubinus, when i execute, i receive:

local name: :a value: nil
$sandbox: #<Rack::Webconsole::Sandbox:0x1384 @locals={:a=>nil}>
result: "4"
result: "Error: undefined local variable or method `a' on an instance of Rack::Webconsole::Sandbox."

With 1.9.3, i receive:

local name: :a value: 4
$sandbox: #<Rack::Webconsole::Sandbox:0x83b4acc @locals={:a=>4}>
result: "4"
$sandbox: #<Rack::Webconsole::Sandbox:0x83b4acc @locals={:a=>4}>
result: "32"

@rogerleite
Copy link
Contributor Author

I found the problem!
Later i'll send a pull request, now work is calling! :X

@txus
Copy link
Member

txus commented Aug 11, 2011

Great! Can't wait to see what it was :)

@rogerleite
Copy link
Contributor Author

Hi txus!
I did a quick and dirty fix. You can see here
I'm planning to make a evaluate method at Repl, just to be more clean. What do you think?

@txus
Copy link
Member

txus commented Aug 13, 2011

Your patch is fine! And thanks to it, I've been able to reproduce the bug in rbx and rbx-2.0.0pre.

The thing is: in rbx, using instance_eval with a string breaks inner eval'ing of local variables.

But since this is an rbx bug and not rack-webconsole's, I prefer not to merge the patch and wait until the bug in rbx is fixed. I've opened a pull request with a failing spec and will try to work on this. If you find the solution please comment there and submit a pull request as well! :) I'll keep you posted anyway.

@rogerleite
Copy link
Contributor Author

Ok, thanks for reply!
I tried to use eval with sandbox's binding, but i have problems with 1.9.3.

@txus
Copy link
Member

txus commented Jan 18, 2012

This was already fixed in Rubinius, but now some tests fail, mostly regarding to multiline stuff. Nevertheless, ripl-multi_line passes all its tests with rbx, so I'm not sure what's wrong.

@txus
Copy link
Member

txus commented Sep 14, 2012

@rogerleite any thoughts on what's wrong with ripl-multiline and rack-webconsole? :)

@txus
Copy link
Member

txus commented Sep 19, 2013

Closing this until we get more insight into the ripl-multiline failures. Feel free to reopen.

@txus txus closed this as completed Sep 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants