Repository navigation
Conversation
…iew. And then, returns unexpected line.
|
Hi @monookenai I do not see any associated issue that would be describing a problem someone was facing in real-life. We need to have an issue related to a Pull Request to make the easy to track and document in releases and version changelog. |
jgebal
left a comment
There was a problem hiding this comment.
I have looked into the code change and into the test and I find it hard to understand:
- what is the test proving?
- what is the code change doing?
When reviewing a simple change, it should be relatively easy to see what is the unwanted and wanted behavior.
The single test that is created does not say anything.
In fact the tests name is not helpful:
--%test(source line is over varchar2 limit) - does not say anything about action or behaviour. The test name describes a state.
Name like: --%test(source line over 4000 limit is trimmed to first 4000) is probably much better.
I think this change can be a valuable improvement but it must be described more clearly.
The filtering needs to be done inside of SQL, not as a separate loop after the query.
Also, the filter condition is wrong, because the last line of source for every object does not have a CHR(10).
You should also make sure that the CHR(10) is also used as the end of line separator in MAC and Windows systems so the behaviour will be the same on DB installed on Windows, Mac, Linx operating systems.
…_source_line' into bugfix/over_varchar2_limit_wrong_source_line
|
@jgebal I wanted to fix the issue where incorrect source text was outputted when an assertion failed. test package; result: at "MYTEST.TEST_PACKAGE1.TEST_MAX_LENGTH", line 15 ***********************'; |
specify line break characters
| where s.owner = :a_owner | ||
| and s.name = :a_object_name | ||
| /*skip the declarations, consider only definitions*/ | ||
| and s.type not in ('PACKAGE', 'TYPE') |
There was a problem hiding this comment.
It's looking better now
I would change the query to be like below for few reasons:
- readability
- logic
with
all_source_filter as (
select lag(
case when substr(text,-1) in (chr(10), chr(13)) then 1 else 0 end
, 1
) over (partition by owner, name, type order by line) prev_line_eol,
a.*
from all_source a
)
select trim(s.text)
from all_source_filter s
where s.owner = :a_owner
and s.name = :a_object_name
/*skip the declarations, consider only definitions*/
and s.type not in ('PACKAGE', 'TYPE')
and nvl(s.prev_line_eol, 1) > 0
order by s.line;What we want to make sure is that when I create a package:
create or replace package test_package1 is
procedure sp_test;
end;create or replace package body test_package1 is
procedure sp_test is
begin
ut.expect('a').to_equal('e');/* [varcahr2 limit]*****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************[********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************varcahr2 limit][over] */
end;
end;and I run the query above
Then the results should show exactly lines 1, 2, 3, 4, 12, 13:
package body test_package1 is
procedure sp_test is
begin
ut.expect('a').to_equal('e');/* [varcahr2 limit]************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
end;
end;I would modify the tests to actually test this specific corner case.
There was a problem hiding this comment.
Thank you for checking query.
I think it enough to detect only LF.
CR source text is formatted as a single line in *_source view.(I use datagrip)
It runnable, but maybe Oracle not recommended.
3999 source text + CRLF is splitted 2 line(3999 + CR, and LF)
| )'; | ||
|
|
||
| c_pks_lf constant varchar2(1000) := | ||
| 'create or replace package test_package_lf is'||c_lf |
There was a problem hiding this comment.
define the package spec and body once. There is no need to have it defined 3 times.
See comment in beforetest
| procedure create_test_package_crlf is | ||
| pragma autonomous_transaction; | ||
| begin | ||
| execute immediate c_pks_crlf; |
There was a problem hiding this comment.
use execute immediate replace(c_pks_lf, c_lf, c_crlf)
That way you can have one common declaration and change newline characters only
|
|
||
| procedure test_over_varchar2_limit_trim_first_4000_lf | ||
| is | ||
| l_actual all_source.text%type; |
There was a problem hiding this comment.
in general it's better not to reference tested-code types in test code variables.
This makes tests more fragile.
In those tests I'd use varchar2(32767)
|
Thanks for your changes @monookenai Your PR uncovers a generic issue. That potentially creates another corner case for parsing package specifications. That should be a new issue by itself. |
|
@monookenai |
query formatting
jgebal
left a comment
There was a problem hiding this comment.
Thanks @monookenai, this is looking almost perfect now.
I added few more comments.
Please update the tests and code before the fix can be merged.
The CRLF situation is unclear as there is no documentation I could find that would explain what is the end of line character in ALL_SOURCE when database server (not client) is running on Windows or on Mac.
I only can check Linux as I run my DB in Docker containers currently.
I'm waiting for some feedback from others.
You may be right that chr(10) is enough to check for.
| --%suite(ut_metadata) | ||
| --%suitepath(utplsql.ut3_tester.core) | ||
|
|
||
| --%test(source line over 4000 limit is trimmed to first 4000 [linebreeak lf]) |
There was a problem hiding this comment.
add: --%context(get_source_definition_line)
The test package is for whole ut_metadata but the tests is testing one specific function.
| c_create_table constant varchar2(1000) := | ||
| 'create table test_table( | ||
| id number(10,0) | ||
| , value varchar2(4000) |
There was a problem hiding this comment.
The generated package is more complex than needed.
It replays the original bug report: an insert into test_table, a select, and a long string literal. None of that matters for get_source_definition_line.
Only the line structure matters. A long comment line removes the need for test_table and the beforeall/afterall DDL entirely.
Keep the UT focused on the problem at hand. It makes it easier to read.
| ||q'[ from test_table t]'||c_lf | ||
| ||q'[ where t.id = 1;]'||c_lf | ||
| ||q'[]'||c_lf | ||
| ||q'[ l_expect := 'varchar2 limit text*********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************';]'||c_lf |
There was a problem hiding this comment.
As mentioned by @mathewbutler in #1396 (comment) use rpad('*', 4000, '*') for readability.
Building it with rpad makes the length explicit and lets you cover the three-row case (over 8000 bytes) as well.
Note:
In utPLSQL, a PR should solve an issue. This is why I created #1396 so we can have a reference for a problem that a PR is fixing.
|
|
||
| c_pks_lf constant varchar2(1000) := | ||
| 'create or replace package test_package1 is'||c_lf | ||
| ||' --%suite(varchar2 limitation)'||c_lf |
There was a problem hiding this comment.
The generated package has --%suite / --%test annotations.
If a drop of this package fails, a test_pacakge1 suite is left behind in UT3_TESTER and gets picked up by next test run.
This package doesn't need annotations at all for the purpose of this test.
|
|
||
| procedure clear_cache is | ||
| begin | ||
| ut3_develop.UT_METADATA.RESET_SOURCE_DEFINITION_CACHE(); |
There was a problem hiding this comment.
UT_METADATA.RESET_SOURCE_DEFINITION_CACHE() is uppercase, which doesn't match the codebase style.
…_source_line' into bugfix/over_varchar2_limit_wrong_source_line
remove annotations( --%suite, --%test. add context.
generate long text using rpad.
|
I'd like to make a new release by the end of this week. It would be good to have this fix as part of it. |
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix · Severity of issue fixed: Low Merge Risk:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1394 +/- ##
========================================
Coverage 94.96% 94.96%
========================================
Files 113 113
Lines 5427 5427
Branches 24 24
========================================
Hits 5154 5154
Misses 257 257
Partials 16 16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I apologize for the delayed response. |
|
Thank you for the contribution @monookenai |
When executing a test package that contains lines with length exceeding 4000 bytes, the line is divided into multiple lines (rows) in
all_source.textcolumn.In that case,
ut_metadata.get_source_definition_linereturns wrong source text and the expectation result in report is showing incorrect line text.Resolves: #1396
Summary by CodeRabbit