Skip to content

Commit

Permalink
Moved client command line utility from utPLSQL main project.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgebal committed May 17, 2017
1 parent 43f2637 commit 5aef96d
Show file tree
Hide file tree
Showing 7 changed files with 682 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/
.sonar/
site/
pages/
release/
*.gz
*.zip
node_modules/
95 changes: 94 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,95 @@
# utPLSQL-sql-cli
A bash/windows command-line client for utPLSQL v3

Bash & windows command-line client for [utPLSQL v3](https://github.com/utPLSQL/utPLSQL/)

Provides an easy way of invoking utPLSQL from command-line.
Main features:

- Provides outputs from first reporter in real-time, so you can see the progress of your test execution
- Ability to run tests with multiple reporters simultaneously
- Ability to save output from every individual reporter to separate output file
- Provides coloured outputs
- Maps project and test files to database objects for reporting purposes
- Allows execution of selected suites, subset of suite

# Requirements

The scripts require `sqlplus` to be installed and configured to be in your PATH.

When using reporters for Sonar or Coveralls the the `ut_run.bat`/`ut_run` script needs to be invoked from project's root directory.

Number of script parameters cannot exceed 39.

# Script Invocation

`ut_run user/password@database [-p=(ut_path|ut_paths)] [-c] [-f=format [-o=output] [-s] ...] [-source_path=path] [-test_path=path]`

# Parameters

```
user - username to connect as
password - password of the user
database - database to connect to
-p=suite_path(s) - A suite path or a comma separated list of suite paths for unit test to be executed.
The path(s) can be in one of the following formats:
schema[.package[.procedure]]
schema:suite[.suite[.suite][...]][.procedure]
Both formats can be mixed in the list.
If only schema is provided, then all suites owner by that schema are executed.
If -p is omitted, the current schema is used.
-f=format - A reporter to be used for reporting.
If no -f option is provided, the default ut_documentation_reporter is used.
Available options:
-f=ut_documentation_reporter
A textual pretty-print of unit test results (usually use for console output)
-f=ut_teamcity_reporter
For reporting live progress of test execution with Teamcity CI.
-f=ut_xunit_reporter
Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity.
-f=ut_coverage_html_reporter
Generates a HTML coverage report with summary and line by line information on code coverage.
Based on open-source simplecov-html coverage reporter for Ruby.
Includes source code in the report.
-f=ut_coveralls_reporter
Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [Coveralls](https://coveralls.io/).
-f=ut_coverage_sonar_reporter
Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
-f=ut_sonar_test_reporter
Generates a JSON report providing detailed information on test execution.
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.
-o=output - Defines file name to save the output from the specified reporter.
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
-s - Forces putting output to to screen for a given -f parameter.
-source_path=path - Path to project source files. Used by coverage reporters. The path needs to be relative to the projects root directory.
-test_path=path - Path to unit test source files. Used by test reporters. The path needs to be relative to the projects root directory.
-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards.
Works only on reporeters that support colors (ut_documentation_reporter)
```

Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter.

**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.**

Examples:

`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`

Invokes all Unit tests from schema/package "hr_test" with two reporters:

- ut_documentation_reporter - will output to screen and save output to file "run.log"
- 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"


`ut_run hr/hr@xe`

Invokes all unit test suites from schema "hr".
Results are displayed to screen using default `ut_documentation_reporter`.

**Enabling color outputs on Windows**

To enable color outputs from SQLPlus on winddows you need to install an open-source utility called [ANSICON](http://adoxa.altervista.org/ansicon/)
39 changes: 39 additions & 0 deletions file_list
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -e

# All parameters are required. This way, users can't pass empty string as parameter.
invalidArgs=0
[ -z "$1" ] && invalidArgs=1
[ -z "$2" ] && invalidArgs=1
[ -z "$3" ] && invalidArgs=1

if [ $invalidArgs -eq 1 ]; then
echo Usage: ut_run.sh "project_path" "sql_param_name" "output_file" "scan_path"
exit 1
fi

# Remove trailing slashes.
projectPath=${1%/}
sqlParamName=$2
outputFile=$3
scanPath=$4

fullScanPath="$projectPath/$scanPath"

if [ ! -d "$fullScanPath" ] || [ -z "$4" ]; then
echo "begin" > $outputFile
echo " open :$sqlParamName for select null from dual where 1= 0;" >> $outputFile
echo "end;" >> $outputFile
echo "/" >> $outputFile
exit 0
fi

echo "declare" > $outputFile
echo " l_list ut_varchar2_list := ut_varchar2_list();" >> $outputFile
echo "begin" >> $outputFile
for f in $(find $fullScanPath/* -type f | sed "s|$projectPath/||"); do
echo " l_list.extend; l_list(l_list.last) := '$f';" >> $outputFile
done
echo " open :$sqlParamName for select * from table(l_list);" >> $outputFile
echo "end;" >> $outputFile
echo "/" >> $outputFile
44 changes: 44 additions & 0 deletions file_list.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@echo off
setlocal EnableDelayedExpansion

REM All parameters are required. This way, users can't pass empty string as parameter.
set invalidArgs=0
set pathNotProvided=0
if [%1] == "" set invalidArgs=1
if [%2] == "" set invalidArgs=1
if [%3] == "" set invalidArgs=1

if %invalidArgs% == 1 (
echo Usage: ut_run.bat "project_path" "sql_param_name" "output_file" "scan_path"
exit /b 1
)
REM Expand relative path from parameter to be a full path
set projectPath=%~f1
set sqlParamName=%~2
set outputFile=%~3
set scanPath=%~4

REM Remove trailing slashes.
if %projectPath:~-1%==\ set projectPath=%projectPath:~0,-1%
if [%scanPath%] == [] (set pathNotProvided=1) else (set "fullScanPath=%projectPath%\%scanPath%")
if not exist "%fullScanPath%\*" set pathNotProvided=1

if %pathNotProvided% == 1 (
echo begin>%outputFile%
echo ^ open :%sqlParamName% for select null from dual where 1 = 0;>>%outputFile%
echo end;>>%outputFile%
echo />>%outputFile%
exit /b 0
)

echo declare>%outputFile%
echo ^ l_list ut_varchar2_list := ut_varchar2_list();>>%outputFile%
echo begin>>%outputFile%
for /f "tokens=* delims= " %%a in ('dir %fullScanPath%\* /B /S /A:-D') do (
set "filePath=%%a"
set filePath=!filePath:%projectPath%\=!
echo ^ l_list.extend; l_list^(l_list.last^) := '!filePath!^';>>%outputFile%
)
echo ^ open :%sqlParamName% for select * from table(l_list);>>%outputFile%
echo end;>>%outputFile%
echo />>%outputFile%
17 changes: 17 additions & 0 deletions ut_run
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

clientDir="$(dirname "$(readlink -f "$0")")"
projectDir="$(pwd)"

if [[ "$clientDir" != "${clientDir% *}" ]]; then
echo "Error: ut_run script path cannot have spaces."
exit 1
fi

if [[ "$#" -eq 0 ]] ; then
echo "Usage: ut_run user/password@database [options...]"
exit 1
fi

sqlplus /nolog @"$clientDir/ut_run.sql" "$clientDir" "$projectDir" "$@"
16 changes: 16 additions & 0 deletions ut_run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@echo off

set clientDir=%~dp0
set projectDir=%__CD__%

if not "%clientDir%" == "%clientDir: =%" (
echo Error: ut_run script path cannot have spaces.
exit /b 1
)

if "%1" == "" (
echo Usage: ut_run user/password@database [options...]
exit /b 1
)

sqlplus /nolog @"%clientDir%\ut_run.sql" '%clientDir%' '%projectDir%' %*
Loading

0 comments on commit 5aef96d

Please sign in to comment.