Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 6, 2020
1 parent 51ddcac commit d874d9b
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.jdt.groovy.core.tests.xform;

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

/**
* Test cases for {@link groovy.transform.BaseScript}.
*/
public final class BaseScriptTests extends GroovyCompilerTestSuite {

@Test
public void testBaseScript1() {
//@formatter:off
String[] sources = {
"Main.groovy",
"print new GroovyShell().evaluate('''\n" +
" @BaseScript(Foo)\n" +
" import groovy.transform.BaseScript\n" +
" abstract class Foo extends Script {\n" +
" def test() { 'works' }\n" +
" }\n" +
" test()\n" +
"''')\n",
};
//@formatter:on

runConformTest(sources, "works");
}

@Test
public void testBaseScript2() {
//@formatter:off
String[] sources = {
"Foo.groovy",
"abstract class Foo extends Script {\n" +
"}\n",

"Main.groovy",
"@groovy.transform.BaseScript(Foo) foo\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 1)\n" +
"\t@groovy.transform.BaseScript(Foo) foo\n" +
"\t ^^^\n" +
"Groovy:Annotation @BaseScript cannot have member 'value' if used on a declaration.\n" +
"----------\n");
}

@Test
public void testBaseScript3() {
//@formatter:off
String[] sources = {
"Main.groovy",
"print new GroovyShell().evaluate('''\n" +
" abstract class Foo extends Script {\n" +
" def test() { 'works' }\n" +
" }\n" +
" @groovy.transform.BaseScript Foo foo\n" +
" test()\n" +
"''')\n",
};
//@formatter:on

runConformTest(sources, "works");
}

@Test
public void testBaseScript4() {
//@formatter:off
String[] sources = {
"Main.groovy",
"print new GroovyShell().evaluate('''\n" +
" abstract class Foo extends Script {\n" +
" abstract def bar()\n" +
" def run() {\n" +
" 'before' + bar() + '-after'\n" +
" }\n" +
" }\n" +
" @groovy.transform.BaseScript Foo foo\n" +
" return '-during'\n" +
"''')\n",
};
//@formatter:on

runConformTest(sources, "before-during-after");
}

@Test
public void testBaseScript5() {
//@formatter:off
String[] sources = {
"Foo.groovy",
"abstract class Foo {\n" +
"}\n",

"Main.groovy",
"@groovy.transform.BaseScript Foo foo\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 1)\n" +
"\t@groovy.transform.BaseScript Foo foo\n" +
"\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Groovy:Declared type Foo -> Foo does not extend groovy.lang.Script class!\n" +
"----------\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ul>
<li>@groovy.transform.AutoFinal (2.5+)</li>
<li>@groovy.transform.AutoImplement (2.5+)</li>
<li>@groovy.transform.BaseScript</li>
<li>@groovy.transform.BaseScript&nbsp;&#x2713;</li>
<li>@groovy.transform.Canonical, et al.&nbsp;&#x2713;</li>
<ul style="margin-bottom: 0">
<li>@groovy.transform.EqualsAndHashCode</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.junit.runners.Suite
org.eclipse.jdt.groovy.core.tests.xform.AnnotationCollectorTests,
org.eclipse.jdt.groovy.core.tests.xform.AutoCloneTests,
org.eclipse.jdt.groovy.core.tests.xform.AutoFinalTests,
org.eclipse.jdt.groovy.core.tests.xform.BaseScriptTests,
org.eclipse.jdt.groovy.core.tests.xform.CanonicalTests,
org.eclipse.jdt.groovy.core.tests.xform.CategoryTests,
org.eclipse.jdt.groovy.core.tests.xform.DelegateTests,
Expand Down

0 comments on commit d874d9b

Please sign in to comment.