Groovy Bar & Grill

August 29, 2006

Groovy Log Splitter

Filed under: Groovy Grill — jawild59 @ 9:46 pm

Matt and Blaine are having fun writing Ruby log splitters. I couldn’t pass up the opportunity to write one in Groovy, so here it is:

  baseFilename = args.size() ? args[0"split.log"
  maxLines = args.size() == ? args[1500000
  fileCount = 0
  lineCount = 0
  inputFile = new File(baseFilename)
  writer = newWriter(baseFilename)
  inputFile.eachLine {
    if (lineCount >= maxLines) {
      writer = newWriter(baseFilename)
    }
    writer.append("${it}\n")
    lineCount++
  }
  
  def newWriter(filename) {
    lineCount = 0
    new File("${fileCount++}_${filename}")
  }

August 16, 2006

Extraneous Period in Groovy println

Filed under: Groovy Grill — jawild59 @ 1:26 pm

Update: Looks like it’s a problem in GroovyTestCase. testXXX() method always outputs a “.”

Update: Ah. It’s JUnit’s text-based test runner that is the culprit. Guess I shouldn’t exclusively use the GUI runner.

GROOVY-1463.

Running this test:

class PrintlnTest extends GroovyTestCase {
  void testSomething() {
    def name = GroovyTestCase.class.simpleName
    assertEquals(GroovyTestCase.class.simpleName, name)
    assertTrue(name.length() == "GroovyTestCase".length())
    println name
    println name
  }
}

produces this output:

.GroovyTestCase
GroovyTestCase

Time: 0

OK (1 test)

Anyone have a clue?

Blog at WordPress.com.