You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/11/19 00:25:30 UTC

[groovy] branch master updated: add check for required parameter when using NamedVariant (additional test)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 059434f  add check for required parameter when using NamedVariant (additional test)
059434f is described below

commit 059434faad631132ef84ff72814f307dbb1029ee
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Nov 19 10:25:24 2021 +1000

    add check for required parameter when using NamedVariant (additional test)
---
 .../groovy/org/codehaus/groovy/classgen/RecordTest.groovy   | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy b/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy
index a86f841..b67602e 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy
+++ b/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy
@@ -136,6 +136,19 @@ class RecordTest {
     }
 
     @Test
+    void testRecordWithDefaultParamsAndMissingRequiredParam() {
+        assertScript '''
+            import static groovy.test.GroovyAssert.shouldFail
+            record Point(int i = 5, int j, int k = 10) {}
+            assert new Point(j: 100).toString() == 'Point[i=5, j=100, k=10]'
+            def err = shouldFail(AssertionError) {
+                assert new Point(i: 50).toString() == 'Point[i=50, j=10]'
+            }
+            assert err.message.contains("Missing required named argument 'j'")
+        '''
+    }
+
+    @Test
     void testNativeRecordOnJDK16plus() {
         assumeTrue(isAtLeastJdk('16.0'))
         assertScript '''