Skip to content

Commit b0a8143

Browse files
committed
Add option to fail on errors
1 parent 5361b15 commit b0a8143

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ Provides an easy way of invoking utPLSQL from command-line. Main features:
66
* Ability to run tests with multiple reporters simultaneously.
77
* Ability to save output from every individual reporter to a separate output file.
88
* Allows execution of selected suites, subset of suite.
9-
* ~~Maps project and test files to database objects for reporting purposes.~~ (Comming Soon)
9+
* Maps project and test files to database objects for reporting purposes. (Comming Soon)
1010

1111
## Downloading
1212
You can download development versions on [Bintray](https://bintray.com/viniciusam/utPLSQL-cli/utPLSQL-cli-develop#files).
1313

1414

1515
## Requirements
1616
* [Java SE Runtime Environment 8](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html)
17-
* ~~When using reporters for Sonar or Coveralls client needs to be invoked from project's root directory.~~
17+
* When using reporters for Sonar or Coveralls client needs to be invoked from project's root directory.
1818

1919
## Usage
2020
utplsql run user/pass@[[host][:port]/]db [-p=(ut_path|ut_paths)] [-f=format [-o=output_file] [-s] ...]
@@ -62,11 +62,12 @@ db - Database to connect to.
6262
-s - Forces putting output to to screen for a given -f parameter.
6363
-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards.
6464
Works only on reporeters that support colors (ut_documentation_reporter).
65+
--no-failure - By default, the client will exit with -1 if any test failed, override this behavior by providing this option.
6566
```
6667

6768
Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter.
6869

69-
~~Sonar and Coveralls reporter will only provide valid reports, when source_path and/or test_path are provided, and ut_run is executed from your project's root path.~~
70+
Sonar and Coveralls reporter will only provide valid reports, when source_path and/or test_path are provided, and ut_run is executed from your project's root path.
7071

7172
Examples:
7273

@@ -77,7 +78,7 @@ utplsql run hr/hr@xe -p=hr_test -f=ut_documentation_reporter -o=run.log -s -f=ut
7778
Invokes all Unit tests from schema/package "hr_test" with two reporters:
7879

7980
* ut_documentation_reporter - will output to screen and save output to file "run.log"
80-
* ~~ut_coverage_html_reporter - will report only on database objects that are mapping to file structure from "source" folder and save output to file "coverage.html"~~
81+
* ut_coverage_html_reporter - will report only on database objects that are mapping to file structure from "source" folder and save output to file "coverage.html"
8182

8283
```
8384
utplsql run hr/hr@xe

src/main/java/io/github/utplsql/cli/Cli.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public static void main(String[] args) {
2020
boolean hasCmd = jc.getParsedCommand() != null;
2121

2222
if (hasCmd && jc.getParsedCommand().equals(RUN_CMD)) {
23-
runCmd.run();
23+
int status = runCmd.run();
24+
System.exit(status);
2425
} else {
2526
jc.usage();
2627
}

src/main/java/io/github/utplsql/cli/RunCommand.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.github.utplsql.api.CustomTypes;
66
import io.github.utplsql.api.OutputBuffer;
77
import io.github.utplsql.api.TestRunner;
8+
import io.github.utplsql.api.exception.SomeTestsFailedException;
89
import io.github.utplsql.api.reporter.Reporter;
910
import io.github.utplsql.api.reporter.ReporterFactory;
1011

@@ -51,6 +52,11 @@ public class RunCommand {
5152
description = "enables printing of test results in colors as defined by ANSICONSOLE standards")
5253
private boolean colorConsole = false;
5354

55+
@Parameter(
56+
names = {"--no-failure"},
57+
description = "will exit with 0 even if tests failed, default false")
58+
private boolean noFailure = false;
59+
5460
@Parameter(names = {"-source_path"}, description = "path to project source files")
5561
private String sourcePath;
5662

@@ -92,7 +98,7 @@ public List<ReporterOptions> getReporterOptionsList() {
9298
return reporterOptionsList;
9399
}
94100

95-
public void run() throws Exception {
101+
public int run() throws Exception {
96102
final ConnectionInfo ci = getConnectionInfo();
97103

98104
final List<ReporterOptions> reporterOptionsList = getReporterOptionsList();
@@ -111,6 +117,7 @@ public void run() throws Exception {
111117

112118
final List<String> sourceFiles = sourceFilesTmp;
113119
final List<String> testFiles = testFilesTmp;
120+
final int[] returnCode = {0};
114121

115122
if (testPaths.isEmpty()) testPaths.add(ci.getUser());
116123

@@ -131,14 +138,17 @@ public void run() throws Exception {
131138

132139
// Run tests.
133140
executorService.submit(() -> {
134-
try (Connection conn = ci.getConnection()){
141+
try (Connection conn = ci.getConnection()) {
135142
new TestRunner()
136143
.addPathList(testPaths)
137144
.addReporterList(reporterList)
138145
.withSourceFiles(sourceFiles)
139146
.withTestFiles(testFiles)
140-
.colorConsole(colorConsole)
147+
.colorConsole(this.colorConsole)
148+
.failOnErrors(!this.noFailure)
141149
.run(conn);
150+
} catch (SomeTestsFailedException e) {
151+
returnCode[0] = -1;
142152
} catch (SQLException e) {
143153
// TODO
144154
e.printStackTrace();
@@ -174,6 +184,7 @@ public void run() throws Exception {
174184

175185
executorService.shutdown();
176186
executorService.awaitTermination(60, TimeUnit.MINUTES);
187+
return returnCode[0];
177188
}
178189

179190
}

0 commit comments

Comments
 (0)