nf-test icon indicating copy to clipboard operation
nf-test copied to clipboard

bug: When an input is passed to output with no modification it causes the snapshot to have the absolute path

Open adamrtalbot opened this issue 1 year ago • 2 comments

If you pass an input file to an output file directly, the snapshot includes the absolute path of the input file. This causes problems because the snapshot is not transferable.

workflow.nf:

workflow TEST {
    take:
        myFile

    main:
        myFile.view()

    emit:
        myFile
}

workflow.nf.test:

nextflow_workflow {

    name "Test Workflow TEST"
    script "workflow.nf"
    workflow "TEST"

    test("Should run without failures") {

        when {
            workflow {
                """
                // define inputs of the workflow here. Example:
                input[0] = Channel.of(
                    file("test-file.txt")
                )
                """
            }
        }

        then {
            assert workflow.success
            assert snapshot(workflow.out).match()
        }

    }

}

test-file.txt is a blank file.

Resulting snapshot (on my mac):

{
    "Should run without failures": {
        "content": [
            {
                "0": [
                    "/Users/redacted/nf-experiments/.nf-test/tests/d6a81a8faa4b5f7c9b99d042d493a949/test-file.txt"
                ],
                "myFile": [
                    "/Users/redacted/nf-experiments/.nf-test/tests/d6a81a8faa4b5f7c9b99d042d493a949/test-file.txt"
                ]
            }
        ],
        "meta": {
            "nf-test": "0.8.4",
            "nextflow": "23.10.1"
        },
        "timestamp": "2024-03-19T16:00:05.400755"
    }
}

adamrtalbot avatar Mar 19 '24 16:03 adamrtalbot

See https://github.com/nf-core/modules/pull/5278 for an example

adamrtalbot avatar Mar 19 '24 16:03 adamrtalbot

Hi Adam,

thanks, I tried to replicate this issue, but I only see this behaviour if the path of the input file is wrong. I was able to run the test with both empty and non-empty files.

 nextflow_workflow {

    name "Test Workflow TEST"
    script "./workflow.nf"
    workflow "TEST"

    test("Should run without failures") {

        when {
            workflow {
                """
                // define inputs of the workflow here. Example:
                input[0] = Channel.of(
                    file("${moduleDir}/test-file2.txt", checkIfExists: true)
                )
                """
            }
        }

        then {
            assert workflow.success
            assert snapshot(workflow.out).match()
        }

    }

}

See here: https://github.com/askimed/nf-test/commit/d8441aff602247d011fbb377b0cb144f7ecc0574

lukfor avatar Jul 13 '24 11:07 lukfor