Skip to content

Commit

Permalink
Merge branch '2.2.0-dev' of github.com:nextflow-io/nf-schema into 2.2…
Browse files Browse the repository at this point in the history
….0-dev
  • Loading branch information
nvnieuwk committed Oct 30, 2024
2 parents af9e968 + f4b9caa commit 5d529a6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

1. Fixed a bug in `samplesheetToList` that caused output mixing when the function was used more than once in channel operators.
2. Added a missing depencency for email format validation.
3. All path formats (with exception to `file-path-pattern`) will now give a proper error message when a `file-path-pattern` has been used.

## Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class FormatDirectoryPathEvaluator implements Evaluator {

// Actual validation logic
def Path file = Nextflow.file(value) as Path
if (file instanceof List) {
return Evaluator.Result.failure("'${value}' is not a directory, but a file path pattern" as String)
}
if (file.exists() && !file.isDirectory()) {
return Evaluator.Result.failure("'${value}' is not a directory, but a file" as String)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class FormatFilePathEvaluator implements Evaluator {

// Actual validation logic
def Path file = Nextflow.file(value) as Path
if (file instanceof List) {
return Evaluator.Result.failure("'${value}' is not a file, but a file path pattern" as String)
}
if (file.exists() && file.isDirectory()) {
return Evaluator.Result.failure("'${value}' is not a file, but a directory" as String)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class FormatPathEvaluator implements Evaluator {

// Actual validation logic
def Path file = Nextflow.file(value) as Path
if (file instanceof List) {
return Evaluator.Result.failure("'${value}' is not a path, but a file path pattern" as String)
}
return Evaluator.Result.success()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ class ValidateParametersTest extends Dsl2Spec{
given:
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
def SCRIPT = """
params.input = 'src/testResource/samplesheet.csv'
params.input = 'src/testResources/samplesheet.csv'
params.outdir = 'src/testResources/testDir'
params.email = "test@domain.com"
include { validateParameters } from 'plugin/nf-schema'
Expand All @@ -1122,7 +1122,7 @@ class ValidateParametersTest extends Dsl2Spec{
given:
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
def SCRIPT = """
params.input = 'src/testResource/samplesheet.csv'
params.input = 'src/testResources/samplesheet.csv'
params.outdir = 'src/testResources/testDir'
params.email = "thisisnotanemail"
include { validateParameters } from 'plugin/nf-schema'
Expand All @@ -1145,4 +1145,56 @@ class ValidateParametersTest extends Dsl2Spec{
!stdout
}

def 'should give an error when a file-path-pattern is used with a file-path format' () {
given:
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
def SCRIPT = """
params.input = 'src/testResources/*.csv'
params.outdir = 'src/testResources/testDir'
include { validateParameters } from 'plugin/nf-schema'
validateParameters(parameters_schema: '$schema')
"""

when:
def config = [:]
def result = new MockScriptRunner(config).setScript(SCRIPT).execute()
def stdout = capture
.toString()
.readLines()
.findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null }


then:
def error = thrown(SchemaValidationException)
error.message.contains("* --input (src/testResources/*.csv): 'src/testResources/*.csv' is not a file, but a file path pattern")
!stdout
}

def 'should give an error when a file-path-pattern is used with a directory-path format' () {
given:
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
def SCRIPT = """
params.input = 'src/testResources/samplesheet.csv'
params.outdir = 'src/testResources/testDi*'
include { validateParameters } from 'plugin/nf-schema'
validateParameters(parameters_schema: '$schema')
"""

when:
def config = [:]
def result = new MockScriptRunner(config).setScript(SCRIPT).execute()
def stdout = capture
.toString()
.readLines()
.findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null }


then:
def error = thrown(SchemaValidationException)
error.message.contains("* --outdir (src/testResources/testDi*): 'src/testResources/testDi*' is not a directory, but a file path pattern")
!stdout
}

}

0 comments on commit 5d529a6

Please sign in to comment.