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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added prompt to the first line of the installer so PL/SQL Developer t…
…reats the installer file as command window.

Added two new assertions: str_like and regexp_like
Reordered declaration of the assertion procedures to enforce users to use implementation with assert description provided
Added tests for the new asserts
  • Loading branch information
Pazus committed Oct 1, 2016
commit 6f93e7774e9a2c0a8e5e227b19aef3fa08050112
3 changes: 2 additions & 1 deletion source/install.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
prompt Installing utplsql framework

whenever sqlerror exit failure rollback
whenever oserror exit failure rollback

prompt Installing utplsql framework
@@types/ut_object.tps
@@types/ut_objects_list.tps
@@types/ut_composite_object.tps
Expand Down
31 changes: 31 additions & 0 deletions source/ut_assert.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,37 @@ create or replace package body ut_assert is
begin
build_assert_result(a_condition, 'this', 'boolean', 'boolean', ut_utils.to_string(true), ut_utils.to_string(a_condition), ut_utils.to_string(a_msg));
end;

-- Strings assertions
procedure str_like(a_msg in varchar2, a_checking_string in varchar2, a_mask in varchar, a_escape_char in varchar2) is
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe is_like or is_matching instead of str_like and a_actual instead of a_checking_string, to keep it consistent with the rest of asserts.

l_condition boolean;
begin
if a_escape_char is not null then
l_condition := a_checking_string like a_mask escape a_escape_char;
else
l_condition := a_checking_string like a_mask;
end if;
build_assert_result(l_condition, 'str_like', 'varchar2', 'varchar2', ut_utils.to_string('like ' || a_mask), ut_utils.to_string(l_condition), a_msg);
end;
procedure str_like(a_msg in varchar2, a_checking_string in varchar2, a_mask in varchar) is
begin
str_like(a_msg, a_checking_string, a_mask, null);
end;
procedure str_like(a_checking_string in varchar2, a_mask in varchar2) is
begin
str_like(a_msg => null, a_checking_string => a_checking_string, a_mask => a_mask);
end;

procedure regexp_like(a_msg in varchar2, a_srcstr in varchar2, a_pattern in varchar2, a_modifier in varchar2 default null) is
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change the name of a_srcstr

l_condition boolean := sys.standard.regexp_like(a_srcstr, a_pattern, a_pattern);
begin
build_assert_result(l_condition, 'regexp_like', 'varchar2', 'varchar2', ut_utils.to_string('pattern ' || a_pattern), ut_utils.to_string(l_condition), a_msg);
end;

procedure regexp_like(a_srcstr in varchar2, a_pattern in varchar2, a_modifier in varchar2 default null) is
begin
regexp_like(null, a_srcstr, a_pattern, a_modifier);
end;

procedure is_null(a_actual in number) is
begin
Expand Down
27 changes: 18 additions & 9 deletions source/ut_assert.pks
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,36 @@ create or replace package ut_assert authid current_user as
procedure report_error(a_message in varchar2);
function get_asserts_results return ut_objects_list;

/* Just need something to play with for now */
procedure are_equal(a_expected in number, a_actual in number);
-- General assertion
procedure this(a_msg in varchar2, a_condition in boolean);
procedure this(a_condition in boolean);

-- Equality assertions
procedure are_equal(a_msg in varchar2, a_expected in number, a_actual in number);
procedure are_equal(a_expected in number, a_actual in number);

procedure are_equal(a_expected in varchar2, a_actual in varchar2);
procedure are_equal(a_msg in varchar2, a_expected in varchar2, a_actual in varchar2);
procedure are_equal(a_expected in varchar2, a_actual in varchar2);

procedure are_equal(a_expected in date, a_actual in date);
procedure are_equal(a_msg in varchar2, a_expected in date, a_actual in date);
procedure are_equal(a_expected in date, a_actual in date);

procedure are_equal(a_expected in timestamp_unconstrained, a_actual in timestamp_unconstrained);
procedure are_equal(a_msg in varchar2, a_expected in timestamp_unconstrained, a_actual in timestamp_unconstrained);
procedure are_equal(a_expected in timestamp_unconstrained, a_actual in timestamp_unconstrained);

procedure are_equal(a_expected in anydata, a_actual in anydata);
procedure are_equal(a_msg in varchar2, a_expected in anydata, a_actual in anydata);
procedure are_equal(a_expected in anydata, a_actual in anydata);

procedure are_equal(a_expected in sys_refcursor, a_actual in sys_refcursor);
procedure are_equal(a_msg in varchar2, a_expected in sys_refcursor, a_actual in sys_refcursor);
procedure are_equal(a_expected in sys_refcursor, a_actual in sys_refcursor);

procedure this(a_condition in boolean);
procedure this(a_msg in varchar2, a_condition in boolean);
-- Strings assertions
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about.
--pattern matching assertions

procedure str_like(a_msg in varchar2, a_checking_string in varchar2, a_mask in varchar, a_escape_char in varchar2);
procedure str_like(a_msg in varchar2, a_checking_string in varchar2, a_mask in varchar);
procedure str_like(a_checking_string in varchar2, a_mask in varchar2);

procedure regexp_like(a_msg in varchar2, a_srcstr in varchar2,a_pattern in varchar2, a_modifier in varchar2 default null);
procedure regexp_like(a_srcstr in varchar2,a_pattern in varchar2, a_modifier in varchar2 default null);

procedure is_null(a_actual in number);
procedure is_null(a_msg in varchar2, a_actual in number);
Expand Down
2 changes: 2 additions & 0 deletions tests/RunAll.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ set serveroutput on size unlimited format truncated
@@lib/RunTest.sql ut_assert/ut_assert.are_equal.varchar2.GivesFailureWhenBothAreNull.sql
@@lib/RunTest.sql ut_assert/ut_assert.are_equal.varchar2.GivesFailureWhenExpectedIsNull.sql
@@lib/RunTest.sql ut_assert/ut_assert.are_equal.varchar2.GivesSuccessForEqualValues.sql
@@lib/RunTest.sql ut_assert/ut_assert.are_equal.varchar2.GivesSuccessForLikeString.sql
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong file names, should be: ut_assert.str_like.varchar2...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests proving that assertions are capable of failing?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests for the regexp_like assertion?

@@lib/RunTest.sql ut_assert/ut_assert.are_equal.varchar2.GivesSuccessForLikeStringWithEscape.sql
@@lib/RunTest.sql ut_assert/ut_assert.are_equal.varchar2.with_text.GivesTheProvidedTextAsMessage.sql

@@lib/RunTest.sql ut_assert/ut_assert.are_equal.date.GivesFailureForDifferentValues.sql
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--Arrange
declare
l_mask varchar2(10) := 'a%b';
l_string varchar2(50) := 'asdfsdfsdfb';
l_result integer;
begin
--Act
ut_assert.str_like(l_string, l_mask);
l_result := ut_assert.get_aggregate_asserts_result();
--Assert
if l_result = ut_utils.tr_success then
:test_result := ut_utils.tr_success;
else
dbms_output.put_line('expected: string like'''||l_mask||''', got: '''||l_result||'''' );
end if;
end;
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--Arrange
declare
l_mask varchar2(10) := 'a%/_b';
l_string varchar2(50) := 'asdfsdfsdf_b';
l_result integer;
begin
--Act
ut_assert.str_like('', l_string, l_mask, '/');
l_result := ut_assert.get_aggregate_asserts_result();
--Assert
if l_result = ut_utils.tr_success then
:test_result := ut_utils.tr_success;
else
dbms_output.put_line('expected: string like'''||l_mask||''' with escape ''/'', got: '''||l_result||'''' );
end if;
end;
/