Skip to content

Commit

Permalink
added tests for File.file? with native.enabled=false
Browse files Browse the repository at this point in the history
complements the fix for #2032 with a test case for testing File.exists?,
File.directory? and File.file? executing jruby without native enabled.

Sponsord by Lookout Inc.
  • Loading branch information
mkristian committed Nov 14, 2014
1 parent f54a41f commit c7ae16f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
20 changes: 20 additions & 0 deletions test/test_file.rb
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
require 'test/unit'
require 'test/test_helper'
require 'rbconfig'
require 'fileutils'
require 'tempfile'
require 'pathname'
require 'jruby'

class TestFile < Test::Unit::TestCase
include TestHelper
WINDOWS = RbConfig::CONFIG['host_os'] =~ /Windows|mswin/

def setup
Expand Down Expand Up @@ -461,13 +463,31 @@ def test_mkdir
end
end

def test_directory_query # - directory?
begin
Dir.mkdir("dir_tmp")
assert(File.directory?("dir_tmp"))
assert(! File.directory?("test/test_file.rb"))
assert(! File.directory?("dir_not_tmp"))
result = jruby("-e 'print File.directory?(\"dir_not_tmp\");print File.directory?(\"dir_tmp\");print File.directory?(\"test/test_file.rb\")'", 'jruby.native.enabled' => 'false')
assert(result == 'falsetruefalse')
ensure
Dir.rmdir("dir_tmp")
end
end

def test_file_query # - file?
assert(File.file?('test/test_file.rb'))
assert(! File.file?('test'))
assert(! File.file?('test_not'))
result = jruby("-e 'print File.file?(\"test_not\");print File.file?(\"test\");print File.file?(\"test/test_file.rb\")'", 'jruby.native.enabled' => 'false' )
assert(result == 'falsefalsetrue')
end

def test_file_exist_query
assert(File.exist?('test'))
assert(! File.exist?('test_not'))
assert(jruby("-e 'print File.exists?(\"test_not\");print File.exists?(\"test\")'", 'jruby.native.enabled' => 'false' ) == 'falsetrue')
end

def test_file_exist_in_jar_file
Expand Down
16 changes: 14 additions & 2 deletions test/test_helper.rb
Expand Up @@ -6,7 +6,8 @@ module TestHelper
# TODO: Consider how this should work if we have --windows or similiar
WINDOWS = RbConfig::CONFIG['host_os'] =~ /Windows|mswin/
SEPARATOR = WINDOWS ? '\\' : '/'
RUBY = if RbConfig::CONFIG['bindir'].match( /!\//) || RbConfig::CONFIG['bindir'].match( /:\//)
IS_JAR_EXECUTION = RbConfig::CONFIG['bindir'].match( /!\//) || RbConfig::CONFIG['bindir'].match( /:\//)
RUBY = if IS_JAR_EXECUTION
exe = 'java'
exe += RbConfig::CONFIG['EXEEXT'] if RbConfig::CONFIG['EXEEXT']
file = File.expand_path('maven/jruby-complete/target/jruby-complete-*.jar')
Expand Down Expand Up @@ -39,7 +40,18 @@ def q
end

def jruby(*args)
ruby = RUBY.sub(/-cp [.]/, "-cp #{ENV["CLASSPATH"]}")
options = []
if args.last.is_a? Hash
options = args.last.collect { |k,v| "-D#{k}=\"#{v}\"" }
args = args[0..-2]
end
if RUBY =~ /-cp /
ruby = RUBY.sub(/-cp [.]/, "-cp #{ENV["CLASSPATH"]}")
.sub(/-cp /, options.join(' ') + ' -cp ')
else
options.each { |a| args.unshift "-J#{a}" }
ruby = RUBY
end
with_jruby_shell_spawning { `#{ruby} #{args.join(' ')}` }
end

Expand Down

0 comments on commit c7ae16f

Please sign in to comment.