Skip to content

Commit

Permalink
Merge branch 'master' into rbx-2-3-0
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Nov 13, 2014
2 parents 4535bf1 + bce3240 commit a0e830b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
15 changes: 15 additions & 0 deletions lib/lotus/utils.rb
Expand Up @@ -2,6 +2,21 @@

module Lotus
# Ruby core extentions and Lotus utilities
#
# @since 0.1.0
module Utils
# @since x.x.x
# @api private
LOTUS_JRUBY_PLATFORM = 'java'.freeze

# Checks if the current VM is JRuby
#
# @return [TrueClass,FalseClass] return if the VM is JRuby or not
#
# @since x.x.x
# @api private
def self.jruby?
RUBY_PLATFORM == LOTUS_JRUBY_PLATFORM
end
end
end
5 changes: 4 additions & 1 deletion lib/lotus/utils/deprecation.rb
@@ -1,3 +1,5 @@
require 'lotus/utils'

module Lotus
module Utils
# Prints a deprecation warning when initialized
Expand Down Expand Up @@ -56,7 +58,8 @@ class Deprecation
# # => old_method is deprecated, please use new_method - called from: test.rb:20:in `start'.
# # => started
def initialize(message)
::Kernel.warn("#{ message } - called from: #{ caller[2] }.")
stack_index = Utils.jruby? ? 1 : 2
::Kernel.warn("#{ message } - called from: #{ caller[stack_index] }.")
end
end
end
Expand Down
9 changes: 7 additions & 2 deletions test/deprecation_test.rb
Expand Up @@ -27,8 +27,13 @@ def run
DeprecationTest.new.old_method
end

stack = $0 == __FILE__ ? "#{ __FILE__ }:27:in `block (3 levels) in <main>'" :
"#{ __FILE__ }:27:in `block (3 levels) in <top (required)>'"
stack = if RUBY_PLATFORM == 'java'
$0 == __FILE__ ? "#{ __FILE__ }:27:in `(root)'" :
"#{ __FILE__ }:27:in `test_0001_prints a deprecation warning for direct call'"
else
$0 == __FILE__ ? "#{ __FILE__ }:27:in `block (3 levels) in <main>'" :
"#{ __FILE__ }:27:in `block (3 levels) in <top (required)>'"
end

err.chomp.must_equal "old_method is deprecated, please use new_method - called from: #{ stack }."
end
Expand Down
15 changes: 3 additions & 12 deletions test/io_test.rb
Expand Up @@ -8,22 +8,13 @@ class IOTest
describe Lotus::Utils::IO do
describe '.silence_warnings' do
it 'lowers verbosity of stdout' do
begin
position = STDOUT.tell

Lotus::Utils::IO.silence_warnings do
IOTest::TEST_CONSTANT = 'redefined'
end

IOTest::TEST_CONSTANT.must_equal('redefined')
STDOUT.tell.must_equal(position)
rescue Errno::ESPIPE
puts 'Skipping this test, IO#tell is not supported in this environment'

_, err = capture_io do
Lotus::Utils::IO.silence_warnings do
IOTest::TEST_CONSTANT = 'redefined'
end
end

err.must_equal ""
end
end
end
14 changes: 14 additions & 0 deletions test/utils_test.rb
@@ -0,0 +1,14 @@
require 'test_helper'
require 'lotus/utils'

describe Lotus::Utils do
describe '.jruby?' do
it 'introspects the current platform' do
if RUBY_PLATFORM == 'java'
assert Lotus::Utils.jruby?, 'expected JRuby platform'
else
assert !Lotus::Utils.jruby?, 'expected non JRuby platform'
end
end
end
end

0 comments on commit a0e830b

Please sign in to comment.