|
Groovy example source code file (GroovyMainTest.groovy)
The Groovy GroovyMainTest.groovy source code
package 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: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.