You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/02/16 21:41:18 UTC
[groovy] branch GROOVY_4_0_X updated: GROOVY-10483: GroovyMain: use default encoding if none supplied
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new 59b0010 GROOVY-10483: GroovyMain: use default encoding if none supplied
59b0010 is described below
commit 59b001019926825cdef75cab99c624ce9d0c7371
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Feb 16 15:22:50 2022 -0600
GROOVY-10483: GroovyMain: use default encoding if none supplied
---
src/main/java/groovy/ui/GroovyMain.java | 2 +-
src/test/groovy/ui/GroovyMainTest.groovy | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/main/java/groovy/ui/GroovyMain.java b/src/main/java/groovy/ui/GroovyMain.java
index a78cc93..643fb10 100644
--- a/src/main/java/groovy/ui/GroovyMain.java
+++ b/src/main/java/groovy/ui/GroovyMain.java
@@ -251,7 +251,7 @@ public class GroovyMain {
final GroovyMain main = new GroovyMain();
// add the ability to parse scripts with a specified encoding
- main.conf.setSourceEncoding(encoding);
+ if (encoding != null) main.conf.setSourceEncoding(encoding);
main.debug = debug;
main.conf.setDebug(main.debug);
diff --git a/src/test/groovy/ui/GroovyMainTest.groovy b/src/test/groovy/ui/GroovyMainTest.groovy
index f9facda..c79407c 100644
--- a/src/test/groovy/ui/GroovyMainTest.groovy
+++ b/src/test/groovy/ui/GroovyMainTest.groovy
@@ -22,7 +22,8 @@ import groovy.test.GroovyTestCase
import static groovy.test.GroovyAssert.isAtLeastJdk
-class GroovyMainTest extends GroovyTestCase {
+final class GroovyMainTest extends GroovyTestCase {
+
private baos = new ByteArrayOutputStream()
private ps = new PrintStream(baos)
@@ -141,6 +142,23 @@ assert new MyConcreteClass() != null"""
}
}
+ // GROOVY-10483
+ void testSourceEncoding() {
+ def configScript = File.createTempFile('config', '.groovy')
+ def sourceCoding = System.setProperty('groovy.source.encoding', 'US-ASCII')
+ try {
+ configScript.text = 'assert configuration.sourceEncoding == "US-ASCII"'
+ GroovyMain.main('--configscript', configScript.path, '-e', '42')
+ } finally {
+ if (sourceCoding) {
+ System.setProperty('groovy.source.encoding', sourceCoding)
+ } else {
+ System.clearProperty('groovy.source.encoding')
+ }
+ configScript.delete()
+ }
+ }
+
void testGroovyASTDump() {
// current xstream causes illegal access errors on JDK9+ - skip on those JDK versions, get coverage on older versions
if (isAtLeastJdk('9.0')) return