GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Feature/rework matcher by lwasylow · Pull Request #1076 · utPLSQL/utPLSQL

Conversation

@lwasylow

@lwasylow lwasylow commented Jun 7, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Adding a matcher within_of.
Rework some of the compound expectation to use a pass a matcher to expectation to remove methods from ut_equal_compound.
Implements #77

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
lwasylow added 8 commits June 1, 2020 21:58
@lwasylow
Initial checkin
48abf1a
@lwasylow
added expectation
7041912
@lwasylow
Adding more methods
13d86b6
@lwasylow
Adding contain and not contain
caeeb30
@lwasylow
Adding code and tests,.
8ff4f6b
@lwasylow
Fixingtoo long names
89cb0bc
@lwasylow
fixing issue
a5481ac
@lwasylow
Update documentation and tests
9ee0e75
@lwasylow
lwasylow requested a review from jgebal June 7, 2020 14:30
@jgebal

jgebal commented Jun 10, 2020

Copy link
Copy Markdown
Member

@lwasylow - sorry for not reviewing it yet.
I'll look at it this week.

lwasylow reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal
jgebal requested changes Jun 13, 2020
View reviewed changes
Comment thread docs/userguide/expectations.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/userguide/expectations.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread source/core/ut_utils.pkb Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread source/core/ut_utils.pkb Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread source/core/ut_utils.pkb Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread source/expectations/ut_expectation_base.tpb Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread source/expectations/ut_expectation_base.tps Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread source/expectations/ut_expectation_base.tpb Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread source/expectations/matchers/ut_equal.tpb Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread source/expectations/matchers/ut_equal.tpb
l_result ut_equal := self;
begin
l_result.options.exclude.add_items(a_items);
l_result.expectation.to_(l_result );

@jgebal jgebal Jun 13, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

all calls to: l_result.expecatation in this type are assuming that the expectation attribute is set.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jgebal jgebal Jun 13, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Given the number of places this is called, it would be good to delegate exception handling to a helper procedure.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jgebal jgebal Jan 31, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@lwasylow
I don't really remember why this change was done.
I think it's part of some clean-up operation but not really part of new matcher. Is your memory any better than mine?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lwasylow lwasylow Jan 31, 2022

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@jgebal

Went back to old conversations on slack from may 27th 2020 and found this:

To not duplicate old methods from matchers we can change behaviour.
UT_MATCHER is additional attribute of expectation which is set when function is called.
Procedure TO_EQUAL in UT_EXPECTATION works the same.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jgebal jgebal Jan 31, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yeah. I've found it. But after 2 years I can't even understand what I had in mind.
I'll put the original (polish) version here, just in case, as the free version of SLACK that we use purges messages history.

Propozycja:
Żeby nie duplikować wszystkich metod z matcherów w ut_Expectation można zmienić to zachowanie w następujący sposób:
ut_matcher a teraz dodatkowy atrybut expectation który jest ustawiany gdy wołana jest funcja.
Procedura to_equal w ut_Expectation działa jak dotychczas - raportuje expecattaion
Funkcja to_equal w ut_Expecattion_compound :
ustawia wartość pola expectation w przekazanym matcher na wartość self
zwraca matcher, tak żeby metchod chaining teraz już używał metod matchera (dzięki temu nie trzeba już duplikować dodatkowych metod w ut_expectation
Matcher może odwołać się teraz do expectation z którego został wywołany.
W procedurze matchera (ostatnia metoda w łańcuchu) self.expecation is null matcher nie woła expecataion, w innym wypadku procedury matcher wołaję metodę to_ przekazując self
W ten sposób składnia:
ut.expect(...).to_( equal(...).incude(...) ) sprawia, że:
matcher nie woła expectation, bo expectation nie jest ustawione w matcher
matcher jest przekazany do expectation i expectation wykonuje sprawdzenie wartości i raportuje
Składnia:
ut.expect(...).to_equal(...).include sprawia że:
to_equal ustawia self jako expectation w matcherze, zwraca matcher i dokonuje się metchod chaining
include wywoływane jest na matcherze i poniewarz jest to procedura i pole expectation jest ustawione, matcher woła metodę ecpectation.to_ przekazując self jako arcument
Powinno działać, ale jest 2 w nocy więc mogę majaczyć

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
lwasylow and others added 17 commits June 14, 2020 20:02
@lwasylow
First code corrections
a660208
@lwasylow
Resolving another comment
ada1ea4
@lwasylow
Updating issues
fe1b0cb
@lwasylow
Update tble
013db74
@jgebal
Separated into two different matchers
b5c73b4
Added synonym and grant for matcher
Reworked expectation to work fine with syntax `to_( matcher() )` for to_be_within.

TODO - add tests for other matchers with `to_( matcher )` and `not_to( matcher )` syntax
@lwasylow
CHECKPOINT
2e721da
@lwasylow
Merge branch 'feature/rework_matcher' of https://github.com/utPLSQL/u…
fbc0f26
…tPLSQL into feature/rework_matcher
@lwasylow
Update uninstall
f182430
@lwasylow
Update progress
e3fb2d7
@lwasylow
Making code a bit more readable
322e0a1
@jgebal
Added tests for be_within_pct
ff15596
Reorganized code so that `be_within_pct` is only supported for `number`
Added tests for non-supported syntax
@jgebal
Fixed test issue
3cae9a2
@jgebal
Fixed stacktrace for failed expectations on chained matchers.
22549db
@lwasylow
Update timestamps
1d771a5
No tests
@jgebal
Fixed and simplified matcher
363c333
@jgebal
Fixed native dynamic SQL types compatibility for 11g
0ea8925
@jgebal
Fixed native dynamic SQL types compatibility for 11g
7c01afb
@sonarqubecloud

sonarqubecloud Bot commented Jun 28, 2020

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 1 Security Hotspot to review)
Code Smell A 18 Code Smells

89.2% 89.2% Coverage
0.0% 0.0% Duplication

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pesse

pesse commented Nov 12, 2020

Copy link
Copy Markdown
Member

What's missing here? Maybe I can help

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal added 2 commits January 28, 2022 23:23
@jgebal
Removing reference to ut3_develop schema.
5e2642a
Added sql-injection check.
@jgebal
Relaxed sql-injection check to work with 11g2
ed06e33
@jgebal jgebal added this to the 3.1.12 milestone Jan 29, 2022
@jgebal

jgebal commented Jan 29, 2022

Copy link
Copy Markdown
Member

While running the feature tests locally just now, I have noticed a pitfall of using interval datatype as a time distance.
The below block fails with exceptions:

set serverout on;
begin
  ut.expect(date '2022-01-30').to_be_within(INTERVAL '1'  MONTH).of_(date '2022-01-30');
end;
/
begin
  ut.expect(date '2022-05-31').to_be_within(INTERVAL '1'  MONTH).of_(date '2022-05-31');
end;
/
begin
  ut.expect(date '2022-01-30').to_be_within(INTERVAL '1'  MONTH).of_(date '2022-01-30');
end;
Error report -
ORA-01839: date not valid for month specified
ORA-06512: at line 11
ORA-06512: at "UT3.UT_BE_WITHIN_HELPER", line 24
ORA-06512: at "UT3.UT_BE_WITHIN", line 114
ORA-06512: at "UT3.UT_EXPECTATION_BASE", line 26
ORA-06512: at "UT3.UT_BE_WITHIN", line 44
ORA-06512: at line 2
01839. 00000 -  "date not valid for month specified"
*Cause:    
*Action:

Error starting at line : 6 in command -
begin
  ut.expect(date '2022-05-31').to_be_within(INTERVAL '1'  MONTH).of_(date '2022-05-31');
end;
Error report -
ORA-01839: date not valid for month specified
ORA-06512: at line 3
ORA-06512: at "UT3.UT_BE_WITHIN_HELPER", line 24
ORA-06512: at "UT3.UT_BE_WITHIN", line 114
ORA-06512: at "UT3.UT_EXPECTATION_BASE", line 26
ORA-06512: at "UT3.UT_BE_WITHIN", line 44
ORA-06512: at line 2
01839. 00000 -  "date not valid for month specified"
*Cause:    
*Action:

This is because:
January 30 + Interval '1' month, according to Interval maths is February 30th 😞
and
May 31st + Inter

val '1' month, according to Interval maths is June 31st

So, we would really need to rethink the maths and meaning of + 1 month to be more like add_months logic which assumes that if the day of month falls beyond last day of a month, it means it should be last day of a month.
Example:

select add_months(date '2022-05-31',1) from dual;
2022-06-30 12:00:00 AM

It seems that only the interval month logic suffers from that problem.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jgebal

jgebal commented Jan 29, 2022

Copy link
Copy Markdown
Member

Well. interval year can also suffer from that problem on leap years.
https://stackoverflow.com/questions/35695175/oracle-db-ora-01839-date-not-valid-for-month-specified-29-02-2016-leap-year

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mathewbutler

mathewbutler commented Jan 30, 2022

Copy link
Copy Markdown

The stack overflow link references this spec:

http://www.inf.fu-berlin.de/lehre/SS05/19517-V/FolienEtc/sql-foundation-aug94.pdf

Table 11— “Valid values for fields in datetime items” (page 130) states:

DAY - “ Within the range 1 to 31, but further constrained by the value of MONTH and YEAR fields, according to the rules for well-formed dates in the Gregorian calendar.”

This suggests that valid Gregorian calendar days should be the result.

I’d this behaviour of INTERVAL types an Oracle bug?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lwasylow

lwasylow commented Jan 30, 2022

Copy link
Copy Markdown
Member Author

Well. interval year can also suffer from that problem on leap years. https://stackoverflow.com/questions/35695175/oracle-db-ora-01839-date-not-valid-for-month-specified-29-02-2016-leap-year

I think we can work this around as we already have function to extract string from interval. I reckon we can try go this route to translate interval into add_months etc.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mathewbutler

mathewbutler commented Jan 30, 2022

Copy link
Copy Markdown

The stack overflow link references this spec:

http://www.inf.fu-berlin.de/lehre/SS05/19517-V/FolienEtc/sql-foundation-aug94.pdf

Table 11— “Valid values for fields in datetime items” (page 130) states:

DAY - “ Within the range 1 to 31, but further constrained by the value of MONTH and YEAR fields, according to the rules for well-formed dates in the Gregorian calendar.”

This suggests that valid Gregorian calendar days should be the result.

I’d this behaviour of INTERVAL types an Oracle bug?

More digging and Oracle state this not a bug - just the way INTERVAL works. There’s an asktom from 2005 - Mr Kyte covers it all:

https://asktom.oracle.com/pls/apex/f?p=100:11:0::::p11_question_id:1157035034361

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jgebal

jgebal commented Jan 30, 2022

Copy link
Copy Markdown
Member

I think I've found a solution that would still rely on internal oracle logic related to intervals.
We currently use the below pseudo-code

declare
  l_result boolean;
begin
  l_result := 
    a_actual  between (a_expected - a_distance) and (a_expected + a_distance);
end;

The above results in problems when we calculate: (a_expected -/+ a_distance) for a_distance expressed as YM Interval when the calculation would result in invalid day of month like below:

select (timestamp '2022-01-30 14:45:56.123456'  + interval '0-1' year to month) from dual;

However we can express the same intent with a different formula:

declare
  l_result boolean;
begin
  l_result := ( least( a_actual, a_expected ) - greatest(a_actual, a_expected) ) year to month <= a_distance;
end;

That way, we avoid the problems with invalid dates rather than adding/subtracting interval to date, we calculate YM distance between dates and then compare it to expected max distance.

For date datatype of expected & actual this would look like below:

declare
  l_result boolean;
begin
  l_result := ( cast(least( a_actual, a_expected ) as timestamp) - cast( greatest(a_actual, a_expected) as timestamp) ) year to month <= a_distance;
end;
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jgebal
Fixed issues with comparison of dates&timestamps using interval year-…
38f3cbc
…month

Improved error handling for null values and incompatible datatypes
Improved handling of negative dates (BC)
Improved reporting of interval text value
Improved datatypes to handle large&small precissions for timestamps
@jgebal

jgebal commented Jan 30, 2022

Copy link
Copy Markdown
Member

I have implemented required fixes.
@lwasylow @mathewbutler - would you mind having a look at latest commit?

lwasylow reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jgebal

jgebal commented Jan 30, 2022

Copy link
Copy Markdown
Member

TODO - review readme and documentation update to assure that the matcher is well explained along with it's limitations and behaviour to make sure there is no confusion when folks will use it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jgebal
jgebal force-pushed the feature/rework_matcher branch from 7c121ab to 4e0c703 Compare January 31, 2022 21:30
@jgebal
Improving code coverage.
86e84c8
@jgebal
jgebal force-pushed the feature/rework_matcher branch from 4e0c703 to 86e84c8 Compare January 31, 2022 21:40
jgebal added 2 commits February 1, 2022 00:14
@jgebal
Improved test stability.
718ac0d
Added human-readable reporting of tests run-time into `ut_documentation_reporter`.
@jgebal
Fixing build process to build using develop branch as testing framewo…
6dbef20
…rk for Pull Requests
@sonarqubecloud

sonarqubecloud Bot commented Jan 31, 2022

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

94.5% 94.5% Coverage
0.0% 0.0% Duplication

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jgebal
Improving test coverage.
25b55b4
@jgebal

jgebal commented Jan 31, 2022

Copy link
Copy Markdown
Member

Question:
Should the to_be_within matcher allow for comparison of

  • timestamp vs timestamp with time zone
  • timestamp vs timestamp with local time zone
  • date vs timestamp
  • etc.

That is, should we relax the strict datatype check that is present for the to_equal and allow for more relaxed check?
I think now is the time for this discussion before we merge and release this new matcher.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal added 2 commits February 1, 2022 01:58
@jgebal
Improving matcher documentation
5b5a5c0
@jgebal
Added tests for 0 value of actual and expected and actual greater tha…
7fec0f9
…n expected (not only smaller).

Updated documentation.
@jgebal

jgebal commented Feb 2, 2022

Copy link
Copy Markdown
Member

I have fixed 2 issues with pct matcher:

  1. divisor=0 on expected = 0
  2. matcher worked only one way.
    ut.expect(99).to_be_within_pct(1).of_(100) was giving SUCCESS
    ut.expect(101).to_be_within_pct(1).of_(100) was giving FAILURE

With the change introduced now we will have:

begin
  ut3_develop.ut.expect(99).to_be_within_pct(1).of_(100);
  ut3_develop.ut.expect(101).to_be_within_pct(1).of_(100);
  ut3_develop.ut.expect(99).to_be_within_pct(1).of_(100);
  ut3_develop.ut.expect(101).to_be_within_pct(1).of_(100);
  ut3_develop.ut.expect(0).to_be_within_pct(1).of_(0);
  ut3_develop.ut.expect(0).to_be_within_pct(100).of_(1);
  ut3_develop.ut.expect( 1.0001 ).to_be_within_pct( -0.01 ).of_(1);
end;
/

SUCCESS
  Actual: 99 (number) was expected to be within 1 % of 100 (number)
SUCCESS
  Actual: 101 (number) was expected to be within 1 % of 100 (number)
SUCCESS
  Actual: 99 (number) was expected to be within 1 % of 100 (number)
SUCCESS
  Actual: 101 (number) was expected to be within 1 % of 100 (number)
SUCCESS
  Actual: 0 (number) was expected to be within 1 % of 0 (number)
SUCCESS
  Actual: 0 (number) was expected to be within 100 % of 1 (number)
SUCCESS
  Actual: 1.0001 (number) was expected to be within -.01 % of 1 (number)

@lwasylow

lwasylow reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jgebal
Fixed issues with precission of distance. NATURAL is a subtype of i…
fd7ef9c
…nteger and cannot be used to express a decimal distace value.

Improved tests coverage for various scenarios.
@sonarqubecloud

sonarqubecloud Bot commented Feb 2, 2022

Copy link
Copy Markdown

Please retry analysis of this Pull-Request directly on SonarCloud.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sonarqubecloud

sonarqubecloud Bot commented Feb 2, 2022

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

95.9% 95.9% Coverage
0.0% 0.0% Duplication

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal
jgebal approved these changes Feb 2, 2022
View reviewed changes
@lwasylow lwasylow linked an issue Feb 3, 2022 that may be closed by this pull request
Add be_within 'fuzzy' matcher #77
Closed
@jgebal
jgebal merged commit b0a2aab into develop Feb 4, 2022
@jgebal
jgebal deleted the feature/rework_matcher branch February 4, 2022 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jgebal jgebal jgebal approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

v3.1.12

Development

Successfully merging this pull request may close these issues.

Add be_within 'fuzzy' matcher

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@lwasylow @jgebal @pesse @mathewbutler
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.