|
Groovy example source code file (GroovyMainTest.groovy)
The Groovy GroovyMainTest.groovy source codepackage groovy.ui class GroovyMainTest extends GroovyTestCase { private baos = new ByteArrayOutputStream() private ps = new PrintStream(baos) void testHelp() { String[] args = ['-h'] GroovyMain.processArgs(args, ps) def out = baos.toString() assert out.contains('usage: groovy') ['-a', '-c', '-d', '-e', '-h', '-i', '-l', '-n', '-p', '-v'].each{ assert out.contains(it) } } void testVersion() { String[] args = ['-v'] GroovyMain.processArgs(args, ps) def out = baos.toString() assert out.contains('Groovy Version:') assert out.contains('JVM:') } void testNoArgs() { String[] args = [] GroovyMain.processArgs(args, ps) def out = baos.toString() assert out.contains('error: neither -e or filename provided') } void testAttemptToRunJavaFile() { String[] args = ['abc.java'] GroovyMain.processArgs(args, ps) def out = baos.toString() assert out.contains('error: error: cannot compile file with .java extension: abc.java') } /** * GROOVY-1512: Add support for begin() and end() methods when processing files by line with -a -ne */ void testAandNEparametersWithBeginEndFunctions() { def originalErr = System.err System.setErr(ps) def tempFile = File.createTempFile("dummy", "txt") tempFile << "dummy text\n" * 10 try { String[] args = ['-a', '-ne', 'def begin() { nb = 0 }; def end() { System.err.println nb }; nb++', tempFile.absolutePath] GroovyMain.main(args) def out = baos.toString() assert out.contains('10') } finally { tempFile.delete() System.setErr(originalErr) } } } Other Groovy examples (source code examples)Here is a short list of links related to this Groovy GroovyMainTest.groovy source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.