Skip to content
Open
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
11 changes: 10 additions & 1 deletion src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,22 @@ public class RunTestsCommand extends AbstractCommand {
)
private boolean smartTesting = false;

@Option(
@Option(
names = {"--stop-on-first-failure", "--stopOnFirstFailure"},
description = "Stop execution immediately after the first test failure",
required = false,
showDefaultValue = Visibility.ALWAYS
)
private boolean stopOnFirstFailure = false;

@Option(
names = {"--no-save", "--noSave"},
description = "Delete test launch directory after successful run",
required = false,
showDefaultValue = Visibility.ALWAYS
)
private boolean noSave = false;

private static Logger log = LoggerFactory.getLogger(RunTestsCommand.class);

@Override
Expand Down Expand Up @@ -306,6 +314,7 @@ public Integer execute() throws Exception {
engine.setCIMode(ciMode);
engine.addProfile(profile);
engine.setStopOnFirstFailure(stopOnFirstFailure);
engine.setNoSave(noSave);
engine.setDryRun(dryRun);
if (withoutTrace) {
engine.setWithTrace(false);
Expand Down
5 changes: 5 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 @@ -96,6 +96,11 @@ public File getConfig() {
return config;
}

@Override
public File getLaunchDir() {
return launchDir;
}

public void defineDirectories(File testDirectory) throws IOException {

if (testDirectory == null) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/askimed/nf/test/core/ITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface ITest extends ITaggable {

public ITestSuite getTestSuite();

public File getLaunchDir();

public void setWithTrace(boolean withTrace);

public void setUpdateSnapshot(boolean updateSnapshot);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class TestExecutionEngine {

private boolean stopOnFirstFailure = false;

private boolean noSave = false;

private static Logger log = LoggerFactory.getLogger(TestExecutionEngine.class);

public void setDebug(boolean debug) {
Expand Down Expand Up @@ -100,6 +102,10 @@ public void setStopOnFirstFailure(boolean stopOnFirstFailure) {
this.stopOnFirstFailure = stopOnFirstFailure;
}

public void setNoSave(boolean noSave) {
this.noSave = noSave;
}

public int execute() throws Throwable {

if (configFile != null) {
Expand Down Expand Up @@ -184,6 +190,22 @@ public int execute() throws Throwable {

}
test.cleanup();

if (noSave
&& result.getStatus() == TestExecutionResultStatus.PASSED
&& !debug
) {
try {
File launchDir = test.getLaunchDir();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with this part of the code. Is launchDir the part where you execute nf-test from or the path where the test is executed from?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

launchDir is the root of where the nf-test is launch from of the form .nf-test/tests/hash/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay perfect! Thanks for the clarification

if (launchDir != null && launchDir.exists()) {
log.info("Deleting launch directory due to --no-save: {}", launchDir);
FileUtil.deleteDirectory(launchDir);
}
} catch (Exception e) {
log.warn("Failed to delete launch directory for test '{}': {}", test, e.getMessage());
}
}

result.setEndTime(System.currentTimeMillis());

log.info("Test '{}' finished. status: {}", result.getTest(), result.getStatus(), result.getThrowable());
Expand Down
63 changes: 63 additions & 0 deletions src/test/java/com/askimed/nf/test/lang/ProcessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,42 @@ public void testExample() throws Exception {
int exitCode = app.run(new String[] { "test", "test-data/process/example/test1.nf.test" });
assertEquals(0, exitCode);

File testsRoot = new File(".nf-test/tests");
File[] testDirs = testsRoot.listFiles(File::isDirectory);
assertNotNull(testDirs, "Could not list test directories");

assertTrue(
testDirs.length == 5,
"Expected test directories to exist without --no-save"
);

for (File testDir : testDirs) {
File workDir = new File(testDir, "work");
assertTrue(
workDir.exists(),
"Launch and Work directory should exist without --no-save"
);
}

}

@Test
public void testExampleNoSaveDeletesLaunchDir() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/process/example/test1.nf.test", "--no-save" });
assertEquals(0, exitCode);

File testsRoot = new File(".nf-test/tests");
File[] testDirs = testsRoot.listFiles(File::isDirectory);
assertNotNull(testDirs, "Could not list test directories");

assertEquals(
0,
testDirs.length,
"Expected all test directories to be deleted with --no-save"
);

}

/*
Expand Down Expand Up @@ -125,6 +161,33 @@ public void testScriptFailed() throws Exception {

}

@Test
public void testScriptFailedKeepsWorkDirWithNoSave() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/process/default/test_process_failed.nf.test", "--no-save" });
assertEquals(1, exitCode);

File testsRoot = new File(".nf-test/tests");
File[] testDirs = testsRoot.listFiles(File::isDirectory);
assertNotNull(testDirs, "Could not list test directories");

assertTrue(
testDirs.length == 1,
"Expected test directories to exist without --no-save"
);

for (File testDir : testDirs) {
File workDir = new File(testDir, "work");

assertTrue(
workDir.exists(),
"Launch and Work directory should still exist with --no-save if process failed"
);
}

}

@Test
public void testScriptWithSyntaxError() throws Exception {

Expand Down
62 changes: 61 additions & 1 deletion src/test/java/com/askimed/nf/test/lang/WorkflowTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.askimed.nf.test.lang;

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

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -193,6 +193,66 @@ public void testRegex() throws Exception {

}

@Test
public void testWorkflowKeepsLaunchDirByDefault() throws Exception {

App app = new App();

int exitCode = app.run(new String[] {
"test",
"test-data/workflow/regex/workflow.nf.test"
});

assertEquals(0, exitCode);

File testsRoot = new File(".nf-test/tests");
File[] testDirs = testsRoot.listFiles(File::isDirectory);
assertNotNull(testDirs, "Could not list test directories");

assertTrue(
testDirs.length > 0,
"Expected test directories to exist without --no-save"
);

for (File testDir : testDirs) {
File workDir = new File(testDir, "work");

assertTrue(
workDir.exists(),
"Launch and Work directory should exist without --no-save"
);
}
}

@Test
public void testWorkflowNoSaveDeletesLaunchDir() throws Exception {

App app = new App();

String testPath = "test-data/workflow/regex/workflow.nf.test";

// Run test with --no-save
int exitCode = app.run(new String[] {
"test",
testPath,
"--no-save"
});

assertEquals(0, exitCode);

// Locate .nf-test directory
File nfTestDir = new File(".nf-test/tests");
File[] remaining = nfTestDir.listFiles(file -> file.isDirectory());

assertNotNull(remaining, "Could not list test directories");

assertEquals(
0,
remaining.length,
"Expected no test directories to remain when --no-save is enabled"
);
}

@Test
public void testWorkflowTopics() throws Exception {

Expand Down