Skip to content

Commit

Permalink
Grab tests: disable execution; concerned with compilation only
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jul 12, 2021
1 parent aa4aa6f commit 2e6a12e
Showing 1 changed file with 55 additions and 38 deletions.
Expand Up @@ -16,27 +16,29 @@
package org.eclipse.jdt.groovy.core.tests.xform;

import org.eclipse.jdt.groovy.core.tests.basic.GroovyCompilerTestSuite;
import org.junit.Before;
import org.junit.Test;

/**
* Test cases for {@link groovy.lang.Grab}, et al.
*/
public final class GrabTests extends GroovyCompilerTestSuite {

@Before
public void setUp() {
vmArguments = new String[] {"-Djava.system.class.loader=org.codehaus.groovy.tools.RootLoader"};
}

@Test
public void testGrab1() {
public void testGrab() {
//@formatter:off
String[] sources = {
"Script.groovy",
"@Grab('joda-time:joda-time:2.10.6')\n" +
"def printDate() {\n" +
" def dt = new org.joda.time.DateTime()\n" +
"Main.java",
"public class Main {\n" +
" public static void main(String[] args) {\n" +
// not concerned with execution
" }\n" +
"}\n",

"Test.groovy",
"@Grab('joda-time:joda-time:2.10.10')\n" +
"import org.joda.time.DateTime\n" +
"void printDate() {\n" +
" def now = new DateTime()\n" +
"}\n" +
"printDate()\n",
};
Expand All @@ -52,68 +54,83 @@ public void testGrab1() {
* <p>
* With grab improvements we get two errors - the missing dependency and the missing type (which is at the right version of that dependency!)
*/
@Test
public void testGrab2() {
@Test // GRECLIPSE-1669
public void testGrabError() {
//@formatter:off
String[] sources = {
"Script.groovy",
"Main.java",
"public class Main {\n" +
" public static void main(String[] args) {\n" +
// not concerned with execution
" }\n" +
"}\n",

"Test.groovy",
"@Grapes([\n" +
" @Grab(group='joda-time', module='joda-time', version='1.6'),\n" +
" @Grab(group='joda-time', module='joda-time', version='2.10.10'),\n" +
" @Grab(group='org.aspectj', module='aspectjweaver', version='1.x')\n" +
"])\n" +
"class C {\n" +
" def printDate() {\n" +
"class Test {\n" +
" void printDate() {\n" +
" def dt = new org.joda.time.DateTime()\n" +
" def world = new org.aspectj.weaver.bcel.BcelWorld()\n" +
" print dt\n" +
" }\n" +
" public static void main(String[] argv) {\n" +
" new C().printDate()\n" +
" }\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Script.groovy (at line 3)\n" +
"1. ERROR in Test.groovy (at line 3)\n" +
"\t@Grab(group='org.aspectj', module='aspectjweaver', version='1.x')\n" +
"\t^^^^^\n" +
"Groovy:Error grabbing Grapes -- [unresolved dependency: org.aspectj#aspectjweaver;1.x: not found]\n" +
"----------\n" +
"2. ERROR in Script.groovy (at line 8)\n" +
"2. ERROR in Test.groovy (at line 8)\n" +
"\tdef world = new org.aspectj.weaver.bcel.BcelWorld()\n" +
"\t ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Groovy:unable to resolve class org.aspectj.weaver.bcel.BcelWorld\n" +
"----------\n");
}

@Test // https://issues.apache.org/jira/browse/GROOVY-9376
public void testGrabResolver() {
@Test // GRECLIPSE-1432
public void testGrabConfig() {
//@formatter:off
String[] sources = {
"Script.groovy",
"@GrabResolver(name='restlet', root='https://maven.restlet.talend.com')\n" +
"@Grab(group='org.restlet.jse', module='org.restlet', version='2.4.3')\n" +
"import org.restlet.Restlet\n",
"Main.java",
"public class Main {\n" +
" public static void main(String[] args) {\n" +
// not concerned with execution
" }\n" +
"}\n",

"Test.groovy",
"@GrabConfig(systemClassLoader=true)\n" +
"@Grab(group='mysql', module='mysql-connector-java', version='5.1.15')\n" +
"class Test {\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources, "");
}

@Test
public void testGrabScriptAndImports_GRE680() {
@Test // GROOVY-9376
public void testGrabResolver() {
//@formatter:off
String[] sources = {
"Script.groovy",
"import org.mortbay.jetty.Server\n" +
"import org.mortbay.jetty.servlet.*\n" +
"import groovy.servlet.*\n" +
"\n" +
"@Grab(group='org.mortbay.jetty', module='jetty-embedded', version='6.1.0')\n" +
"def runServer(duration) { }\n" +
"runServer(10000)\n",
"Main.java",
"public class Main {\n" +
" public static void main(String[] args) {\n" +
// not concerned with execution
" }\n" +
"}\n",

"Test.groovy",
"@GrabResolver(name='restlet', root='https://maven.restlet.talend.com')\n" +
"@Grab(group='org.restlet.jse', module='org.restlet', version='2.4.3')\n" +
"import org.restlet.Restlet\n",
};
//@formatter:on

Expand Down

0 comments on commit 2e6a12e

Please sign in to comment.