Package org.jruby

Examples of org.jruby.RubyInstanceConfig


        }
    }
   
    public void testPrintErrorShouldPrintErrorMessageAndStacktraceWhenBacktraceIsPresent() {
        final ByteArrayOutputStream err = new ByteArrayOutputStream();
        RubyInstanceConfig config = new RubyInstanceConfig() {{
            setInput(System.in); setOutput(System.out); setError(new PrintStream(err)); setObjectSpaceEnabled(false);
        }};
        Ruby ruby = Ruby.newInstance(config);
        RubyException exception = (RubyException)runtime.getClass("NameError").newInstance(ruby.getCurrentContext(), new IRubyObject[]{ruby.newString("A message")},  Block.NULL_BLOCK);
        RubyString[] lines = new RubyString[]{
View Full Code Here


        assertEquals("Line 1: A message (NameError)\n\tfrom Line 2\n", err.toString());
    }
   
    public void testPrintErrorShouldOnlyPrintErrorMessageWhenBacktraceIsNil() {
        final ByteArrayOutputStream err = new ByteArrayOutputStream();
        RubyInstanceConfig config = new RubyInstanceConfig() {{
            setInput(System.in); setOutput(System.out); setError(new PrintStream(err)); setObjectSpaceEnabled(false);
        }};
        Ruby ruby = Ruby.newInstance(config);
        RubyException exception = (RubyException)runtime.getClass("NameError").newInstance(ruby.getCurrentContext(), new IRubyObject[]{ruby.newString("A message")},  Block.NULL_BLOCK);
        ruby.printError(exception);
View Full Code Here

    private RubyInstanceConfig config;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        config = new RubyInstanceConfig();
    }
View Full Code Here

        out = new PrintStream(new ByteArrayOutputStream());
        err = new PrintStream(new ByteArrayOutputStream());
    }

    public void testParsing() {
        RubyInstanceConfig c = new RubyInstanceConfig();
        c.processArguments(new String[]{"-e", "hello", "-e", "world"});
        assertEquals("hello\nworld\n", new String(c.inlineScript()));
        assertNull(c.getScriptFileName());
        assertEquals("-e", c.displayedFileName());

        c = new RubyInstanceConfig();
        c.processArguments(new String[]{"--version"});
        assertTrue(c.isShowVersion());

        c = new RubyInstanceConfig();
        c.processArguments(new String[]{"-n", "myfile.rb"});
        assertTrue(c.isAssumeLoop());
        assertEquals("myfile.rb", c.getScriptFileName());
        assertEquals("myfile.rb", c.displayedFileName());

        c = new RubyInstanceConfig();
        c.processArguments(new String[0]);
        assertEquals("-", c.displayedFileName());
    }
View Full Code Here

            public TestableCommandlineParser(String[] arguments) {
                super();
                processArguments(arguments);
            }
        }
        RubyInstanceConfig c = new TestableCommandlineParser(new String[]{"-I", "someLoadPath", "--", "simple.rb", "-v", "--version"});
        assertEquals("someLoadPath", c.loadPaths().get(0));
        assertEquals("simple.rb", c.getScriptFileName());
        assertEquals("simple.rb", c.displayedFileName());
        assertTrue("Should not be verbose. The -v flag should be a parameter to the script, not the jruby interpreter", !c.isVerbose());
        assertEquals("Script should have two parameters", 2, c.getArgv().length);
        assertEquals("-v", c.getArgv()[0]);
        assertEquals("--version", c.getArgv()[1]);
    }
View Full Code Here

        assertEquals("--version", c.getArgv()[1]);
    }

    public void testHelpDoesNotRunIntepreter() {
        String[] args = new String[]{"-h"};
        RubyInstanceConfig parser = new RubyInstanceConfig();
        parser.processArguments(args);
        assertFalse(parser.isShouldRunInterpreter());

        args = new String[]{"--help"};
        parser = new RubyInstanceConfig();
        parser.processArguments(args);
        assertFalse(parser.isShouldRunInterpreter());
    }
View Full Code Here

        assertFalse(parser.isShouldRunInterpreter());
    }

    public void testCommandTakesOneArgument() {
        String[] args = new String[]{"--command", "gem"};
        RubyInstanceConfig parser = new RubyInstanceConfig();
        parser.processArguments(args);
        assertEquals(1, parser.requiredLibraries().size());
        assertEquals("jruby/commands", parser.requiredLibraries().get(0));
        assertEquals("JRuby::Commands.gem\n", new String(parser.inlineScript()));
    }
View Full Code Here

        assertEquals("JRuby::Commands.gem\n", new String(parser.inlineScript()));
    }

    public void testCommandAllowedOnlyOnceAndRemainderAreScriptArgs() {
        String[] args = new String[]{"--command", "gem", "--command", "irb"};
        RubyInstanceConfig parser = new RubyInstanceConfig();
        parser.processArguments(args);
        assertEquals(2, parser.getArgv().length);
        assertEquals("--command", parser.getArgv()[0]);
        assertEquals("irb", parser.getArgv()[1]);
    }
View Full Code Here

        return null;
    }

    private DynamicMethod jitIsEnabled(final DefaultMethod method, final ThreadContext context, final String name) {
        RubyInstanceConfig instanceConfig = context.getRuntime().getInstanceConfig();
       
        if (method.incrementCallCount() >= instanceConfig.getJitThreshold()) {
            return jitThresholdReached(method, instanceConfig, context, name);
        }

        return null;
    }
View Full Code Here

    public EventHookTest(final String testName) {
        super(testName);
    }

    public void testLineNumbersForNativeTracer() {
        RubyInstanceConfig config = new RubyInstanceConfig();
        config.processArguments(new String[]{"--debug"});
        Ruby rt = JavaEmbedUtils.initialize(Collections.emptyList(), config);
        NativeTracer tracer = new NativeTracer();
        rt.addEventHook(tracer);
        RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();
        evaler.eval(rt, "sleep 0.01\nsleep 0.01\nsleep 0.01");
View Full Code Here

TOP

Related Classes of org.jruby.RubyInstanceConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.