Skip to content
Permalink
Browse files
GROOVY-10483: GroovyMain: use default encoding if none supplied
  • Loading branch information
eric-milles committed Feb 16, 2022
1 parent 9e06219 commit 85676f1855bbe751bac897ea3fdd900fbbe74ecb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
@@ -251,7 +251,7 @@ boolean process(CommandLine parser) throws ParameterException, IOException {
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);
@@ -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

0 comments on commit 85676f1

Please sign in to comment.