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

Skip to content

Commit f2560f9

Browse files
committed
Changes to make it run better from path and some error handling
1 parent 3f2b02b commit f2560f9

6 files changed

Lines changed: 93 additions & 51 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
set -e
33

44
clientPath=${1%/}

client_source/sqlplus/ut_run

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -e
3+
4+
clientDir="$(dirname "$(readlink -f "$0")")"
5+
projectDir="$(pwd)"
6+
7+
if [ ! "$clientDir" == "${clientDir/ /}" ]; then
8+
echo "Error: ut_run script path cannot have spaces."
9+
exit 1
10+
fi
11+
12+
if [ "$@" == "" ]; then
13+
echo "Usage: ut_run user/password@database [options...]"
14+
exit 1
15+
fi
16+
17+
sqlplus /nolog @"$clientDir/ut_run.sql" "$clientDir" "$projectDir" "$@"

client_source/sqlplus/ut_run.bat

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,14 @@
33
set clientDir=%~dp0
44
set projectDir=%__CD__%
55

6-
sqlplus /nolog @%clientDir%\ut_run.sql '%clientDir%' '%projectDir%' %*
6+
if not "%clientDir%" == "%clientDir: =%" (
7+
echo Error: ut_run script path cannot have spaces.
8+
exit /b 1
9+
)
10+
11+
if "%1" == "" (
12+
echo Usage: ut_run user/password@database [options...]
13+
exit /b 1
14+
)
15+
16+
sqlplus /nolog @"%clientDir%\ut_run.sql" '%clientDir%' '%projectDir%' %*

client_source/sqlplus/ut_run.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

client_source/sqlplus/ut_run.sql

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@ Parameters:
5555
Generates a JSON coverage report providing detailed information on code coverage with line numbers.
5656
This coverage report is designed to be consumed by local services like https://about.sonarqube.com/.
5757
-f=ut_sonar_test_reporter
58-
TODO
58+
Generates a JSON report providing detailed information on test specifications.
59+
This report is designed to be consumed by local services like https://about.sonarqube.com/.
5960
If no -f option is provided, the ut_documentation_reporter will be used.
6061
6162
-o=output - file name to save the output provided by the reporter.
6263
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
6364
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
6465
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
6566
-s - Forces putting output to to screen for a given -f parameter.
67+
-source_path=path - Source files path to be used by coverage reporters.
68+
-test_path=path - Test files path to be used by coverage reporters.
6669
-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards
6770
6871
Parameters -f, -o, -s are correlated. That is parameters -o and -s are defining outputs for -f.
@@ -83,9 +86,9 @@ Parameters:
8386
whenever sqlerror exit failure
8487
whenever oserror exit failure
8588

86-
define client_path=&1
87-
define project_path=&2
88-
define conn_str=&3
89+
define client_path="&1"
90+
define project_path="&2"
91+
define conn_str="&3"
8992

9093
conn &conn_str
9194

@@ -333,11 +336,11 @@ column test_path new_value test_path noprint;
333336
select :l_test_path as test_path from dual;
334337

335338
--try running on windows
336-
$ &&client_path\file_list.bat "&&client_path" "&&project_path" "&&source_path" "source_file_list.sql.tmp" "l_source_files"
337-
$ &&client_path\file_list.bat "&&client_path" "&&project_path" "&&test_path" "test_file_list.sql.tmp" "l_test_files"
339+
$ "&&client_path\file_list.bat" "&&client_path" "&&project_path" "&&source_path" "source_file_list.sql.tmp" "l_source_files"
340+
$ "&&client_path\file_list.bat" "&&client_path" "&&project_path" "&&test_path" "test_file_list.sql.tmp" "l_test_files"
338341
--try running on linux/unix
339-
! &&client_path/file_list.sh "&&client_path" "&&project_path" "&&source_path" "source_file_list.sql.tmp" "l_source_files"
340-
! &&client_path/file_list.sh "&&client_path" "&&project_path" "&&test_path" "test_file_list.sql.tmp" "l_test_files"
342+
! "&&client_path/file_list" "&&client_path" "&&project_path" "&&source_path" "source_file_list.sql.tmp" "l_source_files"
343+
! "&&client_path/file_list" "&&client_path" "&&project_path" "&&test_path" "test_file_list.sql.tmp" "l_test_files"
341344

342345
undef source_path
343346
undef test_path

docs/userguide/ut_run-script.md

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,71 @@
1-
The `ut_run.sql` script is designed to allow invocation of utPLSQL with multiple reporters.
1+
The `ut_run.bat` and `ut_run` scripts are designed to allow invocation of utPLSQL with multiple reporters.
22
It allows saving of outcomes into multiple output files.
33
It also facilitates displaying on screen unit test results while the execution is still ongoing.
44
Current limit of script parameters is 39
55

6-
# Scrip invocation
7-
ut_run.sql user/password@database [-p=(ut_path|ut_paths)] [-c] [-f=format [-o=output] [-s] ...]
6+
The easiest way to use it, is by adding the client_source/sqlplus folder on your PATH.
7+
8+
# Script Invocation
9+
ut_run user/password@database [-p=(ut_path|ut_paths)] [-c] [-f=format [-o=output] [-s] ...] [-source_path=path] [-test_path=path]
810

911
# Parameters
1012
```
11-
user - username to connect as
12-
password - password of the user
13-
database - database to connect to
14-
-p=ut_path(s)- A path or a comma separated list of paths to unit test to be executed.
15-
The path can be in one of the following formats:
16-
schema[.package[.procedure]]
17-
schema:suite[.suite[.suite][...]][.procedure]
18-
Both formats can be mixed in the comma separated list.
19-
If only schema is provided, then all suites owner by that schema (user) are executed.
20-
If -p is omitted, the current schema is used.
21-
-f=format - A reporter to be used for reporting.
22-
Available options:
23-
-f=ut_documentation_reporter
24-
A textual pretty-print of unit test results (usually use for console output)
25-
-f=ut_teamcity_reporter
26-
A teamcity Unit Test reporter, that can be used to visualize progress of test execution as the job progresses.
27-
-f=ut_xunit_reporter
28-
A XUnit xml format (as defined at: http://stackoverflow.com/a/9691131 and at https://gist.github.com/kuzuha/232902acab1344d6b578)
29-
Usually used by Continuous Integration servers like Jenkins/Hudson or Teamcity to display test results.
30-
If no -f option is provided, the ut_documentation_reporter will be used.
31-
32-
-o=output - file name to save the output provided by the reporter.
33-
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
34-
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
35-
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
36-
-s - Forces putting output to to screen for a given -f parameter.
37-
-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards
13+
user - username to connect as
14+
password - password of the user
15+
database - database to connect to
16+
-p=ut_path(s) - A path or a comma separated list of paths to unit test to be executed.
17+
The path can be in one of the following formats:
18+
schema[.package[.procedure]]
19+
schema:suite[.suite[.suite][...]][.procedure]
20+
Both formats can be mixed in the comma separated list.
21+
If only schema is provided, then all suites owner by that schema (user) are executed.
22+
If -p is omitted, the current schema is used.
23+
-f=format - A reporter to be used for reporting.
24+
Available options:
25+
-f=ut_documentation_reporter
26+
A textual pretty-print of unit test results (usually use for console output)
27+
-f=ut_teamcity_reporter
28+
A teamcity Unit Test reporter, that can be used to visualize progress of test execution as the job progresses.
29+
-f=ut_xunit_reporter
30+
A XUnit xml format (as defined at: http://stackoverflow.com/a/9691131 and at https://gist.github.com/kuzuha/232902acab1344d6b578)
31+
Usually used by Continuous Integration servers like Jenkins/Hudson or Teamcity to display test results.
32+
-f=ut_coverage_html_reporter
33+
Generates a HTML coverage report providing summary and detailed information on code coverage.
34+
The html reporter is based on open-source simplecov-html reporter for Ruby.
35+
It includes source code of the code that was covered (if possible).
36+
-f=ut_coveralls_reporter
37+
Generates a JSON coverage report providing detailed information on code coverage with line numbers.
38+
This coverage report is designed to be consumed by cloud services like https://coveralls.io/.
39+
-f=ut_coverage_sonar_reporter
40+
Generates a JSON coverage report providing detailed information on code coverage with line numbers.
41+
This coverage report is designed to be consumed by local services like https://about.sonarqube.com/.
42+
-f=ut_sonar_test_reporter
43+
Generates a JSON report providing detailed information on test specifications.
44+
This report is designed to be consumed by local services like https://about.sonarqube.com/.
45+
If no -f option is provided, the ut_documentation_reporter will be used.
46+
47+
-o=output - file name to save the output provided by the reporter.
48+
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
49+
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
50+
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
51+
-s - Forces putting output to to screen for a given -f parameter.
52+
-source_path=path - Source files path to be used by coverage reporters.
53+
-test_path=path - Test files path to be used by coverage reporters.
54+
-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards
3855
```
3956

57+
**To make coverage reporters work source_path and/or test_path cannot be empty, and ut_run need to be executed from your project's path.**
58+
4059
Parameters -f, -o, -s are correlated. That is parameters -o and -s are defining outputs for -f.
4160

4261
Examples of invocation using sqlplus from command line:
4362

44-
`sqlplus /nolog @ut_run hr/hr@xe -p=hr_test -f=ut_documentation_reporter -o=run.log -s -f=ut_teamcity_reporter -o=teamcity.xml`
63+
`ut_run @ut_run hr/hr@xe -p=hr_test -f=ut_documentation_reporter -o=run.log -s -f=ut_html_reporter -o=coverage.html -source_path=source`
4564

4665
All Unit tests from schema/package "hr_test" will be be invoked with two reporters:
4766
- ut_documentation_reporter - will output to screen and save it's output to file "run.log"
48-
- ut_teamcity_reporter - will save it's output to file "teamcity.xml"
67+
- ut_html_reporter - will read file structure from source folder, and save it's output to file "coverage.html"
4968

50-
`sqlplus /nolog @ut_run hr/hr@xe`
69+
`ut_run hr/hr@xe`
5170

52-
All Unit tests from schema "hr" will be be invoked with ut_documentation_reporter as a format and the results will be printed to screen
71+
All Unit tests from schema "hr" will be be invoked with ut_documentation_reporter as a format and the results will be printed to screen.

0 commit comments

Comments
 (0)