blob: 75e5068fb6bb0a2b8d307eb662faf574da91a42e [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.tests.builder;
import junit.framework.*;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.tests.util.Util;
/**
* Basic execution tests of the image builder.
*/
public class ExecutionTests extends Tests {
public ExecutionTests(String name) {
super(name);
}
public static Test suite() {
return new TestSuite(ExecutionTests.class);
}
public void testSuccess() throws JavaModelException {
IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
env.addExternalJar(projectPath, Util.getJavaClassLib());
fullBuild(projectPath);
// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$
"package p1;\n"+ //$NON-NLS-1$
"public class Hello {\n"+ //$NON-NLS-1$
" public static void main(String args[]) {\n"+ //$NON-NLS-1$
" System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$
" }\n"+ //$NON-NLS-1$
"}\n" //$NON-NLS-1$
);
incrementalBuild(projectPath);
expectingNoProblems();
executeClass(projectPath, "p1.Hello", "Hello world\r\n", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testFailure() throws JavaModelException {
IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
env.addExternalJar(projectPath, Util.getJavaClassLib());
fullBuild(projectPath);
// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
IPath helloPath = env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$
"package p1;\n"+ //$NON-NLS-1$
"public class Hello {\n"+ //$NON-NLS-1$
" public static void main(String args[]) {\n"+ //$NON-NLS-1$
" System.out.println(\"Hello world\")\n"+ //$NON-NLS-1$
" }\n"+ //$NON-NLS-1$
"}\n" //$NON-NLS-1$
);
// public static void main(String args[]) {
// System.out.println("Hello world") <-- missing ";"
// }
incrementalBuild(projectPath);
expectingOnlyProblemsFor(helloPath);
executeClass(projectPath, "p1.Hello", "", //$NON-NLS-1$ //$NON-NLS-2$
"java.lang.Error: Unresolved compilation problem: \n" + //$NON-NLS-1$
" Missing semicolon\n" //$NON-NLS-1$
);
}
}