Skip to content

Commit

Permalink
Fix CI mode and add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed May 16, 2024
1 parent 785f473 commit 4eca399
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/askimed/nf/test/core/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void setCIMode(boolean ciMode) {

@Override
public boolean isCIMode() {
return false;
return ciMode;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean match(String id) throws IOException {
// new snapshot --> create snapshot
if (expected == null) {
if (test.isCIMode()) {
throw new RuntimeException("CI mode activated and snapshot with id '" + id + "not found.");
throw new RuntimeException("CI mode activated and snapshot with id '" + id + "' not found.");
}
log.debug("Snapshot '{}' not found.", id);
file.createSnapshot(id, actual);
Expand Down
31 changes: 29 additions & 2 deletions src/test/java/com/askimed/nf/test/lang/ProcessTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.askimed.nf.test.lang;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -15,6 +13,8 @@
import com.askimed.nf.test.util.AnsiText;
import com.askimed.nf.test.util.FileUtil;

import static org.junit.jupiter.api.Assertions.*;

public class ProcessTest {

static {
Expand Down Expand Up @@ -332,4 +332,31 @@ public void testMd5Snapshots() throws Exception {

}

@Test
public void testSnapshotsInCiMode() throws Exception {

File snapshot = new File("test-data/process/snapshots/ci-mode.nf.test.snap");

snapshot.delete();

assertFalse(snapshot.exists());

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/process/snapshots/ci-mode.nf.test" });
assertEquals(0, exitCode);

assertTrue(snapshot.exists());

snapshot.delete();

assertFalse(snapshot.exists());

app = new App();
exitCode = app.run(new String[] { "test", "test-data/process/snapshots/ci-mode.nf.test", "--ci" });
assertEquals(1, exitCode);

assertFalse(snapshot.exists());

}

}
28 changes: 28 additions & 0 deletions test-data/process/snapshots/ci-mode.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
nextflow_process {

name "Test process xy"

script "./process.nf"
process "TEST_PROCESS"

test("Should succeed because two unique snapshots") {

when {
process {
"""
input[0] = "Lukas"
"""
}
}

then {
assert process.success
assert process.out.my_output_files
assert process.out.my_output_files.size() == 1
assert snapshot(process.out.my_output_files).match()
assert snapshot(process.out.my_output_files).match("lukas")
}

}

}

0 comments on commit 4eca399

Please sign in to comment.