Skip to content

Commit

Permalink
Fix unqualified usage of stdin and stdout declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Jul 24, 2020
1 parent 644e3fc commit bcdcaab
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.*

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import nextflow.NF
import nextflow.script.BaseScript
import nextflow.script.BodyDef
import nextflow.script.IncludeDef
Expand Down Expand Up @@ -821,6 +822,7 @@ class NextflowDSLImpl implements ASTTransformation {
// transform the following syntax:
// `stdin from x` --> stdin() from (x)
// `stdout into x` --> `stdout() into (x)`
VariableExpression varX
if( stm.expression instanceof PropertyExpression ) {
def expr = (PropertyExpression)stm.expression
def obj = expr.objectExpression
Expand Down Expand Up @@ -862,6 +864,12 @@ class NextflowDSLImpl implements ASTTransformation {
}
}
}
else if( (varX=isVariableX(stm.expression)) && (varX.name=='stdin' || varX.name=='stdout') && NF.isDsl2Final() ) {
final name = varX.name=='stdin' ? '_in_stdin' : '_out_stdout'
final call = new MethodCallExpression( new VariableExpression('this'), name, new ArgumentListExpression() )
// remove replace the old one with the new one
stm.setExpression(call)
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
package nextflow.script.params

import nextflow.Session
import nextflow.ast.NextflowDSL
import nextflow.script.BaseScript
import nextflow.script.ScriptBinding
import nextflow.script.ScriptMeta
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
import spock.lang.Timeout
import test.Dsl2Spec
import test.MockScriptRunner
/**
*
* @author Paolo Di Tommaso <[email protected]>
*/
@Timeout(5)
class ParamsDsl2Test extends Dsl2Spec {

def 'should not allow unqualified input file' () {
given:
def SCRIPT = '''
process foo {
input:
tuple 'x'
/touch x/
}
workflow {
foo()
}
'''

when:
new MockScriptRunner() .setScript(SCRIPT).execute()
then:
def e = thrown(DeprecationException)
e.message == "Unqualified input file declaration has been deprecated - replace `tuple 'x',..` with `tuple path('x'),..`"
}

def 'should not allow unqualified input val' () {
given:
def SCRIPT = '''
process foo {
input:
tuple X
/echo $X/
}
workflow {
foo()
}
'''

when:
new MockScriptRunner() .setScript(SCRIPT).execute()
then:
def e = thrown(DeprecationException)
e.message == "Unqualified input value declaration has been deprecated - replace `tuple X,..` with `tuple val(X),..`"
}


def 'should not allow unqualified output file' () {
given:
def SCRIPT = '''
process foo {
output:
tuple 'x'
/touch x/
}
workflow {
foo()
}
'''

when:
new MockScriptRunner() .setScript(SCRIPT).execute()
then:
def e = thrown(DeprecationException)
e.message == "Unqualified output path declaration has been deprecated - replace `tuple 'x',..` with `tuple path('x'),..`"
}

def 'should not allow unqualified output value' () {
given:
def SCRIPT = '''
process foo {
output:
tuple X
/echo hello/
}
workflow {
foo()
}
'''

when:
new MockScriptRunner() .setScript(SCRIPT).execute()
then:
def e = thrown(DeprecationException)
e.message == "Unqualified output value declaration has been deprecated - replace `tuple X,..` with `tuple val(X),..`"
}


def 'should allow unqualified stdin and stdout' () {

given:
new Session()
and:
def config = new CompilerConfiguration()
config.setScriptBaseClass(BaseScript.class.name)
config.addCompilationCustomizers( new ASTTransformationCustomizer(NextflowDSL))

def SCRIPT = '''
process alpha {
input:
stdin
output:
stdout
/echo foo/
}
workflow { true }
'''

when:
def binding = new ScriptBinding().setSession(Mock(Session))
def script = (BaseScript)new GroovyShell(binding,config).parse(SCRIPT); script.run()
and:
def process = ScriptMeta.get(script).getProcess('alpha'); process.initialize()

then:
def inputs = process.processConfig.getInputs()
def outputs = process.processConfig.getOutputs()
and:
inputs.size() == 1
inputs[0] instanceof StdInParam
and:
outputs.size() == 1
outputs[0] instanceof StdOutParam

}

def 'should allow unqualified tuple stdin and stdout' () {

given:
new Session()
and:
def config = new CompilerConfiguration()
config.setScriptBaseClass(BaseScript.class.name)
config.addCompilationCustomizers( new ASTTransformationCustomizer(NextflowDSL))

def SCRIPT = '''
process beta {
input:
tuple stdin, val(x)
output:
tuple stdout, path('z')
/echo foo/
}
workflow { true }
'''

when:
def binding = new ScriptBinding().setSession(Mock(Session))
def script = (BaseScript)new GroovyShell(binding,config).parse(SCRIPT); script.run()
and:
def process = ScriptMeta.get(script).getProcess('beta'); process.initialize()

then:
def inputs = process.processConfig.getInputs()
def outputs = process.processConfig.getOutputs()
and:
inputs.size() == 1
and:
def in_tuple = (TupleInParam) inputs.get(0)
and:
in_tuple.inner.size() == 2
in_tuple.inner[0] instanceof StdInParam
in_tuple.inner[1] instanceof ValueInParam

and:
def out_tuple = (TupleOutParam) outputs.get(0)
and:
out_tuple.inner.size() == 2
out_tuple.inner[0] instanceof StdOutParam
out_tuple.inner[1] instanceof FileOutParam

}
}

This file was deleted.

0 comments on commit bcdcaab

Please sign in to comment.