codeconsole commented on code in PR #16139:
URL: https://github.com/apache/grails-core/pull/16139#discussion_r3827317560


##########
grails-test-examples/gsp-compile-static/src/integration-test/groovy/gspstatic/GspCompileStaticSpec.groovy:
##########
@@ -0,0 +1,104 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 gspstatic
+
+import grails.testing.mixin.integration.Integration
+import org.grails.gsp.CompileStaticGroovyPage
+import org.grails.gsp.GroovyPagesTemplateEngine
+import org.springframework.beans.factory.annotation.Autowired
+import spock.lang.Specification
+
+/**
+ * An application whose pages are compiled statically, rendered through a 
running server.
+ *
+ * <p>Static compilation of a page is settled by the build rather than by the 
page, so what proves it
+ * is an application that turned it on and pages that only compile if it 
happened. Each page here uses
+ * something the dynamic path would have resolved at render time - a declared 
model, a name the
+ * framework binds, a tag call, a typed local - and the class the page 
compiled to is checked as well,
+ * because a page that renders correctly renders correctly either way.
+ */
+@Integration
+class GspCompileStaticSpec extends Specification {
+
+    @Autowired
+    GroovyPagesTemplateEngine templateEngine
+
+    void 'a page that declares its model is compiled statically and renders'() 
{
+        when:
+        String body = new 
URL("http://localhost:${serverPort}/demo/declared";).text
+
+        then: 'the model is read with the types it declared'
+        body.contains('<p id="title">Ubik</p>')
+        body.contains('<p id="pages">224</p>')
+
+        and: 'arithmetic on a declared int is done on the int'
+        body.contains('<p id="total">672</p>')
+
+        and: 'a typed g:set declares a local and still writes the scope'
+        body.contains('<p id="upper">UBIK</p>')
+    }
+
+    void 'a page reading the names the framework binds is compiled statically 
and renders'() {
+        when:
+        String body = new 
URL("http://localhost:${serverPort}/demo/frameworkNames?n=7";).text
+
+        then:
+        body.contains('<p id="controller">demo</p>')
+        body.contains('<p id="action">frameworkNames</p>')
+        body.contains('<p id="flash">from flash</p>')
+
+        and: 'params keeps the conversions it declares, so int() is not a 
dynamic call'
+        body.contains('<p id="param">7</p>')
+
+        and: 'a tag call still runs'
+        body.contains('<p id="link">/demo/declared</p>')
+    }
+
+    void 'a page using closures and a tag library renders what it computed'() {
+        when:
+        String body = new URL("http://localhost:${serverPort}/demo/index";).text
+
+        then:
+        body.contains('<li id="book-0">Dune has 412 pages</li>')
+        body.contains('<li id="book-1">Emma has 474 pages</li>')
+        body.contains('<p id="count">2</p>')
+        body.contains('<p id="longest">Emma</p>')
+
+        and: 'a tag library in its own namespace is reached'
+        body.contains('<p id="shout">QUIET</p>')
+    }
+

Review Comment:
   Valid, and worse than you described. Added in 5c45f23: the test reads the 
classes in the task output directory directly.
   
   Wiring it up showed the gap was real — `integrationTest` has no dependency 
on `compileGroovyPages`, so on a clean build that directory is empty and the 
assertion would have been vacuous. My earlier runs only passed because I had 
run the task by hand. The dependency is stated now, and I checked the assertion 
both ways from a cleaned output directory: it fails with `gsp = false` and 
passes with it on.
   
   That also answers the propagation question directly — with the flag off, 
`frameworkNames_gsp` compiles dynamically while `declared_gsp` stays static 
from its `model` directive, so the flag does reach the fork.
   
   On the smaller note: agreed, and the test says so — the two model-directive 
pages are split into their own feature from the one that tests the flag.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to