Skip to content

Commit 5aef96d

Browse files
committed
Moved client command line utility from utPLSQL main project.
1 parent 43f2637 commit 5aef96d

File tree

7 files changed

+682
-1
lines changed

7 files changed

+682
-1
lines changed

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### JetBrains template
3+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
4+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
5+
# User-specific stuff:
6+
.idea/
7+
.sonar/
8+
site/
9+
pages/
10+
release/
11+
*.gz
12+
*.zip
13+
node_modules/

README.md

+94-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,95 @@
11
# utPLSQL-sql-cli
2-
A bash/windows command-line client for utPLSQL v3
2+
3+
Bash & windows command-line client for [utPLSQL v3](https://github.com/utPLSQL/utPLSQL/)
4+
5+
Provides an easy way of invoking utPLSQL from command-line.
6+
Main features:
7+
8+
- Provides outputs from first reporter in real-time, so you can see the progress of your test execution
9+
- Ability to run tests with multiple reporters simultaneously
10+
- Ability to save output from every individual reporter to separate output file
11+
- Provides coloured outputs
12+
- Maps project and test files to database objects for reporting purposes
13+
- Allows execution of selected suites, subset of suite
14+
15+
# Requirements
16+
17+
The scripts require `sqlplus` to be installed and configured to be in your PATH.
18+
19+
When using reporters for Sonar or Coveralls the the `ut_run.bat`/`ut_run` script needs to be invoked from project's root directory.
20+
21+
Number of script parameters cannot exceed 39.
22+
23+
# Script Invocation
24+
25+
`ut_run user/password@database [-p=(ut_path|ut_paths)] [-c] [-f=format [-o=output] [-s] ...] [-source_path=path] [-test_path=path]`
26+
27+
# Parameters
28+
29+
```
30+
user - username to connect as
31+
password - password of the user
32+
database - database to connect to
33+
-p=suite_path(s) - A suite path or a comma separated list of suite paths for unit test to be executed.
34+
The path(s) can be in one of the following formats:
35+
schema[.package[.procedure]]
36+
schema:suite[.suite[.suite][...]][.procedure]
37+
Both formats can be mixed in the list.
38+
If only schema is provided, then all suites owner by that schema are executed.
39+
If -p is omitted, the current schema is used.
40+
-f=format - A reporter to be used for reporting.
41+
If no -f option is provided, the default ut_documentation_reporter is used.
42+
Available options:
43+
-f=ut_documentation_reporter
44+
A textual pretty-print of unit test results (usually use for console output)
45+
-f=ut_teamcity_reporter
46+
For reporting live progress of test execution with Teamcity CI.
47+
-f=ut_xunit_reporter
48+
Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity.
49+
-f=ut_coverage_html_reporter
50+
Generates a HTML coverage report with summary and line by line information on code coverage.
51+
Based on open-source simplecov-html coverage reporter for Ruby.
52+
Includes source code in the report.
53+
-f=ut_coveralls_reporter
54+
Generates a JSON coverage report providing information on code coverage with line numbers.
55+
Designed for [Coveralls](https://coveralls.io/).
56+
-f=ut_coverage_sonar_reporter
57+
Generates a JSON coverage report providing information on code coverage with line numbers.
58+
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
59+
-f=ut_sonar_test_reporter
60+
Generates a JSON report providing detailed information on test execution.
61+
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.
62+
63+
-o=output - Defines file name to save the output from the specified reporter.
64+
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
65+
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
66+
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
67+
-s - Forces putting output to to screen for a given -f parameter.
68+
-source_path=path - Path to project source files. Used by coverage reporters. The path needs to be relative to the projects root directory.
69+
-test_path=path - Path to unit test source files. Used by test reporters. The path needs to be relative to the projects root directory.
70+
-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards.
71+
Works only on reporeters that support colors (ut_documentation_reporter)
72+
```
73+
74+
Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter.
75+
76+
**Sonar and Coveralls reporter will only provide valid reports, when source_path and/or test_path are provided, and ut_run is executed from your project's root path.**
77+
78+
Examples:
79+
80+
`ut_run hr/hr@xe -p=hr_test -f=ut_documentation_reporter -o=run.log -s -f=ut_coverage_html_reporter -o=coverage.html -source_path=source`
81+
82+
Invokes all Unit tests from schema/package "hr_test" with two reporters:
83+
84+
- ut_documentation_reporter - will output to screen and save output to file "run.log"
85+
- ut_coverage_html_reporter - will report **only** on database objects that are mapping to file structure from "source" folder and save output to file "coverage.html"
86+
87+
88+
`ut_run hr/hr@xe`
89+
90+
Invokes all unit test suites from schema "hr".
91+
Results are displayed to screen using default `ut_documentation_reporter`.
92+
93+
**Enabling color outputs on Windows**
94+
95+
To enable color outputs from SQLPlus on winddows you need to install an open-source utility called [ANSICON](http://adoxa.altervista.org/ansicon/)

file_list

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# All parameters are required. This way, users can't pass empty string as parameter.
5+
invalidArgs=0
6+
[ -z "$1" ] && invalidArgs=1
7+
[ -z "$2" ] && invalidArgs=1
8+
[ -z "$3" ] && invalidArgs=1
9+
10+
if [ $invalidArgs -eq 1 ]; then
11+
echo Usage: ut_run.sh "project_path" "sql_param_name" "output_file" "scan_path"
12+
exit 1
13+
fi
14+
15+
# Remove trailing slashes.
16+
projectPath=${1%/}
17+
sqlParamName=$2
18+
outputFile=$3
19+
scanPath=$4
20+
21+
fullScanPath="$projectPath/$scanPath"
22+
23+
if [ ! -d "$fullScanPath" ] || [ -z "$4" ]; then
24+
echo "begin" > $outputFile
25+
echo " open :$sqlParamName for select null from dual where 1= 0;" >> $outputFile
26+
echo "end;" >> $outputFile
27+
echo "/" >> $outputFile
28+
exit 0
29+
fi
30+
31+
echo "declare" > $outputFile
32+
echo " l_list ut_varchar2_list := ut_varchar2_list();" >> $outputFile
33+
echo "begin" >> $outputFile
34+
for f in $(find $fullScanPath/* -type f | sed "s|$projectPath/||"); do
35+
echo " l_list.extend; l_list(l_list.last) := '$f';" >> $outputFile
36+
done
37+
echo " open :$sqlParamName for select * from table(l_list);" >> $outputFile
38+
echo "end;" >> $outputFile
39+
echo "/" >> $outputFile

file_list.bat

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@echo off
2+
setlocal EnableDelayedExpansion
3+
4+
REM All parameters are required. This way, users can't pass empty string as parameter.
5+
set invalidArgs=0
6+
set pathNotProvided=0
7+
if [%1] == "" set invalidArgs=1
8+
if [%2] == "" set invalidArgs=1
9+
if [%3] == "" set invalidArgs=1
10+
11+
if %invalidArgs% == 1 (
12+
echo Usage: ut_run.bat "project_path" "sql_param_name" "output_file" "scan_path"
13+
exit /b 1
14+
)
15+
REM Expand relative path from parameter to be a full path
16+
set projectPath=%~f1
17+
set sqlParamName=%~2
18+
set outputFile=%~3
19+
set scanPath=%~4
20+
21+
REM Remove trailing slashes.
22+
if %projectPath:~-1%==\ set projectPath=%projectPath:~0,-1%
23+
if [%scanPath%] == [] (set pathNotProvided=1) else (set "fullScanPath=%projectPath%\%scanPath%")
24+
if not exist "%fullScanPath%\*" set pathNotProvided=1
25+
26+
if %pathNotProvided% == 1 (
27+
echo begin>%outputFile%
28+
echo ^ open :%sqlParamName% for select null from dual where 1 = 0;>>%outputFile%
29+
echo end;>>%outputFile%
30+
echo />>%outputFile%
31+
exit /b 0
32+
)
33+
34+
echo declare>%outputFile%
35+
echo ^ l_list ut_varchar2_list := ut_varchar2_list();>>%outputFile%
36+
echo begin>>%outputFile%
37+
for /f "tokens=* delims= " %%a in ('dir %fullScanPath%\* /B /S /A:-D') do (
38+
set "filePath=%%a"
39+
set filePath=!filePath:%projectPath%\=!
40+
echo ^ l_list.extend; l_list^(l_list.last^) := '!filePath!^';>>%outputFile%
41+
)
42+
echo ^ open :%sqlParamName% for select * from table(l_list);>>%outputFile%
43+
echo end;>>%outputFile%
44+
echo />>%outputFile%

ut_run

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
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 [[ "$#" -eq 0 ]] ; 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" "$@"

ut_run.bat

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@echo off
2+
3+
set clientDir=%~dp0
4+
set projectDir=%__CD__%
5+
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%' %*

0 commit comments

Comments
 (0)