Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions example/data-driven-example.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
nextflow_process {

name "Test process SAY_HELLO with Spock-style data-driven testing"
script "example/say-hello.nf"
process "SAY_HELLO"

// Spock-style data table testing
testEach("Test with name=#name and number=#number") {
when {
process {
"""
input[0] = "$name"
input[1] = Channel.of($number)
"""
}
}

then {
assert process.success
assert process.out.my_tuples.size() == expectedSize
assert process.out.my_tuples[0][0] == number
assert process.out.my_tuples[0][1] == name
}

where("""
name | number | expectedSize
"alice" | 1 | 1
"bob" | 2 | 1
"charlie" | 3 | 1
""")
}

// Spock-style data pipes testing
testEach("Data pipes test #name-#number") {
when {
process {
"""
input[0] = "$name"
input[1] = Channel.of($number)
"""
}
}

then {
if (shouldFail) {
assert process.failed
} else {
assert process.success
assert process.out.my_tuples[0][1] == name
}
}

where("""
name << ["", "valid-name", "special!@#", "normal"]
number << [1, 2, 3, 4]
shouldFail << [true, false, true, false]
""")
}

// Mixed data pipes and assignments
testEach("Complex test #name with #result") {
when {
process {
"""
input[0] = "$name"
input[1] = Channel.of($number)
"""
}
}

then {
assert process.success
assert process.out.my_tuples[0][0] == number
assert result.contains(name)
}

where("""
name << ["test1", "test2", "test3"]
number << [10, 20, 30]
result = name + "-" + number
""")
}

// Alternative: Data table with || separator (like Spock)
testEach("Edge cases #input || #expected") {
when {
process {
"""
input[0] = "$input"
input[1] = Channel.of(1)
"""
}
}

then {
if (expected) {
assert process.success
} else {
assert process.failed
}
}

where("""
input || expected
"valid" || true
"" || false
"special!@#" || false
"normal-name" || true
""")
}
}
31 changes: 31 additions & 0 deletions example/data-table-test.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
nextflow_process {

name "Data table syntax test"
script "example/say-hello.nf"
process "SAY_HELLO"

// Test the pipe-separated data table syntax
testEach("Table test with #name and #number") {
when {
process {
"""
input[0] = "$name"
input[1] = Channel.of($number)
"""
}
}

then {
assert process.success
assert process.out.my_tuples[0][1] == name
assert process.out.my_tuples[0][0] == number
}

where("""
name | number
"alice" | 1
"bob" | 2
"charlie" | 3
""")
}
}
35 changes: 35 additions & 0 deletions example/double-pipe-test.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
nextflow_process {

name "Double pipe syntax test"
script "example/say-hello.nf"
process "SAY_HELLO"

// Test the double pipe separator syntax (input || expected)
testEach("Test #name || should be #expected") {
when {
process {
"""
input[0] = "$name"
input[1] = Channel.of(1)
"""
}
}

then {
if (expected) {
assert process.success
assert process.out.my_tuples[0][1] == name
} else {
// For this test, all should succeed, but this shows the pattern
assert process.success
}
}

where("""
name || expected
"alice" || true
"bob" || true
"charlie" || true
""")
}
}
31 changes: 31 additions & 0 deletions example/mixed-syntax-test.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
nextflow_process {

name "Mixed syntax test"
script "example/say-hello.nf"
process "SAY_HELLO"

// Test mixed data pipes and computed assignments
testEach("Test #name with result=#result") {
when {
process {
"""
input[0] = "$name"
input[1] = Channel.of($number)
"""
}
}

then {
assert process.success
assert process.out.my_tuples[0][1] == name
assert process.out.my_tuples[0][0] == number
assert result == name + "-" + number
}

where("""
name << ["test1", "test2", "test3"]
number << [10, 20, 30]
result = name + "-" + number
""")
}
}
27 changes: 27 additions & 0 deletions example/simple-data-driven.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
nextflow_process {

name "Simple data-driven test"
script "example/say-hello.nf"
process "SAY_HELLO"

// Basic data table test
testEach("Simple test with #name") {
when {
process {
"""
input[0] = "$name"
input[1] = Channel.of(1)
"""
}
}

then {
assert process.success
assert process.out.my_tuples[0][1] == name
}

where("""
name << ["alice", "bob"]
""")
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/askimed/nf/test/core/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import com.askimed.nf.test.util.HashUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

import com.askimed.nf.test.config.Config;
import com.askimed.nf.test.util.FileUtil;
Expand Down Expand Up @@ -63,6 +68,9 @@ public abstract class AbstractTest implements ITest {
private boolean updateSnapshot = false;

private boolean ciMode = false;
private Map<String, Object> parameters = new HashMap<String, Object>();

public AbstractTest() {

private boolean debug = false;

Expand Down Expand Up @@ -261,4 +269,12 @@ public String toString() {
return getHash().substring(0, 8) + ": " + getName();
}

public void setParameters(Map<String, Object> parameters) {
this.parameters = parameters;
}

public Map<String, Object> getParameters() {
return parameters;
}

}
5 changes: 5 additions & 0 deletions src/main/java/com/askimed/nf/test/core/ITest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.askimed.nf.test.core;

import java.io.File;
import java.util.Map;

import com.askimed.nf.test.config.Config;

Expand Down Expand Up @@ -38,4 +39,8 @@ public interface ITest extends ITaggable {

public boolean isCIMode();

public void setParameters(Map<String, Object> parameters);

public Map<String, Object> getParameters();

}
81 changes: 81 additions & 0 deletions src/main/java/com/askimed/nf/test/lang/DataDrivenTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.askimed.nf.test.lang;

import com.askimed.nf.test.core.ITestSuite;
import com.askimed.nf.test.lang.DataTableParser.DataTable;

import groovy.lang.Closure;

public class DataDrivenTest {

private ITestSuite testSuite;
private DataTable dataTable;
private Closure setupClosure;
private Closure whenClosure;
private Closure thenClosure;
private Closure cleanupClosure;

public DataDrivenTest(ITestSuite testSuite) {
this.testSuite = testSuite;
}

public void setup(Closure closure) {
this.setupClosure = closure;
}

public void when(Closure closure) {
this.whenClosure = closure;
}

public void then(Closure closure) {
this.thenClosure = closure;
}

public void cleanup(Closure closure) {
this.cleanupClosure = closure;
}

/**
* Parse the where block using Spock-style syntax supporting:
* 1. Data tables: a | b || c
* 2. Data pipes: a << [1,2,3]
* 3. Variable assignments: c = a + b
*/
public void where(String whereBlockText) {
this.dataTable = DataTableParser.parseWhereBlock(whereBlockText);
}

/**
* Alternative where method that accepts a closure for Groovy DSL style
* This would capture the closure content and parse it
*/
public void where(Closure closure) {
// TODO: Implement closure-based where blocks
// This would require more sophisticated AST parsing of the closure
throw new UnsupportedOperationException("Closure-based where blocks not yet implemented. Please use string-based where blocks.");
}

// Getters
public DataTable getDataTable() {
return dataTable;
}

public Closure getSetupClosure() {
return setupClosure;
}

public Closure getWhenClosure() {
return whenClosure;
}

public Closure getThenClosure() {
return thenClosure;
}

public Closure getCleanupClosure() {
return cleanupClosure;
}

public ITestSuite getTestSuite() {
return testSuite;
}
}
Loading
Loading