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

Skip to content

Commit 02a071c

Browse files
committed
Separate tag logic.
1 parent 313d5e9 commit 02a071c

13 files changed

Lines changed: 423 additions & 342 deletions

source/core/ut_suite_cache_manager.pkb

Lines changed: 14 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -220,121 +220,7 @@ create or replace package body ut_suite_cache_manager is
220220
and c.name = nvl(upper(sp.procedure_name),c.name)))) where r_num =1;
221221
return l_suite_items;
222222
end;
223-
224-
/*
225-
To support a legact tag notation
226-
, = OR
227-
- = NOT
228-
we will perform a replace of that characters into
229-
new notation.
230-
| = OR
231-
& = AND
232-
! = NOT
233-
*/
234-
function replace_legacy_tag_notation(a_tags varchar2
235-
) return varchar2 is
236-
l_tags ut_varchar2_list := ut_utils.string_to_table(a_tags,',');
237-
l_tags_include varchar2(4000);
238-
l_tags_exclude varchar2(4000);
239-
l_return_tag varchar2(4000);
240-
begin
241-
if instr(a_tags,',') > 0 or instr(a_tags,'-') > 0 then
242-
243-
select '('||listagg( t.column_value,'|')
244-
within group( order by column_value)||')'
245-
into l_tags_include
246-
from table(l_tags) t
247-
where t.column_value not like '-%';
248223

249-
select '('||listagg( replace(t.column_value,'-','!'),' & ')
250-
within group( order by column_value)||')'
251-
into l_tags_exclude
252-
from table(l_tags) t
253-
where t.column_value like '-%';
254-
255-
256-
l_return_tag:=
257-
case
258-
when l_tags_include <> '()' and l_tags_exclude <> '()'
259-
then l_tags_include || ' & ' || l_tags_exclude
260-
when l_tags_include <> '()'
261-
then l_tags_include
262-
when l_tags_exclude <> '()'
263-
then l_tags_exclude
264-
end;
265-
else
266-
l_return_tag := a_tags;
267-
end if;
268-
return l_return_tag;
269-
end;
270-
271-
function create_where_filter(a_tags varchar2
272-
) return varchar2 is
273-
l_tags varchar2(4000);
274-
begin
275-
l_tags := replace(replace_legacy_tag_notation(a_tags),' ');
276-
l_tags := ut_utils.conv_postfix_to_infix_sql(ut_utils.shunt_logical_expression(l_tags));
277-
l_tags := replace(l_tags, '|',' or ');
278-
l_tags := replace(l_tags ,'&',' and ');
279-
l_tags := replace(l_tags ,'!','not');
280-
return l_tags;
281-
end;
282-
283-
/*
284-
Having a base set of suites we will do a further filter down if there are
285-
any tags defined.
286-
*/
287-
function get_tags_suites (
288-
a_suite_items ut_suite_cache_rows,
289-
a_tags varchar2
290-
) return ut_suite_cache_rows is
291-
l_suite_tags ut_suite_cache_rows := ut_suite_cache_rows();
292-
l_sql varchar2(32000);
293-
l_tags varchar2(4000):= create_where_filter(a_tags);
294-
begin
295-
l_sql :=
296-
q'[
297-
with
298-
suites_mv as (
299-
select c.id,value(c) as obj,c.path as path,c.self_type,c.object_owner,c.tags
300-
from table(:suite_items) c
301-
),
302-
suites_matching_expr as (
303-
select c.id,c.path as path,c.self_type,c.object_owner,c.tags
304-
from suites_mv c
305-
where c.self_type in ('UT_SUITE','UT_CONTEXT')
306-
and ]'||l_tags||q'[
307-
),
308-
tests_matching_expr as (
309-
select c.id,c.path as path,c.self_type,c.object_owner,c.tags
310-
from suites_mv c where c.self_type in ('UT_TEST')
311-
and ]'||l_tags||q'[
312-
),
313-
tests_with_tags_inh_from_suite as (
314-
select c.id,c.self_type,c.path,c.tags multiset union distinct t.tags tags,c.object_owner
315-
from suites_mv c join suites_matching_expr t
316-
on (c.path||'.' like t.path || '.%' /*all descendants and self*/ and c.object_owner = t.object_owner)
317-
),
318-
tests_with_tags_prom_to_suite as (
319-
select c.id,c.self_type,c.path,c.tags multiset union distinct t.tags tags,c.object_owner
320-
from suites_mv c join tests_matching_expr t
321-
on (t.path||'.' like c.path || '.%' /*all ancestors and self*/ and c.object_owner = t.object_owner)
322-
)
323-
select obj from suites_mv c,
324-
(select id,row_number() over (partition by id order by id) r_num from
325-
(select id
326-
from tests_with_tags_prom_to_suite tst
327-
where ]'||l_tags||q'[
328-
union all
329-
select id from tests_with_tags_inh_from_suite tst
330-
where ]'||l_tags||q'[
331-
)
332-
) t where c.id = t.id and r_num = 1 ]';
333-
334-
execute immediate l_sql bulk collect into l_suite_tags using a_suite_items;
335-
return l_suite_tags;
336-
end;
337-
338224
/*
339225
We will sort a suites in hierarchical structure.
340226
Sorting from bottom to top so when we consolidate
@@ -387,30 +273,29 @@ with
387273
end;
388274

389275
function get_cached_suite_rows(
390-
a_schema_paths ut_path_items,
391-
a_random_seed positive := null,
392-
a_tags varchar2 := null
276+
a_suites_filtered ut_suite_cache_rows
393277
) return ut_suite_cache_rows is
394278
l_results ut_suite_cache_rows := ut_suite_cache_rows();
395-
l_suite_items ut_suite_cache_rows := ut_suite_cache_rows();
396-
l_schema_paths ut_path_items;
397-
l_tags varchar2(4000) := a_tags;
398279
begin
399280

400-
l_schema_paths := a_schema_paths;
401-
l_suite_items := get_suite_items(a_schema_paths);
402-
if length(l_tags) > 0 then
403-
l_suite_items := get_tags_suites(l_suite_items,l_tags);
404-
end if;
405-
406-
open c_get_bulk_cache_suite(l_suite_items);
281+
open c_get_bulk_cache_suite(a_suites_filtered);
407282
fetch c_get_bulk_cache_suite bulk collect into l_results;
408283
close c_get_bulk_cache_suite;
409284

410285
return l_results;
411286
end;
412287

413-
288+
function get_cached_suites(
289+
a_schema_paths ut_path_items,
290+
a_random_seed positive := null
291+
) return ut_suite_cache_rows is
292+
l_suite_items ut_suite_cache_rows := ut_suite_cache_rows();
293+
l_schema_paths ut_path_items;
294+
begin
295+
l_schema_paths := a_schema_paths;
296+
l_suite_items := get_suite_items(a_schema_paths);
297+
return l_suite_items;
298+
end;
414299

415300
function get_schema_parse_time(a_schema_name varchar2) return timestamp result_cache is
416301
l_cache_parse_time timestamp;
@@ -558,7 +443,7 @@ with
558443
a_schema_paths ut_path_items
559444
) return ut_suite_cache_rows is
560445
begin
561-
return get_cached_suite_rows( a_schema_paths );
446+
return get_cached_suite_rows(get_cached_suites( a_schema_paths ));
562447
end;
563448

564449
function get_suite_items_info(

source/core/ut_suite_cache_manager.pks

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ create or replace package ut_suite_cache_manager authid definer is
5555
* Not to be used publicly. Used internally for building suites at runtime.
5656
*/
5757
function get_cached_suite_rows(
58+
a_suites_filtered ut_suite_cache_rows
59+
) return ut_suite_cache_rows;
60+
61+
function get_cached_suites(
5862
a_schema_paths ut_path_items,
59-
a_random_seed positive := null,
60-
a_tags varchar2 := null
63+
a_random_seed positive := null
6164
) return ut_suite_cache_rows;
62-
65+
6366
function get_schema_paths(a_paths in ut_varchar2_list) return ut_path_items;
6467

6568
/*

source/core/ut_suite_manager.pkb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,18 @@ create or replace package body ut_suite_manager is
355355
a_tags varchar2 := null,
356356
a_skip_all_objects boolean := false
357357
) return t_cached_suites_cursor is
358-
l_unfiltered_rows ut_suite_cache_rows;
359-
l_filtered_rows ut_suite_cache_rows;
360-
l_result t_cached_suites_cursor;
358+
l_unfiltered_rows ut_suite_cache_rows;
359+
l_tag_filter_applied ut_suite_cache_rows;
360+
l_filtered_rows ut_suite_cache_rows;
361+
l_result t_cached_suites_cursor;
361362
begin
362-
l_unfiltered_rows := ut_suite_cache_manager.get_cached_suite_rows(
363+
l_unfiltered_rows := ut_suite_cache_manager.get_cached_suites(
363364
a_schema_paths,
364-
a_random_seed,
365-
a_tags
365+
a_random_seed
366366
);
367367

368-
l_filtered_rows := get_filtered_cursor(l_unfiltered_rows,a_skip_all_objects);
368+
l_tag_filter_applied := ut_suite_tag_filter.apply(l_unfiltered_rows,a_tags);
369+
l_filtered_rows := get_filtered_cursor(ut_suite_cache_manager.get_cached_suite_rows(l_tag_filter_applied),a_skip_all_objects);
369370
reconcile_paths_and_suites(a_schema_paths,l_filtered_rows);
370371

371372
ut_suite_cache_manager.sort_and_randomize_tests(l_filtered_rows,a_random_seed);

0 commit comments

Comments
 (0)