diff --git a/source/core/types/ut_executable_test.tpb b/source/core/types/ut_executable_test.tpb index a11797a54..89ab16dab 100644 --- a/source/core/types/ut_executable_test.tpb +++ b/source/core/types/ut_executable_test.tpb @@ -31,7 +31,7 @@ create or replace type body ut_executable_test as member procedure do_execute( self in out nocopy ut_executable_test, a_item in out nocopy ut_suite_item, - a_expected_error_codes in ut_integer_list + a_expected_error_codes in ut_varchar2_rows ) is l_completed_without_errors boolean; begin @@ -40,10 +40,114 @@ create or replace type body ut_executable_test as member function do_execute( self in out nocopy ut_executable_test, a_item in out nocopy ut_suite_item, - a_expected_error_codes in ut_integer_list + a_expected_error_codes in ut_varchar2_rows ) return boolean is l_expected_except_message varchar2(4000); + l_expected_error_numbers ut_integer_list; + function build_exception_numbers_list( + a_item in out nocopy ut_suite_item, + a_expected_error_codes in ut_varchar2_rows + ) return ut_integer_list is + l_exception_number integer; + l_exception_number_list ut_integer_list := ut_integer_list(); + c_regexp_for_exception_no constant varchar2(30) := '^-?[[:digit:]]{1,5}$'; + + c_integer_exception constant varchar2(1) := 'I'; + c_named_exception constant varchar2(1) := 'N'; + + function is_valid_qualified_name (a_name varchar2) return boolean is + l_name varchar2(500); + begin + l_name := dbms_assert.qualified_sql_name(a_name); + return true; + exception when others then + return false; + end; + + function check_exception_type(a_exception_name in varchar2) return varchar2 is + l_exception_type varchar2(50); + begin + --check if it is a predefined exception + begin + execute immediate 'begin null; exception when '||a_exception_name||' then null; end;'; + l_exception_type := c_named_exception; + exception + when others then + if dbms_utility.format_error_stack() like '%PLS-00485%' then + declare + e_invalid_number exception; + pragma exception_init ( e_invalid_number, -6502 ); + begin + execute immediate 'declare x integer := '||a_exception_name||'; begin null; end;'; + l_exception_type := c_integer_exception; + exception + when others then + null; + end; + end if; + end; + return l_exception_type; + end; + + function get_exception_number (a_exception_var in varchar2) return integer is + l_exc_no integer; + l_exc_type varchar2(50); + function remap_no_data_found (a_number integer) return integer is + begin + return case a_number when 100 then -1403 else a_number end; + end; + begin + l_exc_type := check_exception_type(a_exception_var); + + execute immediate + case l_exc_type + when c_integer_exception then + 'declare l_exception number; begin :l_exception := '||a_exception_var||'; end;' + when c_named_exception then + 'begin raise '||a_exception_var||'; exception when others then :l_exception := sqlcode; end;' + else + 'begin :l_exception := null; end;' + end + using out l_exc_no; + + return remap_no_data_found(l_exc_no); + end; + + begin + if a_expected_error_codes is not empty then + for i in 1 .. a_expected_error_codes.count loop + /** + * Check if its a valid qualified name and if so try to resolve name to an exception number + */ + if is_valid_qualified_name(a_expected_error_codes(i)) then + l_exception_number := get_exception_number(a_expected_error_codes(i)); + elsif regexp_like(a_expected_error_codes(i), c_regexp_for_exception_no) then + l_exception_number := a_expected_error_codes(i); + end if; + + if l_exception_number is null then + a_item.put_warning( + 'Invalid parameter value "'||a_expected_error_codes(i)||'" for "--%throws" annotation. Parameter ignored.', + self.procedure_name, + a_item.line_no + ); + elsif l_exception_number >= 0 then + a_item.put_warning( + 'Invalid parameter value "'||a_expected_error_codes(i)||'" for "--%throws" annotation. Exception value must be a negative integer. Parameter ignored.', + self.procedure_name, + a_item.line_no + ); + else + l_exception_number_list.extend; + l_exception_number_list(l_exception_number_list.last) := l_exception_number; + end if; + l_exception_number := null; + end loop; + end if; + + return l_exception_number_list; + end; function failed_expec_errnum_message(a_expected_error_codes in ut_integer_list) return varchar is l_actual_error_no integer; l_expected_error_codes varchar2(4000); @@ -72,9 +176,9 @@ create or replace type body ut_executable_test as begin --Create a ut_executable object and call do_execute after that get the data to know the test's execution result self.do_execute(a_item); - - if a_expected_error_codes is not null and a_expected_error_codes is not empty then - l_expected_except_message := failed_expec_errnum_message(a_expected_error_codes); + l_expected_error_numbers := build_exception_numbers_list(a_item, a_expected_error_codes); + if l_expected_error_numbers is not null and l_expected_error_numbers is not empty then + l_expected_except_message := failed_expec_errnum_message( l_expected_error_numbers ); if l_expected_except_message is not null then ut_expectation_processor.add_expectation_result( diff --git a/source/core/types/ut_executable_test.tps b/source/core/types/ut_executable_test.tps index 2772720de..88500c9be 100644 --- a/source/core/types/ut_executable_test.tps +++ b/source/core/types/ut_executable_test.tps @@ -22,12 +22,12 @@ create or replace type ut_executable_test authid current_user under ut_executabl member procedure do_execute( self in out nocopy ut_executable_test, a_item in out nocopy ut_suite_item, - a_expected_error_codes in ut_integer_list + a_expected_error_codes in ut_varchar2_rows ), member function do_execute( self in out nocopy ut_executable_test, a_item in out nocopy ut_suite_item, - a_expected_error_codes in ut_integer_list + a_expected_error_codes in ut_varchar2_rows ) return boolean ) final; diff --git a/source/core/types/ut_suite_cache_row.tps b/source/core/types/ut_suite_cache_row.tps index 6817be5ec..fb4a8bb9f 100644 --- a/source/core/types/ut_suite_cache_row.tps +++ b/source/core/types/ut_suite_cache_row.tps @@ -33,7 +33,7 @@ create type ut_suite_cache_row as object ( before_test_list ut_executables, after_each_list ut_executables, after_test_list ut_executables, - expected_error_codes ut_integer_list, + expected_error_codes ut_varchar2_rows, tags ut_varchar2_rows, item ut_executable_test ) diff --git a/source/core/types/ut_suite_item.tpb b/source/core/types/ut_suite_item.tpb index 6478d5c82..9b939727a 100644 --- a/source/core/types/ut_suite_item.tpb +++ b/source/core/types/ut_suite_item.tpb @@ -97,6 +97,16 @@ create or replace type body ut_suite_item as self.results_count.increase_warning_count; end; + member procedure put_warning(self in out nocopy ut_suite_item, a_message varchar2, a_procedure_name varchar2, a_line_no integer) is + l_result varchar2(1000); + begin + l_result := self.object_owner || '.' || self.object_name ; + if a_procedure_name is not null then + l_result := l_result || '.' || a_procedure_name ; + end if; + put_warning( a_message || chr( 10 ) || 'at package "' || upper(l_result) || '", line ' || a_line_no ); + end; + member function get_transaction_invalidators return ut_varchar2_list is begin return transaction_invalidators; diff --git a/source/core/types/ut_suite_item.tps b/source/core/types/ut_suite_item.tps index 53c59a2ea..87f577459 100644 --- a/source/core/types/ut_suite_item.tps +++ b/source/core/types/ut_suite_item.tps @@ -84,7 +84,8 @@ create or replace type ut_suite_item force under ut_event_item ( not instantiable member procedure mark_as_errored(self in out nocopy ut_suite_item, a_error_stack_trace varchar2), not instantiable member function get_error_stack_traces return ut_varchar2_list, not instantiable member function get_serveroutputs return clob, - member procedure put_warning(self in out nocopy ut_suite_item, a_message varchar2) + member procedure put_warning(self in out nocopy ut_suite_item, a_message varchar2), + member procedure put_warning(self in out nocopy ut_suite_item, a_message varchar2, a_procedure_name varchar2, a_line_no integer) ) not final not instantiable / diff --git a/source/core/types/ut_test.tpb b/source/core/types/ut_test.tpb index 9fbcf9269..4ed3f665e 100644 --- a/source/core/types/ut_test.tpb +++ b/source/core/types/ut_test.tpb @@ -18,7 +18,7 @@ create or replace type body ut_test as constructor function ut_test( self in out nocopy ut_test, a_object_owner varchar2 := null, a_object_name varchar2, a_name varchar2, - a_line_no integer, a_expected_error_codes ut_integer_list := null, a_tags ut_varchar2_rows := null + a_line_no integer, a_expected_error_codes ut_varchar2_rows := null, a_tags ut_varchar2_rows := null ) return self as result is begin self.self_type := $$plsql_unit; diff --git a/source/core/types/ut_test.tps b/source/core/types/ut_test.tps index fcf565671..85caf7380 100644 --- a/source/core/types/ut_test.tps +++ b/source/core/types/ut_test.tps @@ -54,10 +54,10 @@ create or replace type ut_test force under ut_suite_item ( /** *Holds the expected error codes list when the user use the annotation throws */ - expected_error_codes ut_integer_list, + expected_error_codes ut_varchar2_rows, constructor function ut_test( self in out nocopy ut_test, a_object_owner varchar2 := null, a_object_name varchar2, a_name varchar2, - a_line_no integer, a_expected_error_codes ut_integer_list := null, a_tags ut_varchar2_rows := null + a_line_no integer, a_expected_error_codes ut_varchar2_rows := null, a_tags ut_varchar2_rows := null ) return self as result, overriding member procedure mark_as_skipped(self in out nocopy ut_test), overriding member function do_execute(self in out nocopy ut_test) return boolean, diff --git a/source/core/ut_suite_builder.pkb b/source/core/ut_suite_builder.pkb index 5f468f756..d13cbaed9 100644 --- a/source/core/ut_suite_builder.pkb +++ b/source/core/ut_suite_builder.pkb @@ -62,9 +62,6 @@ create or replace package body ut_suite_builder is gc_endcontext ); - gc_integer_exception constant varchar2(1) := 'I'; - gc_named_exception constant varchar2(1) := 'N'; - type tt_executables is table of ut_executables index by t_annotation_position; type t_annotation is record( @@ -97,27 +94,6 @@ create or replace package body ut_suite_builder is by_name tt_annotations_by_name ); - function get_qualified_object_name( - a_suite ut_suite_item, a_procedure_name t_object_name - ) return varchar2 is - l_result varchar2(1000); - begin - if a_suite is not null then - l_result := upper( a_suite.object_owner || '.' || a_suite.object_name ); - if a_procedure_name is not null then - l_result := l_result || upper( '.' || a_procedure_name ); - end if; - end if; - return l_result; - end; - - function get_object_reference( - a_suite ut_suite_item, a_procedure_name t_object_name, a_line_no binary_integer - ) return varchar2 is - begin - return chr( 10 ) || 'at package "' || get_qualified_object_name(a_suite, a_procedure_name) || '", line ' || a_line_no; - end; - procedure delete_annotations_range( a_annotations in out nocopy t_annotations_info, a_start_pos t_annotation_position, @@ -163,8 +139,9 @@ create or replace package body ut_suite_builder is ) is begin a_suite.put_warning( - replace(a_message,'%%%','"--%'||a_annotation||'"') - || ' Annotation ignored.' || get_object_reference( a_suite, a_procedure_name, a_line_no ) + replace(a_message,'%%%','"--%'||a_annotation||'"')|| ' Annotation ignored.', + a_procedure_name, + a_line_no ); end; @@ -181,136 +158,26 @@ create or replace package body ut_suite_builder is procedure add_to_throws_numbers_list( a_suite in out nocopy ut_suite, - a_list in out nocopy ut_integer_list, + a_list in out nocopy ut_varchar2_rows, a_procedure_name t_object_name, a_throws_ann_text tt_annotation_texts ) is l_annotation_pos binary_integer; - function is_valid_qualified_name (a_name varchar2) return boolean is - l_name varchar2(500); - begin - l_name := dbms_assert.qualified_sql_name(a_name); - return true; - exception when others then - return false; - end; - - function check_exception_type(a_exception_name in varchar2) return varchar2 is - l_exception_type varchar2(50); - begin - --check if it is a predefined exception - begin - execute immediate 'begin null; exception when '||a_exception_name||' then null; end;'; - l_exception_type := gc_named_exception; - exception - when others then - if dbms_utility.format_error_stack() like '%PLS-00485%' then - begin - execute immediate 'declare x positiven := -('||a_exception_name||'); begin null; end;'; - l_exception_type := gc_integer_exception; - exception - when others then - --invalid exception number (positive) - --TODO add warning for this value - null; - end; - end if; - end; - return l_exception_type; - end; - - function get_exception_number (a_exception_var in varchar2) return integer is - l_exc_no integer; - l_exc_type varchar2(50); - function remap_no_data_found (a_number integer) return integer is - begin - return case a_number when 100 then -1403 else a_number end; - end; - begin - l_exc_type := check_exception_type(a_exception_var); - - if l_exc_type is not null then - - execute immediate - case l_exc_type - when gc_integer_exception then - 'declare - l_exception number; - begin - :l_exception := '||a_exception_var||'; ' - when gc_named_exception then - 'begin - raise '||a_exception_var||'; - exception - when others then - :l_exception := sqlcode; ' - end || - 'end;' - using out l_exc_no; - - end if; - return remap_no_data_found(l_exc_no); - end; - - function build_exception_numbers_list( - a_suite in out nocopy ut_suite, - a_procedure_name t_object_name, - a_line_no integer, - a_annotation_text in varchar2 - ) return ut_integer_list is - l_throws_list ut_varchar2_list; - l_exception_number integer; - l_exception_number_list ut_integer_list := ut_integer_list(); - c_regexp_for_exception_no constant varchar2(30) := '^-?[[:digit:]]{1,5}$'; - begin - --the a_expected_error_codes is converted to a ut_varchar2_list after that is trimmed and filtered to left only valid exception numbers - l_throws_list := ut_utils.trim_list_elements(ut_utils.string_to_table(a_annotation_text, ',', 'Y')); - - for i in 1 .. l_throws_list.count - loop - /** - * Check if its a valid qualified name and if so try to resolve name to an exception number - */ - if is_valid_qualified_name(l_throws_list(i)) then - l_exception_number := get_exception_number(l_throws_list(i)); - elsif regexp_like(l_throws_list(i), c_regexp_for_exception_no) then - l_exception_number := l_throws_list(i); - end if; - - if l_exception_number is null then - a_suite.put_warning( - 'Invalid parameter value "'||l_throws_list(i) - ||'" for "--%throws" annotation. Parameter ignored.'||get_object_reference( a_suite, a_procedure_name, a_line_no ) - ); - else - l_exception_number_list.extend; - l_exception_number_list(l_exception_number_list.last) := l_exception_number; - end if; - l_exception_number := null; - end loop; - - return l_exception_number_list; - end; - begin - a_list := ut_integer_list(); l_annotation_pos := a_throws_ann_text.first; while l_annotation_pos is not null loop if a_throws_ann_text(l_annotation_pos) is null then a_suite.put_warning( - '"--%throws" annotation requires a parameter. Annotation ignored.' - || get_object_reference( a_suite, a_procedure_name, l_annotation_pos ) + '"--%throws" annotation requires a parameter. Annotation ignored.', + a_procedure_name, + l_annotation_pos ); else - a_list := - a_list multiset union - build_exception_numbers_list( - a_suite, - a_procedure_name, - l_annotation_pos, - a_throws_ann_text(l_annotation_pos) - ); + ut_utils.append_to_list( + a_list, + ut_utils.convert_collection( ut_utils.trim_list_elements ( ut_utils.string_to_table( a_throws_ann_text(l_annotation_pos), ',' ) ) ) + ); end if; l_annotation_pos := a_throws_ann_text.next(l_annotation_pos); end loop; @@ -330,8 +197,9 @@ create or replace package body ut_suite_builder is while l_annotation_pos is not null loop if a_tags_ann_text(l_annotation_pos) is null then a_suite.put_warning( - '"--%tags" annotation requires a tag value populated. Annotation ignored.' - || get_object_reference( a_suite, a_procedure_name, l_annotation_pos ) + '"--%tags" annotation requires a tag value populated. Annotation ignored.', + a_procedure_name, + l_annotation_pos ); else l_tag_items := ut_utils.trim_list_elements(ut_utils.string_to_table(a_tags_ann_text(l_annotation_pos),',')); @@ -342,8 +210,9 @@ create or replace package body ut_suite_builder is l_tags_list(l_tags_list.last) := l_tag_items(i); else a_suite.put_warning( - 'Invalid value "'||l_tag_items(i)||'" for "--%tags" annotation. See documentation for details on valid tag values. Annotation value ignored.' - || get_object_reference( a_suite, a_procedure_name, l_annotation_pos ) + 'Invalid value "'||l_tag_items(i)||'" for "--%tags" annotation. See documentation for details on valid tag values. Annotation value ignored.', + a_procedure_name, + l_annotation_pos ); end if; end loop; @@ -857,9 +726,10 @@ create or replace package body ut_suite_builder is if not regexp_like( l_context_name, '^(\w|[$#])+$' ) then a_parent.put_warning( 'Invalid value "'||l_context_name||'" for context name.' || - ' Context name ignored and fallback to auto-name "'||l_default_context_name||'" ' || - get_object_reference( a_parent, null, l_context_pos ) - ); + ' Context name ignored and fallback to auto-name "'||l_default_context_name||'" ', + null, + l_context_pos + ); end if; l_context_name := l_default_context_name; end if; @@ -886,8 +756,10 @@ create or replace package body ut_suite_builder is if l_end_context_pos is null then a_parent.put_warning( - 'Missing "--%endcontext" annotation for a "--%context" annotation. The end of package is considered end of context.'|| get_object_reference( a_parent, null, l_context_pos ) - ); + 'Missing "--%endcontext" annotation for a "--%context" annotation. The end of package is considered end of context.', + null, + l_context_pos + ); l_end_context_pos := a_annotations.by_line.last; end if; diff --git a/source/core/ut_suite_cache_manager.pkb b/source/core/ut_suite_cache_manager.pkb index f52d15bf7..509b28498 100644 --- a/source/core/ut_suite_cache_manager.pkb +++ b/source/core/ut_suite_cache_manager.pkb @@ -57,7 +57,7 @@ create or replace package body ut_suite_cache_manager is select 'UT_LOGICAL_SUITE' as self_type, p.path, p.object_owner, upper( substr(p.path, instr( p.path, '.', -1 ) + 1 ) ) as object_name, cast(null as ut_executables) as x, - cast(null as ut_integer_list) as y, + cast(null as ut_varchar2_rows) as y, cast(null as ut_executable_test) as z from suitepath_part p where p.path diff --git a/test/ut3_tester/core/annotations/test_annot_throws_exception.pkb b/test/ut3_tester/core/annotations/test_annot_throws_exception.pkb index 1ad4f19a5..04e65a6c2 100644 --- a/test/ut3_tester/core/annotations/test_annot_throws_exception.pkb +++ b/test/ut3_tester/core/annotations/test_annot_throws_exception.pkb @@ -20,212 +20,230 @@ is c_e_diff_exc constant number := -20204; c_e_mix_list constant number := -20205; c_e_mix_missin constant number := -20206; - + c_e_positive constant number := 20207; + e_some_exception exception; pragma exception_init(e_some_exception, -20207); end;]'; l_package_spec := ' - create package annotated_package_with_throws is - --%suite(Dummy package to test annotation throws) - - --%test(Throws same annotated exception) - --%throws(-20145) - procedure raised_same_exception; - - --%test(Throws one of the listed exceptions) - --%throws(-20145,-20146, -20189 ,-20563) - procedure raised_one_listed_exception; - - --%test(Leading zero is ignored in exception list) - --%throws(-01476) - procedure leading_0_exception_no; - - --%test(Throws diff exception) - --%throws(-20144) - procedure raised_diff_exception; - - --%test(Throws empty) - --%throws() - procedure empty_throws; - - --%test(Ignores annotation and fails when exception was thrown) - --%throws(hello,784#,0-=234,,u1234) - procedure bad_paramters_with_except; - - --%test(Ignores annotation and succeeds when no exception thrown) - --%throws(hello,784#,0-=234,,u1234) - procedure bad_paramters_without_except; - - --%test(Detects a valid exception number within many invalid ones) - --%throws(7894562, operaqk, -=1, -1, pow74d, posdfk3) - procedure one_valid_exception_number; - - --%test(Gives failure when a exception is expected and nothing is thrown) - --%throws(-20459, -20136, -20145) - procedure nothing_thrown; - - --%test(Single exception defined as a constant number in package) - --%throws(exc_pkg.c_e_single_exc) - procedure single_exc_const_pkg; - - --%test(Gives success when one of annotated exception using constant is thrown) - --%throws(exc_pkg.c_e_list_1,exc_pkg.c_e_list_2) - procedure list_of_exc_constant; - - --%test(Gives failure when the raised exception is different that the annotated one using variable) - --%throws(exc_pkg.c_e_diff_exc) - procedure fail_not_match_exc; - - --%test(Success when one of exception from mixed list of number and constant is thrown) - --%throws(exc_pkg.c_e_mix_list,-20105) - procedure mixed_exc_list; - - --%test(Success when match exception even if other variable on list dont exists) - --%throws(exc_pkg.c_e_mix_missin,utter_rubbish) - procedure mixed_list_notexi; - - --%test(Success resolve and match named exception defined in pragma exception init) - --%throws(exc_pkg.e_some_exception) - procedure named_exc_pragma; - - --%test(Success resolve and match oracle named exception) - --%throws(NO_DATA_FOUND) - procedure named_exc_ora; - - --%test(Success resolve and match oracle named exception dup val index) - --%throws(DUP_VAL_ON_INDEX) - procedure named_exc_ora_dup_ind; - - --%test(Success map no data 100 to -1403) - --%throws(-1403) - procedure nodata_exc_ora; - - --%test(Success for exception defined as varchar) - --%throws(exc_pkg.c_e_varch_exc) - procedure defined_varchar_exc; - - --%test(Non existing constant exception) - --%throws(dummy.c_dummy); - procedure non_existing_const; - - --%test(Bad exception constant) - --%throws(exc_pkg.c_e_dummy); - procedure bad_exc_const; - - end; + create package annotated_package_with_throws is + --%suite(Dummy package to test annotation throws) + + --%test(Throws same annotated exception) + --%throws(-20145) + procedure raised_same_exception; + + --%test(Throws one of the listed exceptions) + --%throws(-20145,-20146, -20189 ,-20563) + procedure raised_one_listed_exception; + + --%test(Leading zero is ignored in exception list) + --%throws(-01476) + procedure leading_0_exception_no; + + --%test(Throws diff exception) + --%throws(-20144) + procedure raised_diff_exception; + + --%test(Throws empty) + --%throws() + procedure empty_throws; + + --%test(Ignores annotation and fails when exception was thrown) + --%throws(hello,784#,0-=234,,u1234) + procedure bad_paramters_with_except; + + --%test(Ignores annotation and succeeds when no exception thrown) + --%throws(hello,784#,0-=234,,u1234) + procedure bad_paramters_without_except; + + --%test(Ignores annotation for positive exception number value) + --%throws(20001) + procedure positive_exception_number; + + --%test(Ignores annotation for positive exception number variable) + --%throws(exc_pkg.c_e_positive) + procedure positive_exception_number_var; + + --%test(Detects a valid exception number within many invalid ones) + --%throws(7894562, operaqk, -=1, -1, pow74d, posdfk3) + procedure one_valid_exception_number; + + --%test(Gives failure when a exception is expected and nothing is thrown) + --%throws(-20459, -20136, -20145) + procedure nothing_thrown; + + --%test(Single exception defined as a constant number in package) + --%throws(exc_pkg.c_e_single_exc) + procedure single_exc_const_pkg; + + --%test(Gives success when one of annotated exception using constant is thrown) + --%throws(exc_pkg.c_e_list_1,exc_pkg.c_e_list_2) + procedure list_of_exc_constant; + + --%test(Gives failure when the raised exception is different that the annotated one using variable) + --%throws(exc_pkg.c_e_diff_exc) + procedure fail_not_match_exc; + + --%test(Success when one of exception from mixed list of number and constant is thrown) + --%throws(exc_pkg.c_e_mix_list,-20105) + procedure mixed_exc_list; + + --%test(Success when match exception even if other variable on list dont exists) + --%throws(exc_pkg.c_e_mix_missin,utter_rubbish) + procedure mixed_list_notexi; + + --%test(Success resolve and match named exception defined in pragma exception init) + --%throws(exc_pkg.e_some_exception) + procedure named_exc_pragma; + + --%test(Success resolve and match oracle named exception) + --%throws(NO_DATA_FOUND) + procedure named_exc_ora; + + --%test(Success resolve and match oracle named exception dup val index) + --%throws(DUP_VAL_ON_INDEX) + procedure named_exc_ora_dup_ind; + + --%test(Success map no data 100 to -1403) + --%throws(-1403) + procedure nodata_exc_ora; + + --%test(Success for exception defined as varchar) + --%throws(exc_pkg.c_e_varch_exc) + procedure defined_varchar_exc; + + --%test(Non existing constant exception) + --%throws(dummy.c_dummy); + procedure non_existing_const; + + --%test(Bad exception constant) + --%throws(exc_pkg.c_e_dummy); + procedure bad_exc_const; + end; '; l_package_body := ' - create package body annotated_package_with_throws is - procedure raised_same_exception is - begin - raise_application_error(-20145, ''Test error''); - end; - - procedure raised_one_listed_exception is - begin - raise_application_error(-20189, ''Test error''); - end; - - procedure leading_0_exception_no is - x integer; - begin - x := 1 / 0; - end; - - procedure raised_diff_exception is - begin - raise_application_error(-20143, ''Test error''); - end; - - procedure empty_throws is - begin - raise_application_error(-20143, ''Test error''); - end; - - procedure bad_paramters_with_except is - begin - raise_application_error(-20143, ''Test error''); - end; - - procedure bad_paramters_without_except is - begin - null; - end; - - procedure one_valid_exception_number is - begin - raise dup_val_on_index; - end; - - procedure nothing_thrown is - begin - null; - end; - - procedure single_exc_const_pkg is - begin - raise_application_error(exc_pkg.c_e_single_exc,''Test''); - end; - - procedure list_of_exc_constant is - begin - raise_application_error(exc_pkg.c_e_list_1,''Test''); - end; - - procedure fail_not_match_exc is - begin - raise NO_DATA_FOUND; - end; - - procedure mixed_exc_list is - begin - raise_application_error(exc_pkg.c_e_mix_list,''Test''); - end; - - procedure mixed_list_notexi is - begin - raise_application_error(exc_pkg.c_e_mix_missin,''Test''); - end; - - procedure named_exc_pragma is - begin - raise exc_pkg.e_some_exception; - end; - - procedure named_exc_ora is - begin - raise NO_DATA_FOUND; - end; - - procedure named_exc_ora_dup_ind is - begin - raise DUP_VAL_ON_INDEX; - end; - - procedure nodata_exc_ora is - begin - raise NO_DATA_FOUND; - end; - - procedure defined_varchar_exc is - begin - raise_application_error(exc_pkg.c_e_varch_exc,''Test''); - end; - - procedure non_existing_const is - begin - raise_application_error(-20143, ''Test error''); - end; - - procedure bad_exc_const is - begin - raise_application_error(-20143, ''Test error''); - end; - + create package body annotated_package_with_throws is + procedure raised_same_exception is + begin + raise_application_error(-20145, ''Test error''); + end; + + procedure raised_one_listed_exception is + begin + raise_application_error(-20189, ''Test error''); + end; + + procedure leading_0_exception_no is + x integer; + begin + x := 1 / 0; + end; + + procedure raised_diff_exception is + begin + raise_application_error(-20143, ''Test error''); + end; + + procedure empty_throws is + begin + raise_application_error(-20143, ''Test error''); + end; + + procedure bad_paramters_with_except is + begin + raise_application_error(-20143, ''Test error''); + end; + + procedure bad_paramters_without_except is + begin + null; + end; + + procedure positive_exception_number is + begin + null; + end; + + procedure positive_exception_number_var is + begin + null; + end; + + procedure one_valid_exception_number is + begin + raise dup_val_on_index; + end; + + procedure nothing_thrown is + begin + null; + end; + + procedure single_exc_const_pkg is + begin + raise_application_error(exc_pkg.c_e_single_exc,''Test''); + end; + + procedure list_of_exc_constant is + begin + raise_application_error(exc_pkg.c_e_list_1,''Test''); + end; + + procedure fail_not_match_exc is + begin + raise NO_DATA_FOUND; + end; + + procedure mixed_exc_list is + begin + raise_application_error(exc_pkg.c_e_mix_list,''Test''); + end; + + procedure mixed_list_notexi is + begin + raise_application_error(exc_pkg.c_e_mix_missin,''Test''); + end; + + procedure named_exc_pragma is + begin + raise exc_pkg.e_some_exception; + end; + + procedure named_exc_ora is + begin + raise NO_DATA_FOUND; + end; + + procedure named_exc_ora_dup_ind is + begin + raise DUP_VAL_ON_INDEX; + end; + + procedure nodata_exc_ora is + begin + raise NO_DATA_FOUND; + end; + + procedure defined_varchar_exc is + begin + raise_application_error(exc_pkg.c_e_varch_exc,''Test''); + end; + + procedure non_existing_const is + begin + raise_application_error(-20143, ''Test error''); end; + + procedure bad_exc_const is + begin + raise_application_error(-20143, ''Test error''); + end; + + end; '; execute immediate l_exception_spec; @@ -277,13 +295,25 @@ is procedure bad_paramters_without_except is begin ut.expect(g_tests_results).to_match('^\s*Ignores annotation and succeeds when no exception thrown \[[,\.0-9]+ sec\]\s*$','m'); - ut.expect(g_tests_results).not_to_match('bad_paramters_without_except'); + ut.expect(g_tests_results).to_match('bad_paramters_without_except\s*Invalid parameter value ".*" for "--%throws" annotation. Parameter ignored.','m'); + end; + + procedure positive_exception_number is + begin + ut.expect(g_tests_results).to_match('^\s*Ignores annotation for positive exception number value \[[,\.0-9]+ sec\]\s*$','m'); + ut.expect(g_tests_results).to_match('positive_exception_number\s*Invalid parameter value "20001" for "--%throws" annotation. Exception value must be a negative integer. Parameter ignored.','m'); + end; + + procedure positive_exception_number_var is + begin + ut.expect(g_tests_results).to_match('^\s*Ignores annotation for positive exception number variable \[[,\.0-9]+ sec\]\s*$','m'); + ut.expect(g_tests_results).to_match('positive_exception_number_var\s*Invalid parameter value ".*" for "--%throws" annotation. Exception value must be a negative integer. Parameter ignored.','m'); end; procedure one_valid_exception_number is begin ut.expect(g_tests_results).to_match('^\s*Detects a valid exception number within many invalid ones \[[\.0-9]+ sec\]\s*$','m'); - ut.expect(g_tests_results).not_to_match('one_valid_exception_number'); + ut.expect(g_tests_results).to_match('one_valid_exception_number\s*Invalid parameter value ".*" for "--%throws" annotation. Parameter ignored.','m'); end; procedure nothing_thrown is @@ -319,13 +349,13 @@ is procedure mixed_list_notexi is begin ut.expect(g_tests_results).to_match('^\s*Success when match exception even if other variable on list dont exists \[[,\.0-9]+ sec\]\s*$','m'); - ut.expect(g_tests_results).not_to_match('mixed_list_notexi'); + ut.expect(g_tests_results).to_match('mixed_list_notexi\s*Invalid parameter value "utter_rubbish" for "--%throws" annotation. Parameter ignored.','m'); end; procedure named_exc_pragma is begin ut.expect(g_tests_results).to_match('^\s*Success resolve and match named exception defined in pragma exception init \[[,\.0-9]+ sec\]\s*$','m'); - ut.expect(g_tests_results).not_to_match('mixed_list_notexi'); + ut.expect(g_tests_results).not_to_match('named_exc_pragma'); end; procedure named_exc_ora is diff --git a/test/ut3_tester/core/annotations/test_annot_throws_exception.pks b/test/ut3_tester/core/annotations/test_annot_throws_exception.pks index ce2e6ba7a..a9d20183d 100644 --- a/test/ut3_tester/core/annotations/test_annot_throws_exception.pks +++ b/test/ut3_tester/core/annotations/test_annot_throws_exception.pks @@ -26,7 +26,13 @@ is --%test(Ignores when only bad parameters are passed, the test does not raise a exception and it shows successful test) procedure bad_paramters_without_except; - + + --%test(Ignores annotation for positive exception number value) + procedure positive_exception_number; + + --%test(Ignores annotation for positive exception number variable) + procedure positive_exception_number_var; + --%test(Detects a valid exception number within many invalid ones) procedure one_valid_exception_number; diff --git a/test/ut3_tester/core/test_suite_builder.pkb b/test/ut3_tester/core/test_suite_builder.pkb index 86d86032a..00d914413 100644 --- a/test/ut3_tester/core/test_suite_builder.pkb +++ b/test/ut3_tester/core/test_suite_builder.pkb @@ -1386,24 +1386,6 @@ create or replace package body test_suite_builder is ); end; - procedure throws_value_invalid is - l_actual clob; - l_annotations ut3.ut_annotations; - begin - --Arrange - l_annotations := ut3.ut_annotations( - ut3.ut_annotation(1, 'suite','Cool', null), - ut3.ut_annotation(3, 'test','A test with invalid throws annotation', 'A_TEST_PROCEDURE'), - ut3.ut_annotation(3, 'throws',' -20145 , bad_variable_name ', 'A_TEST_PROCEDURE') - ); - --Act - l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); - --Assert - ut.expect(l_actual).to_be_like( - '%%Invalid parameter value "bad_variable_name" for "--%throws" annotation. Parameter ignored.%%' - ); - end; - procedure before_aftertest_multi is l_actual clob; diff --git a/test/ut3_tester/core/test_suite_builder.pks b/test/ut3_tester/core/test_suite_builder.pks index 7c7fc77f6..4b49e606f 100644 --- a/test/ut3_tester/core/test_suite_builder.pks +++ b/test/ut3_tester/core/test_suite_builder.pks @@ -161,9 +161,6 @@ create or replace package test_suite_builder is --%test(Gives warning if --%throws annotation has no value) procedure throws_value_empty; - --%test(Gives warning if --%throws annotation has invalid value) - procedure throws_value_invalid; - --%endcontext --%context(--%beforetest/aftertest annotation)