Skip to content

Commit adbdf08

Browse files
committed
Addressing code review comments + cleanup and performance improvements.
Added mystats library to the RunAll for unit tests of framework.
1 parent 7879454 commit adbdf08

26 files changed

+1187
-457
lines changed

docs/userguide/coverage.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ utPLSQL comes with build-in coverage reporting engine. The code coverage reporti
33
* package bodies
44
* type bodies
55
* triggers
6+
* stored procedures
7+
* stored functions
68

79
Note:
810

@@ -11,8 +13,8 @@ Note:
1113
To obtain information about code coverage of your Unit Tests, all you need to do is run your unit tests with one of build-in code coverage reporters.
1214
Following code coverage reporters are supplied with utPLSQL:
1315
* `ut_coverage_html_reporter` - generates a HTML coverage report providing summary and detailed information on code coverage. The html reporter is based on open-source [simplecov-html](https://github.com/colszowka/simplecov-html) reporter for Ruby. It includes source code of the code that was covered (if possible)
14-
* `ut_coverage_json_reporter` - generates a JSON coverage report providing detailed information on code coverage with line numbers. This coverage report is designed to be consumed by cloud services like [coveralls](https://coveralls.io)
15-
* `ut_coverage_xml_reporter` - generates a JSON coverage report providing detailed information on code coverage with line numbers. This coverage report is designed to be consumed by local services like [sonarqube](https://about.sonarqube.com/)
16+
* `ut_coveralls_reporter` - generates a JSON coverage report providing detailed information on code coverage with line numbers. This coverage report is designed to be consumed by cloud services like [coveralls](https://coveralls.io)
17+
* `ut_coverage_sonar_reporter` - generates a JSON coverage report providing detailed information on code coverage with line numbers. This coverage report is designed to be consumed by local services like [sonarqube](https://about.sonarqube.com/)
1618

1719
##Security model
1820
Code coverage is using DBMS_PROFILER to gather information about execution of code under test and therefore follows the [DBMS_PROFILER's Security Model](https://docs.oracle.com/database/121/ARPLS/d_profil.htm#ARPLS67465)
@@ -28,7 +30,9 @@ If the code that is testes is complied as NATIVE, the code coverage will not be
2830

2931
##Running unite tests with coverage
3032
Using code coverage functionality is as easy as using any other [reporter](reporters.md) for utPLSQL project. All you need to do is run your tests from your preferred SQL tool and save the outcomes of reporter to a file.
31-
All you need to do, is pass the constructor of the reporter to your `ut.run`
33+
All you need to do, is pass the constructor of the reporter to your `ut.run`
34+
35+
Example:
3236
```sql
3337
begin
3438
ut.run(ut_coverage_html_reporter());
@@ -105,7 +109,7 @@ end;
105109
Executes test `test_award_bonus` in schema `ut3_user` and gather coverage for that execution on `award_bonus` object from schema `usr`. The exclude list is of no relevance as it is not overlapping with include list.
106110

107111
###Working with projects and project files
108-
Both `sonar` and `coveralls` are utilities that are more project-oriented than database-centric. The report statistics and coverage for project files in version control system.
112+
Both `sonar` and `coveralls` are utilities that are more project-oriented than database-centric. They report statistics and coverage for project files in version control system.
109113
Nowadays, most of database projects are moving away from database-centric approach towards project/product-centric approach.
110114
Coverage reporting of utPLSQL allows you to perform code coverage analysis for your project files.
111115
This feature is supported by all build-in coverage reporting formats.
@@ -141,11 +145,12 @@ begin
141145
);
142146
end;
143147
```
148+
144149
Executes all tests in schema `usr` and reports coverage for that execution on procedure `award_bonus` and function `betwnstr`. The coverage report is mapped-back to file-system object names with paths.
145150

146151
**Reporting using regex file mapping rule**
147152
If file names and paths in your project follow a well established naming conventions,
148-
then you can you can use the predefined rule for mapping file names to object names or you can define your own rule and pass it to the coverage reporter at runtime.
153+
then you can use the predefined rule for mapping file names to object names or you can define your own rule and pass it to the coverage reporter at runtime.
149154

150155
Example of running with predefined regex mapping rule.
151156
```sql
@@ -172,11 +177,14 @@ The predefined file extension to object type mappings
172177
| -------------- | ----------- |
173178
| tpb | type body |
174179
| pkb | package body |
180+
| bdy | package body |
175181
| trg | trigger |
176182
| fnc | function |
177183
| prc | procedure |
178184

179-
Below are examples of filename forms taht will be mapped correctly using predefined rules.
185+
Since package specification and type specifications are not considered by coverage, the file extensions for those objects are not included in the mapping.
186+
187+
Examples of filename paths that will be mapped correctly using predefined rules.
180188
* `[...]directory[/subdirectory[/...]]/object_name.(tpb|pkb|trg|fnc|prc)`
181189
* `[...]directory[/subdirectory[/...]]/schema_name.object_name.(tpb|pkb|trg|fnc|prc)`
182190
* `[...]directory[\subdirectory[\...]]\object_name.(tpb|pkb|trg|fnc|prc)`

examples/between_string/run_betwnstr_test_coverage.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set serveroutput on size unlimited format truncated
1111
set feedback off
1212
set termout off
1313
spool coverage.html
14-
exec ut.run(user, ut_coverage_html_reporter('Demo of between string function tests'));
14+
exec ut.run(user, ut_coverage_html_reporter(a_project_name=>'Demo of between string function tests', a_include_object_list=>ut_varchar2_list('ut3.betwnstr')));
1515
spool off
1616

1717

source/core/coverage/proftab.sql

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
whenever sqlerror continue
2+
3+
create table plsql_profiler_runs
4+
(
5+
runid number primary key, -- unique run identifier,
6+
-- from plsql_profiler_runnumber
7+
related_run number, -- runid of related run (for client/
8+
-- server correlation)
9+
run_owner varchar2(32), -- user who started run
10+
run_date date, -- start time of run
11+
run_comment varchar2(2047), -- user provided comment for this run
12+
run_total_time number, -- elapsed time for this run
13+
run_system_info varchar2(2047), -- currently unused
14+
run_comment1 varchar2(2047), -- additional comment
15+
spare1 varchar2(256) -- unused
16+
);
17+
18+
comment on table plsql_profiler_runs is
19+
'Run-specific information for the PL/SQL profiler';
20+
21+
create table plsql_profiler_units
22+
(
23+
runid number references plsql_profiler_runs,
24+
unit_number number, -- internally generated library unit #
25+
unit_type varchar2(32), -- library unit type
26+
unit_owner varchar2(32), -- library unit owner name
27+
unit_name varchar2(32), -- library unit name
28+
-- timestamp on library unit, can be used to detect changes to
29+
-- unit between runs
30+
unit_timestamp date,
31+
total_time number DEFAULT 0 NOT NULL,
32+
spare1 number, -- unused
33+
spare2 number, -- unused
34+
--
35+
primary key (runid, unit_number)
36+
);
37+
38+
comment on table plsql_profiler_units is
39+
'Information about each library unit in a run';
40+
41+
create table plsql_profiler_data
42+
(
43+
runid number, -- unique (generated) run identifier
44+
unit_number number, -- internally generated library unit #
45+
line# number not null, -- line number in unit
46+
total_occur number, -- number of times line was executed
47+
total_time number, -- total time spent executing line
48+
min_time number, -- minimum execution time for this line
49+
max_time number, -- maximum execution time for this line
50+
spare1 number, -- unused
51+
spare2 number, -- unused
52+
spare3 number, -- unused
53+
spare4 number, -- unused
54+
--
55+
primary key (runid, unit_number, line#),
56+
foreign key (runid, unit_number) references plsql_profiler_units
57+
);
58+
59+
comment on table plsql_profiler_data is
60+
'Accumulated data from all profiler runs';
61+
62+
create sequence plsql_profiler_runnumber start with 1 nocache;
63+
64+
whenever sqlerror exit failure rollback

source/core/coverage/proftab_temp_tables.sql

Lines changed: 0 additions & 233 deletions
This file was deleted.

0 commit comments

Comments
 (0)