From ee336b24c110b07a549ea19f65d274ae4c1fcfa8 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 12 Dec 2022 02:18:11 +0100 Subject: [PATCH] [xml] Add SQL unit tests And make unit test error message more explicit. Close #12627 --- .../sql/comment_assignment/unitTest | 154 ++++++++++++++++++ .../unitTest.expected.result | 1 + PowerEditor/Test/FunctionList/sql/unitTest | 73 +++++++++ .../FunctionList/sql/unitTest.expected.result | 1 + PowerEditor/Test/FunctionList/unitTest.ps1 | 8 + PowerEditor/installer/functionList/sql.xml | 2 +- 6 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 PowerEditor/Test/FunctionList/sql/comment_assignment/unitTest create mode 100644 PowerEditor/Test/FunctionList/sql/comment_assignment/unitTest.expected.result create mode 100644 PowerEditor/Test/FunctionList/sql/unitTest create mode 100644 PowerEditor/Test/FunctionList/sql/unitTest.expected.result diff --git a/PowerEditor/Test/FunctionList/sql/comment_assignment/unitTest b/PowerEditor/Test/FunctionList/sql/comment_assignment/unitTest new file mode 100644 index 000000000..3b7f6f398 --- /dev/null +++ b/PowerEditor/Test/FunctionList/sql/comment_assignment/unitTest @@ -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; +/ + diff --git a/PowerEditor/Test/FunctionList/sql/comment_assignment/unitTest.expected.result b/PowerEditor/Test/FunctionList/sql/comment_assignment/unitTest.expected.result new file mode 100644 index 000000000..17c6b8105 --- /dev/null +++ b/PowerEditor/Test/FunctionList/sql/comment_assignment/unitTest.expected.result @@ -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"} \ No newline at end of file diff --git a/PowerEditor/Test/FunctionList/sql/unitTest b/PowerEditor/Test/FunctionList/sql/unitTest new file mode 100644 index 000000000..966c2c201 --- /dev/null +++ b/PowerEditor/Test/FunctionList/sql/unitTest @@ -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; +/ \ No newline at end of file diff --git a/PowerEditor/Test/FunctionList/sql/unitTest.expected.result b/PowerEditor/Test/FunctionList/sql/unitTest.expected.result new file mode 100644 index 000000000..8c277e176 --- /dev/null +++ b/PowerEditor/Test/FunctionList/sql/unitTest.expected.result @@ -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"} \ No newline at end of file diff --git a/PowerEditor/Test/FunctionList/unitTest.ps1 b/PowerEditor/Test/FunctionList/unitTest.ps1 index 760e10a4d..9ec26b9bc 100644 --- a/PowerEditor/Test/FunctionList/unitTest.ps1 +++ b/PowerEditor/Test/FunctionList/unitTest.ps1 @@ -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 } } diff --git a/PowerEditor/installer/functionList/sql.xml b/PowerEditor/installer/functionList/sql.xml index cd517ccdb..bc905a5fc 100644 --- a/PowerEditor/installer/functionList/sql.xml +++ b/PowerEditor/installer/functionList/sql.xml @@ -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" > - +