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

Skip to content

Commit 312fb95

Browse files
authored
Merge pull request #464 from utPLSQL/feature/add_version_check
Added `version_compatibility_check` function to ut_runner
2 parents bd0c89f + 90efb27 commit 312fb95

15 files changed

Lines changed: 156 additions & 10 deletions

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ env:
3333
- CURRENT_BRANCH=${TRAVIS_BRANCH}
3434
- UTPLSQL_REPO="utPLSQL/utPLSQL"
3535
- UTPLSQL_BUILD_NO="${TRAVIS_BUILD_NUMBER:-0}"
36-
- UTPLSQL_VERSION_PLACEHOLDER='utPLSQL - Version'
36+
- UTPLSQL_VERSION_PATTERN='v?([0-9X]+\.){3}[0-9X]+'
3737
- UTPLSQL_VERSION=$(. .travis/get_project_version.sh)
3838
- UTPLSQL_BUILD_VERSION=$(. .travis/get_project_build_version.sh)
3939
- UTPLSQL_SOURCES_DIR='source'

.travis/update_project_version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
echo Current branch is "${CURRENT_BRANCH}"
44

55
echo Update version in project source files
6-
find ${UTPLSQL_SOURCES_DIR} -type f -name '*' -exec sed -i -r "s/(${UTPLSQL_VERSION_PLACEHOLDER} )[^']*(')?/\1${UTPLSQL_BUILD_VERSION}\2/" {} \;
6+
find ${UTPLSQL_SOURCES_DIR} -type f -name '*' -exec sed -i -r "s/${UTPLSQL_VERSION_PATTERN}/${UTPLSQL_BUILD_VERSION}/" {} \;
77
echo Source files updated with version tag: ${UTPLSQL_BUILD_VERSION}
88

99
echo Update of sonar-project.properties sonar.projectVersion

old_tests/ut/ut.version.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
declare
2-
l_expected varchar2(100) := 'utPLSQL - Version %.%.%';
2+
l_expected varchar2(100) := '%.%.%.%';
33
begin
44
--Assert
5-
if ut.version() like l_expected then
5+
if ut.version() like l_expected then
66
:test_result := ut_utils.tr_success;
77
else
88
dbms_output.put_line('expected version like '''||l_expected ||''' got: '''||ut.version()||'''' );

source/api/ut.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ create or replace package body ut is
2121

2222
function version return varchar2 is
2323
begin
24-
return ut_utils.gc_version;
24+
return ut_runner.version();
2525
end;
2626

2727
function expect(a_actual in anydata, a_message varchar2 := null) return ut_expectation_anydata is

source/api/ut_runner.pkb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ create or replace package body ut_runner is
4343
return ut_utils.gc_version;
4444
end;
4545

46+
function version_compatibility_check( a_requested varchar2, a_current varchar2 := null ) return integer is
47+
l_result boolean := false;
48+
l_requested ut_utils.t_version := ut_utils.to_version(a_requested);
49+
l_current ut_utils.t_version := ut_utils.to_version(coalesce(a_current,version()));
50+
begin
51+
if l_requested.major = l_current.major
52+
and (l_requested.minor < l_current.minor
53+
or l_requested.minor = l_current.minor and l_requested.bugfix <= l_current.bugfix) then
54+
l_result := true;
55+
end if;
56+
return ut_utils.boolean_to_int(l_result);
57+
end;
58+
4659
procedure run(
4760
a_paths ut_varchar2_list, a_reporters ut_reporters, a_color_console boolean := false,
4861
a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,

source/api/ut_runner.pks

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ create or replace package ut_runner authid current_user is
1919

2020
function version return varchar2;
2121

22+
/**
23+
* Check if version is compatible with another version (by default the current framework version)
24+
* Version is compatible if:
25+
* a_current.major = a_requested.major
26+
* a_requested.minor < a_current.minor or a_requested.minor = a_current.minor and a_requested.bugfix <= a_current.bugfix
27+
*
28+
* @param a_requested requested utPLSQL version string
29+
* @param a_current current utPLSQL version string, if null is passed, defaults to current framework version
30+
* @return 1/0 1-true, 0-false
31+
* @exception 20214 if passed version string is not matching version pattern
32+
*/
33+
function version_compatibility_check( a_requested varchar2, a_current varchar2 := null ) return integer;
34+
2235
/**
2336
* Run suites/tests by path
2437
* Accepts value of the following formats:

source/core/ut_utils.pkb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,5 +382,20 @@ create or replace package body ut_utils is
382382
execute immediate 'delete from ut_cursor_data';
383383
end;
384384

385+
function to_version(a_version_no varchar2) return t_version is
386+
l_result t_version;
387+
c_version_part_regex varchar2(20) := '[0-9]+';
388+
begin
389+
390+
if regexp_like(a_version_no,'v?([0-9]+(\.|$)){1,4}') then
391+
l_result.major := regexp_substr(a_version_no, c_version_part_regex, 1, 1);
392+
l_result.minor := regexp_substr(a_version_no, c_version_part_regex, 1, 2);
393+
l_result.bugfix := regexp_substr(a_version_no, c_version_part_regex, 1, 3);
394+
l_result.build := regexp_substr(a_version_no, c_version_part_regex, 1, 4);
395+
else
396+
raise_application_error(gc_invalid_version_no, 'Version string "'||a_version_no||'" is not a valid version');
397+
end if;
398+
return l_result;
399+
end;
385400
end ut_utils;
386401
/

source/core/ut_utils.pks

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ create or replace package ut_utils authid definer is
2222

2323
*/
2424

25-
gc_version constant varchar2(50) := 'utPLSQL - Version X.X.X.X';
25+
gc_version constant varchar2(50) := 'X.X.X.X';
2626

2727
/* Constants: Event names */
2828
gc_run constant varchar2(12) := 'run';
@@ -85,6 +85,10 @@ create or replace package ut_utils authid definer is
8585
gc_some_tests_failed constant pls_integer := -20213;
8686
pragma exception_init(ex_some_tests_failed, -20213);
8787

88+
-- Any of tests failed
89+
ex_invalid_version_no exception;
90+
gc_invalid_version_no constant pls_integer := -20214;
91+
pragma exception_init(ex_invalid_version_no, -20214);
8892

8993
gc_max_storage_varchar2_len constant integer := 4000;
9094
gc_max_output_string_length constant integer := 4000;
@@ -96,6 +100,15 @@ create or replace package ut_utils authid definer is
96100
gc_timestamp_format constant varchar2(100) := 'yyyy-mm-dd"T"hh24:mi:ssxff';
97101
gc_timestamp_tz_format constant varchar2(100) := 'yyyy-mm-dd"T"hh24:mi:ssxff tzh:tzm';
98102
gc_null_string constant varchar2(4) := 'NULL';
103+
104+
type t_version is record(
105+
major natural,
106+
minor natural,
107+
bugfix natural,
108+
build natural
109+
);
110+
111+
99112
/*
100113
Function: test_result_to_char
101114
returns a string representation of a test_result.
@@ -218,12 +231,12 @@ create or replace package ut_utils authid definer is
218231
procedure append_to_clob(a_src_clob in out nocopy clob, a_new_data varchar2);
219232

220233
function convert_collection(a_collection ut_varchar2_list) return ut_varchar2_rows;
221-
234+
222235
/**
223236
* Set session's action and module using dbms_application_info
224237
*/
225238
procedure set_action(a_text in varchar2);
226-
239+
227240
/**
228241
* Set session's client info using dbms_application_info
229242
*/
@@ -235,5 +248,14 @@ create or replace package ut_utils authid definer is
235248

236249
procedure cleanup_temp_tables;
237250

251+
/**
252+
* Converts version string into version record
253+
*
254+
* @param a_version_no string representation of version in format vX.X.X.X where X is a positive integer
255+
* @return t_version record with up to four positive numbers containing version
256+
* @throws 20214 if passed version string is not matching version pattern
257+
*/
258+
function to_version(a_version_no varchar2) return t_version;
259+
238260
end ut_utils;
239261
/

source/reporters/ut_coverage_report_html_helper.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ create or replace package body ut_coverage_report_html_helper is
236236
l_file_part :=
237237
chr(10)||
238238
'</div><div id="footer">' ||
239-
'Generated by <a href="http://github.com/utPLSQL/utPLSQL">'||ut_utils.gc_version||'</a><br/>' ||
239+
'Generated by <a href="http://github.com/utPLSQL/utPLSQL">utPLSQL '||ut_utils.gc_version||'</a><br/>' ||
240240
'Based on <a href="http://github.com/colszowka/simplecov-html">simplecov-html</a> v0.10.0 '||l_using||'' ||
241241
'</div><div class="source_files">';
242242
ut_utils.append_to_clob(l_result, l_file_part);

test/install_and_run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ utPLSQL-cli/bin/utplsql run ${UT3_TESTER}/${UT3_TESTER_PASSWORD}@${CONNECTION_ST
1414
-test_path=test -c \
1515
-f=ut_documentation_reporter -o=test_results.log -s \
1616
-f=ut_coverage_sonar_reporter -o=coverage.xml \
17-
-f=ut_coverage_html_reporter -o=coverage.html \
17+
-f=ut_coverage_html_reporter -o=coverage.html \
1818
-f=ut_coveralls_reporter -o=coverage.json \
1919
-f=ut_sonar_test_reporter -o=test_results.xml
2020

0 commit comments

Comments
 (0)