Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add option to fail on errors
  • Loading branch information
viniciusam committed Jul 20, 2017
commit b0a8143d5538d77f32bd02c6ea5a63d97e5ebaf5
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Provides an easy way of invoking utPLSQL from command-line. Main features:
* Ability to run tests with multiple reporters simultaneously.
* Ability to save output from every individual reporter to a separate output file.
* Allows execution of selected suites, subset of suite.
* ~~Maps project and test files to database objects for reporting purposes.~~ (Comming Soon)
* Maps project and test files to database objects for reporting purposes. (Comming Soon)

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


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

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

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

~~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.~~
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.

Examples:

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

* ut_documentation_reporter - will output to screen and save output to file "run.log"
* ~~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"~~
* 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"

```
utplsql run hr/hr@xe
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/github/utplsql/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public static void main(String[] args) {
boolean hasCmd = jc.getParsedCommand() != null;

if (hasCmd && jc.getParsedCommand().equals(RUN_CMD)) {
runCmd.run();
int status = runCmd.run();
System.exit(status);
} else {
jc.usage();
}
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/io/github/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.utplsql.api.CustomTypes;
import io.github.utplsql.api.OutputBuffer;
import io.github.utplsql.api.TestRunner;
import io.github.utplsql.api.exception.SomeTestsFailedException;
import io.github.utplsql.api.reporter.Reporter;
import io.github.utplsql.api.reporter.ReporterFactory;

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

@Parameter(
names = {"--no-failure"},
description = "will exit with 0 even if tests failed, default false")
private boolean noFailure = false;

@Parameter(names = {"-source_path"}, description = "path to project source files")
private String sourcePath;

Expand Down Expand Up @@ -92,7 +98,7 @@ public List<ReporterOptions> getReporterOptionsList() {
return reporterOptionsList;
}

public void run() throws Exception {
public int run() throws Exception {
final ConnectionInfo ci = getConnectionInfo();

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

final List<String> sourceFiles = sourceFilesTmp;
final List<String> testFiles = testFilesTmp;
final int[] returnCode = {0};

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

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

// Run tests.
executorService.submit(() -> {
try (Connection conn = ci.getConnection()){
try (Connection conn = ci.getConnection()) {
new TestRunner()
.addPathList(testPaths)
.addReporterList(reporterList)
.withSourceFiles(sourceFiles)
.withTestFiles(testFiles)
.colorConsole(colorConsole)
.colorConsole(this.colorConsole)
.failOnErrors(!this.noFailure)
.run(conn);
} catch (SomeTestsFailedException e) {
returnCode[0] = -1;
} catch (SQLException e) {
// TODO
e.printStackTrace();
Expand Down Expand Up @@ -174,6 +184,7 @@ public void run() throws Exception {

executorService.shutdown();
executorService.awaitTermination(60, TimeUnit.MINUTES);
return returnCode[0];
}

}