1515 */
1616package nextflow.util
1717
18+ import java.nio.file.Files
1819import java.nio.file.Path
1920
21+ import nextflow.exception.AbortOperationException
2022import nextflow.script.dsl.Nullable
2123import nextflow.script.types.Bag
2224import 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