Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support $: (LOADPATH) in jars and make File-based requiring more SAFE

Move libraries to lib/ruby/1.8


git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@1619 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
commit 1bafbf40b5e6cb67a40a0ddb3cd1fb183954bd2f 1 parent 8f3e6d1
Thomas E Enebo enebo authored
1  build.xml
View
@@ -169,6 +169,7 @@
<path refid="build.classpath"/>
<pathelement path="${lib.dir}/jruby.jar"/>
<pathelement path="${test.classes.dir}"/>
+ <pathelement path="${test.dir}/requireTest.jar"/>
</classpath>
<sysproperty key="jruby.base" value="${basedir}"/>
<sysproperty key="jruby.home" value="${basedir}"/>
468 src/lib/ruby/1.8/getoptlong.rb
View
@@ -0,0 +1,468 @@
+# -*- Ruby -*-
+# Copyright (C) 1998, 1999, 2000 Motoyuki Kasahara
+#
+# You may redistribute it and/or modify it under the same license
+# terms as Ruby.
+#
+
+#
+# Documents and latest version of `getoptlong.rb' are found at:
+# http://www.sra.co.jp/people/m-kasahr/ruby/getoptlong/
+#
+
+#
+# Parse command line options just like GNU getopt_long().
+#
+class GetoptLong
+ #
+ # Orderings.
+ #
+ ORDERINGS = [REQUIRE_ORDER = 0, PERMUTE = 1, RETURN_IN_ORDER = 2]
+
+ #
+ # Argument flags.
+ #
+ ARGUMENT_FLAGS = [NO_ARGUMENT = 0, REQUIRED_ARGUMENT = 1,
+ OPTIONAL_ARGUMENT = 2]
+
+ #
+ # Status codes.
+ #
+ STATUS_YET, STATUS_STARTED, STATUS_TERMINATED = 0, 1, 2
+
+ #
+ # Error types.
+ #
+ class Error < StandardError; end
+ class AmbigousOption < Error; end
+ class NeedlessArgument < Error; end
+ class MissingArgument < Error; end
+ class InvalidOption < Error; end
+
+ #
+ # Initializer.
+ #
+ def initialize(*arguments)
+ #
+ # Current ordering.
+ #
+ if ENV.include?('POSIXLY_CORRECT')
+ @ordering = REQUIRE_ORDER
+ else
+ @ordering = PERMUTE
+ end
+
+ #
+ # Hash table of option names.
+ # Keys of the table are option names, and their values are canonical
+ # names of the options.
+ #
+ @canonical_names = Hash.new
+
+ #
+ # Hash table of argument flags.
+ # Keys of the table are option names, and their values are argument
+ # flags of the options.
+ #
+ @argument_flags = Hash.new
+
+ #
+ # Whether error messages are output to $deferr.
+ #
+ @quiet = FALSE
+
+ #
+ # Status code.
+ #
+ @status = STATUS_YET
+
+ #
+ # Error code.
+ #
+ @error = nil
+
+ #
+ # Error message.
+ #
+ @error_message = nil
+
+ #
+ # Rest of catenated short options.
+ #
+ @rest_singles = ''
+
+ #
+ # List of non-option-arguments.
+ # Append them to ARGV when option processing is terminated.
+ #
+ @non_option_arguments = Array.new
+
+ if 0 < arguments.length
+ set_options(*arguments)
+ end
+ end
+
+ #
+ # Set ordering.
+ #
+ def ordering=(ordering)
+ #
+ # The method is failed if option processing has already started.
+ #
+ if @status != STATUS_YET
+ set_error(ArgumentError, "argument error")
+ raise RuntimeError,
+ "invoke ordering=, but option processing has already started"
+ end
+
+ #
+ # Check ordering.
+ #
+ if !ORDERINGS.include?(ordering)
+ raise ArgumentError, "invalid ordering `#{ordering}'"
+ end
+ if ordering == PERMUTE && ENV.include?('POSIXLY_CORRECT')
+ @ordering = REQUIRE_ORDER
+ else
+ @ordering = ordering
+ end
+ end
+
+ #
+ # Return ordering.
+ #
+ attr_reader :ordering
+
+ #
+ # Set options
+ #
+ def set_options(*arguments)
+ #
+ # The method is failed if option processing has already started.
+ #
+ if @status != STATUS_YET
+ raise RuntimeError,
+ "invoke set_options, but option processing has already started"
+ end
+
+ #
+ # Clear tables of option names and argument flags.
+ #
+ @canonical_names.clear
+ @argument_flags.clear
+
+ arguments.each do |arg|
+ #
+ # Each argument must be an Array.
+ #
+ if !arg.is_a?(Array)
+ raise ArgumentError, "the option list contains non-Array argument"
+ end
+
+ #
+ # Find an argument flag and it set to `argument_flag'.
+ #
+ argument_flag = nil
+ arg.each do |i|
+ if ARGUMENT_FLAGS.include?(i)
+ if argument_flag != nil
+ raise ArgumentError, "too many argument-flags"
+ end
+ argument_flag = i
+ end
+ end
+ raise ArgumentError, "no argument-flag" if argument_flag == nil
+
+ canonical_name = nil
+ arg.each do |i|
+ #
+ # Check an option name.
+ #
+ next if i == argument_flag
+ begin
+ if !i.is_a?(String) || i !~ /^-([^-]|-.+)$/
+ raise ArgumentError, "an invalid option `#{i}'"
+ end
+ if (@canonical_names.include?(i))
+ raise ArgumentError, "option redefined `#{i}'"
+ end
+ rescue
+ @canonical_names.clear
+ @argument_flags.clear
+ raise
+ end
+
+ #
+ # Register the option (`i') to the `@canonical_names' and
+ # `@canonical_names' Hashes.
+ #
+ if canonical_name == nil
+ canonical_name = i
+ end
+ @canonical_names[i] = canonical_name
+ @argument_flags[i] = argument_flag
+ end
+ raise ArgumentError, "no option name" if canonical_name == nil
+ end
+ return self
+ end
+
+ #
+ # Set/Unset `quit' mode.
+ #
+ attr_writer :quiet
+
+ #
+ # Return the flag of `quiet' mode.
+ #
+ attr_reader :quiet
+
+ #
+ # `quiet?' is an alias of `quiet'.
+ #
+ alias quiet? quiet
+
+ #
+ # Terminate option processing.
+ #
+ def terminate
+ return nil if @status == STATUS_TERMINATED
+ raise RuntimeError, "an error has occured" if @error != nil
+
+ @status = STATUS_TERMINATED
+ @non_option_arguments.reverse_each do |argument|
+ ARGV.unshift(argument)
+ end
+
+ @canonical_names = nil
+ @argument_flags = nil
+ @rest_singles = nil
+ @non_option_arguments = nil
+
+ return self
+ end
+
+ #
+ # Examine whether option processing is terminated or not.
+ #
+ def terminated?
+ return @status == STATUS_TERMINATED
+ end
+
+ #
+ # Set an error (protected).
+ #
+ def set_error(type, message)
+ $deferr.print("#{$0}: #{message}\n") if !@quiet
+
+ @error = type
+ @error_message = message
+ @canonical_names = nil
+ @argument_flags = nil
+ @rest_singles = nil
+ @non_option_arguments = nil
+
+ raise type, message
+ end
+ protected :set_error
+
+ #
+ # Examine whether an option processing is failed.
+ #
+ attr_reader :error
+
+ #
+ # `error?' is an alias of `error'.
+ #
+ alias error? error
+
+ #
+ # Return an error message.
+ #
+ def error_message
+ return @error_message
+ end
+
+ #
+ # Get next option name and its argument as an array.
+ #
+ def get
+ option_name, option_argument = nil, ''
+
+ #
+ # Check status.
+ #
+ return nil if @error != nil
+ case @status
+ when STATUS_YET
+ @status = STATUS_STARTED
+ when STATUS_TERMINATED
+ return nil
+ end
+
+ #
+ # Get next option argument.
+ #
+ if 0 < @rest_singles.length
+ argument = '-' + @rest_singles
+ elsif (ARGV.length == 0)
+ terminate
+ return nil
+ elsif @ordering == PERMUTE
+ while 0 < ARGV.length && ARGV[0] !~ /^-./
+ @non_option_arguments.push(ARGV.shift)
+ end
+ if ARGV.length == 0
+ terminate
+ return nil
+ end
+ argument = ARGV.shift
+ elsif @ordering == REQUIRE_ORDER
+ if (ARGV[0] !~ /^-./)
+ terminate
+ return nil
+ end
+ argument = ARGV.shift
+ else
+ argument = ARGV.shift
+ end
+
+ #
+ # Check the special argument `--'.
+ # `--' indicates the end of the option list.
+ #
+ if argument == '--' && @rest_singles.length == 0
+ terminate
+ return nil
+ end
+
+ #
+ # Check for long and short options.
+ #
+ if argument =~ /^(--[^=]+)/ && @rest_singles.length == 0
+ #
+ # This is a long style option, which start with `--'.
+ #
+ pattern = $1
+ if @canonical_names.include?(pattern)
+ option_name = pattern
+ else
+ #
+ # The option `option_name' is not registered in `@canonical_names'.
+ # It may be an abbreviated.
+ #
+ match_count = 0
+ @canonical_names.each_key do |key|
+ if key.index(pattern) == 0
+ option_name = key
+ match_count += 1
+ end
+ end
+ if 2 <= match_count
+ set_error(AmbigousOption, "option `#{argument}' is ambiguous")
+ elsif match_count == 0
+ set_error(InvalidOption, "unrecognized option `#{argument}'")
+ end
+ end
+
+ #
+ # Check an argument to the option.
+ #
+ if @argument_flags[option_name] == REQUIRED_ARGUMENT
+ if argument =~ /=(.*)$/
+ option_argument = $1
+ elsif 0 < ARGV.length
+ option_argument = ARGV.shift
+ else
+ set_error(MissingArgument,
+ "option `#{argument}' requires an argument")
+ end
+ elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
+ if argument =~ /=(.*)$/
+ option_argument = $1
+ elsif 0 < ARGV.length && ARGV[0] !~ /^-./
+ option_argument = ARGV.shift
+ else
+ option_argument = ''
+ end
+ elsif argument =~ /=(.*)$/
+ set_error(NeedlessArgument,
+ "option `#{option_name}' doesn't allow an argument")
+ end
+
+ elsif argument =~ /^(-(.))(.*)/
+ #
+ # This is a short style option, which start with `-' (not `--').
+ # Short options may be catenated (e.g. `-l -g' is equivalent to
+ # `-lg').
+ #
+ option_name, ch, @rest_singles = $1, $2, $3
+
+ if @canonical_names.include?(option_name)
+ #
+ # The option `option_name' is found in `@canonical_names'.
+ # Check its argument.
+ #
+ if @argument_flags[option_name] == REQUIRED_ARGUMENT
+ if 0 < @rest_singles.length
+ option_argument = @rest_singles
+ @rest_singles = ''
+ elsif 0 < ARGV.length
+ option_argument = ARGV.shift
+ else
+ # 1003.2 specifies the format of this message.
+ set_error(MissingArgument, "option requires an argument -- #{ch}")
+ end
+ elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
+ if 0 < @rest_singles.length
+ option_argument = @rest_singles
+ @rest_singles = ''
+ elsif 0 < ARGV.length && ARGV[0] !~ /^-./
+ option_argument = ARGV.shift
+ else
+ option_argument = ''
+ end
+ end
+ else
+ #
+ # This is an invalid option.
+ # 1003.2 specifies the format of this message.
+ #
+ if ENV.include?('POSIXLY_CORRECT')
+ set_error(InvalidOption, "illegal option -- #{ch}")
+ else
+ set_error(InvalidOption, "invalid option -- #{ch}")
+ end
+ end
+ else
+ #
+ # This is a non-option argument.
+ # Only RETURN_IN_ORDER falled into here.
+ #
+ return '', argument
+ end
+
+ return @canonical_names[option_name], option_argument
+ end
+
+ #
+ # `get_option' is an alias of `get'.
+ #
+ alias get_option get
+
+ #
+ # Iterator version of `get'.
+ #
+ def each
+ loop do
+ option_name, option_argument = get_option
+ break if option_name == nil
+ yield option_name, option_argument
+ end
+ end
+
+ #
+ # `each_option' is an alias of `each'.
+ #
+ alias each_option each
+end
124 src/lib/ruby/1.8/getopts.rb
View
@@ -0,0 +1,124 @@
+#
+# getopts.rb -
+# $Release Version: $
+# $Revision$
+# $Date$
+# by Yasuo OHBA(SHL Japan Inc. Technology Dept.)
+#
+# --
+# this is obsolete; use getoptlong
+#
+# 2000-03-21
+# modified by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
+#
+# 2002-03-05
+# rewritten by Akinori MUSHA <knu@ruby-lang.org>
+#
+
+$RCS_ID=%q$Header$
+
+
+def getopts(single_options, *options)
+ boolopts = {}
+ valopts = {}
+
+ #
+ # set defaults
+ #
+ single_options.scan(/.:?/) do |opt|
+ if opt.size == 1
+ boolopts[opt] = false
+ else
+ valopts[opt[0, 1]] = nil
+ end
+ end if single_options
+
+ options.each do |arg|
+ opt, val = arg.split(':', 2)
+
+ if val
+ valopts[opt] = val.empty? ? nil : val
+ else
+ boolopts[opt] = false
+ end
+ end
+
+ #
+ # scan
+ #
+ c = 0
+ argv = ARGV
+
+ while arg = argv.shift
+ case arg
+ when /\A--(.*)/
+ if $1.empty? # xinit -- -bpp 24
+ break
+ end
+
+ opt, val = $1.split('=', 2)
+
+ if opt.size == 1
+ argv.unshift arg
+ return nil
+ elsif valopts.key? opt # imclean --src +trash
+ valopts[opt] = val || argv.shift or return nil
+ elsif boolopts.key? opt # ruby --verbose
+ boolopts[opt] = true
+ else
+ argv.unshift arg
+ return nil
+ end
+
+ c += 1
+ when /\A-(.+)/
+ opts = $1
+
+ until opts.empty?
+ opt = opts.slice!(0, 1)
+
+ if valopts.key? opt
+ val = opts
+
+ if val.empty? # ruby -e 'p $:'
+ valopts[opt] = argv.shift or return nil
+ else # cc -ohello ...
+ valopts[opt] = val
+ end
+
+ c += 1
+ break
+ elsif boolopts.key? opt
+ boolopts[opt] = true # ruby -h
+ c += 1
+ else
+ argv.unshift arg
+ return nil
+ end
+ end
+ else
+ argv.unshift arg
+ break
+ end
+ end
+
+ #
+ # set
+ #
+ $OPT = {}
+
+ boolopts.each do |opt, val|
+ $OPT[opt] = val
+
+ sopt = opt.gsub(/[^A-Za-z0-9_]/, '_')
+ eval "$OPT_#{sopt} = val"
+ end
+ valopts.each do |opt, val|
+ $OPT[opt] = val
+
+ sopt = opt.gsub(/[^A-Za-z0-9_]/, '_')
+ eval "$OPT_#{sopt} = val"
+ end
+
+ c
+end
2  src/lib/ruby/1.8/socket.rb
View
@@ -0,0 +1,2 @@
+module Socket
+end
56 src/lib/ruby/1.8/stringio.rb
View
@@ -0,0 +1,56 @@
+class StringIO
+ attr_accessor :pos
+
+ def newInstance(string=String.new)
+ @string = string
+ @close_read = false
+ @close_write = false
+ end
+
+ def close() close_read; close_write; end
+ def closed?() closed_read? && closed_write?; end
+ def close_read() @close_read = true; end
+ def closed_read?() @close_read; end
+ def close_write() @close_write = true; end
+ def closed_write?() @close_write; end
+
+ def each(sep="\n")
+ line = gets
+ while line != nil
+ yield(line)
+ line = gets
+ end
+ end
+ def each_byte() @string.substr(@pos).each_byte; end
+ def each_line() each; end
+ def eof() @pos = length + 1; end
+ def eof?() @pos > length; end
+ def getc()
+ c = @string[@pos]
+ @pos = @pos + 1
+ c
+ end
+ def gets(sep="\n")
+ i = @string.index(sep, @pos)
+ @string.substr(@pos, i)
+ end
+ def length() @string.length; end
+# def putc(c) @string << c; end
+ def print() @string.print; end
+ def printf(*args) @string.printf(*args); end
+# def puts(s) @string << s; end
+ alias readline gets
+ def rewind() @pos = 0; end
+# def seek(amount, whence=IO::SEEK_SET)
+# if whence == IO::SEEK_CUR then
+# @pos = @pos + amount
+# else if whence == IO::SEEK_END then
+# @pos = length + amount
+# else
+# @pos = amount
+# end
+# end
+# alias size length
+ def string; @string; end
+ def write(s); puts "SSSS #{s}"; @string = s; end
+end
133 src/org/jruby/internal/runtime/load/LoadService.java
View
@@ -77,31 +77,31 @@ public LoadService(Ruby runtime) {
}
public void init(List additionalDirectories) {
- for (Iterator iter = additionalDirectories.iterator(); iter.hasNext();) {
- addPath((String) iter.next());
- }
- if (runtime.getSafeLevel() == 0) {
- String jrubyLib = System.getProperty("jruby.lib");
- if (jrubyLib != null) {
- addPath(jrubyLib);
- }
- }
-
- String jrubyHome = System.getProperty("jruby.home");
- if (jrubyHome != null) {
- char sep = File.separatorChar;
- String rubyDir = jrubyHome + sep + "lib" + sep + "ruby" + sep;
-
- addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION);
- addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION + sep + "java");
- addPath(rubyDir + "site_ruby");
- addPath(rubyDir + Constants.RUBY_MAJOR_VERSION);
- addPath(rubyDir + Constants.RUBY_MAJOR_VERSION + sep + "java");
- }
-
- if (runtime.getSafeLevel() == 0) {
- addPath(".");
+ for (Iterator iter = additionalDirectories.iterator(); iter.hasNext();) {
+ addPath((String) iter.next());
+ }
+ if (runtime.getSafeLevel() == 0) {
+ String jrubyLib = System.getProperty("jruby.lib");
+ if (jrubyLib != null) {
+ addPath(jrubyLib);
}
+ }
+
+ String jrubyHome = System.getProperty("jruby.home");
+ if (jrubyHome != null) {
+ char sep = File.separatorChar;
+ String rubyDir = jrubyHome + sep + "lib" + sep + "ruby" + sep;
+
+ addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION);
+ addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION + sep + "java");
+ addPath(rubyDir + "site_ruby");
+ addPath(rubyDir + Constants.RUBY_MAJOR_VERSION);
+ addPath(rubyDir + Constants.RUBY_MAJOR_VERSION + sep + "java");
+ }
+
+ if (runtime.getSafeLevel() == 0) {
+ addPath(".");
+ }
}
private void addPath(String path) {
@@ -194,11 +194,31 @@ public void registerBuiltin(String name, Library library) {
* @param name the file to find, this is a path name
* @return the correct file
*/
- private URL findFile(String name) {
+ private URL findFile(String name) {
try {
if (name.startsWith("jar:")) {
return new URL(name);
}
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+
+ // Absolute path names
+ if (name.startsWith("/") || name.startsWith("\\")) {
+ // Load from local filesystem
+ File current = new File(name);
+ if (current.exists() && current.isFile()) {
+ return current.toURL();
+ }
+
+ // otherwise, try to load from classpath
+ URL loc = classLoader.getResource(name);
+
+ // Make sure this is not a directory or unavailable in some way
+ if (isRequireable(loc)) {
+ return loc;
+ }
+ }
+
for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) {
String entry = pathIter.next().toString();
if (entry.startsWith("jar:")) {
@@ -211,42 +231,41 @@ private URL findFile(String name) {
} catch (IOException e) {
throw IOError.fromException(runtime, e);
}
- } else {
- File current = new File(entry, name);
- if (current.exists() && current.isFile()) {
- return current.toURL();
- }
+ }
+
+ // Load from local filesystem
+ File current = new File(entry, name);
+ if (current.exists() && current.isFile()) {
+ return current.toURL();
+ }
+
+ // otherwise, try to load from classpath
+ URL loc = classLoader.getResource(entry + "/" + name);
+
+ // Make sure this is not a directory or unavailable in some way
+ if (isRequireable(loc)) {
+ return loc;
}
}
- File current = new File(name);
- // Make sure that the file exists and isn't a directory
- if (current.exists() && current.isFile()) {
- return current.toURL();
- }
-
- // otherwise, try to load from classpath
- URL loc = Thread.currentThread().getContextClassLoader().getResource(name);
-
- // libraries is a name in a jar file to allow jar files to include modules into the
- // distribution classpath. We should perhaps kill this in favor of moving src/library
- // files into top of jar file via ant build process?
- if (loc == null) {
- loc =
- Thread.currentThread().getContextClassLoader().getResource("libraries/" + name);
- }
-
- // make sure resource URL has something available or return null
- if (loc != null) {
- try {
- loc.openStream().close();
- } catch (Exception ioe) {
- loc = null;
- }
- }
-
- return loc;
+
+ // Try to load from classpath without prefix. "A/b.rb" will not load as
+ // "./A/b.rb" in a jar file.
+ URL loc = classLoader.getResource(name);
+
+ return isRequireable(loc) ? loc : null;
} catch (MalformedURLException e) {
throw new IOError(runtime, e.getMessage());
}
}
+
+ /* Directories and unavailable resources are not able to open a stream. */
+ private boolean isRequireable(URL loc) {
+ if (loc != null) {
+ try {
+ loc.openStream().close();
+ return true;
+ } catch (Exception e) {}
+ }
+ return false;
+ }
}
1  test/org/jruby/test/MainTestSuite.java
View
@@ -53,6 +53,7 @@ public static Test suite() throws Throwable {
suite.addTest(new TestSuite(TestRubyHash.class));
suite.addTest(new TestSuite(TestRubyTime.class));
suite.addTest(new TestSuite(TestRuby.class));
+ suite.addTest(new TestSuite(TestRequire.class));
suite.addTest(new TestSuite(TestJavaUtil.class));
suite.addTestSuite(TestJavaClass.class);
suite.addTest(new TestSuite(TestKernel.class));
4 test/org/jruby/test/ScriptTestSuite.java
View
@@ -41,6 +41,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
+import java.util.ArrayList;
/**
* @author Anders
@@ -91,6 +92,9 @@ public static Test suite() throws java.io.IOException {
private static Ruby setupInterpreter() {
Ruby runtime = Ruby.getDefaultInstance();
+
+ runtime.getLoadService().init(new ArrayList());
+
return runtime;
}
58 test/org/jruby/test/TestRequire.java
View
@@ -0,0 +1,58 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2005 Thomas E Enebo <enebo@acm.org>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+ package org.jruby.test;
+
+import java.util.ArrayList;
+
+import org.jruby.Ruby;
+
+/**
+ * Simple test to make sure require works properly in conjunction with jars
+ * in the classpath.
+ */
+public class TestRequire extends TestRubyBase {
+ public TestRequire(String name) {
+ super(name);
+ }
+ public void setUp() {
+ runtime = Ruby.getDefaultInstance();
+
+ runtime.getLoadService().init(new ArrayList());
+ }
+
+ public void tearDown() {
+ super.tearDown();
+ }
+
+ public void testRubyRequire() throws Exception {
+ String result = eval("require 'A/C'; puts A::C.new.meth");
+ assertEquals("ok", result);
+ result = eval("$: << 'A'; require 'B'; puts B.new.meth");
+ assertEquals("ok", result);
+ }
+}
BIN  test/requireTest.jar
View
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.