askimed / nf-test

Simple test framework for Nextflow pipelines
https://www.nf-test.com
MIT License
145 stars 23 forks source link

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

Open adamrtalbot opened 8 months ago

adamrtalbot commented 8 months ago

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 commented 8 months ago

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

lukfor commented 4 months ago

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