Skip to content

Commit 66b7438

Browse files
jorgeebentsherman
andauthored
Fix different task hash with v2 parser. (#6789)
Co-authored-by: Ben Sherman <bentshermann@gmail.com>
1 parent 54a5958 commit 66b7438

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

modules/nf-lang/src/main/java/nextflow/script/control/ScriptToGroovyHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,14 @@ public String getSourceText(Statement node) {
180180
builder.append( line.substring(0, k) );
181181
}
182182

183+
// determine range of current line
183184
var begin = (i == first) ? colx - 1 : 0;
184185
var end = (i == last) ? colz - 1 : line.length();
186+
187+
// skip trailing newline (e.g. for block statements)
188+
if( i == last && begin == end )
189+
continue;
190+
185191
builder.append( line.substring(begin, end) ).append('\n');
186192
}
187193
return builder.toString();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2024-2025, Seqera Labs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package nextflow.script.control
18+
19+
import spock.lang.Shared
20+
import spock.lang.Specification
21+
import test.TestUtils
22+
23+
/**
24+
*
25+
* @author Ben Sherman <bentshermann@gmail.com>
26+
*/
27+
class ScriptToGroovyHelperTest extends Specification {
28+
29+
@Shared
30+
ScriptParser scriptParser
31+
32+
def setupSpec() {
33+
scriptParser = new ScriptParser()
34+
}
35+
36+
def parse(String contents) {
37+
scriptParser.compiler().getSources().clear()
38+
def source = scriptParser.parse('main.nf', contents.stripIndent())
39+
assert !TestUtils.hasSyntaxErrors(source)
40+
return source
41+
}
42+
43+
def 'should get source text of process body' () {
44+
given:
45+
def source = parse('''\
46+
process hello {
47+
script:
48+
"""
49+
echo 'hello!'
50+
"""
51+
}
52+
''')
53+
def sgh = new ScriptToGroovyHelper(source)
54+
55+
when:
56+
def process = source.getAST().getProcesses().first()
57+
then:
58+
sgh.getSourceText(process.exec) == ' """\n echo \'hello!\'\n """\n'
59+
}
60+
61+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
set -e
2+
3+
#
4+
# run normal mode
5+
#
6+
echo ''
7+
8+
NXF_SYNTAX_PARSER=v1 $NXF_RUN | tee stdout
9+
10+
[[ `< .nextflow.log grep -c 'Submitted process > hello'` == 1 ]] || false
11+
12+
#
13+
# RESUME mode
14+
#
15+
echo ''
16+
NXF_SYNTAX_PARSER=v2 $NXF_RUN -resume | tee stdout
17+
18+
[[ `< .nextflow.log grep -c 'Cached process > hello'` == 1 ]] || false
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env nextflow
2+
/*
3+
* Copyright 2013-2024, Seqera Labs
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
process hello {
19+
input:
20+
val greeting
21+
22+
output:
23+
stdout
24+
25+
script:
26+
"""
27+
echo '${greeting}'
28+
"""
29+
}
30+
31+
workflow {
32+
hello( 'ciao' ).view()
33+
}

0 commit comments

Comments
 (0)