Skip to content

Commit 0fed636

Browse files
authored
Merge pull request #233 from utPLSQL/feature/add_filter_coverage_by_expr
Add coverage filter options by regular expression
2 parents 8f83f25 + 8c1516c commit 0fed636

7 files changed

Lines changed: 137 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ The TNS alias used in the connect string must match the alias of the credential
201201
-exclude=pckg_list - Comma-separated object list to exclude from the coverage report.
202202
Format: [schema.]package[,[schema.]package ...].
203203
See coverage reporting options in framework documentation.
204+
205+
-include-schema-expr=regex - Regular expression matching the names of schemas to include in the coverage report.
206+
-exclude-schema-expr=regex - Regular expression matching the names of schemas to exclude from the coverage report.
207+
-include-object-expr=regex - Regular expression matching the names of objects to include in the coverage report.
208+
-exclude-object-expr=regex - Regular expression matching the names of objects to exclude from the coverage report.
209+
Case-insensitive. Object expressions are matched against the object name without the schema.
210+
Anchor them with `^` and `$`, otherwise any partial match counts.
211+
If an include expression is given, `-include` and `--coverage-schemes` are ignored.
212+
All exclude options are always applied and can be combined.
213+
Ignored when `-source_path` is used (file mapping defines the coverage scope).
214+
See https://www.utplsql.org/utPLSQL/latest/userguide/coverage.html#filtering-objects-in-coverage-reports
204215
205216
-q - Does not output the informational messages normally printed to console.
206217
(--quiet) Default: false
@@ -247,6 +258,12 @@ Invokes all Unit tests from schema/package "hr_test" with two reporters:
247258

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

261+
```
262+
> utplsql run hr/hr@xe -p=hr_test -f=ut_coverage_html_reporter -o=coverage.html -include-schema-expr=^HR$ -exclude-object-expr=_TMP$
263+
```
264+
265+
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".
266+
250267
### info
251268
`utplsql info [<ConnectionURL>]`
252269

‎src/main/java/org/utplsql/cli/RunAction.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ TestRunner newTestRunner(List<Reporter> reporterList) {
167167
.randomTestOrderSeed(config.getRandomTestOrderSeed())
168168
.addTags(Arrays.asList(config.getTags()))
169169
.addCoverageSchemes(Arrays.asList(config.getCoverageSchemes()))
170+
.includeSchemaExpr(config.getIncludeSchemaExpr())
171+
.excludeSchemaExpr(config.getExcludeSchemaExpr())
172+
.includeObjectExpr(config.getIncludeObjectExpr())
173+
.excludeObjectExpr(config.getExcludeObjectExpr())
170174
.oraStuckTimeout(config.getOraStuckTimeout());
171175
}
172176

‎src/main/java/org/utplsql/cli/RunPicocliCommand.java‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,34 @@ public class RunPicocliCommand implements IRunCommand {
8181
private String excludeObjects = null;
8282

8383

84+
@Option(
85+
names = {"-include-schema-expr"},
86+
description = "Regular expression to include in the coverage report schemas whose name matches the expression. " +
87+
"See coverage reporting options in framework documentation"
88+
)
89+
private String includeSchemaExpr;
90+
91+
@Option(
92+
names = {"-exclude-schema-expr"},
93+
description = "Regular expression to exclude from the coverage report schemas whose name matches the expression. " +
94+
"See coverage reporting options in framework documentation"
95+
)
96+
private String excludeSchemaExpr;
97+
98+
@Option(
99+
names = {"-include-object-expr"},
100+
description = "Regular expression to include in the coverage report objects whose name matches the expression. " +
101+
"See coverage reporting options in framework documentation"
102+
)
103+
private String includeObjectExpr;
104+
105+
@Option(
106+
names = {"-exclude-object-expr"},
107+
description = "Regular expression to exclude from the coverage report objects whose name matches the expression. " +
108+
"See coverage reporting options in framework documentation"
109+
)
110+
private String excludeObjectExpr;
111+
84112
@Option(
85113
names = {"-D", "--dbms_output"},
86114
description = "Enables DBMS_OUTPUT for the TestRunner (default: DISABLED)"
@@ -249,6 +277,10 @@ public RunCommandConfig getRunCommandConfig() {
249277
.tags(tags.toArray(new String[0]))
250278
.coverageSchemes(coverageSchemes.toArray(new String[0]))
251279
.oraStuckTimeout(oraStuckTimeout)
280+
.includeSchemaExpr(includeSchemaExpr)
281+
.excludeSchemaExpr(excludeSchemaExpr)
282+
.includeObjectExpr(includeObjectExpr)
283+
.excludeObjectExpr(excludeObjectExpr)
252284
.create();
253285
}
254286

‎src/main/java/org/utplsql/cli/config/RunCommandConfig.java‎

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ public class RunCommandConfig extends ConnectionConfig {
2424
private final String[] tags;
2525
private final String[] coverageSchemes;
2626
private final Integer oraStuckTimeout;
27+
private final String includeSchemaExpr;
28+
private final String excludeSchemaExpr;
29+
private final String includeObjectExpr;
30+
private final String excludeObjectExpr;
2731

28-
@ConstructorProperties({"connectString", "suitePaths", "reporters", "outputAnsiColor", "failureExitCode", "skipCompatibilityCheck", "includePackages", "excludePackages", "sourceMapping", "testMapping", "logConfigLevel", "timeoutInMinutes", "dbmsOutput", "randomTestOrder", "randomTestOrderSeed", "tags", "coverageSchemes", "oraStuckTimeout"})
29-
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) {
32+
@ConstructorProperties({"connectString", "suitePaths", "reporters", "outputAnsiColor", "failureExitCode", "skipCompatibilityCheck", "includePackages", "excludePackages", "sourceMapping", "testMapping", "logConfigLevel", "timeoutInMinutes", "dbmsOutput", "randomTestOrder", "randomTestOrderSeed", "tags", "coverageSchemes", "oraStuckTimeout", "includeSchemaExpr", "excludeSchemaExpr", "includeObjectExpr", "excludeObjectExpr"})
33+
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) {
3034
super(connectString);
3135
this.suitePaths = suitePaths;
3236
this.reporters = reporters;
@@ -45,6 +49,10 @@ public RunCommandConfig(String connectString, String[] suitePaths, ReporterConfi
4549
this.tags = tags;
4650
this.coverageSchemes = coverageSchemes;
4751
this.oraStuckTimeout = oraStuckTimeout;
52+
this.includeSchemaExpr = includeSchemaExpr;
53+
this.excludeSchemaExpr = excludeSchemaExpr;
54+
this.includeObjectExpr = includeObjectExpr;
55+
this.excludeObjectExpr = excludeObjectExpr;
4856
}
4957

5058
public String[] getSuitePaths() {
@@ -113,6 +121,14 @@ public String[] getCoverageSchemes() {
113121

114122
public Integer getOraStuckTimeout() { return oraStuckTimeout; }
115123

124+
public String getIncludeSchemaExpr() { return includeSchemaExpr; }
125+
126+
public String getExcludeSchemaExpr() { return excludeSchemaExpr; }
127+
128+
public String getIncludeObjectExpr() { return includeObjectExpr; }
129+
130+
public String getExcludeObjectExpr() { return excludeObjectExpr; }
131+
116132
public static class Builder {
117133

118134
private String connectString;
@@ -133,6 +149,10 @@ public static class Builder {
133149
private String[] tags = new String[0];
134150
private String[] coverageSchemes = new String[0];
135151
private Integer oraStuckTimeout;
152+
private String includeSchemaExpr;
153+
private String excludeSchemaExpr;
154+
private String includeObjectExpr;
155+
private String excludeObjectExpr;
136156

137157
public Builder connectString(String connectString) {
138158
this.connectString = connectString;
@@ -224,8 +244,28 @@ public Builder oraStuckTimeout(Integer oraStuckTimeout) {
224244
return this;
225245
}
226246

247+
public Builder includeSchemaExpr(String includeSchemaExpr) {
248+
this.includeSchemaExpr = includeSchemaExpr;
249+
return this;
250+
}
251+
252+
public Builder excludeSchemaExpr(String excludeSchemaExpr) {
253+
this.excludeSchemaExpr = excludeSchemaExpr;
254+
return this;
255+
}
256+
257+
public Builder includeObjectExpr(String includeObjectExpr) {
258+
this.includeObjectExpr = includeObjectExpr;
259+
return this;
260+
}
261+
262+
public Builder excludeObjectExpr(String excludeObjectExpr) {
263+
this.excludeObjectExpr = excludeObjectExpr;
264+
return this;
265+
}
266+
227267
public RunCommandConfig create() {
228-
return new RunCommandConfig(connectString, suitePaths, reporters, outputAnsiColor, failureExitCode, skipCompatibilityCheck, includePackages, excludePackages, sourceMapping, testMapping, logConfigLevel, timeoutInMinutes, dbmsOutput, randomTestOrder, randomTestOrderSeed, tags, coverageSchemes, oraStuckTimeout);
268+
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);
229269
}
230270
}
231271
}

‎src/test/java/org/utplsql/cli/PicocliRunCommandTest.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ void runCommandAllArguments() throws Exception {
4949
"-owner_subexpression=1",
5050
"-type_subexpression=2",
5151
"-name_subexpression=3",
52-
"--coverage-schemes=schema1,other_schema");
52+
"--coverage-schemes=schema1,other_schema",
53+
"-include-schema-expr=^APP$",
54+
"-exclude-schema-expr=^APP_TEST$",
55+
"-include-object-expr=^PKG_",
56+
"-exclude-object-expr=_TMP$");
5357

5458
assertNotNull(config.getConnectString());
5559
assertThat( config.getSuitePaths(), is(new String[]{"app.betwnstr", "app.basic"}));
5660
assertThat( config.getTags(), is(new String[]{"tag1", "tag.2"}));
61+
assertEquals( "^APP$", config.getIncludeSchemaExpr() );
62+
assertEquals( "^APP_TEST$", config.getExcludeSchemaExpr() );
63+
assertEquals( "^PKG_", config.getIncludeObjectExpr() );
64+
assertEquals( "_TMP$", config.getExcludeObjectExpr() );
5765
assertTrue( config.isOutputAnsiColor() );
5866
assertEquals( LoggerConfiguration.ConfigLevel.NONE, config.getLogConfigLevel());
5967
assertEquals( 10, config.getFailureExitCode());

‎src/test/java/org/utplsql/cli/RunCommandArgumentsTest.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import static org.hamcrest.MatcherAssert.assertThat;
1010
import static org.hamcrest.Matchers.contains;
11+
import static org.hamcrest.Matchers.equalTo;
1112

1213
public class RunCommandArgumentsTest {
1314

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

73+
@Test
74+
void provideExpressionFilters() {
75+
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(),
76+
"-include-schema-expr=^APP$",
77+
"-exclude-schema-expr=^APP_TEST$",
78+
"-include-object-expr=^PKG_",
79+
"-exclude-object-expr=_TMP$"
80+
);
81+
82+
TestRunner testRunner = runCmd.newTestRunner(new ArrayList<>());
83+
assertThat( testRunner.getOptions().includeSchemaExpr, equalTo("^APP$") );
84+
assertThat( testRunner.getOptions().excludeSchemaExpr, equalTo("^APP_TEST$") );
85+
assertThat( testRunner.getOptions().includeObjectExpr, equalTo("^PKG_") );
86+
assertThat( testRunner.getOptions().excludeObjectExpr, equalTo("_TMP$") );
87+
}
88+
7289
@Test
7390
void provideCoverageSchemes() {
7491
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(),

‎src/test/java/org/utplsql/cli/RunCommandConfigParamsArePassedToTestRunnerTest.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,19 @@ void oraStuckTimeout() {
3939
TestRunner testRunner = new RunAction(config).newTestRunner(new ArrayList<>());
4040
assertThat( testRunner.getOptions().oraStuckTimeout, equalTo(2) );
4141
}
42+
43+
@Test
44+
void expressionFilters() {
45+
RunCommandConfig config = new RunCommandConfig.Builder()
46+
.includeSchemaExpr("^APP$")
47+
.excludeSchemaExpr("^APP_TEST$")
48+
.includeObjectExpr("^PKG_")
49+
.excludeObjectExpr("_TMP$")
50+
.create();
51+
TestRunner testRunner = new RunAction(config).newTestRunner(new ArrayList<>());
52+
assertThat( testRunner.getOptions().includeSchemaExpr, equalTo("^APP$") );
53+
assertThat( testRunner.getOptions().excludeSchemaExpr, equalTo("^APP_TEST$") );
54+
assertThat( testRunner.getOptions().includeObjectExpr, equalTo("^PKG_") );
55+
assertThat( testRunner.getOptions().excludeObjectExpr, equalTo("_TMP$") );
56+
}
4257
}

0 commit comments

Comments
 (0)