Can't see stdout from spock tests & don't understand why file cannot be found

I’m trying to debug some sample code. The Spock tests are failing because it can’t find a file, but I don’t understand why it can’t find the file. I’ve added a “println” before the line that creates the File object (to show the current directory), but I never see that output in the console, or in the test report. I’ve looked at the various reports of issues like this, and I’ve tried to augment the build script with those recommendations, but it’s not making any difference.

For background, the sample code I’m working with is from the code dump for the PackT book “Groovy for Domain-specific Languages - Second Edition”. My root cause is probably not a Gradle issue, but I would like to understand how to properly configure the tests so that I can see all the relevant output.

The following is a key piece of code:

static void loadRewardRules() {
    Binding binding = new Binding()

    binding.onConsume = onConsume
    binding.onPurchase = onPurchase
    binding.onUpgrade = onUpgrade

    println "currdir[${new File(".").getCanonicalPath()}]"
    GroovyShell shell = new GroovyShell(binding)
    shell.evaluate(new File("src/main/groovy/com/dearle/groovydsl/chapters/eleven/BroadBandPlus/offers/Offers.groovy"))

    onConsume = binding.onConsume
    onPurchase = binding.onPurchase
    onUpgrade = binding.onUpgrade   
}

When I run the build, I see exceptions like this:
ChapterElevenSpec > Run Binding 1 example FAILED
java.io.FileNotFoundException: /home/opnfv/work/GroovyDSLBook/groovy-for-dsl/src/main/groovy/com/dearle/groovydsl/chapters/eleven/BroadBandPlus/offers/Offers.groovy (/home/opnfv/work/GroovyDSLBook/groovy-for-dsl/src/main/groovy/com/dearle/groovydsl/chapters/eleven/BroadBandPlus/offers/Offers.groovy)
at groovy.lang.GroovyCodeSource.(GroovyCodeSource.java:106)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:636)
at com.dearle.groovydsl.chapters.eleven.BroadbandPlus.RewardService.loadRewardRules(RewardService.groovy:115)
at ChapterElevenSpec.setup(ChapterElevenSpec.groovy:161)

Following various advice, I have the following in my build script:

    logging.captureStandardOutput LogLevel.INFO

tasks.withType(Test) {
  testLogging { 
    showStandardStreams = true
    exceptionFormat "full"
    minGranularity = 3
  }
}

I imagine some of these nuggets are obsolete now, but it’s hard to tell from the history.

I’ve run the test in the debugger, and stopped at the relevant lines in that method. Using the “display” view, I was able to verify that the specified file (Offers.groovy) is present at that location, assuming the current directory is the project root, and I believe I verified that by evaluating that expression I’m trying to print in the “Display” view in Eclipse.

Please illuminate me.

I’ve resolved these issues.

The FNF error was simply due to a package path that differed by case in one character, which I didn’t notice. These samples were apparently written and tested on MS Windows, which I’m guessing didn’t care about case variations.

My problem with not seeing the output was simply because the class that I added the “println” to was being executed as a script evaluation, which was trapping standard out. I discovered this (after I fixed the case problem) when I noticed the test assertions that were expecting standard out to produce a small text string were failing, because my print statement was part of the output.

Once I changed my print statement to to go standard err instead, I was able to see the output on the console.