Skip to content

Commit 07c34b3

Browse files
committed
Fix failing tests
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent c52ecd8 commit 07c34b3

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

modules/nf-commons/src/main/nextflow/util/TypeHelper.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ class TypeHelper {
139139
}
140140
}
141141

142+
/**
143+
* Convert a string representing a file path to a Path.
144+
* Report an error if the path does not exist.
145+
*
146+
* @param str
147+
*/
142148
static Path asPathType(String str) {
143149
final result = FileHelper.asPath(str)
144150
if( !Files.exists(result) )

modules/nf-commons/src/test/nextflow/util/TypeHelperTest.groovy

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
*/
1616
package nextflow.util
1717

18+
import java.nio.file.Files
1819
import java.nio.file.Path
1920

21+
import nextflow.exception.AbortOperationException
2022
import nextflow.script.dsl.Nullable
2123
import nextflow.script.types.Bag
2224
import nextflow.script.types.Record
@@ -87,6 +89,9 @@ class TypeHelperTest extends Specification {
8789
// ---- asType ----
8890

8991
def 'should convert raw value to target type'() {
92+
given:
93+
def inputFile = Files.createTempFile('test', '.txt')
94+
9095
expect: 'primitive type'
9196
TypeHelper.asType(null, String) == null
9297
TypeHelper.asType('42', String) == '42'
@@ -105,17 +110,20 @@ class TypeHelperTest extends Specification {
105110
result == [1, 2] as Set
106111

107112
when: 'path type'
108-
result = TypeHelper.asType('/tmp/test.txt', Path)
113+
result = TypeHelper.asType(inputFile.toString(), Path)
109114
then:
110115
result instanceof Path
111-
result.toString() == '/tmp/test.txt'
116+
result == inputFile
112117

113118
when: 'record type'
114119
result = TypeHelper.asType([name: 'Alice', count: 5], Sample)
115120
then:
116121
result instanceof RecordMap
117122
result.name == 'Alice'
118123
result.count == 5
124+
125+
cleanup:
126+
inputFile?.delete()
119127
}
120128

121129
def 'should convert raw data structure to lists and records'() {
@@ -184,18 +192,18 @@ class TypeHelperTest extends Specification {
184192
result.extra == 'value'
185193
}
186194

187-
def 'should throw GroovyCastException when a required field is null'() {
195+
def 'should report error when a required field is null'() {
188196
when:
189197
TypeHelper.asRecordType([name: null, count: 5], Sample)
190198
then:
191-
thrown(GroovyCastException)
199+
thrown(AbortOperationException)
192200
}
193201

194-
def 'should throw GroovyCastException when a required field is absent'() {
202+
def 'should report error when a required field is absent'() {
195203
when:
196204
TypeHelper.asRecordType([name: 'Alice'], Sample)
197205
then:
198-
thrown(GroovyCastException)
206+
thrown(AbortOperationException)
199207
}
200208

201209
}

0 commit comments

Comments
 (0)