Skip to content

Commit 5d529a6

Browse files
committed
Merge branch '2.2.0-dev' of github.com:nextflow-io/nf-schema into 2.2.0-dev
2 parents af9e968 + f4b9caa commit 5d529a6

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
1. Fixed a bug in `samplesheetToList` that caused output mixing when the function was used more than once in channel operators.
1313
2. Added a missing depencency for email format validation.
14+
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.
1415

1516
## Improvements
1617

plugins/nf-schema/src/main/nextflow/validation/CustomEvaluators/FormatDirectoryPathEvaluator.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class FormatDirectoryPathEvaluator implements Evaluator {
3333

3434
// Actual validation logic
3535
def Path file = Nextflow.file(value) as Path
36+
if (file instanceof List) {
37+
return Evaluator.Result.failure("'${value}' is not a directory, but a file path pattern" as String)
38+
}
3639
if (file.exists() && !file.isDirectory()) {
3740
return Evaluator.Result.failure("'${value}' is not a directory, but a file" as String)
3841
}

plugins/nf-schema/src/main/nextflow/validation/CustomEvaluators/FormatFilePathEvaluator.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class FormatFilePathEvaluator implements Evaluator {
3333

3434
// Actual validation logic
3535
def Path file = Nextflow.file(value) as Path
36+
if (file instanceof List) {
37+
return Evaluator.Result.failure("'${value}' is not a file, but a file path pattern" as String)
38+
}
3639
if (file.exists() && file.isDirectory()) {
3740
return Evaluator.Result.failure("'${value}' is not a file, but a directory" as String)
3841
}

plugins/nf-schema/src/main/nextflow/validation/CustomEvaluators/FormatPathEvaluator.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class FormatPathEvaluator implements Evaluator {
3333

3434
// Actual validation logic
3535
def Path file = Nextflow.file(value) as Path
36+
if (file instanceof List) {
37+
return Evaluator.Result.failure("'${value}' is not a path, but a file path pattern" as String)
38+
}
3639
return Evaluator.Result.success()
3740
}
3841
}

plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ class ValidateParametersTest extends Dsl2Spec{
10971097
given:
10981098
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
10991099
def SCRIPT = """
1100-
params.input = 'src/testResource/samplesheet.csv'
1100+
params.input = 'src/testResources/samplesheet.csv'
11011101
params.outdir = 'src/testResources/testDir'
11021102
params.email = "test@domain.com"
11031103
include { validateParameters } from 'plugin/nf-schema'
@@ -1122,7 +1122,7 @@ class ValidateParametersTest extends Dsl2Spec{
11221122
given:
11231123
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
11241124
def SCRIPT = """
1125-
params.input = 'src/testResource/samplesheet.csv'
1125+
params.input = 'src/testResources/samplesheet.csv'
11261126
params.outdir = 'src/testResources/testDir'
11271127
params.email = "thisisnotanemail"
11281128
include { validateParameters } from 'plugin/nf-schema'
@@ -1145,4 +1145,56 @@ class ValidateParametersTest extends Dsl2Spec{
11451145
!stdout
11461146
}
11471147

1148+
def 'should give an error when a file-path-pattern is used with a file-path format' () {
1149+
given:
1150+
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
1151+
def SCRIPT = """
1152+
params.input = 'src/testResources/*.csv'
1153+
params.outdir = 'src/testResources/testDir'
1154+
include { validateParameters } from 'plugin/nf-schema'
1155+
1156+
validateParameters(parameters_schema: '$schema')
1157+
"""
1158+
1159+
when:
1160+
def config = [:]
1161+
def result = new MockScriptRunner(config).setScript(SCRIPT).execute()
1162+
def stdout = capture
1163+
.toString()
1164+
.readLines()
1165+
.findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null }
1166+
1167+
1168+
then:
1169+
def error = thrown(SchemaValidationException)
1170+
error.message.contains("* --input (src/testResources/*.csv): 'src/testResources/*.csv' is not a file, but a file path pattern")
1171+
!stdout
1172+
}
1173+
1174+
def 'should give an error when a file-path-pattern is used with a directory-path format' () {
1175+
given:
1176+
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
1177+
def SCRIPT = """
1178+
params.input = 'src/testResources/samplesheet.csv'
1179+
params.outdir = 'src/testResources/testDi*'
1180+
include { validateParameters } from 'plugin/nf-schema'
1181+
1182+
validateParameters(parameters_schema: '$schema')
1183+
"""
1184+
1185+
when:
1186+
def config = [:]
1187+
def result = new MockScriptRunner(config).setScript(SCRIPT).execute()
1188+
def stdout = capture
1189+
.toString()
1190+
.readLines()
1191+
.findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null }
1192+
1193+
1194+
then:
1195+
def error = thrown(SchemaValidationException)
1196+
error.message.contains("* --outdir (src/testResources/testDi*): 'src/testResources/testDi*' is not a directory, but a file path pattern")
1197+
!stdout
1198+
}
1199+
11481200
}

0 commit comments

Comments
 (0)