[xml] Add SQL unit tests

And make unit test error message more explicit.

Close #12627
pull/12641/head
Don Ho 2022-12-12 02:18:11 +01:00
parent e596baad11
commit ee336b24c1
6 changed files with 238 additions and 1 deletions

View File

@ -0,0 +1,154 @@
create package CheckFunctionList_pck
as
function ctrlData(
po_severity in out nocopy varchar2,
po_err_code in out nocopy varchar2,
po_err_message in out nocopy varchar2,
p_Data in ind_work_data_r
) return boolean;
procedure INIT_DECODE_RULES1 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules
);
procedure INIT_DECODE_RULES2 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules);
function GetEsecId
return tab1.esec_id%type;
procedure pippo;
procedure INIT_DECODE_RULES3 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2
,po_guid in guid_list_t := guid_list_t()
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules);
procedure INIT_DECODE_RULES4 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2
,po_guid in guid_list_t := guid_list_t()
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules
);
procedure INIT_DECODE_RULES5 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2 -- this is a comment with (brackets)
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules);
procedure INIT_DECODE_RULES6 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2 -- this is a comment with (brackets)
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules
);
end CheckFunctionList_pck;
/
create package body CheckFunctionList_pck
as
function ctrlData(
po_severity in out nocopy varchar2,
po_err_code in out nocopy varchar2,
po_err_message in out nocopy varchar2,
p_Data in ind_work_data_r
) return boolean
is
begin
return null;
end ctrlData;
procedure INIT_DECODE_RULES1 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules
)
as
begin
null;
end INIT_DECODE_RULES1;
procedure INIT_DECODE_RULES2 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules)
as
begin
null;
end INIT_DECODE_RULES2;
function GetEsecId
return tab1.esec_id%type
is
begin
return null;
end GetEsecId;
procedure pippo
is
begin
null;
end pippo;
procedure INIT_DECODE_RULES3 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2
,po_guid in guid_list_t := guid_list_t()
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules)
as
begin
null;
end INIT_DECODE_RULES3;
procedure INIT_DECODE_RULES4 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2
,po_guid in guid_list_t := guid_list_t()
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules
)
as
begin
null;
end INIT_DECODE_RULES4;
procedure INIT_DECODE_RULES5 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2 -- this is a comment with (brackets)
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules)
as
begin
null;
end INIT_DECODE_RULES5;
procedure INIT_DECODE_RULES6 (po_severity in out varchar2
,po_err_code in out varchar2
,po_err_message in out varchar2 -- this is a comment with (brackets)
,po_tabDecRules out nocopy report_utl_pck.tTabDecRules
)
as
begin
null;
end INIT_DECODE_RULES6;
end CheckFunctionList_pck;
/

View File

@ -0,0 +1 @@
{"leaves":["ctrlData(\r\n po_severity in out nocopy varchar2,\r\n po_err_code in out nocopy varchar2,\r\n po_err_message in out nocopy varchar2,\r\n p_Data in ind_work_data_r\r\n) return boolean","INIT_DECODE_RULES1 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2\r\n ,po_tabDecRules out nocopy report_utl_pck.tTabDecRules\r\n )","INIT_DECODE_RULES2 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2\r\n ,po_tabDecRules out nocopy report_utl_pck.tTabDecRules)","GetEsecId\r\nreturn tab1.esec_id%type","pippo","INIT_DECODE_RULES3 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2\r\n ,po_guid in guid_list_t := guid_list_t()","INIT_DECODE_RULES4 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2\r\n ,po_guid in guid_list_t := guid_list_t()","INIT_DECODE_RULES5 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2 -- this is a comment with (brackets)","INIT_DECODE_RULES6 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2 -- this is a comment with (brackets)","ctrlData(\r\n po_severity in out nocopy varchar2,\r\n po_err_code in out nocopy varchar2,\r\n po_err_message in out nocopy varchar2,\r\n p_Data in ind_work_data_r\r\n) return boolean\r\nis\r\nbegin\r\n return null","INIT_DECODE_RULES1 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2\r\n ,po_tabDecRules out nocopy report_utl_pck.tTabDecRules\r\n )","INIT_DECODE_RULES2 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2\r\n ,po_tabDecRules out nocopy report_utl_pck.tTabDecRules)","GetEsecId\r\nreturn tab1.esec_id%type\r\nis\r\nbegin\r\n return null","pippo","INIT_DECODE_RULES3 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2\r\n ,po_guid in guid_list_t := guid_list_t()","INIT_DECODE_RULES4 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2\r\n ,po_guid in guid_list_t := guid_list_t()","INIT_DECODE_RULES5 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2 -- this is a comment with (brackets)","INIT_DECODE_RULES6 (po_severity in out varchar2\r\n ,po_err_code in out varchar2\r\n ,po_err_message in out varchar2 -- this is a comment with (brackets)"],"root":"unitTest"}

View File

@ -0,0 +1,73 @@
CREATE OR REPLACE PACKAGE BODY emp_mgmt AS
tot_emps NUMBER;
tot_depts NUMBER;
FUNCTION hire
(last_name VARCHAR2, job_id VARCHAR2,
manager_id NUMBER, salary NUMBER,
commission_pct NUMBER, department_id NUMBER)
RETURN NUMBER IS new_empno NUMBER;
BEGIN
SELECT employees_seq.NEXTVAL
INTO new_empno
FROM DUAL;
INSERT INTO employees
VALUES (new_empno, 'First', 'Last','first.last@oracle.com',
'(123)123-1234','18-JUN-02','IT_PROG',90000000,00,
100,110);
tot_emps := tot_emps + 1;
RETURN(new_empno);
END;
FUNCTION create_dept(department_id NUMBER, location_id NUMBER)
RETURN NUMBER IS
new_deptno NUMBER;
BEGIN
SELECT departments_seq.NEXTVAL
INTO new_deptno
FROM dual;
INSERT INTO departments
VALUES (new_deptno, 'department name', 100, 1700);
tot_depts := tot_depts + 1;
RETURN(new_deptno);
END;
PROCEDURE remove_emp (employee_id NUMBER) IS
BEGIN
DELETE FROM employees
WHERE employees.employee_id = remove_emp.employee_id;
tot_emps := tot_emps - 1;
END;
PROCEDURE remove_dept(department_id NUMBER) IS
BEGIN
DELETE FROM departments
WHERE departments.department_id = remove_dept.department_id;
tot_depts := tot_depts - 1;
SELECT COUNT(*) INTO tot_emps FROM employees;
END;
PROCEDURE increase_sal(employee_id NUMBER, salary_incr NUMBER) IS
curr_sal NUMBER;
BEGIN
SELECT salary INTO curr_sal FROM employees
WHERE employees.employee_id = increase_sal.employee_id;
IF curr_sal IS NULL
THEN RAISE no_sal;
ELSE
UPDATE employees
SET salary = salary + salary_incr
WHERE employee_id = employee_id;
END IF;
END;
PROCEDURE increase_comm(employee_id NUMBER, comm_incr NUMBER) IS
curr_comm NUMBER;
BEGIN
SELECT commission_pct
INTO curr_comm
FROM employees
WHERE employees.employee_id = increase_comm.employee_id;
IF curr_comm IS NULL
THEN RAISE no_comm;
ELSE
UPDATE employees
SET commission_pct = commission_pct + comm_incr;
END IF;
END;
END emp_mgmt;
/

View File

@ -0,0 +1 @@
{"leaves":["hire \r\n (last_name VARCHAR2, job_id VARCHAR2, \r\n manager_id NUMBER, salary NUMBER, \r\n commission_pct NUMBER, department_id NUMBER) \r\n RETURN NUMBER IS new_empno NUMBER","create_dept(department_id NUMBER, location_id NUMBER) \r\n RETURN NUMBER IS \r\n new_deptno NUMBER","remove_emp (employee_id NUMBER)","remove_dept(department_id NUMBER)","increase_sal(employee_id NUMBER, salary_incr NUMBER)","increase_comm(employee_id NUMBER, comm_incr NUMBER)"],"root":"unitTest"}

View File

@ -32,6 +32,11 @@ Try {
$expectedRes = Get-Content $testRoot$dirName\unitTest.expected.result
$generatedRes = Get-Content $testRoot$dirName\unitTest.result.json
# Some parser results contain CRLF or LF (\r\n or \n) dependent of file EOL format
# In order to make tests pass in any environment, all the CRLF turning into LF (if any) in both strings
$expectedRes = $expectedRes.replace('\r\n','\n')
$generatedRes = $generatedRes.replace('\r\n','\n')
if ($generatedRes -eq $expectedRes)
{
Remove-Item $testRoot$dirName\unitTest.result.json
@ -39,6 +44,9 @@ Try {
}
else
{
$expectedRes
"`nvs`n"
$generatedRes
return -1
}
}

View File

@ -14,7 +14,7 @@
mainExpr="^[ \t]*((PROCEDURE)|(FUNCTION))[\s]+[A-Za-z][\w_]*([\s]*(?'open'\().*?(\)))?(([\s]*;)|([\s]*([ia]s)\s)|([\s]+(RETURN)([\s]+[\w%\.]+)+(([\s]*;)|([\s]+([ia]s)\s))))"
displayMode="$className->$functionName"
>
<functionName>
<functionName>
<nameExpr expr="[\s]+[A-Za-z][\w_]*([\s]*(?'open'\().*?(\)))?(([\s]*;)|([\s]*([ia]s)\s)|([\s]+(RETURN)([\s]+[\w%\.]+)+(([\s]*;)|([\s]+([ia]s)\s))))"/>
<nameExpr expr="[A-Za-z][\w_]*([\s]*(?'open'\().*?(\)))?(([\s]*;)|([\s]*([ia]s)\s)|([\s]+(RETURN)([\s]+[\w%\.]+)+(([\s]*;)|([\s]+([ia]s)\s))))"/>
<nameExpr expr="[A-Za-z][\w_]*([\s]*\([^\)]*\))?(([\s]+(RETURN)([\s]+[\w%\.]+)+))*"/>