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

Skip to content

Commit b5bad33

Browse files
authored
Merge pull request #196 from Pazus/suitepath_current_user_shortcut
Suitepath current user shortcut
2 parents 5022e83 + 389d0d6 commit b5bad33

12 files changed

Lines changed: 430 additions & 7 deletions

docs/userguide/annotations.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ create or replace package payments as
144144

145145
end payments;
146146
```
147-
148-
A `%suitepath` is formed by valid sqlnames separated by dots. The depth of the suites path is not limited. The fully qualified path to a test is formed by `<user>:[<suitepath>.]<test package>.<test procedure>`.
149-
150-
You can also use `%suitepath` to define the starting going of tests to execute. If you want to run only payments tests of the `FOO` schema then you gen execute `ut.run('foo:payments');` and all suites that have `payments` in their `%suitepath`s will be executed. This way you can filter the execution up to a single test. Only tests/suites which are children of the defined path are executed and all the parents `%beforeall`, `%beforeeach`, `%aftereach`, `%afterall` elements. So all the preparation and cleanup is performed as if you execute all the tests of the schema.
147+
A `%suitepath` can be provided in tree ways:
148+
* schema - execute all test in the schema
149+
* [schema]:suite1[.suite2][.suite3]...[.procedure] - execute all tests in all suites from suite1[.suite2][.suite3]...[.procedure] path. If schema is not provided, then current schema is used. Example: `:all.rooms_tests`.
150+
* [schema.]package[.procedure] - execute all tests in the test package provided. The whole hierarchy of suites in the schema is build before, all before/after hooks of partn suites for th provided suite package are executed as well. Example: `tests.test_contact.test_last_name_validator` or simply `test_contact.test_last_name_validator` if `tests` is the current schema.

source/core/ut_suite_manager.pkb

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ create or replace package body ut_suite_manager is
330330
else
331331
for i in 1 .. a_paths.count loop
332332
l_path := a_paths(i);
333-
if l_path is null or not (regexp_like(l_path, '^\w+(\.\w+){0,2}$') or regexp_like(l_path, '^\w+:\w+(\.\w+)*$')) then
333+
if l_path is null or not (regexp_like(l_path, '^\w+(\.\w+){0,2}$') or regexp_like(l_path, '^(\w+)?:\w+(\.\w+)*$')) then
334334
raise_application_error(ut_utils.gc_invalid_path_format, 'Invalid path format: ' || nvl(l_path, 'NULL'));
335335
end if;
336336
end loop;
@@ -347,6 +347,7 @@ create or replace package body ut_suite_manager is
347347
l_suite_path varchar2(4000);
348348
l_root_suite_name varchar2(4000);
349349
l_objects_to_run ut_suite_items;
350+
c_current_schema constant all_tables.owner%type := sys_context('USERENV','CURRENT_SCHEMA');
350351

351352
function clean_paths(a_paths ut_varchar2_list) return ut_varchar2_list is
352353
l_paths_temp ut_varchar2_list := ut_varchar2_list();
@@ -400,6 +401,18 @@ create or replace package body ut_suite_manager is
400401
end if;
401402
end skip_by_path;
402403

404+
function package_exists_in_cur_schema(p_package_name varchar2) return boolean is
405+
l_cnt number;
406+
begin
407+
select count(*)
408+
into l_cnt
409+
from all_objects t
410+
where t.object_name = upper(p_package_name)
411+
and t.object_type = 'PACKAGE'
412+
and t.owner = c_current_schema;
413+
return l_cnt > 0;
414+
end package_exists_in_cur_schema;
415+
403416
begin
404417
l_paths := clean_paths(a_paths);
405418

@@ -410,9 +423,33 @@ create or replace package body ut_suite_manager is
410423
-- to be improved later
411424
for i in 1 .. l_paths.count loop
412425
l_path := l_paths(i);
413-
l_schema := regexp_substr(l_path, '^(\w+)(\.|:|$)', 1, 1, null, 1);
414426

415-
l_schema := sys.dbms_assert.schema_name(upper(l_schema));
427+
if regexp_like(l_path, '^(\w+)?:') then
428+
l_schema := regexp_substr(l_path, '^(\w+)?:',subexpression => 1);
429+
-- transform ":path1[.path2]" to "schema:path1[.path2]"
430+
if l_schema is not null then
431+
l_schema := sys.dbms_assert.schema_name(upper(l_schema));
432+
else
433+
l_path := c_current_schema || l_path;
434+
l_schema := c_current_schema;
435+
end if;
436+
else
437+
-- When path is one of: schema or schema.package[.object] or package[.object]
438+
-- transform it back to schema[.package[.object]]
439+
begin
440+
l_schema := regexp_substr(l_path, '^\w+');
441+
l_schema := sys.dbms_assert.schema_name(upper(l_schema));
442+
exception
443+
when sys.dbms_assert.invalid_schema_name then
444+
if package_exists_in_cur_schema(l_schema) then
445+
l_path := c_current_schema || '.' || l_path;
446+
l_schema := c_current_schema;
447+
else
448+
raise;
449+
end if;
450+
end;
451+
452+
end if;
416453

417454
l_schema_suites := get_schema_suites(upper(l_schema));
418455

tests/RunAll.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,21 @@ create table ut$test_table (val varchar2(1));
121121

122122
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheSchema.sql
123123
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByPath.sql
124+
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByPathCurUser.sql
124125
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByPath.sql
126+
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByPathCurUser.sql
125127
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByPath.sql
128+
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByPathCurUser.sql
126129
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByName.sql
130+
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByNameCurUser.sql
127131
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByName.sql
132+
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByNameCurUser.sql
128133
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByName.sql
134+
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByNameCurUser.sql
129135
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPath.sql
136+
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPathCurUser.sql
130137
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPath.sql
138+
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPathCurUser.sql
131139

132140
@@lib/RunTest.sql ut_expectations/greater_or_equal.sql
133141
@@lib/RunTest.sql ut_expectations/greater_than.sql
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
PROMPT Prepare runner for the top 2 package by package name for current user
2+
3+
--Arrange
4+
declare
5+
c_path varchar2(100) := 'test_package_2';
6+
l_objects_to_run ut_suite_items;
7+
8+
l_test0_suite ut_logical_suite;
9+
l_test1_suite ut_logical_suite;
10+
l_test2_suite ut_logical_suite;
11+
begin
12+
--Act
13+
l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path));
14+
15+
--Assert
16+
ut.expect(l_objects_to_run.count).to_equal(1);
17+
l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite);
18+
19+
ut.expect(l_test0_suite.name).to_equal('tests');
20+
ut.expect(l_test0_suite.items.count).to_equal(1);
21+
l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite);
22+
23+
ut.expect(l_test1_suite.name).to_equal('test_package_1');
24+
ut.expect(l_test1_suite.items.count).to_equal(1);
25+
l_test2_suite := treat(l_test1_suite.items(1) as ut_logical_suite);
26+
27+
ut.expect(l_test2_suite.name).to_equal('test_package_2');
28+
ut.expect(l_test2_suite.items.count).to_equal(2);
29+
30+
31+
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
32+
:test_result := ut_utils.tr_success;
33+
end if;
34+
35+
end;
36+
/
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
PROMPT Prepare runner for the top 2 package by path for current user
2+
3+
--Arrange
4+
declare
5+
c_path varchar2(100) := ':tests.test_package_1.test_package_2';
6+
l_objects_to_run ut_suite_items;
7+
8+
l_test0_suite ut_logical_suite;
9+
l_test1_suite ut_logical_suite;
10+
l_test2_suite ut_logical_suite;
11+
begin
12+
--Act
13+
l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path));
14+
15+
--Assert
16+
ut.expect(l_objects_to_run.count).to_equal(1);
17+
l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite);
18+
19+
ut.expect(l_test0_suite.name).to_equal('tests');
20+
ut.expect(l_test0_suite.items.count).to_equal(1);
21+
l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite);
22+
23+
ut.expect(l_test1_suite.name).to_equal('test_package_1');
24+
ut.expect(l_test1_suite.items.count).to_equal(1);
25+
l_test2_suite := treat(l_test1_suite.items(1) as ut_logical_suite);
26+
27+
ut.expect(l_test2_suite.name).to_equal('test_package_2');
28+
ut.expect(l_test2_suite.items.count).to_equal(2);
29+
30+
31+
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
32+
:test_result := ut_utils.tr_success;
33+
end if;
34+
35+
end;
36+
/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
PROMPT Prepare runner for the top 2 package procedure by path for current user
2+
3+
--Arrange
4+
declare
5+
c_path varchar2(100) := ':tests.test_package_1.test_package_2.test2';
6+
l_objects_to_run ut_suite_items;
7+
8+
l_test0_suite ut_logical_suite;
9+
l_test1_suite ut_logical_suite;
10+
l_test2_suite ut_logical_suite;
11+
l_test_proc ut_test;
12+
begin
13+
--Act
14+
l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path));
15+
16+
--Assert
17+
ut.expect(l_objects_to_run.count).to_equal(1);
18+
l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite);
19+
20+
ut.expect(l_test0_suite.name).to_equal('tests');
21+
ut.expect(l_test0_suite.items.count).to_equal(1);
22+
l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite);
23+
24+
ut.expect(l_test1_suite.name).to_equal('test_package_1');
25+
ut.expect(l_test1_suite.items.count).to_equal(1);
26+
l_test2_suite := treat(l_test1_suite.items(1) as ut_logical_suite);
27+
28+
ut.expect(l_test2_suite.name).to_equal('test_package_2');
29+
ut.expect(l_test2_suite.items.count).to_equal(1);
30+
31+
l_test_proc := treat(l_test2_suite.items(1) as ut_test);
32+
ut.expect(l_test_proc.name).to_equal('test2');
33+
ut.expect(l_test_proc.before_test is not null).to_be_true;
34+
ut.expect(l_test_proc.after_test is not null).to_be_true;
35+
36+
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
37+
:test_result := ut_utils.tr_success;
38+
else
39+
dbms_output.put_line(q'[ut.expect(l_objects_to_run.count).to_equal(1);=]'||l_objects_to_run.count);
40+
dbms_output.put_line(q'[ut.expect(l_test0_suite.name).to_equal('tests');=]'||l_test0_suite.name);
41+
dbms_output.put_line(q'[ut.expect(l_test0_suite.items.count).to_equal(1);=]'||l_test0_suite.items.count);
42+
dbms_output.put_line(q'[ut.expect(l_test1_suite.name).to_equal('test_package_1');=]'||l_test1_suite.name);
43+
dbms_output.put_line(q'[ut.expect(l_test1_suite.items.count).to_equal(1);=]'||l_test1_suite.items.count);
44+
dbms_output.put_line(q'[ut.expect(l_test2_suite.name).to_equal('test_package_2');=]'||l_test2_suite.name);
45+
dbms_output.put_line(q'[ut.expect(l_test2_suite.items.count).to_equal(1);=]'||l_test2_suite.items.count);
46+
dbms_output.put_line(q'[ut.expect(l_test_proc.name).to_equal('test2');=]'||l_test_proc.name);
47+
dbms_output.put_line(q'[ut.expect(l_test_proc.before_test is not null).to_be_true;=]'||ut_utils.to_string(l_test_proc.before_test is not null));
48+
dbms_output.put_line(q'[ut.expect(l_test_proc.after_test is not null).to_be_true;=]'||ut_utils.to_string(l_test_proc.after_test is not null));
49+
end if;
50+
51+
end;
52+
/
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
PROMPT Prepare runner for the top package by package name for current user
2+
3+
--Arrange
4+
declare
5+
c_path varchar2(100) := 'test_package_1';
6+
l_objects_to_run ut_suite_items;
7+
8+
l_test0_suite ut_logical_suite;
9+
l_test1_suite ut_suite;
10+
l_test2_suite ut_suite;
11+
begin
12+
--Act
13+
l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path));
14+
15+
--Assert
16+
ut.expect(l_objects_to_run.count).to_equal(1);
17+
l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite);
18+
19+
ut.expect(l_test0_suite.name).to_equal('tests');
20+
ut.expect(l_test0_suite.items.count).to_equal(1);
21+
l_test1_suite := treat(l_test0_suite.items(1) as ut_suite);
22+
23+
ut.expect(l_test1_suite.name).to_equal('test_package_1');
24+
ut.expect(l_test1_suite.items.count).to_equal(3);
25+
ut.expect(l_test1_suite.before_each is not null).to_be_true;
26+
27+
ut.expect(l_test1_suite.items(1).name).to_equal('test1');
28+
ut.expect(l_test1_suite.items(1).description).to_equal('Test1 from test package 1');
29+
ut.expect(treat(l_test1_suite.items(1) as ut_test).before_test.is_defined).to_be_false;
30+
ut.expect(treat(l_test1_suite.items(1) as ut_test).after_test.is_defined).to_be_false;
31+
ut.expect(treat(l_test1_suite.items(1) as ut_test).ignore_flag).to_equal(0);
32+
33+
ut.expect(l_test1_suite.items(2).name).to_equal('test2');
34+
ut.expect(l_test1_suite.items(2).description).to_equal('Test2 from test package 1');
35+
ut.expect(treat(l_test1_suite.items(2) as ut_test).before_test.is_defined).to_be_true;
36+
ut.expect(treat(l_test1_suite.items(2) as ut_test).after_test.is_defined).to_be_true;
37+
ut.expect(treat(l_test1_suite.items(2) as ut_test).ignore_flag).to_equal(0);
38+
39+
-- temporary behavior.
40+
-- decided that when executed by package, not path, only that package has to execute
41+
l_test2_suite := treat(l_test1_suite.items(3) as ut_suite);
42+
43+
ut.expect(l_test2_suite.name).to_equal('test_package_2');
44+
ut.expect(l_test2_suite.items.count).to_equal(2);
45+
46+
47+
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
48+
:test_result := ut_utils.tr_success;
49+
else
50+
declare
51+
l_results ut_assert_results;
52+
begin
53+
l_results := ut_assert_processor.get_asserts_results;
54+
for i in 1..l_results.count loop
55+
if l_results(i).result > ut_utils.tr_success then
56+
dbms_output.put_line(l_results(i).get_result_clob);
57+
end if;
58+
end loop;
59+
end;
60+
61+
end if;
62+
63+
end;
64+
/
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
PROMPT Prepare runner for the top package by path for current user
2+
3+
--Arrange
4+
declare
5+
c_path varchar2(100) := ':tests';
6+
l_objects_to_run ut_suite_items;
7+
8+
l_test0_suite ut_logical_suite;
9+
l_test1_suite ut_logical_suite;
10+
l_test2_suite ut_logical_suite;
11+
begin
12+
--Act
13+
l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path));
14+
15+
--Assert
16+
ut.expect(l_objects_to_run.count).to_equal(1);
17+
l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite);
18+
19+
ut.expect(l_test0_suite.name).to_equal('tests');
20+
ut.expect(l_test0_suite.items.count).to_equal(1);
21+
l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite);
22+
23+
ut.expect(l_test1_suite.name).to_equal('test_package_1');
24+
ut.expect(l_test1_suite.items.count).to_equal(3);
25+
l_test2_suite := treat(l_test1_suite.items(3) as ut_logical_suite);
26+
27+
ut.expect(l_test2_suite.name).to_equal('test_package_2');
28+
ut.expect(l_test2_suite.items.count).to_equal(2);
29+
30+
31+
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
32+
:test_result := ut_utils.tr_success;
33+
end if;
34+
35+
end;
36+
/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
PROMPT Prepare runner for the top package procedure by path for current user
2+
3+
--Arrange
4+
declare
5+
c_path varchar2(100) := ':tests.test_package_1.test2';
6+
l_objects_to_run ut_suite_items;
7+
8+
l_test0_suite ut_logical_suite;
9+
l_test1_suite ut_logical_suite;
10+
l_test2_suite ut_logical_suite;
11+
l_test_proc ut_test;
12+
begin
13+
--Act
14+
l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path));
15+
16+
--Assert
17+
ut.expect(l_objects_to_run.count).to_equal(1);
18+
l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite);
19+
20+
ut.expect(l_test0_suite.name).to_equal('tests');
21+
ut.expect(l_test0_suite.items.count).to_equal(1);
22+
l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite);
23+
24+
ut.expect(l_test1_suite.name).to_equal('test_package_1');
25+
ut.expect(l_test1_suite.items.count).to_equal(1);
26+
l_test_proc := treat(l_test1_suite.items(1) as ut_test);
27+
28+
ut.expect(l_test_proc.name).to_equal('test2');
29+
ut.expect(l_test_proc.description).to_equal('Test2 from test package 1');
30+
ut.expect(l_test_proc.before_test is not null).to_be_true;
31+
ut.expect(l_test_proc.after_test is not null).to_be_true;
32+
33+
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
34+
:test_result := ut_utils.tr_success;
35+
end if;
36+
37+
end;
38+
/

0 commit comments

Comments
 (0)