I’m wondering if someone can help me figure out ho...
# nf-test
m
I’m wondering if someone can help me figure out how to add helper groovy functions. I have the following code in my
.nf-test
file
Copy code
...
then {
////////////////////////////////////////////////////////
// CLOSURE VERSION OF HELPER FUNCTION WORKS. BUT HAVING TROUBLE MOVING IT TO test/lib/debugOut.groovy AND USING IT IN THE TEST.
////////////////////////////////////////////////////////
// def RESET = "\033[0m"
// def CYAN  = "\033[36m"
// def YELLOW = "\033[33m"
// def GREEN = "\033[32m"
// def MAGENTA = "\033[35m"
// def debugOut
// debugOut = { obj, indent = "", top = true ->

//     // Only print top-level object
//     // equivalent to println "process.out:"
//     if (top) {
//         println ""
//         println "--------------------------------"
//         println "PROCESS OUTPUT"
//         println "$obj"
//         println "--------------------------------"
//         println ""
//         println "--------------------------------"
//         println "DETAILED TREE VIEW OF PROCESS OUTPUT"
//         println "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"
//         }

//     if (obj instanceof Map) {
//         obj.each { k, v ->
//             println "${indent}${CYAN}${k}${RESET}:"
//             printTree(v, indent + "  ", false)  // recursive call, top=false
//         }
//     }
//     else if (obj instanceof List) {
//         obj.eachWithIndex { v, i ->
//             println "${indent}${YELLOW}- [$i]${RESET}"
//             printTree(v, indent + "  ", false)
//         }
//     }
//     // File / Path / string pointing to a real file
//     else if (obj instanceof File || obj instanceof java.nio.file.Path ||
//             (obj instanceof String && new File(obj).exists())) {
//         println "${indent}${GREEN}${obj}${RESET}"
//     }
//     else {
//         println "${indent}${MAGENTA}${obj}${RESET}"
//     }
// }
 
            debugOut(process.out)
}
When I try to move this into
tests/lib/debugOut.groovy
, I can’t call it anymore
Copy code
Test Process DECOMPRESS_GENOME

  Test [f08b1056] '.fa.gz - decompresses to .fa' FAILED (26.618s)

  groovy.lang.MissingMethodException: No signature of method: com.askimed.nf.test.lang.process.ProcessContext.debugOut() is applicable for argument types: (com.askimed.nf.test.lang.channels.Channels) values: [[0:[[[id:test_fa], /ibex/project/c2303/20260309_NEXTFLOW-ALGAE-TAXA-FROM-GENOME/.nf-test/tests/f08b1056fb8439342cb24ee0a38d3c3c/work/2e/fc6a86a6c75f05b31e8a41a62a5491/GCA_009858895.3_ASM985889v3_genomic.200409.fa]], ...]]
  Nextflow stdout:
  
  Nextflow stderr:
  

FAILURE: Executed 1 tests in 26.721s (1 failed)
Even when I convert this closure to a function I get the same issue. I have this explicitly defined in my
nf-test.config
file (even though I think this is just re-instating the default config)
Copy code
// load the helper groovy functions
    libDir "tests/lib"
Does anyone know what I’m doing wrong to try and get this helper function to work in my nf-tests?
n
You need to put your function in a class and make the function static:
Copy code
class LibClass {
    static debugOut() {...}
}
Then you will be able to use it like this:
Copy code
then {
    LibClass.debugOut(...)
}
You can name your class anything,
LibClass
is just an example here 😛
m
Ahh okay. I was confused because in the documentation it said nf-test supports including third party libraries (e.g. jar files ) or functions from groovy files So I thought we would be able to use it without wrapping it in a class https://www.nf-test.com/docs/assertions/libraries/?h=lib Thank you!
n
Yeah the documentation can be improved in many ways, We'll get there at some point 😁