Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reorganized tests, so that both Ruby and Java unit tests use a common…

… list of Ruby test cases. (A few tests break when run from Java, they're commented away for now).

Added an IO#readlines method.


git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@403 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
commit 6c205c2f86897bc518fbfa27ff6230bb05a45460 1 parent d95bcd5
@ghostganz ghostganz authored
View
4 minirunit.rb
@@ -53,13 +53,13 @@ def test_load(test)
$curtestOK=true
load(test)
rescue Exception => boom
- puts 'KO'
+ puts 'ERROR'
$failed.push(sprintf("exception raised %s %d -- \n\tException: %s\n\t%s", $what, $testnum, boom.to_s, boom.backtrace.join "\n\t"))
else
if $curtestOK
puts 'OK'
else
- puts 'KO'
+ puts 'FAILED'
end
end
end
View
43 org/jruby/RubyIO.java
@@ -95,6 +95,9 @@ public static RubyClass createIOClass(Ruby ruby) {
ioClass.defineMethod("printf", CallbackFactory.getOptSingletonMethod(RubyIO.class, "printf"));
ioClass.defineMethod("puts", CallbackFactory.getOptSingletonMethod(RubyIO.class, "puts"));
+ ioClass.defineMethod("readlines", CallbackFactory.getOptMethod(RubyIO.class, "readlines"));
+// ioClass.defineMethod("readlines", CallbackFactory.getOptSingletonMethod(RubyIO.class, "readlines"));
+
return ioClass;
}
@@ -595,4 +598,44 @@ public static RubyObject printf(Ruby ruby, RubyObject recv, RubyObject args[]) {
return ruby.getNil();
}
+
+ public RubyArray readlines(RubyObject[] args) {
+ RubyObject[] separatorArgument;
+ if (args.length > 0) {
+ if (! args[0].isKindOf(ruby.getClasses().getStringClass())) {
+ throw new TypeError(ruby, args[0], ruby.getClasses().getStringClass());
+ }
+ separatorArgument = new RubyObject[] { args[0] };
+ } else {
+ separatorArgument = new RubyObject[0];
+ }
+
+ RubyArray result = RubyArray.newArray(ruby);
+ RubyObject line;
+ while (! (line = internalGets(separatorArgument)).isNil()) {
+ result.push(line);
+ }
+ return result;
+ }
+
+ public static RubyArray readlines(Ruby ruby, RubyObject recv, RubyObject args[]) {
+ if (args.length < 1) {
+ throw new ArgumentError(ruby, args.length, 1);
+ }
+ if (! args[0].isKindOf(ruby.getClasses().getStringClass())) {
+ throw new TypeError(ruby, args[0], ruby.getClasses().getStringClass());
+ }
+ RubyString fileName = (RubyString) args[0];
+
+ RubyObject[] separatorArguments;
+ if (args.length >= 2) {
+ separatorArguments = new RubyObject[] { args[1] };
+ } else {
+ separatorArguments = new RubyObject[0];
+ }
+
+ RubyIO file = (RubyIO) RubyKernel.open(ruby, recv, new RubyObject[] { fileName });
+
+ return file.readlines(separatorArguments);
+ }
}
View
6 org/jruby/exceptions/TypeError.java
@@ -44,4 +44,8 @@
public TypeError(Ruby ruby, String msg) {
super(ruby, ruby.getExceptions().getTypeError(), msg);
}
-}
+
+ public TypeError(Ruby ruby, RubyObject object, RubyClass rbClass) {
+ this(ruby, "wrong argument type " + object.getRubyClass() + " (expected " + rbClass);
+ }
+}
View
2  org/jruby/test/MainTestSuite.java
@@ -39,7 +39,7 @@
*/
public class MainTestSuite extends TestSuite {
- public static Test suite() {
+ public static Test suite() throws Throwable {
TestSuite suite = new TestSuite();
suite.addTest(new TestSuite(TestRubyObject.class));
suite.addTest(new TestSuite(TestRubyNil.class));
View
129 org/jruby/test/ScriptTestSuite.java
@@ -46,75 +46,86 @@
public class ScriptTestSuite extends TestSuite {
+ private static final String TEST_DIR = "test";
+ private static final String TEST_INDEX = "test" + File.separator + "test_index";
+
public ScriptTestSuite(String name) {
super(name);
}
- public static Test suite() {
+ public static Test suite() throws java.io.IOException {
TestSuite suite = new TestSuite();
- Ruby ruby = Ruby.getDefaultInstance(null);
- ruby.initLoad(new ArrayList());
-
- suite.addTest(new ScriptTest(ruby, "testRegexp"));
- suite.addTest(new ScriptTest(ruby, "testStringEval"));
- suite.addTest(new ScriptTest(ruby, "testHereDocument"));
- suite.addTest(new ScriptTest(ruby, "testClass"));
-// suite.addTest(new ScriptTest(ruby, "testArray"));
- suite.addTest(new ScriptTest(ruby, "testVariableAndMethod"));
- suite.addTest(new ScriptTest(ruby, "testIf"));
- suite.addTest(new ScriptTest(ruby, "testLoops"));
- suite.addTest(new ScriptTest(ruby, "testMethods"));
- suite.addTest(new ScriptTest(ruby, "testGlobalVars"));
- suite.addTest(new ScriptTest(ruby, "testClasses"));
- suite.addTest(new ScriptTest(ruby, "testNumber"));
- suite.addTest(new ScriptTest(ruby, "testFloat"));
- suite.addTest(new ScriptTest(ruby, "testBlock"));
- suite.addTest(new ScriptTest(ruby, "testRange"));
- suite.addTest(new ScriptTest(ruby, "testString"));
-// suite.addTest(new ScriptTest(ruby, "testException"));
-// suite.addTest(new ScriptTest(ruby, "testSpecialVar"));
- suite.addTest(new ScriptTest(ruby, "testFile"));
- suite.addTest(new ScriptTest(ruby, "testMarshal"));
- suite.addTest(new ScriptTest(ruby, "testHash"));
- suite.addTest(new ScriptTest(ruby, "testSymbol"));
- suite.addTest(new ScriptTest(ruby, "testRandom"));
- suite.addTest(new ScriptTest(ruby, "testStruct"));
- suite.addTest(new ScriptTest(ruby, "testGC"));
+ Ruby ruby = Ruby.getDefaultInstance(null);
+ ruby.initLoad(new ArrayList());
+
+ File testIndex = new File("test/test_index");
+ if (! testIndex.canRead()) {
+ suite.addTest(new FailingTest("ScriptTestSuite",
+ "Couldn't locate " + TEST_INDEX +
+ ". Make sure you run the tests from the base " +
+ "directory of the JRuby sourcecode."));
+ return suite;
+ }
+
+ BufferedReader testFiles =
+ new BufferedReader(new InputStreamReader(new FileInputStream(testIndex)));
+ String line;
+ while ((line = testFiles.readLine()) != null) {
+ line = line.trim();
+ if (line.startsWith("#") || line.length() == 0) {
+ continue;
+ }
+ suite.addTest(new ScriptTest(ruby, line));
+ }
return suite;
}
+ private static class FailingTest extends TestCase {
+ private final String message;
+
+ public FailingTest(String name, String message) {
+ super(name);
+ this.message = message;
+ }
+
+ public void runTest() throws Throwable {
+ fail(message);
+ }
+ }
+
+
private static class ScriptTest extends TestCase {
- private final Ruby ruby;
- private final String filename;
- private final File script;
-
- public ScriptTest(Ruby ruby, String filename) {
- super(filename);
- this.ruby = ruby;
- this.filename = filename;
- this.script = new File("test/" + filename + ".rb");
- }
-
- public void runTest() throws Throwable {
- StringBuffer scriptString = new StringBuffer((int) script.length());
- BufferedReader br = new BufferedReader(new FileReader(script));
- String line;
- while ((line = br.readLine()) != null) {
- scriptString.append(line).append('\n');
- }
- br.close();
-
- // At the end of the tests we need a value to tell us if they failed.
- scriptString.append("$curtestOK").append('\n');
-
- RubyBoolean isOk = (RubyBoolean) ruby.evalScript(scriptString.toString());
- if (isOk.isFalse()) {
- fail(filename + " failed");
- }
-
- System.out.flush(); // Without a flush Ant will miss some of our output
- }
+ private final Ruby ruby;
+ private final String filename;
+ private final File script;
+
+ public ScriptTest(Ruby ruby, String filename) {
+ super(filename);
+ this.ruby = ruby;
+ this.filename = filename;
+ this.script = new File(TEST_DIR + File.separator + filename);
+ }
+
+ public void runTest() throws Throwable {
+ StringBuffer scriptString = new StringBuffer((int) script.length());
+ BufferedReader br = new BufferedReader(new FileReader(script));
+ String line;
+ while ((line = br.readLine()) != null) {
+ scriptString.append(line).append('\n');
+ }
+ br.close();
+
+ // At the end of the tests we need a value to tell us if they failed.
+ scriptString.append("$curtestOK").append('\n');
+
+ RubyBoolean isOk = (RubyBoolean) ruby.evalScript(scriptString.toString());
+ if (isOk.isFalse()) {
+ fail(filename + " failed");
+ }
+
+ System.out.flush(); // Without a flush Ant will miss some of our output
+ }
}
}
View
63 test/testSuite.rb
@@ -24,52 +24,27 @@
#
require 'minirunit'
-test_load('test/testRegexp.rb')
-test_load('test/testStringEval.rb')
-test_load('test/testHereDocument.rb')
-test_load('test/testClass.rb')
-test_load('test/testArray.rb')
-test_load('test/testVariableAndMethod.rb')
-test_load('test/testIf.rb')
-test_load('test/testLoops.rb')
-test_load('test/testMethods.rb')
-test_load('test/testGlobalVars.rb')
-test_load('test/testClasses.rb')
-test_load('test/testNumber.rb')
-test_load('test/testFloat.rb')
-test_load('test/testBlock.rb')
-test_load('test/testRange.rb')
-test_load('test/testString.rb')
-test_load('test/testException.rb')
-test_load('test/testSpecialVar.rb')
-test_load('test/testFile.rb')
-test_load('test/testThread.rb')
-test_load('test/testMarshal.rb')
-test_load('test/testRequire.rb')
-test_load('test/testBackquote.rb')
-test_load('test/testHash.rb')
-test_load('test/testSymbol.rb')
-test_load('test/testPackUnpack.rb')
-test_load('test/testRandom.rb')
-test_load('test/testStruct.rb')
-test_load('test/testGC.rb')
+TEST_INDEX = "test/test_index"
-# MRI Ruby tests (from sample/test.rb in Matz's Ruby Interpreter):
+def valid?(line)
+ if /^\#/ =~ line
+ # Commented
+ return false
+ end
+ if line.empty?
+ return false
+ end
+ return true
+end
-test_load('test/mri/testAssignment.rb')
-test_load('test/mri/testCondition.rb')
-test_load('test/mri/testCase.rb')
-test_load('test/mri/testIfUnless.rb')
-test_load('test/mri/testWhileUntil.rb')
-test_load('test/mri/testException.rb')
-test_load('test/mri/testArray.rb')
-test_load('test/mri/testHash.rb')
-test_load('test/mri/testIterator.rb')
-test_load('test/mri/testFloat.rb')
-test_load('test/mri/testBignum.rb')
-test_load('test/mri/testString.rb')
-test_load('test/mri/testAssignment2.rb')
-test_load('test/mri/testCall.rb')
+open(TEST_INDEX) {|test_index|
+ test_index.readlines.each {|line|
+ line.strip!
+ if valid?(line)
+ test_load('test/' + line)
+ end
+ }
+}
puts
View
48 test/test_index
@@ -0,0 +1,48 @@
+
+# Basic JRuby unit tests
+
+testRegexp.rb
+testStringEval.rb
+testHereDocument.rb
+testClass.rb
+##testArray.rb
+testVariableAndMethod.rb
+testIf.rb
+testLoops.rb
+testMethods.rb
+testGlobalVars.rb
+testClasses.rb
+testNumber.rb
+testFloat.rb
+testBlock.rb
+testRange.rb
+testString.rb
+testException.rb
+##testSpecialVar.rb
+testFile.rb
+#testThread.rb
+testMarshal.rb
+##testBackquote.rb
+testHash.rb
+testSymbol.rb
+testPackUnpack.rb
+testRandom.rb
+testStruct.rb
+testGC.rb
+
+# MRI Ruby tests (from sample/test.rb in Matz's Ruby Interpreter):
+
+mri/testAssignment.rb
+mri/testCondition.rb
+mri/testCase.rb
+mri/testIfUnless.rb
+##mri/testWhileUntil.rb
+mri/testException.rb
+##mri/testArray.rb
+mri/testHash.rb
+mri/testIterator.rb
+mri/testFloat.rb
+mri/testBignum.rb
+#mri/testString.rb
+mri/testAssignment2.rb
+mri/testCall.rb
Please sign in to comment.
Something went wrong with that request. Please try again.