|
1 | 1 | package grails.compiler |
2 | | -import grails.persistence.Entity |
3 | 2 |
|
| 3 | +import grails.persistence.Entity |
4 | 4 | import org.codehaus.groovy.control.MultipleCompilationErrorsException |
5 | | - |
6 | 5 | import spock.lang.Ignore |
7 | 6 | import spock.lang.Issue |
8 | 7 | import spock.lang.Specification |
9 | 8 |
|
10 | | - |
11 | 9 | class GrailsCompileStaticCompilationErrorsSpec extends Specification { |
12 | 10 |
|
13 | 11 | @Issue('GRAILS-11056') |
@@ -469,6 +467,62 @@ class SomeService { |
469 | 467 | e.message.contains 'Cannot find matching method java.lang.String#lastName()' |
470 | 468 |
|
471 | 469 | } |
| 470 | + |
| 471 | + @Issue('grails/grails-core#10157') |
| 472 | + void 'Test constraints block which imports from a non-existent class'() { |
| 473 | + given: |
| 474 | + def gcl = new GroovyClassLoader() |
| 475 | + |
| 476 | + when: 'a class marked with @GrailsCompileStatic imports constraints from a non-existent class' |
| 477 | + gcl.parseClass(''' |
| 478 | +package grails.compiler |
| 479 | +
|
| 480 | +import grails.validation.Validateable |
| 481 | +
|
| 482 | +@GrailsCompileStatic |
| 483 | +class SomeValidateableClassWithInvalidImport implements Validateable { |
| 484 | + String name |
| 485 | +
|
| 486 | + static constraints = { |
| 487 | + importFrom SomeNonExistentClass |
| 488 | + } |
| 489 | +} |
| 490 | +''') |
| 491 | + then: 'an error is thrown' |
| 492 | + thrown(MultipleCompilationErrorsException) |
| 493 | + } |
| 494 | + |
| 495 | + @Issue('grails/grails-core#10157') |
| 496 | + void 'Test constraints block which imports constraints'() { |
| 497 | + given: |
| 498 | + def gcl = new GroovyClassLoader() |
| 499 | + |
| 500 | + when: 'a class marked with @GrailsCompileStatic imports constraints from a non-existent class' |
| 501 | + def c = gcl.parseClass(''' |
| 502 | +package grails.compiler |
| 503 | +
|
| 504 | +import grails.validation.Validateable |
| 505 | +
|
| 506 | +@GrailsCompileStatic |
| 507 | +class SomeValidateableClassWithValidImport implements Validateable { |
| 508 | + String name |
| 509 | +
|
| 510 | + static constraints = { |
| 511 | + importFrom SomeOtherValidateableClass |
| 512 | + } |
| 513 | +} |
| 514 | +
|
| 515 | +class SomeOtherValidateableClass implements Validateable { |
| 516 | + String name |
| 517 | + static constraints = { |
| 518 | + name size: 3..15 |
| 519 | + } |
| 520 | +} |
| 521 | +''') |
| 522 | + |
| 523 | + then: 'the constraints were properly imported' |
| 524 | + gcl.loadClass('grails.compiler.SomeValidateableClassWithValidImport').constraintsMap['name'].getAppliedConstraint('size').range == 3..15 |
| 525 | + } |
472 | 526 | } |
473 | 527 |
|
474 | 528 | @Entity |
|
0 commit comments