Skip to content

Commit

Permalink
chore: Return proper JBang exit status based on failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christophd committed Mar 9, 2023
1 parent 3642713 commit eff2d8c
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.consol.citrus.CitrusInstanceManager;
import com.consol.citrus.cucumber.CucumberTestEngine;
import com.consol.citrus.main.TestRunConfiguration;
import com.consol.citrus.report.TestReporter;
import com.consol.citrus.report.TestResults;
import com.consol.citrus.util.FileUtils;
import org.citrusframework.yaks.jbang.YaksJBangMain;
import picocli.CommandLine.Command;
Expand Down Expand Up @@ -117,8 +120,12 @@ private int run() throws Exception {

TestRunConfiguration configuration = new TestRunConfiguration();
final CucumberTestEngine engine = new CucumberTestEngine(configuration);

final ExitStatusTestReporter exitStatus = new ExitStatusTestReporter();
CitrusInstanceManager.addInstanceProcessor(instance -> instance.addTestReporter(exitStatus));

engine.run();
return 0;
return exitStatus.exitStatus();
}

private String loadFromClipboard(String file) throws UnsupportedFlavorException, IOException {
Expand Down Expand Up @@ -232,4 +239,24 @@ protected void doConsumeParameters(Stack<String> args, Run cmd) {
}
}

/**
* Special test reporter provides proper exit status based on successful/failed tests.
*/
private static class ExitStatusTestReporter implements TestReporter {
private static final int DEFAULT = 0;
private static final int ERRORS = 1;

private int exitStatus = DEFAULT;

@Override
public void generateReport(TestResults testResults) {
if (testResults.getFailed() > 0) {
exitStatus = ERRORS;
}
}

int exitStatus() {
return exitStatus;
}
}
}

0 comments on commit eff2d8c

Please sign in to comment.