Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor builder tests
Browse files Browse the repository at this point in the history
eric-milles committed Sep 20, 2020
1 parent 8fe6793 commit 572a347
Showing 14 changed files with 54 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -76,9 +76,7 @@ private IPath[] createModularProject(final String name, final boolean isGroovy)
} else {
env.removeGroovyNature(name);
}
env.setOutputFolder(prjPath, "bin");
env.removePackageFragmentRoot(prjPath, "");
IPath srcPath = env.addPackageFragmentRoot(prjPath, "src");
IPath srcPath = env.getPackageFragmentRootPath(prjPath, "src");
try {
return new IPath[] {prjPath, srcPath, env.addClass(srcPath,
"module-info", "module " + name.toLowerCase() + " {\n}\n")};
@@ -88,16 +86,14 @@ private IPath[] createModularProject(final String name, final boolean isGroovy)
}

private IPath[] createSimpleProject(final String name, final boolean isGroovy) throws Exception {
IPath path = env.addProject(name, "1.8");
IPath prjPath = env.addProject(name, "1.8");
if (isGroovy) {
env.addGroovyJars(path);
env.addGroovyJars(prjPath);
} else {
env.removeGroovyNature(name);
}
fullBuild(path);
env.setOutputFolder(path, "bin");
env.removePackageFragmentRoot(path, "");
return new IPath[] {path, env.addPackageFragmentRoot(path, "src")};
fullBuild(prjPath);
return new IPath[] {prjPath, env.getPackageFragmentRootPath(prjPath, "src")};
}

private void addJUnitAndSpock(final IPath projectPath) throws Exception {
@@ -385,20 +381,22 @@ public void testProjectCompilerConfigScript2() throws Exception {

@Test // https://github.com/groovy/groovy-eclipse/issues/550
public void testProjectBasedirAsOutputLocation() throws Exception {
IPath path = env.addProject("Project", "1.8");
env.setOutputFolder(path, "");
env.addGroovyJars(path);
IPath prj = env.addProject("Project", "1.8");
env.removePackageFragmentRoot(prj, "src");
env.addPackageFragmentRoot(prj, "");
env.setOutputFolder(prj, "");
env.addGroovyJars(prj);

//@formatter:off
env.addGroovyClass(path, "p", "Script",
env.addGroovyClass(prj, "p", "Script",
"package p\n" +
"println 'Groovy!'\n");
//@formatter:on

fullBuild(path);
fullBuild(prj);
expectingNoProblems();
expectingCompiledClasses("p.Script");
executeClass(path, "p.Script", "Groovy!", null);
executeClass(prj, "p.Script", "Groovy!", null);
}

@Test
@@ -3342,10 +3340,10 @@ public void test98667() throws Exception {
}

@Test // https://bugs.eclipse.org/bugs/show_bug.cgi?id=164707
public void testBug164707() throws Exception {
IPath projectPath = env.addProject("Project");
env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_SOURCE, "invalid");
fullBuild(projectPath);
public void testBug164707() {
IPath prj = env.addProject("Project");
env.getJavaProject(prj).setOption(JavaCore.COMPILER_SOURCE, "invalid");
fullBuild(prj);
expectingNoProblems();
}

@@ -3447,41 +3445,24 @@ public void testTags4() throws Exception {
assertEquals("Wrong priority", IMarker.PRIORITY_HIGH, priority);
}

@Test // When a groovy file name clashes with an existing type
@Test // a groovy file name clashes with an existing type
public void testBuildClash() throws Exception {
IPath[] paths = createSimpleProject("Project", true);

//@formatter:off
env.addGroovyClass(paths[1], "", "Stack",
"class StackTester {\n" +
" def o = new Stack();\n" +
" public static void main(String[] args) {\n" +
" System.out.println('>>'+new StackTester().o.getClass());\n" +
" System.out.println(\"Hello world\");\n" +
" }\n" +
"}\n");
//@formatter:on

incrementalBuild(paths[0]);
expectingCompiledClasses("StackTester");
expectingNoProblems();
executeClass(paths[0], "StackTester", ">>class java.util.Stack\nHello world\n", "");

//@formatter:off
env.addGroovyClass(paths[1], "", "Stack",
"class StackTester {\n" +
" def o = new Stack();\n" +
" public static void main(String[] args) {\n" +
" System.out.println('>>'+new StackTester().o.getClass());\n" +
" System.out.println(\"Hello world\");\n" +
" def x = new Stack()\n" +
" static main(args) {\n" +
" print(new StackTester().x.class)\n" +
" }\n" +
"}\n");
//@formatter:on

incrementalBuild(paths[0]);
expectingCompiledClasses("StackTester");
expectingNoProblems();
executeClass(paths[0], "StackTester", ">>class java.util.Stack\nHello world\n", "");
expectingCompiledClasses("StackTester", "StackTester"); // twice?
executeClass(paths[0], "StackTester", "class java.util.Stack", "");
}

@Test
Original file line number Diff line number Diff line change
@@ -49,8 +49,7 @@ public final class BuildAccessRulesTests extends BuilderTestSuite {
@Before
public void setUp() throws Exception {
prj = env.addProject("Project", "1.7");
src = prj.append("src");
env.createFolder(src);
src = env.getPackageFragmentRootPath(prj, "src");
env.setClasspath(prj, new IClasspathEntry[] {
JavaCore.newSourceEntry(src),
GroovyRuntime.newGroovyClasspathContainerEntry(false, false, null),
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jdt.core.IAccessRule;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
@@ -161,7 +162,6 @@ protected final void incrementalBuild(IPath projectPath) {
}
}

@SuppressWarnings("cast")
protected void executeClass(IPath projectPath, String className, String expectingOutput, String expectedError) {
List<String> classpath = new ArrayList<>();
IPath workspacePath = env.getWorkspaceRootPath();
@@ -315,9 +315,9 @@ public IPath addProject(String projectName) {
public IPath addProject(String projectName, String compliance) {
try {
IPath projectPath = super.addProject(projectName, compliance);
removePackageFragmentRoot(projectPath, "");
addPackageFragmentRoot(projectPath, "src");

new ProjectScope(getProject(projectName)).getNode(JavaRuntime.ID_PLUGIN)
.put(JavaRuntime.PREF_COMPILER_COMPLIANCE_DOES_NOT_MATCH_JRE, JavaCore.IGNORE);
IClasspathAttribute[] attributes;
if (JavaCore.compareJavaVersions(compliance, "9") < 0) {
attributes = new IClasspathAttribute[0];
@@ -327,6 +327,9 @@ public IPath addProject(String projectName, String compliance) {
addEntry(projectPath, JavaCore.newContainerEntry(JavaRuntime.newDefaultJREContainerPath(), new IAccessRule[0], attributes, false));

addGroovyNature(projectName);
IProject project = getProject(projectName);
setPreference(project, "org.codehaus.groovy.eclipse.dsl", "org.codehaus.groovy.eclipse.dsl.disabled", "true");
setPreference(project, JavaRuntime.ID_PLUGIN, JavaRuntime.PREF_COMPILER_COMPLIANCE_DOES_NOT_MATCH_JRE, "ignore");

return projectPath;
} catch (JavaModelException e) {
@@ -462,6 +465,16 @@ public IPath addGroovyClassExtension(IPath packageFragmentRootPath, String packa
return addGroovyClassExtension(packageFragmentRootPath, className, contents, fileExtension);
}

public void setPreference(IProject project, String node, String key, String val) {
IEclipsePreferences prefs = new ProjectScope(project).getNode(node);
prefs.put(key, val);
try {
prefs.flush();
} catch (org.osgi.service.prefs.BackingStoreException e) {
throw new RuntimeException(e);
}
}

public <U extends ICompilationUnit> U getUnit(IPath path) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
@SuppressWarnings("unchecked")
Original file line number Diff line number Diff line change
@@ -58,9 +58,7 @@ private static void assertContainsProblem(Set<IProblem> problems, String expecte
private IPath[] createGroovyProject() throws Exception {
IPath prj = env.addProject("Project");
env.addGroovyJars(prj);
env.setOutputFolder(prj, "bin");
env.removePackageFragmentRoot(prj, "");
return new IPath[] {prj, env.addPackageFragmentRoot(prj, "src")};
return new IPath[] {prj, env.getPackageFragmentRootPath(prj, "src")};
}

//--------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -41,12 +41,8 @@ private IPath createGenericProject() throws Exception {
return env.getProject("Project").getFullPath();
}
IPath projectPath = env.addProject("Project");
// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, "");
env.addGroovyJars(projectPath);
fullBuild(projectPath);
env.addPackageFragmentRoot(projectPath, "src");
env.setOutputFolder(projectPath, "bin");
return projectPath;
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -409,10 +409,7 @@ private CompilationUnit createScriptInGroovyProject(String name, String contents
IPath projectPath = env.addProject("Project");
env.addGroovyJars(projectPath);

// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, "");
env.addPackageFragmentRoot(projectPath, "scripts");
env.setOutputFolder(projectPath, "bin");
IProject project = env.getProject("Project");
IPath path;
if (isGroovy) {
Original file line number Diff line number Diff line change
@@ -282,11 +282,9 @@ private ICompilationUnit createCompUnit(String pack, String name, String text) t
private IPath createGenericProject() throws Exception {
IPath projectPath = env.addProject("Project");
env.addGroovyJars(projectPath);
env.removePackageFragmentRoot(projectPath, "");
IPath root = env.addPackageFragmentRoot(projectPath, "src");
env.setOutputFolder(projectPath, "bin");
fullBuild(projectPath);
return root;

return env.getPackageFragmentRootPath(projectPath, "src");
}

//--------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,11 +38,6 @@ public void setUp() throws Exception {
IPath projectPath = env.addProject("Project");
env.addGroovyJars(projectPath);
fullBuild(projectPath);

// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, "");
env.addPackageFragmentRoot(projectPath, "src");
env.setOutputFolder(projectPath, "bin");
}

@Test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,11 +55,7 @@ public void testCreateJavaCompilationUnit() throws Exception {
IPath projectPath = env.addProject("Project");
fullBuild(projectPath);

// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, "");

IPath root = env.addPackageFragmentRoot(projectPath, "src");
env.setOutputFolder(projectPath, "bin");
IPath root = env.getPackageFragmentRootPath(projectPath, "src");

IPath path = env.addClass(root, "p1", "Hello",
"package p1;\n" +
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -172,10 +172,8 @@ private void checkJavaProject(IProject proj) throws Exception {

private static IProject createProject() throws Exception {
IPath projectPath = env.addProject("Project");
env.removePackageFragmentRoot(projectPath, "");

IPath root = env.addPackageFragmentRoot(projectPath, "src");
env.setOutputFolder(projectPath, "bin");
IPath root = env.getPackageFragmentRootPath(projectPath, "src");

env.addClass(root, "p1", "HelloJava",
"package p1;\n" +
Original file line number Diff line number Diff line change
@@ -28,11 +28,7 @@ protected final IFile createProject(boolean isGroovy) throws Exception {
env.removeGroovyNature("Project");
}

// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, "");

IPath root = env.addPackageFragmentRoot(projectPath, "src");
env.setOutputFolder(projectPath, "bin");
IPath root = env.getPackageFragmentRootPath(projectPath, "src");

if (isGroovy) {
env.addGroovyJars(projectPath);
@@ -66,14 +62,9 @@ protected final IFile createSimpleJavaProject() throws Exception {
protected final IPath createEmptyGroovyProject() throws Exception {
IPath projectPath = env.addProject("Project");
env.addGroovyJars(projectPath);

// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, "");
IPath root = env.addPackageFragmentRoot(projectPath, "src");

env.setOutputFolder(projectPath, "bin");
fullBuild(projectPath);
return root;

return env.getPackageFragmentRootPath(projectPath, "src");
}

protected final IPath createAnnotationGroovyProject() throws Exception {
Original file line number Diff line number Diff line change
@@ -126,15 +126,11 @@ private void checkExist(GroovyCompilationUnit unit) {

private GroovyCompilationUnit createSimpleGroovyProject(String pack, String contents) throws Exception {
IPath projectPath = env.addProject("Project");
env.addGroovyNature("Project");
env.addGroovyJars(projectPath);
fullBuild(projectPath);
expectingNoProblems();
// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, "");

IPath root = env.addPackageFragmentRoot(projectPath, "src");
env.setOutputFolder(projectPath, "bin");
IPath root = env.getPackageFragmentRootPath(projectPath, "src");
IPath path = env.addGroovyClass(root, "", "Groovy", contents);
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
return (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(file);
Original file line number Diff line number Diff line change
@@ -75,13 +75,7 @@ public final void setUpSearchTestCase() throws Exception {

protected IProject createGroovyProject() throws Exception {
IPath projectPath = env.addProject("Project");
env.addGroovyNature("Project");
env.addGroovyJars(projectPath);

// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, "");
env.addPackageFragmentRoot(projectPath, "src");
env.setOutputFolder(projectPath, "bin");
env.fullBuild(projectPath);

return env.getProject("Project");
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog" />
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.codehaus.groovy.alltests" />
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider" />
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Xmx1g -Dgroovy.antlr4=false -Dgroovy.enable.parameterized.type.cache=false" />
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Xmx1536m -Dgroovy.antlr4=false -Dgroovy.enable.parameterized.type.cache=false" />
<stringAttribute key="pde.version" value="3.3" />
<stringAttribute key="product" value="org.eclipse.platform.ide" />
<booleanAttribute key="run_in_ui_thread" value="true" />

0 comments on commit 572a347

Please sign in to comment.