Skip to content
Merged
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
93 changes: 47 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,68 @@ 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] ...]

```
user - Username to connect as.
password - Password of the user.
host - Server address, defaults to 127.0.0.1.
port - Server port, defaults to 1521.
db - Database to connect to.
-p=suite_path(s) - A suite path or a comma separated list of suite paths for unit test to be executed.
The path(s) can be in one of the following formats:
schema[.package[.procedure]]
schema:suite[.suite[.suite][...]][.procedure]
Both formats can be mixed in the list.
If only schema is provided, then all suites owner by that schema are executed.
If -p is omitted, the current schema is used.
-f=format - A reporter to be used for reporting.
If no -f option is provided, the default ut_documentation_reporter is used.
Available options:
-f=ut_documentation_reporter
A textual pretty-print of unit test results (usually use for console output)
-f=ut_teamcity_reporter
For reporting live progress of test execution with Teamcity CI.
-f=ut_xunit_reporter
Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity.
-f=ut_coverage_html_reporter
Generates a HTML coverage report with summary and line by line information on code coverage.
Based on open-source simplecov-html coverage reporter for Ruby.
Includes source code in the report.
-f=ut_coveralls_reporter
Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [Coveralls](https://coveralls.io/).
-f=ut_coverage_sonar_reporter
Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
-f=ut_sonar_test_reporter
Generates a JSON report providing detailed information on test execution.
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.

-o=output - Defines file name to save the output from the specified reporter.
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
-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).
user - Username to connect as.
password - Password of the user.
host - Server address, defaults to 127.0.0.1.
port - Server port, defaults to 1521.
db - Database to connect to.
-p=suite_path(s) - A suite path or a comma separated list of suite paths for unit test to be executed.
The path(s) can be in one of the following formats:
schema[.package[.procedure]]
schema:suite[.suite[.suite][...]][.procedure]
Both formats can be mixed in the list.
If only schema is provided, then all suites owner by that schema are executed.
If -p is omitted, the current schema is used.
-f=format - A reporter to be used for reporting.
If no -f option is provided, the default ut_documentation_reporter is used.
Available options:
-f=ut_documentation_reporter
A textual pretty-print of unit test results (usually use for console output)
-f=ut_teamcity_reporter
For reporting live progress of test execution with Teamcity CI.
-f=ut_xunit_reporter
Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity.
-f=ut_coverage_html_reporter
Generates a HTML coverage report with summary and line by line information on code coverage.
Based on open-source simplecov-html coverage reporter for Ruby.
Includes source code in the report.
-f=ut_coveralls_reporter
Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [Coveralls](https://coveralls.io/).
-f=ut_coverage_sonar_reporter
Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
-f=ut_sonar_test_reporter
Generates a JSON report providing detailed information on test execution.
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.

-o=output - Defines file name to save the output from the specified reporter.
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
-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).
--failure-exit-code - Override the exit code on failure, defaults to 1. You can set it to 0 to always exit with a success status.
```

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
13 changes: 9 additions & 4 deletions src/main/java/io/github/utplsql/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public class Cli {

public static final int DEFAULT_ERROR_CODE = 1;

public static final String HELP_CMD = "-h";
public static final String RUN_CMD = "run";

Expand All @@ -15,14 +17,15 @@ public static void main(String[] args) {
RunCommand runCmd = new RunCommand();
jc.addCommand(RUN_CMD, runCmd);

int exitCode = DEFAULT_ERROR_CODE;

try {
jc.parse(args);
boolean hasCmd = jc.getParsedCommand() != null;

if (hasCmd && jc.getParsedCommand().equals(RUN_CMD)) {
runCmd.run();
if (RUN_CMD.equals(jc.getParsedCommand())) {
exitCode = runCmd.run();
} else {
jc.usage();
throw new ParameterException("Command not specified.");
}
} catch (ParameterException e) {
if (jc.getParsedCommand() != null) {
Expand All @@ -34,6 +37,8 @@ public static void main(String[] args) {
} catch (Exception e) {
e.printStackTrace();
}

System.exit(exitCode);
}

private static class HelpCommand {
Expand Down
29 changes: 20 additions & 9 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 = {"--failure-exit-code"},
description = "override the exit code on failure, default = 1")
private int failureExitCode = 1;

@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 @@ -123,25 +130,28 @@ public void run() throws Exception {
reporterList.add(reporter);
}
} catch (SQLException e) {
// TODO
e.printStackTrace();
System.out.println(e.getMessage());
return Cli.DEFAULT_ERROR_CODE;
}

ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size());

// 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(true)
.run(conn);
} catch (SomeTestsFailedException e) {
returnCode[0] = this.failureExitCode;
} catch (SQLException e) {
// TODO
e.printStackTrace();
System.out.println(e.getMessage());
returnCode[0] = Cli.DEFAULT_ERROR_CODE;
}
});

Expand All @@ -163,8 +173,8 @@ public void run() throws Exception {

new OutputBuffer(ro.getReporterObj()).printAvailable(conn, printStreams);
} catch (SQLException | FileNotFoundException e) {
// TODO
e.printStackTrace();
System.out.println(e.getMessage());
returnCode[0] = Cli.DEFAULT_ERROR_CODE;
} finally {
if (fileOutStream != null)
fileOutStream.close();
Expand All @@ -174,6 +184,7 @@ public void run() throws Exception {

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

}