/**
 * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Eclipse Public License (EPL).
 * Please see the license.txt included with this distribution for details.
 * Any modifications to this file must keep this entire header intact.
 */
package org.python.pydev.runners;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.python.pydev.core.IPythonNature;
import org.python.pydev.core.TestDependent;
import org.python.pydev.editor.codecompletion.revisited.jython.JythonCodeCompletionTestsBase;
import org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule;
import org.python.pydev.runners.UniversalRunner.AbstractRunner;
import org.python.pydev.shared_core.structure.Tuple;

public class JythonUniversalRunnerTest extends JythonCodeCompletionTestsBase {

    public static void main(String[] args) {
        junit.textui.TestRunner.run(JythonUniversalRunnerTest.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        CompiledModule.COMPILED_MODULES_ENABLED = true;
        this.restorePythonPath(TestDependent.JYTHON_LIB_LOCATION + "|" + TestDependent.JAVA_RT_JAR_LOCATION, false);
    }

    @Override
    public void tearDown() throws Exception {
        CompiledModule.COMPILED_MODULES_ENABLED = false;
        super.tearDown();
    }

    public void testUniversalRunnerWithJython() throws Exception {
        AbstractRunner runner = UniversalRunner.getRunner(nature);
        assertEquals(nature.getInterpreterType(), IPythonNature.INTERPRETER_TYPE_JYTHON);
        Tuple<String, String> output = runner.runCodeAndGetOutput(
                "import sys\nprint 'test'\nprint >> sys.stderr, 'err'", null, null, new NullProgressMonitor());
        assertEquals("test", output.o1.trim());
        assertEquals("err", output.o2.trim());

        Tuple<Process, String> createProcess = runner.createProcess(TestDependent.TEST_PYSRC_LOC
                + "universal_runner_test.py", null, null, new NullProgressMonitor());
        output = SimpleRunner.getProcessOutput(createProcess.o1, "", new NullProgressMonitor(), "utf-8");
        assertEquals("stdout", output.o1.trim());
        assertEquals("stderr", output.o2.trim());
    }

}

@@ -1590,37 +1590,571 @@
 N);%0A
-        Tuple%3CString, String%3E
+%0A        // This test can fail because JYthon on first run (or change of classpath) can print%0A        // a lot of messages like:%0A        //    *sys-package-mgr*: processing new jar, ...%0A        // So do a pre-run that does not check stderr%0A        Tuple%3CString, String%3E output = runner.runCodeAndGetOutput(%0A                %22import sys%5Cnprint 'test'%5Cnprint %3E%3E sys.stderr, 'err'%22, null, null, new NullProgressMonitor());%0A        assertEquals(%22test%22, output.o1.trim());%0A%0A        // Now be more strict and make sure that stderr has exactly the correct output %0A       
  out
@@ -2790,11 +2790,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Deal with "*sys-package-mgr*: processing new jar" in test