askimed/nf-test

Bug: nf-test v0.8.2 fails to parse regex strings when loaded in params block

Closed this issue · 2 comments

Hi @lukfor ,

We started using v0.8.2 and started updating some older testcases. What we noticed is that Groovy fails to parse template script when we try to load a regex string containing special characters. I will document the test case below and finally the error message.
workflow..nf

process exampleProc {

    storeDir "${outputDir}/exampleProc"
    input:
        tuple(
            val(outputDir),
            val(localOutputDir),
            val(someRegexString)
        )

    output:
        tuple(
            val(outputDir),
            path("example_output/example*.txt")
        )

    shell:
        """
        mkdir -p !{localOutputDir}
        echo !{someRegexString} > "!{localOutputDir}/example1.txt"
        """
}


workflow PipeWf {
    take:
        inputCh

    main:
        inputCh
            | exampleProc
            | set { outputCh }

    emit:
        outputCh

workflow.nf.test


nextflow_workflow {

    name "Test workflow"
    script "testing_examples/workflow.nf"
    workflow "PipeWf"

    test("Output will exist in default outputDir") {

        when {

            params {
                outDir = "$outputDir"
                load("params.yaml")
            }
            workflow {
                """
                input[0] = Channel.of([params.outDir,params.localOutputDir])
                """
            }
        }

        then {
              assert workflow.success
              assert path("${outputDir}/exampleProc/example_output").exists()
            }
    }
}

params.yaml

localOutputDir: "example_output"
someRegex: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'

Finally, error message:

Test workflow

  Test [6c7a7547] 'Output will exist in default outputDir' FAILED (0.025s)

  groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
  SimpleTemplateScript1.groovy: 1: Unexpected character: '"' @ line 1, column 13.
     out.print("""localOutputDir: \"example_output\"
                 ^
  
  1 error
  



FAILURE: Executed 1 tests in 0.031s (1 failed)

I have tried in various combination, however the regexes keep throwing these errors. Is this a bug or I simply am not aware of some Groovy limitations?

Hi Ivo, thanks! It seems you have to escape \ and $, otherwise Groovy expects a template variable.

localOutputDir: "example_output"
someRegex: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\$'

Since version 0.8.2, it is possible to use variables such as ${projectDir} in params.yaml. This explains the broken behaviour.

Thank you @lukfor . I will test that out!