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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ The TNS alias used in the connect string must match the alias of the credential
-exclude=pckg_list - Comma-separated object list to exclude from the coverage report.
Format: [schema.]package[,[schema.]package ...].
See coverage reporting options in framework documentation.

-include-schema-expr=regex - Regular expression matching the names of schemas to include in the coverage report.
-exclude-schema-expr=regex - Regular expression matching the names of schemas to exclude from the coverage report.
-include-object-expr=regex - Regular expression matching the names of objects to include in the coverage report.
-exclude-object-expr=regex - Regular expression matching the names of objects to exclude from the coverage report.
Case-insensitive. Object expressions are matched against the object name without the schema.
Anchor them with `^` and `$`, otherwise any partial match counts.
If an include expression is given, `-include` and `--coverage-schemes` are ignored.
All exclude options are always applied and can be combined.
Ignored when `-source_path` is used (file mapping defines the coverage scope).
See https://www.utplsql.org/utPLSQL/latest/userguide/coverage.html#filtering-objects-in-coverage-reports

-q - Does not output the informational messages normally printed to console.
(--quiet) Default: false
Expand Down Expand Up @@ -247,6 +258,12 @@ Invokes all Unit tests from schema/package "hr_test" with two reporters:

Invokes all unit test suites from schema "hr". Results are displayed to screen using default ut_documentation_reporter.

```
> utplsql run hr/hr@xe -p=hr_test -f=ut_coverage_html_reporter -o=coverage.html -include-schema-expr=^HR$ -exclude-object-expr=_TMP$
```

Runs the tests from "hr_test" and writes an HTML coverage report that covers all objects in schema "HR" except those whose name ends with "_TMP".

### info
`utplsql info [<ConnectionURL>]`

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/utplsql/cli/RunAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
} catch (DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed | ReporterTimeoutException e) {
System.out.println(e.getMessage());
returnCode = Cli.DEFAULT_ERROR_CODE;
} catch (Throwable e) {

Check warning on line 112 in src/main/java/org/utplsql/cli/RunAction.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Catch Exception instead of Throwable.

See more on https://sonarcloud.io/project/issues?id=utPLSQL_utPLSQL-cli&issues=AaFLjdnaiuOCX-cJFCED&open=AaFLjdnaiuOCX-cJFCED&pullRequest=233
e.printStackTrace();
returnCode = Cli.DEFAULT_ERROR_CODE;
}
Expand Down Expand Up @@ -167,6 +167,10 @@
.randomTestOrderSeed(config.getRandomTestOrderSeed())
.addTags(Arrays.asList(config.getTags()))
.addCoverageSchemes(Arrays.asList(config.getCoverageSchemes()))
.includeSchemaExpr(config.getIncludeSchemaExpr())
.excludeSchemaExpr(config.getExcludeSchemaExpr())
.includeObjectExpr(config.getIncludeObjectExpr())
.excludeObjectExpr(config.getExcludeObjectExpr())
.oraStuckTimeout(config.getOraStuckTimeout());
}

Expand All @@ -192,7 +196,7 @@

compatibilityProxy = checkFrameworkCompatibility(conn);

logger.info("Connected to Oracle database: {}", new DefaultDatabaseInformation().getOracleVersion(conn));

Check warning on line 199 in src/main/java/org/utplsql/cli/RunAction.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Invoke method(s) only conditionally.

See more on https://sonarcloud.io/project/issues?id=utPLSQL_utPLSQL-cli&issues=AaFLjdnaiuOCX-cJFCEC&open=AaFLjdnaiuOCX-cJFCEC&pullRequest=233
logger.info("utPLSQL core: {}", compatibilityProxy.getVersionDescription());
} catch (SQLException e) {
if (e.getErrorCode() == 1017 || e.getErrorCode() == 12514) {
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/org/utplsql/cli/RunPicocliCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,34 @@
private String excludeObjects = null;


@Option(
names = {"-include-schema-expr"},
description = "Regular expression to include in the coverage report schemas whose name matches the expression. " +
"See coverage reporting options in framework documentation"
)
private String includeSchemaExpr;

@Option(
names = {"-exclude-schema-expr"},
description = "Regular expression to exclude from the coverage report schemas whose name matches the expression. " +
"See coverage reporting options in framework documentation"
)
private String excludeSchemaExpr;

@Option(
names = {"-include-object-expr"},
description = "Regular expression to include in the coverage report objects whose name matches the expression. " +
"See coverage reporting options in framework documentation"
)
private String includeObjectExpr;

@Option(
names = {"-exclude-object-expr"},
description = "Regular expression to exclude from the coverage report objects whose name matches the expression. " +
"See coverage reporting options in framework documentation"
)
private String excludeObjectExpr;

@Option(
names = {"-D", "--dbms_output"},
description = "Enables DBMS_OUTPUT for the TestRunner (default: DISABLED)"
Expand Down Expand Up @@ -213,7 +241,7 @@

// Prepare Reporter configs
List<ReporterConfig> reporterConfigs = new ArrayList<>();
for (Format format : reporters) {

Check warning on line 244 in src/main/java/org/utplsql/cli/RunPicocliCommand.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a stream instead of this loop.

See more on https://sonarcloud.io/project/issues?id=utPLSQL_utPLSQL-cli&issues=AaFLjduNiuOCX-cJFCEF&open=AaFLjduNiuOCX-cJFCEF&pullRequest=233
reporterConfigs.add(new ReporterConfig(format.format, format.outputFile, format.outputToScreen));
}

Expand Down Expand Up @@ -249,6 +277,10 @@
.tags(tags.toArray(new String[0]))
.coverageSchemes(coverageSchemes.toArray(new String[0]))
.oraStuckTimeout(oraStuckTimeout)
.includeSchemaExpr(includeSchemaExpr)
.excludeSchemaExpr(excludeSchemaExpr)
.includeObjectExpr(includeObjectExpr)
.excludeObjectExpr(excludeObjectExpr)
.create();
}

Expand Down
46 changes: 43 additions & 3 deletions src/main/java/org/utplsql/cli/config/RunCommandConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
private final String[] tags;
private final String[] coverageSchemes;
private final Integer oraStuckTimeout;
private final String includeSchemaExpr;
private final String excludeSchemaExpr;
private final String includeObjectExpr;
private final String excludeObjectExpr;

@ConstructorProperties({"connectString", "suitePaths", "reporters", "outputAnsiColor", "failureExitCode", "skipCompatibilityCheck", "includePackages", "excludePackages", "sourceMapping", "testMapping", "logConfigLevel", "timeoutInMinutes", "dbmsOutput", "randomTestOrder", "randomTestOrderSeed", "tags", "coverageSchemes", "oraStuckTimeout"})
public RunCommandConfig(String connectString, String[] suitePaths, ReporterConfig[] reporters, boolean outputAnsiColor, Integer failureExitCode, boolean skipCompatibilityCheck, String[] includePackages, String[] excludePackages, FileMapperConfig sourceMapping, FileMapperConfig testMapping, ConfigLevel logConfigLevel, Integer timeoutInMinutes, boolean dbmsOutput, boolean randomTestOrder, Integer randomTestOrderSeed, String[] tags, String[] coverageSchemes, Integer oraStuckTimeout) {
@ConstructorProperties({"connectString", "suitePaths", "reporters", "outputAnsiColor", "failureExitCode", "skipCompatibilityCheck", "includePackages", "excludePackages", "sourceMapping", "testMapping", "logConfigLevel", "timeoutInMinutes", "dbmsOutput", "randomTestOrder", "randomTestOrderSeed", "tags", "coverageSchemes", "oraStuckTimeout", "includeSchemaExpr", "excludeSchemaExpr", "includeObjectExpr", "excludeObjectExpr"})
public RunCommandConfig(String connectString, String[] suitePaths, ReporterConfig[] reporters, boolean outputAnsiColor, Integer failureExitCode, boolean skipCompatibilityCheck, String[] includePackages, String[] excludePackages, FileMapperConfig sourceMapping, FileMapperConfig testMapping, ConfigLevel logConfigLevel, Integer timeoutInMinutes, boolean dbmsOutput, boolean randomTestOrder, Integer randomTestOrderSeed, String[] tags, String[] coverageSchemes, Integer oraStuckTimeout, String includeSchemaExpr, String excludeSchemaExpr, String includeObjectExpr, String excludeObjectExpr) {

Check warning on line 33 in src/main/java/org/utplsql/cli/config/RunCommandConfig.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Constructor has 22 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=utPLSQL_utPLSQL-cli&issues=AaFLjdsYiuOCX-cJFCEE&open=AaFLjdsYiuOCX-cJFCEE&pullRequest=233
super(connectString);
this.suitePaths = suitePaths;
this.reporters = reporters;
Expand All @@ -45,6 +49,10 @@
this.tags = tags;
this.coverageSchemes = coverageSchemes;
this.oraStuckTimeout = oraStuckTimeout;
this.includeSchemaExpr = includeSchemaExpr;
this.excludeSchemaExpr = excludeSchemaExpr;
this.includeObjectExpr = includeObjectExpr;
this.excludeObjectExpr = excludeObjectExpr;
}

public String[] getSuitePaths() {
Expand Down Expand Up @@ -113,6 +121,14 @@

public Integer getOraStuckTimeout() { return oraStuckTimeout; }

public String getIncludeSchemaExpr() { return includeSchemaExpr; }

public String getExcludeSchemaExpr() { return excludeSchemaExpr; }

public String getIncludeObjectExpr() { return includeObjectExpr; }

public String getExcludeObjectExpr() { return excludeObjectExpr; }

public static class Builder {

private String connectString;
Expand All @@ -133,6 +149,10 @@
private String[] tags = new String[0];
private String[] coverageSchemes = new String[0];
private Integer oraStuckTimeout;
private String includeSchemaExpr;
private String excludeSchemaExpr;
private String includeObjectExpr;
private String excludeObjectExpr;

public Builder connectString(String connectString) {
this.connectString = connectString;
Expand Down Expand Up @@ -224,8 +244,28 @@
return this;
}

public Builder includeSchemaExpr(String includeSchemaExpr) {
this.includeSchemaExpr = includeSchemaExpr;
return this;
}

public Builder excludeSchemaExpr(String excludeSchemaExpr) {
this.excludeSchemaExpr = excludeSchemaExpr;
return this;
}

public Builder includeObjectExpr(String includeObjectExpr) {
this.includeObjectExpr = includeObjectExpr;
return this;
}

public Builder excludeObjectExpr(String excludeObjectExpr) {
this.excludeObjectExpr = excludeObjectExpr;
return this;
}

public RunCommandConfig create() {
return new RunCommandConfig(connectString, suitePaths, reporters, outputAnsiColor, failureExitCode, skipCompatibilityCheck, includePackages, excludePackages, sourceMapping, testMapping, logConfigLevel, timeoutInMinutes, dbmsOutput, randomTestOrder, randomTestOrderSeed, tags, coverageSchemes, oraStuckTimeout);
return new RunCommandConfig(connectString, suitePaths, reporters, outputAnsiColor, failureExitCode, skipCompatibilityCheck, includePackages, excludePackages, sourceMapping, testMapping, logConfigLevel, timeoutInMinutes, dbmsOutput, randomTestOrder, randomTestOrderSeed, tags, coverageSchemes, oraStuckTimeout, includeSchemaExpr, excludeSchemaExpr, includeObjectExpr, excludeObjectExpr);
}
}
}
10 changes: 9 additions & 1 deletion src/test/java/org/utplsql/cli/PicocliRunCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ void runCommandAllArguments() throws Exception {
"-owner_subexpression=1",
"-type_subexpression=2",
"-name_subexpression=3",
"--coverage-schemes=schema1,other_schema");
"--coverage-schemes=schema1,other_schema",
"-include-schema-expr=^APP$",
"-exclude-schema-expr=^APP_TEST$",
"-include-object-expr=^PKG_",
"-exclude-object-expr=_TMP$");

assertNotNull(config.getConnectString());
assertThat( config.getSuitePaths(), is(new String[]{"app.betwnstr", "app.basic"}));
assertThat( config.getTags(), is(new String[]{"tag1", "tag.2"}));
assertEquals( "^APP$", config.getIncludeSchemaExpr() );
assertEquals( "^APP_TEST$", config.getExcludeSchemaExpr() );
assertEquals( "^PKG_", config.getIncludeObjectExpr() );
assertEquals( "_TMP$", config.getExcludeObjectExpr() );
assertTrue( config.isOutputAnsiColor() );
assertEquals( LoggerConfiguration.ConfigLevel.NONE, config.getLogConfigLevel());
assertEquals( 10, config.getFailureExitCode());
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/org/utplsql/cli/RunCommandArgumentsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;

public class RunCommandArgumentsTest {

Expand Down Expand Up @@ -69,6 +70,22 @@ void provideTags() {
assertThat( testRunner.getOptions().tags, contains("tag1", "tag.2") );
}

@Test
void provideExpressionFilters() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(),
"-include-schema-expr=^APP$",
"-exclude-schema-expr=^APP_TEST$",
"-include-object-expr=^PKG_",
"-exclude-object-expr=_TMP$"
);

TestRunner testRunner = runCmd.newTestRunner(new ArrayList<>());
assertThat( testRunner.getOptions().includeSchemaExpr, equalTo("^APP$") );
assertThat( testRunner.getOptions().excludeSchemaExpr, equalTo("^APP_TEST$") );
assertThat( testRunner.getOptions().includeObjectExpr, equalTo("^PKG_") );
assertThat( testRunner.getOptions().excludeObjectExpr, equalTo("_TMP$") );
}

@Test
void provideCoverageSchemes() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertTrue;

Check warning on line 12 in src/test/java/org/utplsql/cli/RunCommandConfigParamsArePassedToTestRunnerTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'org.junit.jupiter.api.Assertions.assertTrue'.

See more on https://sonarcloud.io/project/issues?id=utPLSQL_utPLSQL-cli&issues=AaFLjdwUiuOCX-cJFCEG&open=AaFLjdwUiuOCX-cJFCEG&pullRequest=233

public class RunCommandConfigParamsArePassedToTestRunnerTest {

Expand Down Expand Up @@ -39,4 +39,19 @@
TestRunner testRunner = new RunAction(config).newTestRunner(new ArrayList<>());
assertThat( testRunner.getOptions().oraStuckTimeout, equalTo(2) );
}

@Test
void expressionFilters() {
RunCommandConfig config = new RunCommandConfig.Builder()
.includeSchemaExpr("^APP$")
.excludeSchemaExpr("^APP_TEST$")
.includeObjectExpr("^PKG_")
.excludeObjectExpr("_TMP$")
.create();
TestRunner testRunner = new RunAction(config).newTestRunner(new ArrayList<>());
assertThat( testRunner.getOptions().includeSchemaExpr, equalTo("^APP$") );
assertThat( testRunner.getOptions().excludeSchemaExpr, equalTo("^APP_TEST$") );
assertThat( testRunner.getOptions().includeObjectExpr, equalTo("^PKG_") );
assertThat( testRunner.getOptions().excludeObjectExpr, equalTo("_TMP$") );
}
}
Loading