Skip to content

Commit

Permalink
Fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rainboyan committed Jun 15, 2024
1 parent 28b49c5 commit 61e356e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,37 @@ import spock.lang.Specification

class GrailsCompileStaticCompilationErrorsSpec extends Specification {

void 'Test compiling valid static finder calls'() {
given:
def gcl = new GroovyClassLoader()

when: 'a class marked with @GrailsCompileStatic invokes valid finders'
def c = gcl.parseClass('''
package grails.compiler
@GrailsCompileStatic
class SomeClass {
def someMethod() {
List<Person> people = Person.findAll()
people = Person.list()
int number = Person.count()
Person person = Person.findWhere([name: 'William'])
person = Person.findOrCreateWhere([name: 'William'])
person = Person.findOrSaveWhere([name: 'William'])
}
}
''')
then: 'no errors are thrown'
c
}

@Issue('GRAILS-11056')
void 'Test compiling valid dynamic finder calls'() {
given:
def gcl = new GroovyClassLoader()

when: 'a class marked with @GrailsCompileStatic invokes valid dynamic finders'
when: 'a class marked with @GrailsCompileStatic invokes invalid dynamic finders'
def c = gcl.parseClass('''
package grails.compiler
Expand All @@ -30,8 +55,9 @@ class SomeClass {
}
}
''')
then: 'no errors are thrown'
c
then: 'an error is thrown'
MultipleCompilationErrorsException e = thrown()
e.message.contains '[Static type checking] - Non-static method grails.compiler.Person'
}

@Issue('GRAILS-9996')
Expand Down Expand Up @@ -83,7 +109,7 @@ class SomeOtherNewClass {

@Ignore
@Issue(['GRAILS-11056', 'GRAILS-11057'])
void 'Test comping a dynmaic finder call with the wrong number of arguments'() {
void 'Test comping a dynamic finder call with the wrong number of arguments'() {
given:
def gcl = new GroovyClassLoader()

Expand Down Expand Up @@ -616,6 +642,7 @@ class SomeOtherValidateableClass implements Validateable {
}

@Entity
@GrailsCompileStatic
class Person {
String name
static hasMany = [towns: String]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
package grails.compiler

import grails.persistence.Entity

import org.codehaus.groovy.control.MultipleCompilationErrorsException

import spock.lang.Ignore
import spock.lang.Issue
import spock.lang.Specification


class GrailsTypeCheckedCompilationErrorsSpec extends Specification {

void 'Test compiling valid static finder calls'() {
given:
def gcl = new GroovyClassLoader()

when: 'a class marked with @GrailsTypeChecked invokes valid dynamic finders'
def c = gcl.parseClass('''
package grails.compiler
@GrailsTypeChecked
class SomeClass {
def someMethod() {
List<Company> people = Company.findAll()
people = Company.list()
int number = Company.count()
Company company = Company.findWhere([name: 'William'])
company = Company.findOrCreateWhere([name: 'William'])
company = Company.findOrSaveWhere([name: 'William'])
}
}
''')
then: 'no errors are thrown'
c
}

@Issue(['GRAILS-11056', 'GRAILS-11204'])
void 'Test compiling valid dynamic finder calls'() {
given:
Expand All @@ -32,8 +56,9 @@ class SomeClass {
}
}
''')
then: 'no errors are thrown'
c
then: 'an error is thrown'
MultipleCompilationErrorsException e = thrown()
e.message.contains '[Static type checking] - Non-static method grails.compiler.Company'
}

@Issue(['GRAILS-11056', 'GRAILS-11204'])
Expand Down Expand Up @@ -376,6 +401,7 @@ class SomeClass {
}
}

@GrailsCompileStatic
@Entity
class Company {
String name
Expand Down

0 comments on commit 61e356e

Please sign in to comment.