diff --git a/.travis.yml b/.travis.yml index 2293bf983..5da14e7a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,16 +5,13 @@ addons: apt: packages: - unzip - # Java8 Required for Sonar and SQLCL - - oracle-java8-installer - - oracle-java8-set-default + # Java9 Required for Sonar and SQLCL + - oracle-java9-installer + - oracle-java9-set-default sonarcloud: organization: utplsql token: secure: ${SONAR_TOKEN} - branches: - - develop - - master services: - docker @@ -46,14 +43,14 @@ env: - DOCKHER_HUB_REPO="${DOCKER_BASE_TAG:-$UT3_DOCKER_REPO}" #utPLSQL released version directory - UTPLSQL_DIR="utPLSQL_latest_release" - - SELFTESTING_BRANCH="develop" + - SELFTESTING_BRANCH=${TRAVIS_BRANCH} - UTPLSQL_CLI_VERSION="3.1.0" # Maven - MAVEN_HOME=/usr/local/maven - MAVEN_CFG=$HOME/.m2 matrix: - - ORACLE_VERSION="${DOCKER_TAG_11G:-11g-r2-xe}" CONNECTION_STR='127.0.0.1:1521/XE' DOCKER_OPTIONS='--shm-size=1g' - - ORACLE_VERSION="${DOCKER_TAG_12C:-12c-r1-se2}" CONNECTION_STR='127.0.0.1:1521/ORCLPDB1' DOCKER_OPTIONS="-v /dev/pdbs:/opt/oracle/oradata/pdbs" + - ORACLE_VERSION="${DOCKER_TAG_11G:-11g-r2-xe}" CONNECTION_STR='127.0.0.1:1521/XE' DOCKER_OPTIONS='--shm-size=1g' + - ORACLE_VERSION="${DOCKER_TAG_12C:-12c-r1-se2}" CONNECTION_STR='127.0.0.1:1521/ORCLPDB1' DOCKER_OPTIONS="-v /dev/pdbs:/opt/oracle/oradata/pdbs" - ORACLE_VERSION="${DOCKER_TAG_12C2:-12c-r2-se2}" CONNECTION_STR='127.0.0.1:1521/ORCLPDB1' DOCKER_OPTIONS="-v /dev/pdbs:/opt/oracle/oradata/pdbs" cache: @@ -64,12 +61,10 @@ cache: - $MAVEN_CFG before_install: - #The update_project_version is done before deployment to validate that the change of project files does not break installation + #The update_project_version.sh is done before deployment to validate that the change of project files does not break installation - bash .travis/update_project_version.sh - - git config --global user.email "builds@travis-ci.com" - - git config --global user.name "${UTPLSQL_BUILD_USER_NAME}" - - git remote rm origin - - git remote add origin https://${github_api_token}@github.com/${UTPLSQL_REPO} + #Allow for sonar to blame issues + - git fetch --unshallow # download latest utPLSQL release #- curl -LOk $(curl --silent https://api.github.com/repos/utPLSQL/utPLSQL/releases/latest | awk '/browser_download_url/ { print $2 }' | grep ".zip" | sed 's/"//g') - git clone --depth=1 --branch=${SELFTESTING_BRANCH:-master} https://github.com/utPLSQL/utPLSQL.git $UTPLSQL_DIR @@ -81,45 +76,24 @@ install: - unzip utPLSQL-cli.zip && chmod -R u+x utPLSQL-cli # Get ojdbc via maven - bash .travis/maven_cfg.sh - - pip install mkdocs - bash .travis/install_sqlcl.sh - sudo mkdir -p /dev/pdbs - sudo chmod -R 777 /dev/pdbs + - df -h - if [[ ! $TRAVIS_TAG ]]; then bash .travis/start_db.sh; fi - df -h before_script: - if [[ ! $TRAVIS_TAG ]]; then bash .travis/install.sh; fi - if [[ ! $TRAVIS_TAG ]]; then bash .travis/install_utplsql_release.sh; fi - - if [[ ! $TRAVIS_TAG ]]; then bash .travis/create_additional_grants_for_old_tests.sh; fi - if [[ ! $TRAVIS_TAG ]]; then bash .travis/run_examples.sh; fi - if [[ ! $TRAVIS_TAG ]]; then bash .travis/run_old_tests.sh; fi script: - if [[ ! $TRAVIS_TAG ]]; then bash test/install_and_run_tests.sh; fi - - if [[ ! $TRAVIS_TAG ]] && [ "${TRAVIS_REPO_SLUG}" = "${UTPLSQL_REPO}" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then sonar-scanner; fi + - if [[ ! $TRAVIS_TAG ]]; then bash .travis/validate_report_files.sh; fi + - if [[ ! $TRAVIS_TAG ]] && [ "${TRAVIS_REPO_SLUG}" = "${UTPLSQL_REPO}" ]; then bash .travis/run_sonar_scanner.sh; fi - if [[ ! $TRAVIS_TAG ]]; then bash .travis/coveralls_uploader.sh; fi - - bash .travis/build_docs.sh - - if [[ ! $TRAVIS_TAG ]]; then bash .travis/push_release_version.sh; fi - - bash .travis/push_docs_to_gh_pages.sh - -before_deploy: - - bash .travis/build_release_archive.sh - -deploy: - provider: releases - api_key: $github_api_token - file: - - utPLSQL.zip - - utPLSQL.tar.gz - - utPLSQL.zip.md5 - - utPLSQL.tar.gz.md5 - skip_cleanup: true - on: - repo: ${UTPLSQL_REPO} - tags: true - # when building from a release tag, use only first job "#xxx.1" to publish artifacts - condition: "${TRAVIS_JOB_NUMBER} =~ \\.1$" notifications: slack: @@ -127,3 +101,37 @@ notifications: - secure: "nemt9n2y5sVCAKqa/s7JDQ8AcM59Xu/XbH/RkMOXvPgc+KtR8lBtVD1LkvJ5BaQhqgjuDT7DNt/uisQJ7k6a2OsrVFbnkypZ1hCvntOBpJyoSpD/YL1X8a9GbGojuJcph0BX76KN21LaOVdyOfY0TSlw53XiYWS8iL5HtjpWCbIwHL1SJ8JT8mhdT4hDoUWZjcZ4s4bLH6BQm4un/bMQOmB4sDoCeg4CllJwxgkswVF7OHpOFjgPetvUp7ps8b/Rj8en6zCj9drb0SVbXFgumo2Wd1bC3HHZB8MAZU0kuEV5VgUdum6EelUL5yfB72hssNQA0+CaT3HjBFkTlqWYJmjC4/xyGN3sseiW82T9FDY0g0GAGayNRW+QSiTQ1hbJEcAnNe0GrBUdRsgXdI6COd76YP5VxzRSF6H7niLfgCZdKbIivKUd1o+wBhuyJmqCFIkRWmT38tMGJqJAzbY1jq5gQXbb6E7gt+KdTjlSjcnJYf7XI7zqm+BRr+fbA0ixfXHvfqOBgZN6g08y9nPlDnIjtSF2NSdrj2zqYQAtKuWSOD1bnTyfDJyrtK7OLffZcMYD5Bcss4c8op8tP7MGTjt1S046SJocboh6H4c/nTokpoMRsWs6MKRdebl8C2RObGf5FebSOJg+oh2ZYS5Z/G9GshiY2BD/81+Hc4Miacc=" on_success: change on_failure: always + +jobs: + include: + - stage: deploy + env: ORACLE_VERSION="none" + before_install: skip + install: + - pip install mkdocs + before_script: skip + script: + - if [[ ($TRAVIS_BRANCH == develop) && ($TRAVIS_PULL_REQUEST == false) ]]; then bash .travis/trigger_travis.sh $TRAVIS_ACCESS_TOKEN; fi + - #The update_project_version.sh needs to be done before pushing changes to develop branch + - bash .travis/update_project_version.sh + - git config --global user.email "builds@travis-ci.com" + - git config --global user.name "${UTPLSQL_BUILD_USER_NAME}" + - git remote rm origin + - git remote add origin https://${github_api_token}@github.com/${UTPLSQL_REPO} + - if [[ ! $TRAVIS_TAG ]]; then bash .travis/push_release_version.sh; fi + - bash .travis/build_docs.sh + - bash .travis/push_docs_to_gh_pages.sh + before_deploy: + - bash .travis/build_release_archive.sh + deploy: + provider: releases + api_key: $github_api_token + file: + - utPLSQL.zip + - utPLSQL.tar.gz + - utPLSQL.zip.md5 + - utPLSQL.tar.gz.md5 + skip_cleanup: true + on: + repo: ${UTPLSQL_REPO} + tags: true diff --git a/.travis/create_additional_grants_for_old_tests.sh b/.travis/create_additional_grants_for_old_tests.sh deleted file mode 100644 index c07bfc4a7..000000000 --- a/.travis/create_additional_grants_for_old_tests.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -cd source -set -ev - -#additional privileges to run scripted tests -"$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA <<-SQL -set feedback on ---needed for Mystats script to work -grant select any dictionary to $UT3_OWNER; ---Needed for testing a coverage outside ut3_owner. -grant create any procedure, drop any procedure, execute any procedure to $UT3_OWNER; - -exit -SQL - -#Create additional users -"$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA <<-SQL -set feedback off -@create_utplsql_owner.sql $UT3_USER $UT3_USER_PASSWORD $UT3_TABLESPACE - -exit -SQL \ No newline at end of file diff --git a/.travis/install.sh b/.travis/install.sh index 0cc3400dc..bb99a0e2d 100644 --- a/.travis/install.sh +++ b/.travis/install.sh @@ -11,6 +11,37 @@ alter session set plsql_warnings = 'ENABLE:ALL', 'DISABLE:(5004,5018,6000,6001,6 @install_headless.sql $UT3_OWNER $UT3_OWNER_PASSWORD SQL +#uninstall core of utplsql +"$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA <<-SQL +set feedback off +set verify off + +@uninstall_all.sql $UT3_OWNER +declare + v_leftover_objects_count integer; +begin + select sum(cnt) + into v_leftover_objects_count + from (select count(1) cnt from dba_objects where owner = '$UT3_OWNER' + union all + select count(1) cnt from dba_synonyms where table_owner = '$UT3_OWNER' + ); + if v_leftover_objects_count > 0 then + raise_application_error(-20000, 'Not all objects were successfully uninstalled - leftover objects count='||v_leftover_objects_count); + end if; +end; +/ +SQL + +#reinstall core of utplsql +"$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA <<-SQL +set feedback off +set verify off + +alter session set plsql_warnings = 'ENABLE:ALL', 'DISABLE:(5004,5018,6000,6001,6003,6009,6010,7206)'; +@install.sql $UT3_OWNER +SQL + #additional privileges to run scripted tests "$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA <<-SQL set feedback on @@ -38,3 +69,30 @@ revoke execute on dbms_crypto from $UT3_TESTER; grant create job to $UT3_TESTER; exit SQL + +#additional privileges to run tests +"$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA <<-SQL +set feedback on +--needed for Mystats script to work +grant select any dictionary to $UT3_OWNER; +--Needed for testing a coverage outside ut3_owner. +grant create any procedure, drop any procedure, execute any procedure to $UT3_OWNER; + +exit +SQL + +#Create additional users +"$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA <<-SQL +set feedback off +@create_utplsql_owner.sql $UT3_USER $UT3_USER_PASSWORD $UT3_TABLESPACE + +exit +SQL + +#Grant UT3 framework to UT3$USER# +"$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA <<-SQL +set feedback off +@create_user_grants.sql $UT3_OWNER $UT3_USER + +exit +SQL diff --git a/.travis/lib/xml_validator.jar b/.travis/lib/xml_validator.jar new file mode 100644 index 000000000..ccac6370b Binary files /dev/null and b/.travis/lib/xml_validator.jar differ diff --git a/.travis/push_docs_to_gh_pages.sh b/.travis/push_docs_to_gh_pages.sh index 86ee00310..d2c5a685c 100644 --- a/.travis/push_docs_to_gh_pages.sh +++ b/.travis/push_docs_to_gh_pages.sh @@ -17,87 +17,85 @@ PAGES_TARGET_BRANCH="gh-pages" LATEST_DOCS_BRANCH="develop" # TRAVIS_* variables are set by travis directly and only need to be if testing externally -# Since we are running job matrix, only thie first job slave will need to do the work -if [[ "${TRAVIS_JOB_NUMBER}" =~ \.1$ ]]; then - # We don't want a pull request automatically updating the repository - if [ "$TRAVIS_PULL_REQUEST" == "false" ] && { [ "${CURRENT_BRANCH}" == "${LATEST_DOCS_BRANCH}" ] || [ -n "${TRAVIS_TAG}" ]; }; then +# We don't want a pull request automatically updating the repository +if [ "$TRAVIS_PULL_REQUEST" == "false" ] && { [ "${CURRENT_BRANCH}" == "${LATEST_DOCS_BRANCH}" ] || [ -n "${TRAVIS_TAG}" ]; }; then - # ENV Variable checks are to help with configuration troubleshooting, they silently exit with unique message. - # Anyone one of them not set can be used to turn off this functionality. + # ENV Variable checks are to help with configuration troubleshooting, they silently exit with unique message. + # Anyone one of them not set can be used to turn off this functionality. - # If a version of the project is not defined - [[ -n "${UTPLSQL_VERSION}" ]] || { echo "variable UTPLSQL_VERSION is not defines or missing value"; exit 0; } - # Fail if the markdown documentation is not present. - [[ -f ./docs/index.md ]] || { echo "file docs/index.md not found"; exit 1; } + # If a version of the project is not defined + [[ -n "${UTPLSQL_VERSION}" ]] || { echo "variable UTPLSQL_VERSION is not defines or missing value"; exit 0; } + # Fail if the markdown documentation is not present. + [[ -f ./docs/index.md ]] || { echo "file docs/index.md not found"; exit 1; } - # Save some useful information - SHA=`git rev-parse --verify HEAD` + # Save some useful information + SHA=`git rev-parse --verify HEAD` - # clone the repository and switch to PAGES_TARGET_BRANCH branch - mkdir pages - cd pages - git clone https://${github_api_token}@github.com/${UTPLSQL_REPO} . + # clone the repository and switch to PAGES_TARGET_BRANCH branch + mkdir pages + cd pages + git clone https://${github_api_token}@github.com/${UTPLSQL_REPO} . - PAGES_BRANCH_EXISTS=$(git ls-remote --heads origin ${PAGES_TARGET_BRANCH}) + PAGES_BRANCH_EXISTS=$(git ls-remote --heads origin ${PAGES_TARGET_BRANCH}) - if [ -n "$PAGES_BRANCH_EXISTS" ] ; then - echo "Pages Branch Found" - git checkout ${PAGES_TARGET_BRANCH} - else - echo "Creating Pages Branch" - git checkout --orphan ${PAGES_TARGET_BRANCH} - git rm -rf . - fi - #clear out develop documentation directory and copy docs contents to it. - echo "updating 'develop' directory" - mkdir -p develop - rm -rf develop/**./* || exit 0 - cp -a ../docs/. ./develop - # If a Tagged Build then copy to it's own directory as well and to the 'latest' release directory - if [ -n "$TRAVIS_TAG" ]; then - echo "Creating ${UTPLSQL_VERSION}" - mkdir -p ${UTPLSQL_VERSION} - rm -rf ${UTPLSQL_VERSION}/**./* || exit 0 - cp -a ../docs/. ${UTPLSQL_VERSION} - echo "Populating 'latest' directory" - mkdir -p latest - rm -rf latest/**./* || exit 0 - cp -a ../docs/. latest - fi - # Stage changes for commit - git add . - #Check if there are doc changes, if none exit the script - if [[ -z `git diff HEAD --exit-code` ]] && [ -n "${PAGES_BRANCH_EXISTS}" ] ; then - echo "No changes to docs detected." - exit 0 - fi - #Changes where detected, so we need to update the version log. - now=$(date +"%d %b %Y - %r") - if [ ! -f index.md ]; then - echo "---" >>index.md - echo "layout: default" >>index.md - echo "---" >>index.md - echo "" >>index.md - echo "# Documentation versions" >>index.md - echo "" >>index.md - echo "" >>index.md #- 7th line - placeholder for latest release doc - echo "" >>index.md #- 8th line - placeholder for develop branch doc - echo "" >>index.md - echo "## Released Version Doc History" >>index.md - echo "" >>index.md - fi - #If build running on a TAG - it's a new release - need to add it to documentation - if [ -n "${TRAVIS_TAG}" ]; then - sed -i '7s@.*@'" - [Latest ${TRAVIS_TAG} documentation](latest/) - Created $now"'@' index.md - #add entry to the top of version history (line end of file - ## Released Version Doc History - sed -i '12i'" - [${TRAVIS_TAG} documentation](${UTPLSQL_VERSION}/) - Created $now" index.md - fi - #replace 4th line in log - sed -i '8s@.*@'" - [Latest development version](develop/) - Created $now"'@' index.md - #Add and Commit the changes back to pages repo. - git add . - git commit -m "Deploy to gh-pages branch: base commit ${SHA}" - # Now that we're all set up, we can push. - git push --quiet origin HEAD:${PAGES_TARGET_BRANCH} + if [ -n "$PAGES_BRANCH_EXISTS" ] ; then + echo "Pages Branch Found" + git checkout ${PAGES_TARGET_BRANCH} + else + echo "Creating Pages Branch" + git checkout --orphan ${PAGES_TARGET_BRANCH} + git rm -rf . fi + #clear out develop documentation directory and copy docs contents to it. + echo "updating 'develop' directory" + mkdir -p develop + rm -rf develop/**./* || exit 0 + cp -a ../docs/. ./develop + # If a Tagged Build then copy to it's own directory as well and to the 'latest' release directory + if [ -n "$TRAVIS_TAG" ]; then + echo "Creating ${UTPLSQL_VERSION}" + mkdir -p ${UTPLSQL_VERSION} + rm -rf ${UTPLSQL_VERSION}/**./* || exit 0 + cp -a ../docs/. ${UTPLSQL_VERSION} + echo "Populating 'latest' directory" + mkdir -p latest + rm -rf latest/**./* || exit 0 + cp -a ../docs/. latest + fi + # Stage changes for commit + git add . + #Check if there are doc changes, if none exit the script + if [[ -z `git diff HEAD --exit-code` ]] && [ -n "${PAGES_BRANCH_EXISTS}" ] ; then + echo "No changes to docs detected." + exit 0 + fi + #Changes where detected, so we need to update the version log. + now=$(date +"%d %b %Y - %r") + if [ ! -f index.md ]; then + echo "---" >>index.md + echo "layout: default" >>index.md + echo "---" >>index.md + echo "" >>index.md + echo "# Documentation versions" >>index.md + echo "" >>index.md + echo "" >>index.md #- 7th line - placeholder for latest release doc + echo "" >>index.md #- 8th line - placeholder for develop branch doc + echo "" >>index.md + echo "## Released Version Doc History" >>index.md + echo "" >>index.md + fi + #If build running on a TAG - it's a new release - need to add it to documentation + if [ -n "${TRAVIS_TAG}" ]; then + sed -i '7s@.*@'" - [Latest ${TRAVIS_TAG} documentation](latest/) - Created $now"'@' index.md + #add entry to the top of version history (line end of file - ## Released Version Doc History + sed -i '12i'" - [${TRAVIS_TAG} documentation](${UTPLSQL_VERSION}/) - Created $now" index.md + fi + #replace 4th line in log + sed -i '8s@.*@'" - [Latest development version](develop/) - Created $now"'@' index.md + #Add and Commit the changes back to pages repo. + git add . + git commit -m "Deploy to gh-pages branch: base commit ${SHA}" + # Now that we're all set up, we can push. + git push --quiet origin HEAD:${PAGES_TARGET_BRANCH} fi + diff --git a/.travis/push_release_version.sh b/.travis/push_release_version.sh index d0288f418..43ca773d8 100644 --- a/.travis/push_release_version.sh +++ b/.travis/push_release_version.sh @@ -5,19 +5,13 @@ # - branch name is = develop or branch name is like release/vX.X.X... if [ "${TRAVIS_REPO_SLUG}" = "${UTPLSQL_REPO}" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [[ "${CURRENT_BRANCH}" =~ ^(release/v[0-9]+\.[0-9]+\.[0-9]+.*|develop)$ ]]; then echo Current branch is "${CURRENT_BRANCH}" - echo Current job number is "${TRAVIS_JOB_NUMBER}" - #The publishing is done only once (for first job on a build matrix) - if [[ "${TRAVIS_JOB_NUMBER}" =~ \.1$ ]]; then - echo "Committing version & buildNo into branch (${CURRENT_BRANCH})" - git add sonar-project.properties - git add VERSION - git add source/* - git commit -m 'Updated project version after build [skip ci]' - echo "Pushing to origin" - git push --quiet origin HEAD:${CURRENT_BRANCH} - else - echo "Publishing of version skipped for job No.: ${TRAVIS_JOB_NUMBER}" - fi + echo "Committing version & buildNo into branch (${CURRENT_BRANCH})" + git add sonar-project.properties + git add VERSION + git add source/* + git commit -m 'Updated project version after build [skip ci]' + echo "Pushing to origin" + git push --quiet origin HEAD:${CURRENT_BRANCH} else echo "Publishing of version skipped for branch ${CURRENT_BRANCH}, pull request ${TRAVIS_PULL_REQUEST}" fi diff --git a/.travis/run_sonar_scanner.sh b/.travis/run_sonar_scanner.sh new file mode 100755 index 000000000..5cad42e29 --- /dev/null +++ b/.travis/run_sonar_scanner.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +#Run Sonar based on conditions + +MAIN_DEV_BRANCH="develop" + +BRANCH_SONAR_PROPERTY="sonar.branch.name" +BRANCH_SONAR_TARGET_PROPERTY="sonar.branch.target" + +PR_SONAR_BRANCH_PROPERTY="sonar.pullrequest.branch" +PR_KEY_PROPERTY="sonar.pullrequest.key" +PR_SONAR_BASE_PROPERTY="sonar.pullrequest.base" +PR_SONAR_TOKEN_PROPERTY="sonar.pullrequest.github.token.secured" + +#Add property to file +function add_sonar_property { + echo "$1=$2" >> sonar-project.properties +} + + +if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then + BRANCH=$TRAVIS_BRANCH; + PR_BRANCH="" + echo "BRANCH=$BRANCH" +else + BRANCH=$TRAVIS_PULL_REQUEST_BRANCH + PR_BRANCH=$TRAVIS_BRANCH + echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$TRAVIS_PULL_REQUEST, BRANCH=$BRANCH" + +fi + + +#Are we running on utPLSQL repo and not an external PR? +echo "Check if we running from develop or on branch" +if [ "${TRAVIS_REPO_SLUG}" = "${UTPLSQL_REPO}" ] && [[ ! "${BRANCH}" =~ ^(release/v[0-9]+\.[0-9]+\.[0-9]+.*|"${MAIN_DEV_BRANCH}")$ ]]; then + + echo "" >> sonar-project.properties + if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then + echo "Updating sonar properties to include branch ${BRANCH}" + add_sonar_property "${BRANCH_SONAR_PROPERTY}" "${BRANCH}" + add_sonar_property "${BRANCH_SONAR_TARGET_PROPERTY}" "${MAIN_DEV_BRANCH}" + elif [ "${TRAVIS_PULL_REQUEST_SLUG}" = "${TRAVIS_REPO_SLUG}" ]; then + echo "Updating sonar properties to include pull request ${BRANCH}" + add_sonar_property "${PR_SONAR_TOKEN_PROPERTY}" "${GITHUB_TRAVISCI_TOKEN}" + add_sonar_property "${PR_SONAR_BRANCH_PROPERTY}" "${BRANCH}" + add_sonar_property "${PR_KEY_PROPERTY}" "${PR}" + add_sonar_property "${PR_SONAR_BASE_PROPERTY}" "${PR_BRANCH}" + else + echo "PR from external source no changes to properties." + fi +else + echo "No need to update sonar we building on release or develop" +fi + +#Execute Sonar scanner +sonar-scanner \ No newline at end of file diff --git a/.travis/trigger_travis.sh b/.travis/trigger_travis.sh new file mode 100644 index 000000000..039b00bbb --- /dev/null +++ b/.travis/trigger_travis.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# Trigger a new Travis-CI job. +# Ordinarily, a new Travis job is triggered when a commit is pushed to a +# GitHub repository. The trigger-travis.sh script provides a programmatic +# way to trigger a new Travis job. + +# To use this script to trigger a dependent build in Travis, do two things: +# +# 1. Set an environment variable TRAVIS_ACCESS_TOKEN by navigating to +# https://travis-ci.org/MYGITHUBID/MYGITHUBPROJECT/settings +# The TRAVIS_ACCESS_TOKEN environment variable will be set when Travis runs +# the job, but won't be visible to anyone browsing https://travis-ci.org/. +# + +echoerr() { echo "$@" 1>&2; } + +TRAVIS_URL=travis-ci.org +BRANCH=develop +USER="utPLSQL" +RESULT=1 +declare -a REPO_MATRIX=("utPLSQL-java-api" "utPLSQL-v2-v3-migration" "utPLSQL-cli" "utPLSQL-maven-plugin" "utPLSQL-demo-project") + +TOKEN=$1 + +if [ -n "$TRAVIS_REPO_SLUG" ] ; then + MESSAGE=",\"message\": \"Triggered by upstream build of $TRAVIS_REPO_SLUG commit "`git rev-parse --short HEAD`"\"" +else + MESSAGE=",\"message\": \"Triggered manually from shell\"" +fi + +# For debugging: +#echo "MESSAGE=$MESSAGE" + +body="{ +\"request\": { + \"branch\":\"$BRANCH\" + $MESSAGE +}}" + +for DOWNSTREAM_BUILD in "${REPO_MATRIX[@]}"; do + + curl -s -X POST \ + -H "Content-Type: application/json" \ + -H "Accept: application/json" \ + -H "Travis-API-Version: 3" \ + -H "Authorization: token ${TOKEN}" \ + -d "$body" \ + https://api.${TRAVIS_URL}/repo/${USER}%2F${DOWNSTREAM_BUILD}/requests \ + | tee ${DOWNSTREAM_BUILD}-output.txt + + if grep -q '"@type": "error"' ${DOWNSTREAM_BUILD}-output.txt; then + RESULT=0 + echoerr "" + echoerr "ERROR: Failed to start ${DOWNSTREAM_BUILD}" + echoerr "" + fi + if grep -q 'access denied' ${DOWNSTREAM_BUILD}-output.txt; then + RESULT=0 + echoerr "" + echoerr "ERROR: Failed to start ${DOWNSTREAM_BUILD} - access denied" + echoerr "" + fi + +done + +if [[ RESULT -eq 0 ]]; then + exit 1 +fi diff --git a/.travis/validate_report_files.sh b/.travis/validate_report_files.sh new file mode 100644 index 000000000..621297a0b --- /dev/null +++ b/.travis/validate_report_files.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +GL_VALID=1 +XSD_DIR="$TRAVIS_BUILD_DIR/.travis/xsd" +XML_JAR_DIR="$TRAVIS_BUILD_DIR/.travis/lib" +#XML Validator +XML_VALIDATOR="$XML_JAR_DIR/xml_validator.jar" +HTML_VALIDATOR_URL="https://validator.w3.org/nu/" + +HTML_FILENAME="coverage.html" +declare -A XML_FILES +XML_FILES["junit_test_results.xml"]="junit4.xsd" +XML_FILES["tfs_test_results.xml"]="junit_windy.xsd" + +function ValidateHtml { + EXCLUSION_REGEX=".*Element\s.?ol.?\snot\sallowed\sas\schild\sof\selement\s.?pre.*" + #HTML Validation API + VALIDATOR_OUT="gnu" + WARNING_REGEX="info warning:" + ERROR_REGEX="error:" + #Validate HTML + HTML_VALIDATION_RESULTS=$(curl -H "Content-Type: text/html; charset=utf-8" --data-binary @$1 "$HTML_VALIDATOR_URL?out=$VALIDATOR_OUT&filterpattern=$EXCLUSION_REGEX") + + ERROR_COUNT=$(echo "$HTML_VALIDATION_RESULTS" | grep -c "$ERROR_REGEX") + WARNING_COUNT=$(echo "$HTML_VALIDATION_RESULTS" | grep -c "$WARNING_REGEX") + + if [ "$ERROR_COUNT" -gt 0 ]; then + GL_VALID=0 + echo "" + echo "******************************" + echo "HTML File is invalid" + echo "There are $ERROR_COUNT errors, $WARNING_COUNT warning in $HTML_FILENAME" + echo "Please see results:" + echo "$HTML_VALIDATION_RESULTS" | grep "$ERROR_REGEX" + fi +} + +function ValidateXML() { + echo "Validate File $2 against schema $1" + VALIDATION_RESULT=$(java -jar $XML_VALIDATOR -s $1 $2 2>&1) + + if [ $? -ne 0 ]; then + GL_VALID=0 + echo "" + echo "******************************" + echo "XML is invalid" + echo "Please see results:" + echo "$VALIDATION_RESULT" + fi +} + +ValidateHtml "$HTML_FILENAME" + +for XMLFILE in "${!XML_FILES[@]}"; do + #echo "$XMLFILE" "${XML_FILES[$XMLFILE]}"; + ValidateXML "$XSD_DIR/${XML_FILES[$XMLFILE]}" "$XMLFILE" +done + +if [ $GL_VALID -ne 1 ]; then + echo "" + echo "******************************" + echo "Validation failed please see results above." + exit 1 +else + exit 0 +fi diff --git a/.travis/xsd/junit4.xsd b/.travis/xsd/junit4.xsd new file mode 100644 index 000000000..1142fb28d --- /dev/null +++ b/.travis/xsd/junit4.xsd @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.travis/xsd/junit_windy.xsd b/.travis/xsd/junit_windy.xsd new file mode 100644 index 000000000..fe134662a --- /dev/null +++ b/.travis/xsd/junit_windy.xsd @@ -0,0 +1,206 @@ + + + + + JUnit test result schema for the Apache Ant JUnit and JUnitReport tasks +Copyright © 2011, Windy Road Technology Pty. Limited +The Apache Ant JUnit XML Schema is distributed under the terms of the Apache License Version 2.0 http://www.apache.org/licenses/ +Permission to waive conditions of this license may be requested from Windy Road Support (http://windyroad.org/support). + + + + + + + + + + Contains an aggregation of testsuite results + + + + + + + + + + Derived from testsuite/@name in the non-aggregated documents + + + + + Starts at '0' for the first testsuite and is incremented by 1 for each following testsuite + + + + + + + + + + + + Contains the results of exexuting a testsuite + + + + + Properties (e.g., environment settings) set during test execution + + + + + + + + + + + + + + + + + + + + + + + + Indicates that the test errored. An errored test is one that had an unanticipated problem. e.g., an unchecked throwable; or a problem with the implementation of the test. Contains as a text node relevant data for the error, e.g., a stack trace + + + + + + + The error message. e.g., if a java exception is thrown, the return value of getMessage() + + + + + The type of error that occured. e.g., if a java execption is thrown the full class name of the exception. + + + + + + + + + Indicates that the test failed. A failure is a test which the code has explicitly failed by using the mechanisms for that purpose. e.g., via an assertEquals. Contains as a text node relevant data for the failure, e.g., a stack trace + + + + + + + The message specified in the assert + + + + + The type of the assert. + + + + + + + + + + Name of the test method + + + + + Full class name for the class the test method is in. + + + + + Time taken (in seconds) to execute the test + + + + + + + Data that was written to standard out while the test was executed + + + + + + + + + + Data that was written to standard error while the test was executed + + + + + + + + + + + Full class name of the test for non-aggregated testsuite documents. Class name without the package for aggregated testsuites documents + + + + + + + + + + when the test was executed. Timezone may not be specified. + + + + + Host on which the tests were executed. 'localhost' should be used if the hostname cannot be determined. + + + + + + + + + + The total number of tests in the suite + + + + + The total number of tests in the suite that failed. A failure is a test which the code has explicitly failed by using the mechanisms for that purpose. e.g., via an assertEquals + + + + + The total number of tests in the suite that errored. An errored test is one that had an unanticipated problem. e.g., an unchecked throwable; or a problem with the implementation of the test. + + + + + Time taken (in seconds) to execute the tests in the suite + + + + + + + + + diff --git a/VERSION b/VERSION index 903cd9f2a..d95827c3d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.1.1 +v3.1.2 diff --git a/development/install.sh b/development/install.sh index 42bc88d85..4104e2672 100755 --- a/development/install.sh +++ b/development/install.sh @@ -18,7 +18,3 @@ if ! .travis/install_utplsql_release.sh; then echo -e ${header}"\nFailed to install utPLSQL from branch ${SELFTESTING_BRANCH} into ${UT3_RELEASE_VERSION_SCHEMA}\n"${header} exit 1 fi -if ! .travis/create_additional_grants_for_old_tests.sh; then - echo -e ${header}"Failed to add grants needed old_tests\n"${header} - exit 1 -fi diff --git a/development/releasing.md b/development/releasing.md index 44fe4914c..added5a92 100644 --- a/development/releasing.md +++ b/development/releasing.md @@ -4,17 +4,19 @@ With every build, the build process on Travis updates files with an appropriate This step is performed, to confirm that the update of versions works properly. To create a release: - - create release branch and wait for release build to complete successfully - - merge release branch to master and wait for master build to complete successfully - - create a release from the master branch using github web page and populate release description using information found on the issues and pull requests for release + - create release branch from development branch and make sure to name the release branch: `release/vX.Y.Z` + - update, commit and push at least one file change in the release branch, to kickoff a Travis build + - wait for th build to complete successfully + - merge the release branch to master and wait for master build to complete successfully + - create a release from the master branch using [github releases page](https://github.com/utPLSQL/utPLSQL/releases) and populate release description using information found on the issues and pull requests since previous release. + To find issues closed after certain date use [advanced filters](https://help.github.com/articles/searching-issues-and-pull-requests/#search-by-open-or-closed-state) The following will happen: - - build executed on branch `release/v1.2.3-[something]` updates files `sonar-project.properties`, `VERSION` with project version derived from the release branch name + - build executed on branch `release/vX.Y.Z-[something]` updates files `sonar-project.properties`, `VERSION` with project version derived from the release branch name - changes to those two files are committed and pushed back to release branch by Travis - when a release is created, a new tag is added in on the repository and a tag build is executed - the documentation for new release is published on `utplsql.github.io` and installation archives are added to the tag. Note: -The released version does not provide access to un-versioned source files (the default zip file from GitHub is empty). The sources for release are provided in separate zip files delivered from the Travis build process. -This is because we do not keep version in our source files in develop branch. +The built zip files include HTML documentation generated from MD files. diff --git a/docs/index.md b/docs/index.md index 781048235..693c8076b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -16,7 +16,7 @@ The framework follows industry standards and best patterns of modern Unit Testin - [Using reporters](userguide/reporters.md) - [Reporting errors](userguide/exception-reporting.md) - [Code coverage](userguide/coverage.md) - - [Cheat-sheet](https://www.cheatography.com/jgebal/cheat-sheets/utplsql-v3/#downloads) + - [Cheat-sheet](https://www.cheatography.com/jgebal/cheat-sheets/utplsql-v3-1-2/#downloads) - About - [Project Details](about/project-details.md) - [License](about/license.md) diff --git a/docs/userguide/advanced_data_comparison.md b/docs/userguide/advanced_data_comparison.md index e1e5ee36c..3eb45fe50 100644 --- a/docs/userguide/advanced_data_comparison.md +++ b/docs/userguide/advanced_data_comparison.md @@ -7,7 +7,7 @@ utPLSQL expectations incorporates advanced data comparison options when comparin - nested table and varray Advanced data-comparison options are available for the [`equal`](expectations.md#equal) matcher. - + ## Syntax ``` @@ -23,6 +23,9 @@ Advanced data-comparison options are available for the [`equal`](expectations.md - `exclude(a_items varchar2)` - item or comma separated list of items to exclude - `include(a_items ut_varchar2_list)` - table of items to include - `exclude(a_items ut_varchar2_list)` - table of items to exclude + - `unordered` - perform compare on unordered set of data, return only missing or actual + - `join_by(a_columns varchar2)` - columns or comma seperated list of columns to join two cursors by + - `join_by(a_columns ut_varchar2_list)` - table of columns to join two cursors by Each item in the comma separated list can be: - a column name of cursor to be compared @@ -55,7 +58,7 @@ Columns 'ignore_me' and "ADate" will get excluded from cursor comparison. The cursor data is equal, when those columns are excluded. This option is useful in scenarios, when you need to exclude incomparable/unpredictable column data like CREATE_DATE of a record that is maintained by default value on a table column. - + ## Selecting columns for data comparison Consider the following example @@ -92,6 +95,135 @@ Only the columns 'RN', "A_Column" will be compared. Column 'SOME_COL' is exclude This option can be useful in scenarios where you need to narrow-down the scope of test so that the test is only focused on very specific data. +##Unordered + +Unordered option allows for quick comparison of two cursors without need of ordering them in any way. + +Result of such comparison will be limited to only information about row existing or not existing in given set without actual information about exact differences. + + + +```sql +procedure unordered_tst is + l_actual sys_refcursor; + l_expected sys_refcursor; +begin + open l_expected for select username, user_id from all_users + union all + select 'TEST' username, -600 user_id from dual + order by 1 desc; + open l_actual for select username, user_id from all_users + union all + select 'TEST' username, -610 user_id from dual + order by 1 asc; + ut.expect( l_actual ).to_equal( l_expected ).unordered; +end; +``` + + + +Above test will result in two differences of one row extra and one row missing. + + + +```sql + Diff: + Rows: [ 2 differences ] + Missing: TEST-600 + Extra: TEST-610 +``` + + + + + +## Join By option + +You can now join two cursors by defining a primary key or composite key that will be used to uniquely identify and compare rows. This option allows us to exactly show which rows are missing, extra and which are different without ordering clause. In the situation where the join key is not unique, join will partition set over rows with a same key and join on row number as well as given join key. The extra rows or missing will be presented to user as well as not matching rows. + +Join by option can be used in conjunction with include or exclude options. However if any of the join keys is part of exclude set, comparison will fail and report to user that sets could not be joined on specific key (excluded). + +```sql +procedure join_by_username is + l_actual sys_refcursor; + l_expected sys_refcursor; +begin + open l_expected for select username, user_id from all_users + union all + select 'TEST' username, -600 user_id from dual + order by 1 desc; + open l_actual for select username, user_id from all_users + union all + select 'TEST' username, -610 user_id from dual + order by 1 asc; + ut.expect( l_actual ).to_equal( l_expected ).join_by('USERNAME'); +end; +``` +This will show you difference in row 'TEST' regardless of order. + +```sql + Rows: [ 1 differences ] + PK TEST - Expected: -600 + PK TEST - Actual: -610 +``` + +Assumption is that join by is made by column name so that what will be displayed as part of results. + +Join by options currently doesn't support nested table inside cursor comparison, however is still possible to compare a collection as a whole. + +Example. + +```sql + procedure compare_collection_in_rec is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_annotated_object; + l_expected_tab ut3.ut_annotated_object; + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_actual_tab from dual; + + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_expected_tab from dual; + + --Arrange + open l_actual for select l_actual_tab as nested_table from dual; + + open l_expected for select l_expected_tab as nested_table from dual; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('NESTED_TABLE/ANNOTATIONS'); + + end; +``` + + + +In case when a there is detected collection inside cursor and we cannot join key. Comparison will present a failed joins and also a message about collection being detected. + +```sql +Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = 1 ] +Diff: + Unable to join sets: + Join key NESTED_TABLE/ANNOTATIONS/TEXT does not exists in expected + Join key NESTED_TABLE/ANNOTATIONS/TEXT does not exists in actual + Please make sure that your join clause is not refferring to collection element +``` + + + + + +**Please note that .join_by option will take longer to process due to need of parsing via primary keys.** + ## Defining item as XPath When using XPath expression, keep in mind the following: @@ -109,4 +241,4 @@ begin open l_actual for select rownum as rn, 'a' as "A_Column", 'x' SOME_COL, a.* from all_objects a where rownum < 4; ut.expect( l_actual ).to_equal( l_expected ).include( '/ROW/RN|/ROW/A_Column|/ROW/SOME_COL' ); end; -``` +``` diff --git a/docs/userguide/annotations.md b/docs/userguide/annotations.md index d1c495eb2..3b8f0a9dd 100644 --- a/docs/userguide/annotations.md +++ b/docs/userguide/annotations.md @@ -21,16 +21,20 @@ We strongly recommend putting package level annotations at the very top of packa | `--%suitepath()` | Package | Similar to java package. The annotation allows logical grouping of suites into hierarchies. | | `--%displayname()` | Package/procedure | Human-readable and meaningful description of a suite/test. `%displayname(Name of the suite/test)`. The annotation is provided for flexibility and convenience only. It has exactly the same meaning as `` in `test` and `suite` annotations. If description is provided using both `suite`/`test` and `displayname`, then the one defined as last takes precedence. | | `--%test()` | Procedure | Denotes that the annotated procedure is a unit test procedure. Optional test description can by provided (see `displayname`). | -| `--%throws([,[,...]])`| Procedure | Denotes that the annotated procedure must throw one of the exception numbers provided. If no valid numbers were provided as annotation parameters the annotation is ignored. Applicable to test procedures only. | +| `--%throws([,...])`| Procedure | Denotes that the annotated test procedure must throw one of the exceptions provided. Supported forms of exceptions are: numeric literals, numeric contant names, exception constant names, predefined Oracle exception names. | | `--%beforeall` | Procedure | Denotes that the annotated procedure should be executed once before all elements of the suite. | +| `--%beforeall([[.].][,...])` | Package | Denotes that the mentioned procedure(s) should be executed once before all elements of the suite. | | `--%afterall` | Procedure | Denotes that the annotated procedure should be executed once after all elements of the suite. | +| `--%afterall([[.].][,...])` | Package | Denotes that the mentioned procedure(s) should be executed once after all elements of the suite. | | `--%beforeeach` | Procedure | Denotes that the annotated procedure should be executed before each `%test` procedure in the suite. | +| `--%beforeeach([[.].][,...])` | Package | Denotes that the mentioned procedure(s) should be executed before each `%test` procedure in the suite. | | `--%aftereach` | Procedure | Denotes that the annotated procedure should be executed after each `%test` procedure in the suite. | -| `--%beforetest()` | Procedure | Denotes that mentioned procedure should be executed before the annotated `%test` procedure. | -| `--%aftertest()` | Procedure | Denotes that mentioned procedure should be executed after the annotated `%test` procedure. | +| `--%aftereach([[.].][,...])` | Package | Denotes that the mentioned procedure(s) should be executed after each `%test` procedure in the suite. | +| `--%beforetest([[.].][,...])` | Procedure | Denotes that mentioned procedure(s) should be executed before the annotated `%test` procedure. | +| `--%aftertest([[.].][,...])` | Procedure | Denotes that mentioned procedure(s) should be executed after the annotated `%test` procedure. | | `--%rollback()` | Package/procedure | Defines transaction control. Supported values: `auto`(default) - a savepoint is created before invocation of each "before block" is and a rollback to specific savepoint is issued after each "after" block; `manual` - rollback is never issued automatically. Property can be overridden for child element (test in suite) | | `--%disabled` | Package/procedure | Used to disable a suite or a test. Disabled suites/tests do not get executed, they are however marked and reported as disabled in a test run. | -| `--%context()` | Package | Denotes start of a nested context (sub-suite) in a suite package | +| `--%context()` | Package | Denotes start of a named context (sub-suite) in a suite package | | `--%endcontext` | Package | Denotes end of a nested context (sub-suite) in a suite package | ### Suite @@ -65,7 +69,7 @@ test_package Finished in .002415 seconds 0 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s) -``` +``` Suite package with description. ```sql @@ -82,7 +86,7 @@ Tests for a package Finished in .001646 seconds 0 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s) -``` +``` When multiple `--%suite` annotations are specified in package, the first annotation will be used and a warning message will appear indicating duplicate annotation. ```sql @@ -107,7 +111,7 @@ Warnings: Finished in .003318 seconds 0 tests, 0 failed, 0 errored, 0 disabled, 1 warning(s) -``` +``` When `--%suite` annotation is bound to procedure, it is ignored and results in package not getting recognized as test suite. ```sql @@ -127,7 +131,7 @@ ORA-06512: at "UT3.UT", line 115 ORA-06512: at "UT3.UT", line 306 ORA-06512: at "UT3.UT", line 364 ORA-06512: at line 1 -``` +``` ### Test @@ -166,14 +170,14 @@ Tests for a package Finished in .004109 seconds 1 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s) -``` +``` Test procedure with description. ```sql create or replace package test_package as --%suite(Tests for a package) - --%test(Description of tesed behavior) + --%test(Description of tested behavior) procedure some_test; end; / @@ -188,18 +192,18 @@ exec ut.run('test_package'); ``` ``` Tests for a package - Description of tesed behavior [.005 sec] + Description of tested behavior [.005 sec] Finished in .006828 seconds 1 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s) -``` +``` When multiple `--%test` annotations are specified for a procedure, the first annotation will be used and a warning message will appear indicating duplicate annotation. ```sql create or replace package test_package as --%suite(Tests for a package) - --%test(Description of tesed behavior) + --%test(Description of tested behavior) --%test(Duplicate description) procedure some_test; end; @@ -215,7 +219,7 @@ exec ut.run('test_package'); ``` ``` Tests for a package - Description of tesed behavior [.007 sec] + Description of tested behavior [.007 sec] Warnings: @@ -226,7 +230,7 @@ Warnings: Finished in .008815 seconds 1 tests, 0 failed, 0 errored, 0 disabled, 1 warning(s) -``` +``` ### Disabled Marks annotated suite package or test procedure as disabled. @@ -237,7 +241,7 @@ create or replace package test_package as --%suite(Tests for a package) --%disabled - --%test(Description of tesed behavior) + --%test(Description of tested behavior) procedure some_test; --%test(Description of another behavior) @@ -258,19 +262,19 @@ exec ut.run('test_package'); ``` ``` Tests for a package - Description of tesed behavior [0 sec] (DISABLED) + Description of tested behavior [0 sec] (DISABLED) Description of another behavior [0 sec] (DISABLED) Finished in .001441 seconds 2 tests, 0 failed, 0 errored, 2 disabled, 0 warning(s) -``` +``` Disabling individual test(s). ```sql create or replace package test_package as --%suite(Tests for a package) - --%test(Description of tesed behavior) + --%test(Description of tested behavior) procedure some_test; --%test(Description of another behavior) @@ -292,7 +296,7 @@ exec ut.run('test_package'); ``` ``` Tests for a package - Description of tesed behavior [.004 sec] + Description of tested behavior [.004 sec] Description of another behavior [0 sec] (DISABLED) Finished in .005868 seconds @@ -301,8 +305,35 @@ Finished in .005868 seconds ### Beforeall +There are two possible ways to use the `--%beforeall` annotation. + +As a procedure level annotation: +```sql +--%suite(Some test suite) + +--%beforeall +procedure to_be_executed_before_all; + +--%test +procedure some_test; +``` Marks annotated procedure to be executed before all test procedures in a suite. +As a package level annotation (not associated with any procedure). +```sql +--%suite(Some test suite) + +--%beforeall(to_be_executed_before_all, other_package.some_setup) + +--%test +procedure some_test; + +procedure to_be_executed_before_all; + +``` +Indicates that the procedure(s) mentioned as the annotation parameter are to be executed before all test procedures in a suite. + + If `--%beforeall` raises an exception, suite content cannot be safely executed as the setup was not executed successfully for the suite. If `--%beforeall` raises an exception the following will happen: @@ -320,7 +351,7 @@ For multiple `--%beforeall` procedures order of execution is defined by annotati create or replace package test_package as --%suite(Tests for a package) - --%test(Description of tesed behavior) + --%test(Description of tested behavior) procedure some_test; --%test(Description of another behavior) @@ -350,51 +381,67 @@ exec ut.run('test_package'); ``` Tests for a package --- SETUP_STUFF invoked --- - Description of tesed behavior [.004 sec] + Description of tested behavior [.004 sec] Description of another behavior [.003 sec] Finished in .012292 seconds 2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s) ``` -In the below example, procedure `another_setup` is invoked after `initial_setup`. -The `another_setup` still gets invoked before any test from that suite package is executed. +In the below example a combination pacakge and procedure level `--%beforeall` annotations is used. +The order of execution of the beforeall procedures is determined by the annotation position in package. +All of the `--%beforeall` procedures get invoked before any test is executed in a suite. ```sql - create or replace package test_package as - --%suite(Tests for a package) - - --%beforeall - procedure initial_setup; - - --%test(Description of tesed behavior) - procedure some_test; - - --%test(Description of another behavior) - procedure other_test; - - --%beforeall - procedure another_setup; - - end; - / - create or replace package body test_package as - procedure another_setup is - begin - dbms_output.put_line('--- ANOTHER_SETUP invoked ---'); - end; - - procedure initial_setup is - begin - dbms_output.put_line('--- INITIAL_SETUP invoked ---'); - end; - - procedure some_test is begin null; end; - - procedure other_test is begin null; end; - end; - / -``` + create or replace package test_package as + --%suite(Tests for a package) + + --%beforeall(initial_setup,test_package.another_setup) + + --%test(Description of tested behavior) + procedure some_test; + + --%test(Description of another behavior) + procedure other_test; + + --%beforeall + procedure next_setup; + + --%beforeall(one_more_setup) + + procedure another_setup; + procedure one_more_setup; + procedure initial_setup; + end; + / + create or replace package body test_package as + procedure one_more_setup is + begin + dbms_output.put_line('--- ONE_MORE_SETUP invoked ---'); + end; + + procedure next_setup is + begin + dbms_output.put_line('--- NEXT_SETUP invoked ---'); + end; + + procedure another_setup is + begin + dbms_output.put_line('--- ANOTHER_SETUP invoked ---'); + end; + + procedure initial_setup is + begin + dbms_output.put_line('--- INITIAL_SETUP invoked ---'); + end; + + procedure some_test is begin null; end; + + procedure other_test is begin null; end; + end; + / + ``` + ```sql exec ut.run('test_package'); ``` @@ -402,10 +449,12 @@ The `another_setup` still gets invoked before any test from that suite package i Tests for a package --- INITIAL_SETUP invoked --- --- ANOTHER_SETUP invoked --- - Description of tesed behavior [.004 sec] - Description of another behavior [.004 sec] + --- NEXT_SETUP invoked --- + --- ONE_MORE_SETUP invoked --- + Description of tested behavior [.003 sec] + Description of another behavior [.002 sec] -Finished in .016672 seconds +Finished in .018944 seconds 2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s) ``` @@ -419,7 +468,7 @@ When procedure is annotated as both `--%beforeall` and `--%test`, the procedure --%beforeall procedure initial_setup; - --%test(Description of tesed behavior) + --%test(Description of tested behavior) --%beforeall procedure some_test; @@ -441,14 +490,14 @@ When procedure is annotated as both `--%beforeall` and `--%test`, the procedure end; / ``` - + ```sql exec ut.run('test_package'); ``` ``` Tests for a package --- INITIAL_SETUP invoked --- - Description of tesed behavior [.003 sec] + Description of tested behavior [.003 sec] Description of another behavior [.004 sec] @@ -463,13 +512,39 @@ Warnings: Finished in .012158 seconds 2 tests, 0 failed, 0 errored, 0 disabled, 2 warning(s) -``` - + ``` + ### Afterall +There are two possible ways to use the `--%afterall` annotation. + +As a procedure level annotation: +```sql +--%suite(Some test suite) + +--%afterall +procedure to_be_executed_after_all; + +--%test +procedure some_test; +``` Marks annotated procedure to be executed after all test procedures in a suite. +As a package level annotation (not associated with any procedure). +```sql +--%suite(Some test suite) + +--%afterall(to_be_executed_after_all, other_package.some_cleanup) + +--%test +procedure some_test; + +procedure to_be_executed_after_all; + +``` +Indicates that the procedure(s) mentioned as the annotation parameter are to be executed after all test procedures in a suite. + If `--%afterall` raises an exception the following will happen: - a warning will be raised, indicating that `--%afterall` procedure has failed - execution will continue uninterrupted for rest of the suite @@ -487,7 +562,7 @@ All rules defined for `--%beforeall` also apply for `--%afterall` annotation. Se create or replace package test_package as --%suite(Tests for a package) - --%test(Description of tesed behavior) + --%test(Description of tested behavior) procedure some_test; --%test(Description of another behavior) @@ -516,7 +591,7 @@ exec ut.run('test_package'); ``` ``` Tests for a package - Description of tesed behavior [.003 sec] + Description of tested behavior [.003 sec] Description of another behavior [.005 sec] ---CLEANUP_STUFF invoked --- @@ -526,13 +601,40 @@ Finished in .014161 seconds ### Beforeeach -Marks annotated procedure to be executed before each test procedure in a suite. - The procedure annotated as `--%beforeeach` is getting executed before each test in a suite. That means that the procedure will be executed as many times as there are test in suite package. +There are two possible ways to use the `--%beforeeach` annotation. + +As a procedure level annotation: +```sql +--%suite(Some test suite) + +--%beforeeach +procedure to_be_executed_before_each; + +--%test +procedure some_test; +``` +Marks annotated procedure to be executed before each test procedures in a suite. + +As a package level annotation (not associated with any procedure). +```sql +--%suite(Some test suite) + +--%beforeeach(to_be_executed_before_each, other_package.some_setup) + +--%test +procedure some_test; + +procedure to_be_executed_before_each; + +``` +Indicates that the procedure(s) mentioned as the annotation parameter are to be executed before each test procedure in a suite. + + If a test is marked as disabled the `--%beforeeach` procedure is not invoked for that test. - + If `--%beforeeach` raises an unhandled exception the following will happen: - the following `--%beforeeach` as well as all `--%beforetest` for that test **will not be executed** - the test will be marked as errored and exception stack trace will be captured and reported @@ -550,7 +652,7 @@ For multiple `--%beforeeach` procedures order of execution is defined by annotat create or replace package test_package as --%suite(Tests for a package) - --%test(Description of tesed behavior) + --%test(Description of tested behavior) procedure some_test; --%test(Description of another behavior) @@ -593,7 +695,7 @@ exec ut.run('test_package'); ``` Tests for a package ---SETUP_STUFF invoked --- - Description of tesed behavior [.004 sec] + Description of tested behavior [.004 sec] ---SETUP_FOR_TEST invoked --- ---SOME_TEST invoked --- Description of another behavior [.006 sec] @@ -604,6 +706,7 @@ Finished in .014683 seconds 2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s) ``` +See [beforeall](#Beforeall) for more examples. ### Aftereach @@ -612,8 +715,36 @@ Marks annotated procedure to be executed after each test procedure in a suite. The procedure annotated as `--%aftereach` is getting executed after each test in a suite. That means that the procedure will be executed as many times as there are test in suite package. +There are two possible ways to use the `--%aftereach` annotation. + +As a procedure level annotation: +```sql +--%suite(Some test suite) + +--%aftereach +procedure to_be_executed_after_each; + +--%test +procedure some_test; +``` +Marks annotated procedure to be executed after each test procedures in a suite. + +As a package level annotation (not associated with any procedure). +```sql +--%suite(Some test suite) + +--%aftereach(to_be_executed_after_each, other_package.some_setup) + +--%test +procedure some_test; + +procedure to_be_executed_after_each; + +``` +Indicates that the procedure(s) mentioned as the annotation parameter are to be executed after each test procedure in a suite. + If a test is marked as disabled the `--%aftereach` procedure is not invoked for that test. - + If `--%aftereach` raises an unhandled exception the following will happen: - the test will be marked as errored and exception stack trace will be captured and reported - the `--%aftertest`, `--%aftereach` procedures **will be executed** for the errored test @@ -630,7 +761,7 @@ As a rule, the `--%aftereach` gets executed even if the associated `--%beforeeac create or replace package test_package as --%suite(Tests for a package) - --%test(Description of tesed behavior) + --%test(Description of tested behavior) procedure some_test; --%test(Description of another behavior) @@ -671,7 +802,7 @@ exec ut.run('test_package'); ``` ``` Tests for a package - Description of tesed behavior [.006 sec] + Description of tested behavior [.006 sec] ---SOME_TEST invoked --- ---CLEANUP_FOR_TEST invoked --- Description of another behavior [.006 sec] @@ -683,15 +814,20 @@ Finished in .018115 seconds 2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s) ``` +See [beforeall](#Beforeall) for more examples. + ### Beforetest -Indicates a specific setup to be executed for a test. -Used alongside `--%test` annotation. Indicates procedure name to be executed before specific test. +Indicates specific setup procedure(s) to be executed for a test. The procedure(s) can be located either: +- within current package (package name is optional) +- within another package + +The annotation need to be placed alongside `--%test` annotation. The `--%beforetest` procedures are executed after invoking all `--%beforeeach` for a test. -If a test is marked as disabled the `--%beforetest` procedure is not invoked for that test. - +If a test is marked as disabled the `--%beforetest` procedures are not invoked for that test. + If `--%beforetest` raises an unhandled exception the following will happen: - the following `--%beforetest` for that test **will not be executed** - the test will be marked as errored and exception stack trace will be captured and reported @@ -701,7 +837,9 @@ If `--%beforetest` raises an unhandled exception the following will happen: When multiple `--%beforetest` procedures are defined for a test, all of them will be executed before invoking the test. -For multiple `--%beforetest` procedures order of execution is defined by annotation position in the package specification. +The order of execution for `--%beforetest` procedures is defined by: +- position of procedure on the list within single annotation +- annotation position As a rule, the `--%beforetest` execution gets aborted if preceding `--%beforeeach` or `--%beforetest` failed. @@ -709,13 +847,13 @@ As a rule, the `--%beforetest` execution gets aborted if preceding `--%beforeeac create or replace package test_package as --%suite(Tests for a package) - --%test(Description of tesed behavior) - --%beforetest(setup_for_a_test) + --%test(Description of tested behavior) + --%beforetest(test_package.setup_for_a_test) --%beforetest(another_setup_for_a_test) procedure some_test; --%test(Description of another behavior) - --%beforetest(setup_for_a_test) + --%beforetest(test_package.setup_for_a_test, another_setup_for_a_test) procedure other_test; procedure another_setup_for_a_test; @@ -752,28 +890,30 @@ exec ut.run('test_package'); ``` ``` Tests for a package - Description of tesed behavior [.011 sec] + Description of tested behavior [.008 sec] ---SETUP_FOR_A_TEST invoked --- ---ANOTHER_SETUP_FOR_A_TEST invoked --- ---SOME_TEST invoked --- Description of another behavior [.005 sec] ---SETUP_FOR_A_TEST invoked --- + ---ANOTHER_SETUP_FOR_A_TEST invoked --- ---OTHER_TEST invoked --- -Finished in .018446 seconds +Finished in .015185 seconds 2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s) ``` ### Aftertest -Indicates a specific cleanup to be executed for a test. -Used alongside `--%test` annotation. Indicates procedure name to be executed after specific test. +Indicates specific cleanup procedure(s) to be executed for a test. The procedure(s) can be located either: +- within current package (package name is optional) +- within another package + +The annotation need to be placed alongside `--%test` annotation. -The `--%aftertest` procedures are executed before invoking any `--%aftereach` for a test. +If a test is marked as disabled the `--%aftertest` procedures are not invoked for that test. -If a test is marked as disabled the `--%aftertest` procedure is not invoked for that test. - If `--%aftertest` raises an unhandled exception the following will happen: - the test will be marked as errored and exception stack trace will be captured and reported - the following `--%aftertest` and all `--%aftereach` procedures **will be executed** for the errored test @@ -782,7 +922,9 @@ If `--%aftertest` raises an unhandled exception the following will happen: When multiple `--%aftertest` procedures are defined for a test, all of them will be executed before invoking the test. -For multiple `--%aftertest` procedures order of execution is defined by annotation position in the package specification. +The order of execution for `--%aftertest` procedures is defined by: +- position of procedure on the list within single annotation +- annotation position As a rule, the `--%aftertest` gets executed even if the associated `--%beforeeach`, `--%beforetest`, `--%test` or other `--%aftertest` procedures have raised unhandled exceptions. @@ -790,13 +932,13 @@ As a rule, the `--%aftertest` gets executed even if the associated `--%beforeeac create or replace package test_package as --%suite(Tests for a package) - --%test(Description of tesed behavior) - --%aftertest(cleanup_for_a_test) + --%test(Description of tested behavior) + --%aftertest(test_package.cleanup_for_a_test) --%aftertest(another_cleanup_for_a_test) procedure some_test; --%test(Description of another behavior) - --%aftertest(cleanup_for_a_test) + --%aftertest(test_package.cleanup_for_a_test, another_cleanup_for_a_test) procedure other_test; procedure another_cleanup_for_a_test; @@ -833,15 +975,16 @@ exec ut.run('test_package'); ``` ``` Tests for a package - Description of tesed behavior [.01 sec] + Description of tested behavior [.008 sec] ---SOME_TEST invoked --- ---CLEANUP_FOR_A_TEST invoked --- ---ANOTHER_CLEANUP_FOR_A_TEST invoked --- Description of another behavior [.006 sec] ---OTHER_TEST invoked --- ---CLEANUP_FOR_A_TEST invoked --- + ---ANOTHER_CLEANUP_FOR_A_TEST invoked --- -Finished in .018691 seconds +Finished in .016873 seconds 2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s) ``` @@ -858,21 +1001,21 @@ With this comes a challenge. How to group tests, related to one tested procedure This is where utPLSQL contexts come handy. Contexts allow for creating sub-suites within a suite package and they allow for grouping of tests that are somehow related. - + In essence, context behaves like a suite within a suite. Context have following characteristics: - start with the `--%context` annotation and ends with `--%endcontext` -- can have a name provided a parameter for example `--%context(Remove rooms by name)` +- can have a name provided as parameter for example `--%context(remove_rooms_by_name)` - when no name is provided for context, the context is names `context_N` where `N` is the number of the context in suite - can have their own `--%beforeall`, `--%beforeeach`, `--%afterall` and `--%aftereach` procedures - `--%beforeall`, `--%beforeeach`, `--%afterall` and `--%aftereach` procedures defined at suite level, propagate to context - test suite package can have multiple contexts in it - contexts cannot be nested - + The below example illustrates usage of `--%context` for separating tests for individual procedures of package. - + Tested tables and code ```sql create table rooms ( @@ -938,6 +1081,7 @@ Below test suite defines: ```sql create or replace package test_rooms_management is + gc_null_value_exception constant integer := -1400; --%suite(Rooms management) --%beforeall @@ -945,6 +1089,7 @@ create or replace package test_rooms_management is --%context(remove_rooms_by_name) + --%description(Remove rooms by name) --%test(Removes a room without content in it) procedure remove_empty_room; @@ -957,13 +1102,14 @@ create or replace package test_rooms_management is --%context(add_rooms_content) + --%description(Add content to a room) --%test(Fails when room name is not valid) - --%throws(-1403) + --%throws(no_data_found) procedure fails_on_room_name_invalid; --%test(Fails when content name is null) - --%throws(-1400) + --%throws(gc_null_value_exception) procedure fails_on_content_null; --%test(Adds a content to existing room) @@ -1025,7 +1171,7 @@ create or replace package body test_rooms_management is begin --Act add_rooms_content('Dining Room',null); - --Assert by --%throws annotation + --Assert done by --%throws annotation end; procedure add_content_success is @@ -1179,21 +1325,43 @@ Keep in mind that when your test runs as autonomous transaction it will not see ### Throws -The `--%throws` annotation allows you to specify a list of exception numbers that can be expected from a test. +The `--%throws` annotation allows you to specify a list of exceptions as one of: +- number literals - example `--%throws(-20134)` +- variables of type exception defined in a package specification - example `--%throws(exc_pkg.c_exception_No_variable)` +- variables of type number defined in a package specification - example `--%throws(exc_pkg.c_some_exception)` +- [predefined oracle exceptions](https://docs.oracle.com/cd/E11882_01/timesten.112/e21639/exceptions.htm#CIHFIGFE) - example `--%throws(no_data_found)` -If `--%throws(-20001,-20002)` is specified and no exception is raised or the exception raised is not on the list of provided exception numbers, the test is marked as failed. +The annotation is ignored, when no valid arguments are provided. Examples of invalid annotations `--%throws()`,`--%throws`, `--%throws(abe, 723pf)`. -The framework ignores bad arguments. `--%throws(7894562, operaqk, -=1, -20496, pow74d, posdfk3)` will be interpreted as `--%throws(-20496)`. -The annotation is ignored, when no valid arguments are provided `--%throws()`,`--%throws`, `--%throws(abe, 723pf)`. +If `--%throws` annotation is specified with arguments and no exception is raised, the test is marked as failed. +If `--%throws` annotation is specified with arguments and exception raised is not on the list of provided exceptions, the test is marked as failed. + +The framework will raise a warning, when `--%throws` annotation has invalid arguments or when no arguments were provided. + +Annotation `--%throws(7894562, operaqk, -=1, -20496, pow74d, posdfk3)` will be interpreted as `--%throws(-20496)`. + +Please note that `NO_DATA_FOUND` exception is a special case in Oracle. To capture it use `NO_DATA_FOUND` named exception or `-1403` exception No. + Example: ```sql +create or replace package exc_pkg is + c_e_option1 constant number := -20200; + c_e_option2 constant varchar2(10) := '-20201'; + c_e_option3 number := -20202; + + e_option4 exception; + pragma exception_init(e_option4, -20203); + +end; +/ + create or replace package example_pgk as --%suite(Example Throws Annotation) --%test(Throws one of the listed exceptions) - --%throws(-20145,-20146, -20189 ,-20563) + --%throws(-20145,bad,-20146, -20189 ,-20563) procedure raised_one_listed_exception; --%test(Throws different exception than expected) @@ -1207,6 +1375,30 @@ create or replace package example_pgk as --%test(Gives failure when an exception is expected and nothing is thrown) --%throws(-20459, -20136, -20145) procedure nothing_thrown; + + --%test(Throws package exception option1) + --%throws(exc_pkg.c_e_option1) + procedure raised_option1_exception; + + --%test(Throws package exception option2) + --%throws(exc_pkg.c_e_option2) + procedure raised_option2_exception; + + --%test(Throws package exception option3) + --%throws(exc_pkg.c_e_option3) + procedure raised_option3_exception; + + --%test(Throws package exception option4) + --%throws(exc_pkg.e_option4) + procedure raised_option4_exception; + + --%test(Raise name exception) + --%throws(DUP_VAL_ON_INDEX) + procedure raise_named_exc; + + --%test(Invalid throws annotation) + --%throws + procedure bad_throws_annotation; end; / @@ -1230,19 +1422,55 @@ create or replace package body example_pgk is begin ut.expect(1).to_equal(1); end; + + procedure raised_option1_exception is + begin + raise_application_error(exc_pkg.c_e_option1, 'Test error'); + end; + + procedure raised_option2_exception is + begin + raise_application_error(exc_pkg.c_e_option2, 'Test error'); + end; + + procedure raised_option3_exception is + begin + raise_application_error(exc_pkg.c_e_option3, 'Test error'); + end; + + procedure raised_option4_exception is + begin + raise exc_pkg.e_option4; + end; + + procedure raise_named_exc is + begin + raise DUP_VAL_ON_INDEX; + end; + + procedure bad_throws_annotation is + begin + null; + end; end; / - -exec ut.run('example_pgk'); + +exec ut3.ut.run('example_pgk'); ``` Running the test will give report: ``` Example Throws Annotation - Throws one of the listed exceptions [.018 sec] - Throws different exception than expected [.008 sec] (FAILED - 1) - Throws different exception than listed [.007 sec] (FAILED - 2) + Throws one of the listed exceptions [.002 sec] + Throws different exception than expected [.002 sec] (FAILED - 1) + Throws different exception than listed [.003 sec] (FAILED - 2) Gives failure when an exception is expected and nothing is thrown [.002 sec] (FAILED - 3) + Throws package exception option1 [.003 sec] + Throws package exception option2 [.002 sec] + Throws package exception option3 [.002 sec] + Throws package exception option4 [.002 sec] + Raise name exception [.002 sec] + Invalid throws annotation [.002 sec] Failures: @@ -1250,19 +1478,31 @@ Failures: Actual: -20143 was expected to equal: -20144 ORA-20143: Test error ORA-06512: at "UT3.EXAMPLE_PGK", line 9 + ORA-06512: at "UT3.EXAMPLE_PGK", line 9 ORA-06512: at line 6 2) raised_unlisted_exception Actual: -20143 was expected to be one of: (-20144, -1, -20145) ORA-20143: Test error ORA-06512: at "UT3.EXAMPLE_PGK", line 14 + ORA-06512: at "UT3.EXAMPLE_PGK", line 14 ORA-06512: at line 6 3) nothing_thrown Expected one of exceptions (-20459, -20136, -20145) but nothing was raised. -Finished in .038692 seconds -4 tests, 3 failed, 0 errored, 0 disabled, 0 warning(s) + +Warnings: + + 1) example_pgk + Invalid parameter value "bad" for "--%throws" annotation. Parameter ignored. + at "UT3.EXAMPLE_PGK.RAISED_ONE_LISTED_EXCEPTION", line 6 + 2) example_pgk + "--%throws" annotation requires a parameter. Annotation ignored. + at "UT3.EXAMPLE_PGK.BAD_THROWS_ANNOTATION", line 42 + +Finished in .025784 seconds +10 tests, 3 failed, 0 errored, 0 disabled, 2 warning(s) ``` ## Order of execution @@ -1335,7 +1575,7 @@ end test_employee_pkg; ``` When processing the test suite `test_employee_pkg` defined in [Example of annotated test package](#example), the order of execution will be as follows. - + ``` create a savepoint 'before-suite' execute setup_employees (--%beforeall) diff --git a/docs/userguide/coverage.md b/docs/userguide/coverage.md index b8ec894be..1d4ca93c5 100644 --- a/docs/userguide/coverage.md +++ b/docs/userguide/coverage.md @@ -230,14 +230,14 @@ C: \hr.test_betwnstr.pks ``` -By default, utPLSQL will convert file paths into database objects using the following regular expression `/((\w+)\.)?(\w+)\.(\w{3})$` +By default, utPLSQL will convert file paths into database objects using the following regular expression `/(((\w|[$#])+)\.)?((\w|[$#])+)\.(\w{3})$` - object owner (if it is present) is identified by the expression in the second set of brackets -- object name is identified by the expression in the third set of brackets -- object type is identified by the expression in the fourth set of brackets +- object name is identified by the expression in the fourth set of brackets +- object type is identified by the expression in the sixth set of brackets **Note** -> utPLSQL will replace any '\' with '/' for the purpose of mapping files to objects. The paths shown in the results will remain (contain '\' where it was present). +> utPLSQL will replace any '\\' with '/' for the purpose of mapping files to objects. The paths shown in the results will remain (contain '\' where it was present). > This is done to simplify the syntax of regular expressions. Regular expression will always use '/' as a directory separator on a file path regardless of whether you're on a Windows or Unix system. **Note** diff --git a/docs/userguide/expectations.md b/docs/userguide/expectations.md index ae1176be5..4c6f3aa68 100644 --- a/docs/userguide/expectations.md +++ b/docs/userguide/expectations.md @@ -165,7 +165,11 @@ end; ## be_empty Unary matcher that validates if the provided dataset is empty. -Can be used with `refcursor` or `nested table`/`varray` passed as `ANYDATA` +Can be used with `BLOB`,`CLOB`, `refcursor` or `nested table`/`varray` passed as `ANYDATA` + +**Note:** +BLOB/CLOB that is initialized is not NULL but it is actually equal to `empty_blob()`/`empty_clob()`. + Usage: ```sql @@ -794,7 +798,7 @@ The matrix below illustrates the data types supported by different matchers. |**equal** | X | X | X | X | X | X | X | X | X | X | X | X | X | X | |**match** | | | X | | | | | | X | | | | | | |**be_like** | | | X | | | | | | X | | | | | | -|**be_empty** | | | | | | | | | | | | X | X | | +|**be_empty** | X | | X | | | | | | | | | X | X | | |**have_count** | | | | | | | | | | | | X | X | | diff --git a/docs/userguide/install.md b/docs/userguide/install.md index 88e2a2e63..0b9bec462 100644 --- a/docs/userguide/install.md +++ b/docs/userguide/install.md @@ -70,7 +70,7 @@ cd source sqlplus sys/sys_pass@db as sysdba @install_headless.sql utp3 my_verySecret_password utp3_tablespace ``` -The script needs to be executed by SYSDBA, in order to grant access to DBMS_LOCK system package. +The script needs to be executed by `SYSDBA`, in order to grant access to `DBMS_LOCK` and `DBMS_CRYPTO` system packages. # Recommended Schema @@ -88,7 +88,7 @@ If the installation and utPLSQL owner user is one and the same, the user must ha - CREATE SYNONYM - ALTER SESSION -In addition the user must be granted the execute privilege on `DBMS_LOCK` package. +In addition the user must be granted the execute privilege on `DBMS_LOCK` and `DBMS_CRYPTO` packages. utPLSQL is using [DBMS_PROFILER tables](https://docs.oracle.com/cd/E18283_01/appdev.112/e16760/d_profil.htm#i999476) for code coverage. The tables required by DBMS_PROFILER will be created in the installation schema unless they already exist. The uninstall process will **not** drop profiler tables, as they can potentially be shared and reused for profiling PLSQL code. @@ -135,12 +135,13 @@ Example invocation: cd source sqlplus admin/admins_password@database @create_synonyms_and_grants_for_public.sql ut3 ``` -To grant utPLSQL to an individual user, execute script `source/create_synonyms_and_grants_for_user.sql`, provide `schema_name` where utPLSQL is installed and `user_name` to grant access for. +To grant utPLSQL to an individual user, execute scripts `source/create_user_grants.sql` and `source/create_user_synonyms.sql`, provide `schema_name` where utPLSQL is installed and `user_name` to grant access for. Example invocation: ```bash cd source -sqlplus admin/admins_password@database @create_synonyms_and_grants_for_user.sql ut3 hr +sqlplus ut3_user/ut3_password@database @create_user_grants.sql ut3 hr +sqlplus user/user_password@database @create_user_synonyms.sql ut3 hr ``` The following tools that support the SQL*Plus commands can be used to run the installation script: diff --git a/docs/userguide/running-unit-tests.md b/docs/userguide/running-unit-tests.md index f31c24912..54116cf65 100644 --- a/docs/userguide/running-unit-tests.md +++ b/docs/userguide/running-unit-tests.md @@ -93,8 +93,26 @@ end; ``` Executes all tests from package _hr.test_apply_bonus_ and all tests from schema _cust_. +```sql +begin + ut.run(ut_varchar2_list('hr.test_apply_bonus,cust)'); +end; +``` + +Executes all tests from package _hr.test_apply_bonus_ and all tests from schema _cust_. + +```sql +begin + ut.run('hr.test_apply_bonus,cust'); +end; +``` + +Executes all tests from package _hr.test_apply_bonus_ and all tests from schema _cust_. + Using a list of items to execute allows you to execute a fine-grained set of tests. +List can be passed as a comma separated list or a list of *ut_varchar2_list objects* or as a list within ut_varchar2_list. + **Note:** diff --git a/old_tests/RunAll.sql b/old_tests/RunAll.sql index 936789bd3..f785aabc1 100644 --- a/old_tests/RunAll.sql +++ b/old_tests/RunAll.sql @@ -37,99 +37,19 @@ create table ut$test_table (val varchar2(1)); exec ut_coverage.coverage_start(); exec ut_coverage.set_develop_mode(true); -@@lib/RunTest.sql ut_expectation_processor/who_called_expectation.parseStackTrace.sql -@@lib/RunTest.sql ut_expectation_processor/who_called_expectation.parseStackTraceWith0x.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNotBoolean.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNull.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsTrue.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesSuccessWhenExpessionIsFalse.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_like.FailsForUnsupportedDatatype.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenAnydataIsNull.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenCollectionPassedIsNull.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenObjectPassedIsNull.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsFalse.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsNotBoolean.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsNull.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_be_true.GivesSuccessWhenExpessionIsTrue.sql -@@ut_expectations/ut.expect.not_to_equal.GivesFailureForEqualValues.sql -@@ut_expectations/ut.expect.not_to_equal.GivesSuccessForDifferentValues.sql -@@lib/RunTest.sql ut_expectations/ut.expect.to_match.FailsForUnsupportedDatatype.sql -@@lib/RunTest.sql ut_expectations/ut_data_value_object.compare.Gives0WhenComparingIdenticalObjects.sql @@lib/RunTest.sql ut_expectations/ut_expectation_processor.nulls_are_equal.raisesExceptionWhenTryingToSetNullValue.sql @@lib/RunTest.sql ut_expectations/ut_expectation_processor.stackOnFailedTest.sql @@lib/RunTest.sql ut_expectations/ut_expectation_processor.stackOnUtFail.sql -@@ut_matchers/be_between.sql -@@ut_matchers/be_like.sql -@@ut_matchers/match.sql - -@@lib/RunTest.sql ut_matchers/timestamp_between.sql -@@lib/RunTest.sql ut_matchers/timestamp_ltz_between.sql -@@lib/RunTest.sql ut_matchers/timestamp_ltz_not_between.sql -@@lib/RunTest.sql ut_matchers/timestamp_not_between.sql -@@lib/RunTest.sql ut_matchers/timestamp_tz_between.sql -@@lib/RunTest.sql ut_matchers/timestamp_tz_not_between.sql - @@lib/RunTest.sql ut_metadata/ut_metadata.form_name.TrimStandaloneProgramName.sql -@@lib/RunTest.sql ut_output_buffer/get_lines.RecievesALineFromBufferTableAndDeletes.sql -@@lib/RunTest.sql ut_output_buffer/get_lines.WaitsForMoreDataToAppearForSpecifiedTime.sql -@@lib/RunTest.sql ut_output_buffer/get_lines.WaitsForTheDataToAppearForSpecifiedTime.sql -@@lib/RunTest.sql ut_output_buffer/send_line.DoesNotSendLineIfNullTextGiven.sql -@@lib/RunTest.sql ut_output_buffer/send_line.SendsALineIntoBufferTable.sql - -@@lib/RunTest.sql ut_reporters/ut_coverage_sonar_reporter.AcceptsFileMapping.sql -@@lib/RunTest.sql ut_reporters/ut_coverage_sonar_reporter.BuildsSonarCoverageReport.sql @@lib/RunTest.sql ut_reporters/ut_documentation_reporter.providesCorrectLineFromStacktrace.sql -@@lib/RunTest.sql ut_reporters/ut_sonar_test_reporter.AcceptsFileMapping.sql -@@lib/RunTest.sql ut_reporters/ut_sonar_test_reporter.ProducesExpectedOutputs.sql -@@lib/RunTest.sql ut_reporters/ut_teamcity_reporter.ProducesExpectedOutputs.sql -@@lib/RunTest.sql ut_reporters/ut_html_reporter.UserOverrideSchemaCoverage.sql -@@lib/RunTest.sql ut_reporters/ut_html_reporter.DefaultSchemaCoverage.sql @@lib/RunTest.sql ut_reporters/ut_documentation_reporter.reportMultipleWarnings.sql @@lib/RunTest.sql ut_reporters/ut_documentation_reporter.reportTestTiming.sql - -@@lib/RunTest.sql ut/ut.run.AcceptsCoverageFileList.sql -@@lib/RunTest.sql ut/ut.run.AcceptsCoverageFileListWithSutePaths.sql -@@lib/RunTest.sql ut/ut.run.AcceptsSutePaths.sql -@@lib/RunTest.sql ut/ut.run.ExecutesSuccesfullyAnEmptySuite.sql -@@lib/RunTest.sql ut/ut.run.FailsToExecuteAnInvalidPackageBody.sql -@@lib/RunTest.sql ut/ut.run.function.AcceptsCoverageFileList.sql -@@lib/RunTest.sql ut/ut.run.function.AcceptsCoverageFileListWithSutePaths.sql -@@lib/RunTest.sql ut/ut.run.function.AcceptsSutePaths.sql -@@lib/RunTest.sql ut/ut.run.function.WithGivenReporter.ExectutesAllInCurrentSchemaUsingReporter.sql -@@lib/RunTest.sql ut/ut.run.function.WithNoParams.ExecutesAllFromCurrentSchema.sql -@@lib/RunTest.sql ut/ut.run.function.WithPackageName.ExecutesAllFromGivenPackage.sql ---@@lib/RunTest.sql ut.run/ut.run.function.WithPackageName.ExecutesAllFromGivenPackageOnly.sql --TODO this one doesn't work at the moment -@@lib/RunTest.sql ut/ut.run.function.WithSchemaName.ExecutesAllFromGivenSchema.sql -@@lib/RunTest.sql ut/ut.run.function.WithSuitePath.ExecutesAllFromGivenPath.sql -@@lib/RunTest.sql ut/ut.run.WithGivenReporter.ExectutesAllInCurrentSchemaUsingReporter.sql -@@lib/RunTest.sql ut/ut.run.WithNoParams.ExecutesAllFromCurrentSchema.sql -@@lib/RunTest.sql ut/ut.run.WithPackageName.ExecutesAllFromGivenPackage.sql ---@@lib/RunTest.sql ut.run/ut.run.WithPackageName.ExecutesAllFromGivenPackageOnly.sql --TODO this one doesn't work at the moment -@@lib/RunTest.sql ut/ut.run.WithSchemaName.ExecutesAllFromGivenSchema.sql -@@lib/RunTest.sql ut/ut.run.WithSuitePath.ExecutesAllFromGivenPath.sql -@@lib/RunTest.sql ut/ut.version.sql +@@lib/RunTest.sql ut_reporters/ut_html_reporter.DefaultSchemaCoverage.sql +@@lib/RunTest.sql ut_reporters/ut_html_reporter.UserOverrideSchemaCoverage.sql @@lib/RunTest.sql ut_suite_manager/ut_suite_manager.AllowsDescriptionsWithComma.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheSchema.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByPath.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByPathCurUser.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByPath.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByPathCurUser.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByPath.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByPathCurUser.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByName.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByNameCurUser.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByName.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByNameCurUser.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByName.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByNameCurUser.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPath.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPathCurUser.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPath.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPathCurUser.sql -@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.DoesntFindTheSuiteWhenPackageSpecIsInvalid.sql @@lib/RunTest.sql ut_suite_manager/ut_suite_manager.emptySuitePath.sql @@lib/RunTest.sql ut_suite_manager/ut_suite_manager.get_schema_ut_packages.IncludesPackagesWithSutePath.sql @@lib/RunTest.sql ut_suite_manager/ut_suite_manager.IncludesInvalidPackageBodiesInTheRun.sql @@ -171,24 +91,6 @@ exec ut_coverage.set_develop_mode(true); @@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.RunsWithInvalidValues.sql @@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.RunsWithNullValue.sql @@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.Success.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.Blob.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.Clob.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.Date.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.NullBlob.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.NullClob.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.NullDate.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.NullNumber.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.NullTimestamp.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.NullVarchar2.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.Timestamp.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.TimestampWithLocalTimeZone.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.TimestampWithTimeZone.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.Varchar2.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.veryBigBlob.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.veryBigClob.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.veryBigNumber.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.veryBigVarchar2.sql -@@lib/RunTest.sql ut_utils/ut_utils.to_string.verySmallNumber.sql --Finally @@lib/RunSummary diff --git a/old_tests/ut/ut.run.AcceptsCoverageFileList.sql b/old_tests/ut/ut.run.AcceptsCoverageFileList.sql deleted file mode 100644 index 0dea02727..000000000 --- a/old_tests/ut/ut.run.AcceptsCoverageFileList.sql +++ /dev/null @@ -1,30 +0,0 @@ -declare - l_output_data dbms_output.chararr; - l_num_lines integer := 100000; - l_packages_reported integer := 0; -begin - --act - ut.run( - ut_sonar_test_reporter(), a_source_files => ut_varchar2_list(), - a_test_files => ut_varchar2_list('tests/test_package_1.pkb','tests/test_package_2.pkb','tests/test_package_3.pkb') - ); - dbms_output.get_lines( l_output_data, l_num_lines); - - for i in 1 .. l_num_lines loop - if l_output_data(i) like '%tests/test_package_1.pkb%' escape '\' - or l_output_data(i) like '%tests/test_package_2.pkb%' - or l_output_data(i) like '%tests/test_package_3.pkb%' then - l_packages_reported := l_packages_reported + 1; - end if; - end loop; - - if l_packages_reported = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all package paths were found in the outputs. Expected 3, got '||l_packages_reported); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.AcceptsCoverageFileListWithSutePaths.sql b/old_tests/ut/ut.run.AcceptsCoverageFileListWithSutePaths.sql deleted file mode 100644 index 73046daf9..000000000 --- a/old_tests/ut/ut.run.AcceptsCoverageFileListWithSutePaths.sql +++ /dev/null @@ -1,30 +0,0 @@ -declare - l_output_data dbms_output.chararr; - l_num_lines integer := 100000; - l_packages_reported integer := 0; -begin - --act - ut.run( - ut_varchar2_list('test_package_1','test_package_3'), ut_sonar_test_reporter(), - a_source_files => ut_varchar2_list(), a_test_files => ut_varchar2_list('tests/test_package_1.pkb','tests/test_package_2.pkb','tests/test_package_3.pkb') - ); - dbms_output.get_lines( l_output_data, l_num_lines); - - for i in 1 .. l_num_lines loop - if l_output_data(i) like '%tests/test_package_1.pkb%' escape '\' - or l_output_data(i) like '%tests/test_package_2.pkb%' - or l_output_data(i) like '%tests/test_package_3.pkb%' then - l_packages_reported := l_packages_reported + 1; - end if; - end loop; - - if l_packages_reported = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all package paths were found in the outputs. Expected 3, got '||l_packages_reported); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.AcceptsSutePaths.sql b/old_tests/ut/ut.run.AcceptsSutePaths.sql deleted file mode 100644 index 1ed2b001b..000000000 --- a/old_tests/ut/ut.run.AcceptsSutePaths.sql +++ /dev/null @@ -1,27 +0,0 @@ -declare - l_output_data dbms_output.chararr; - l_num_lines integer := 100000; - l_packages_executed integer := 0; -begin - --act - ut.run(ut_varchar2_list('test_package_1','test_package_3'),ut_teamcity_reporter()); - dbms_output.get_lines( l_output_data, l_num_lines); - - for i in 1 .. l_num_lines loop - if l_output_data(i) like '%Finished %''%test\_package\_1''%' escape '\' - or l_output_data(i) like '%Finished %''%test_package_2''%' - or l_output_data(i) like '%Finished %''%test_package_3''%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 3, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.ExecutesSuccesfullyAnEmptySuite.sql b/old_tests/ut/ut.run.ExecutesSuccesfullyAnEmptySuite.sql deleted file mode 100644 index 35a752acd..000000000 --- a/old_tests/ut/ut.run.ExecutesSuccesfullyAnEmptySuite.sql +++ /dev/null @@ -1,30 +0,0 @@ -set termout off -create or replace package empty_suite as - -- %suite - - procedure not_a_test; -end; -/ -create or replace package body empty_suite as - procedure not_a_test is begin null; end; -end; -/ -set termout on -declare - l_result integer; -begin - select * - into l_result - from table(ut.run('empty_suite',utplsql_test_reporter())); ---Assert - if l_result = ut_utils.gc_error then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected failure of ''empty_suite'' got: '''||ut_utils.test_result_to_char(l_result)||'''' ); - end if; -end; -/ - -set termout off -drop package empty_suite; -set termout on diff --git a/old_tests/ut/ut.run.FailsToExecuteAnInvalidPackageBody.sql b/old_tests/ut/ut.run.FailsToExecuteAnInvalidPackageBody.sql deleted file mode 100644 index b37fe1529..000000000 --- a/old_tests/ut/ut.run.FailsToExecuteAnInvalidPackageBody.sql +++ /dev/null @@ -1,35 +0,0 @@ -set termout off -create table test_dependency_table (id integer); -create or replace package test_dependencies as - -- %suite - - -- %test - procedure dependant; -end; -/ -create or replace package body test_dependencies as - gc_dependant_variable test_dependency_table.id%type; - procedure dependant is begin null; end; -end; -/ -drop table test_dependency_table; -set termout on - -declare - l_result integer; -begin - select * - into l_result - from table(ut.run('test_dependencies',utplsql_test_reporter())); ---Assert - if l_result = ut_utils.gc_error then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected failure of ''test_dependencies'' got: '''||ut_utils.test_result_to_char(l_result)||'''' ); - end if; -end; -/ - -set termout off -drop package test_dependencies; -set termout on diff --git a/old_tests/ut/ut.run.WithGivenReporter.ExectutesAllInCurrentSchemaUsingReporter.sql b/old_tests/ut/ut.run.WithGivenReporter.ExectutesAllInCurrentSchemaUsingReporter.sql deleted file mode 100644 index 88aa01d1e..000000000 --- a/old_tests/ut/ut.run.WithGivenReporter.ExectutesAllInCurrentSchemaUsingReporter.sql +++ /dev/null @@ -1,27 +0,0 @@ -declare - l_output_data dbms_output.chararr; - l_num_lines integer := 100000; - l_packages_executed integer := 0; -begin - --act - ut.run(ut_teamcity_reporter()); - dbms_output.get_lines( l_output_data, l_num_lines); - - for i in 1 .. l_num_lines loop - if l_output_data(i) like '%Finished %''%test\_package\_1''%' escape '\' - or l_output_data(i) like '%Finished %''%test_package_2''%' - or l_output_data(i) like '%Finished %''%test_package_3''%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_num_lines loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 3, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.WithNoParams.ExecutesAllFromCurrentSchema.sql b/old_tests/ut/ut.run.WithNoParams.ExecutesAllFromCurrentSchema.sql deleted file mode 100644 index f50403dcd..000000000 --- a/old_tests/ut/ut.run.WithNoParams.ExecutesAllFromCurrentSchema.sql +++ /dev/null @@ -1,27 +0,0 @@ -declare - l_output_data dbms_output.chararr; - l_num_lines integer := 100000; - l_packages_executed integer := 0; -begin - --act - ut.run(); - dbms_output.get_lines( l_output_data, l_num_lines); - - for i in 1 .. l_num_lines loop - if l_output_data(i) like '%test\_package\_1%' escape '\' - or l_output_data(i) like '%test_package_2%' - or l_output_data(i) like '%test_package_3%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_num_lines loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 3, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.WithPackageName.ExecutesAllFromGivenPackage.sql b/old_tests/ut/ut.run.WithPackageName.ExecutesAllFromGivenPackage.sql deleted file mode 100644 index cd6371e64..000000000 --- a/old_tests/ut/ut.run.WithPackageName.ExecutesAllFromGivenPackage.sql +++ /dev/null @@ -1,27 +0,0 @@ -declare - l_output_data dbms_output.chararr; - l_num_lines integer := 100000; - l_packages_executed integer := 0; -begin - --act - ut.run(user||'.test_package_3'); - dbms_output.get_lines( l_output_data, l_num_lines); - - for i in 1 .. l_num_lines loop - if l_output_data(i) like '%test\_package\_1%' escape '\' - or l_output_data(i) like '%test_package_2%' - or l_output_data(i) like '%test_package_3%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 1 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_num_lines loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 1, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.WithPackageName.ExecutesAllFromGivenPackageOnly.sql b/old_tests/ut/ut.run.WithPackageName.ExecutesAllFromGivenPackageOnly.sql deleted file mode 100644 index 09f5fcdea..000000000 --- a/old_tests/ut/ut.run.WithPackageName.ExecutesAllFromGivenPackageOnly.sql +++ /dev/null @@ -1,27 +0,0 @@ -declare - l_output_data dbms_output.chararr; - l_num_lines integer := 100000; - l_packages_executed integer := 0; -begin - --act - ut.run(user||'.test_package_1'); - dbms_output.get_lines( l_output_data, l_num_lines); - - for i in 1 .. l_num_lines loop - if l_output_data(i) like '%test\_package\_1%' escape '\' - or l_output_data(i) like '%test_package_2%' - or l_output_data(i) like '%test_package_3%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 1 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_num_lines loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: more than just package test_package_1 was executed. Expected 1, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.WithSchemaName.ExecutesAllFromGivenSchema.sql b/old_tests/ut/ut.run.WithSchemaName.ExecutesAllFromGivenSchema.sql deleted file mode 100644 index ce568ecea..000000000 --- a/old_tests/ut/ut.run.WithSchemaName.ExecutesAllFromGivenSchema.sql +++ /dev/null @@ -1,27 +0,0 @@ -declare - l_output_data dbms_output.chararr; - l_num_lines integer := 100000; - l_packages_executed integer := 0; -begin - --act - ut.run(user); - dbms_output.get_lines( l_output_data, l_num_lines); - - for i in 1 .. l_num_lines loop - if l_output_data(i) like '%test\_package\_1%' escape '\' - or l_output_data(i) like '%test_package_2%' - or l_output_data(i) like '%test_package_3%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_num_lines loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 3, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.WithSuitePath.ExecutesAllFromGivenPath.sql b/old_tests/ut/ut.run.WithSuitePath.ExecutesAllFromGivenPath.sql deleted file mode 100644 index d31099e9f..000000000 --- a/old_tests/ut/ut.run.WithSuitePath.ExecutesAllFromGivenPath.sql +++ /dev/null @@ -1,27 +0,0 @@ -declare - l_output_data dbms_output.chararr; - l_num_lines integer := 100000; - l_packages_executed integer := 0; -begin - --act - ut.run(user||':tests.test_package_1'); - dbms_output.get_lines( l_output_data, l_num_lines); - - for i in 1 .. l_num_lines loop - if l_output_data(i) like '%test\_package\_1%' escape '\' - or l_output_data(i) like '%test_package_2%' - or l_output_data(i) like '%test_package_3%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 2 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_num_lines loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 2, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.function.AcceptsCoverageFileList.sql b/old_tests/ut/ut.run.function.AcceptsCoverageFileList.sql deleted file mode 100644 index c5b7af70c..000000000 --- a/old_tests/ut/ut.run.function.AcceptsCoverageFileList.sql +++ /dev/null @@ -1,29 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_packages_reported integer := 0; -begin - --act - select * bulk collect into l_output_data - from table(ut.run( - ut_sonar_test_reporter(), a_source_files => ut_varchar2_list(), - a_test_files => ut_varchar2_list('tests/test_package_1.pkb','tests/test_package_2.pkb','tests/test_package_3.pkb') - )); - - for i in 1 .. l_output_data.count loop - if l_output_data(i) like '%tests/test_package_1.pkb%' escape '\' - or l_output_data(i) like '%tests/test_package_2.pkb%' - or l_output_data(i) like '%tests/test_package_3.pkb%' then - l_packages_reported := l_packages_reported + 1; - end if; - end loop; - - if l_packages_reported = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all package paths were found in the outputs. Expected 3, got '||l_packages_reported); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.function.AcceptsCoverageFileListWithSutePaths.sql b/old_tests/ut/ut.run.function.AcceptsCoverageFileListWithSutePaths.sql deleted file mode 100644 index e3f0055c1..000000000 --- a/old_tests/ut/ut.run.function.AcceptsCoverageFileListWithSutePaths.sql +++ /dev/null @@ -1,29 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_packages_reported integer := 0; -begin - --act - select * bulk collect into l_output_data - from table(ut.run( - ut_varchar2_list('test_package_1','test_package_3'), ut_sonar_test_reporter(), - a_source_files => ut_varchar2_list(), a_test_files => ut_varchar2_list('tests/test_package_1.pkb','tests/test_package_2.pkb','tests/test_package_3.pkb') - )); - - for i in 1 .. l_output_data.count loop - if l_output_data(i) like '%tests/test_package_1.pkb%' escape '\' - or l_output_data(i) like '%tests/test_package_2.pkb%' - or l_output_data(i) like '%tests/test_package_3.pkb%' then - l_packages_reported := l_packages_reported + 1; - end if; - end loop; - - if l_packages_reported = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all package paths were found in the outputs. Expected 3, got '||l_packages_reported); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.function.AcceptsSutePaths.sql b/old_tests/ut/ut.run.function.AcceptsSutePaths.sql deleted file mode 100644 index 98abbae39..000000000 --- a/old_tests/ut/ut.run.function.AcceptsSutePaths.sql +++ /dev/null @@ -1,26 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_packages_executed integer := 0; -begin - --act - select * bulk collect into l_output_data - from table(ut.run(ut_varchar2_list('test_package_1','test_package_3'),ut_teamcity_reporter())); - - for i in 1 .. l_output_data.count loop - if l_output_data(i) like '%Finished %''%test\_package\_1''%' escape '\' - or l_output_data(i) like '%Finished %''%test_package_2''%' - or l_output_data(i) like '%Finished %''%test_package_3''%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 3, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.function.WithGivenReporter.ExectutesAllInCurrentSchemaUsingReporter.sql b/old_tests/ut/ut.run.function.WithGivenReporter.ExectutesAllInCurrentSchemaUsingReporter.sql deleted file mode 100644 index a4d779f93..000000000 --- a/old_tests/ut/ut.run.function.WithGivenReporter.ExectutesAllInCurrentSchemaUsingReporter.sql +++ /dev/null @@ -1,26 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_packages_executed integer := 0; -begin - --act - select * bulk collect into l_output_data - from table(ut.run(ut_teamcity_reporter())); - - for i in 1 .. l_output_data.count loop - if l_output_data(i) like '%Finished %''%test\_package\_1''%' escape '\' - or l_output_data(i) like '%Finished %''%test_package_2''%' - or l_output_data(i) like '%Finished %''%test_package_3''%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 3, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.function.WithNoParams.ExecutesAllFromCurrentSchema.sql b/old_tests/ut/ut.run.function.WithNoParams.ExecutesAllFromCurrentSchema.sql deleted file mode 100644 index c9e80068e..000000000 --- a/old_tests/ut/ut.run.function.WithNoParams.ExecutesAllFromCurrentSchema.sql +++ /dev/null @@ -1,26 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_packages_executed integer := 0; -begin - --act - select * bulk collect into l_output_data - from table(ut.run()); - - for i in 1 .. l_output_data.count loop - if l_output_data(i) like '%test\_package\_1%' escape '\' - or l_output_data(i) like '%test_package_2%' - or l_output_data(i) like '%test_package_3%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 3, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.function.WithPackageName.ExecutesAllFromGivenPackage.sql b/old_tests/ut/ut.run.function.WithPackageName.ExecutesAllFromGivenPackage.sql deleted file mode 100644 index f630baeb6..000000000 --- a/old_tests/ut/ut.run.function.WithPackageName.ExecutesAllFromGivenPackage.sql +++ /dev/null @@ -1,26 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_packages_executed integer := 0; -begin - --act - select * bulk collect into l_output_data - from table(ut.run(user||'.test_package_3')); - - for i in 1 .. l_output_data.count loop - if l_output_data(i) like '%test\_package\_1%' escape '\' - or l_output_data(i) like '%test_package_2%' - or l_output_data(i) like '%test_package_3%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 1 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 1, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.function.WithPackageName.ExecutesAllFromGivenPackageOnly.sql b/old_tests/ut/ut.run.function.WithPackageName.ExecutesAllFromGivenPackageOnly.sql deleted file mode 100644 index 2cdc8e717..000000000 --- a/old_tests/ut/ut.run.function.WithPackageName.ExecutesAllFromGivenPackageOnly.sql +++ /dev/null @@ -1,26 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_packages_executed integer := 0; -begin - --act - select * bulk collect into l_output_data - from table(ut.run(user||'.test_package_1')); - - for i in 1 .. l_output_data.count loop - if l_output_data(i) like '%test\_package\_1%' escape '\' - or l_output_data(i) like '%test_package_2%' - or l_output_data(i) like '%test_package_3%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 1 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: more than just package test_package_1 was executed. Expected 1, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.function.WithSchemaName.ExecutesAllFromGivenSchema.sql b/old_tests/ut/ut.run.function.WithSchemaName.ExecutesAllFromGivenSchema.sql deleted file mode 100644 index bccf6583a..000000000 --- a/old_tests/ut/ut.run.function.WithSchemaName.ExecutesAllFromGivenSchema.sql +++ /dev/null @@ -1,26 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_packages_executed integer := 0; -begin - --act - select * bulk collect into l_output_data - from table(ut.run(user)); - - for i in 1 .. l_output_data.count loop - if l_output_data(i) like '%test\_package\_1%' escape '\' - or l_output_data(i) like '%test_package_2%' - or l_output_data(i) like '%test_package_3%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 3 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 3, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.run.function.WithSuitePath.ExecutesAllFromGivenPath.sql b/old_tests/ut/ut.run.function.WithSuitePath.ExecutesAllFromGivenPath.sql deleted file mode 100644 index f44c13e79..000000000 --- a/old_tests/ut/ut.run.function.WithSuitePath.ExecutesAllFromGivenPath.sql +++ /dev/null @@ -1,26 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_packages_executed integer := 0; -begin - --act - select * bulk collect into l_output_data - from table(ut.run(user||':tests.test_package_1')); - - for i in 1 .. l_output_data.count loop - if l_output_data(i) like '%test\_package\_1%' escape '\' - or l_output_data(i) like '%test_package_2%' - or l_output_data(i) like '%test_package_3%' then - l_packages_executed := l_packages_executed + 1; - end if; - end loop; - - if l_packages_executed = 2 then - :test_result := ut_utils.gc_success; - else - for i in 1 .. l_output_data.count loop - dbms_output.put_line(l_output_data(i)); - end loop; - dbms_output.put_line('Failed: not all packages were found in the outputs. Expected 2, got '||l_packages_executed); - end if; -end; -/ diff --git a/old_tests/ut/ut.version.sql b/old_tests/ut/ut.version.sql deleted file mode 100644 index 22d04056e..000000000 --- a/old_tests/ut/ut.version.sql +++ /dev/null @@ -1,11 +0,0 @@ -declare - l_expected varchar2(100) := '%.%.%.%'; -begin ---Assert - if ut.version() like l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected version like '''||l_expected ||''' got: '''||ut.version()||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectation_processor/who_called_expectation.parseStackTrace.sql b/old_tests/ut_expectation_processor/who_called_expectation.parseStackTrace.sql deleted file mode 100644 index 9333a9b6a..000000000 --- a/old_tests/ut_expectation_processor/who_called_expectation.parseStackTrace.sql +++ /dev/null @@ -1,34 +0,0 @@ -declare - l_stack_trace varchar2(4000); - l_source_line varchar2(4000); -begin -l_stack_trace := q'[----- PL/SQL Call Stack ----- - object line object - handle number name -34f88e4420 124 package body SCH_TEST.UT_EXPECTATION_PROCESSOR -353dfeb2f8 26 SCH_TEST.UT_EXPECTATION_RESULT -cba249ce0 112 SCH_TEST.UT_EXPECTATION -3539881cf0 21 SCH_TEST.UT_EXPECTATION_NUMBER -351a608008 28 package body SCH_TEST.TPKG_PRIOR_YEAR_GENERATION -351a6862b8 6 anonymous block -351fe31010 1825 package body SYS.DBMS_SQL -20befbe4d8 129 SCH_TEST.UT_EXECUTABLE -20befbe4d8 65 SCH_TEST.UT_EXECUTABLE -34f8ab7cd8 80 SCH_TEST.UT_TEST -34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM -34f8ab9b10 74 SCH_TEST.UT_SUITE -34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM -cba24bfd0 75 SCH_TEST.UT_LOGICAL_SUITE -353dfecf30 59 SCH_TEST.UT_RUN -34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM -357f5421e8 77 package body SCH_TEST.UT_RUNNER -357f5421e8 111 package body SCH_TEST.UT_RUNNER -20be951ab0 292 package body SCH_TEST.UT -20be951ab0 320 package body SCH_TEST.UT -]'; - l_source_line := ut_expectation_processor.WHO_CALLED_EXPECTATION(l_stack_trace); - if l_source_line like 'at "SCH_TEST.TPKG_PRIOR_YEAR_GENERATION", line 28 %' then - :test_result := ut_utils.gc_success; - end if; -end; -/ diff --git a/old_tests/ut_expectation_processor/who_called_expectation.parseStackTraceWith0x.sql b/old_tests/ut_expectation_processor/who_called_expectation.parseStackTraceWith0x.sql deleted file mode 100644 index 1b9996a80..000000000 --- a/old_tests/ut_expectation_processor/who_called_expectation.parseStackTraceWith0x.sql +++ /dev/null @@ -1,28 +0,0 @@ -declare - l_stack_trace varchar2(4000); - l_source_line varchar2(4000); -begin -l_stack_trace := q'[----- PL/SQL Call Stack ----- - object line object - handle number name -0x80e701d8 26 UT3.UT_EXPECTATION_RESULT -0x85e10150 112 UT3.UT_EXPECTATION -0x8b54bad8 21 UT3.UT_EXPECTATION_NUMBER -0x85cfd238 20 package body UT3.UT_EXAMPLETEST -0x85def380 6 anonymous block -0x85e93750 1825 package body SYS.DBMS_SQL -0x80f4f608 129 UT3.UT_EXECUTABLE -0x80f4f608 65 UT3.UT_EXECUTABLE -0x8a116010 76 UT3.UT_TEST -0x8a3348a0 48 UT3.UT_SUITE_ITEM -0x887e9948 67 UT3.UT_LOGICAL_SUITE -0x8a26de20 59 UT3.UT_RUN -0x8a3348a0 48 UT3.UT_SUITE_ITEM -0x838d17c0 28 anonymous block -]'; - l_source_line := ut_expectation_processor.WHO_CALLED_EXPECTATION(l_stack_trace); - if l_source_line like 'at "UT3.UT_EXAMPLETEST", line 20 %' then - :test_result := ut_utils.gc_success; - end if; -end; -/ diff --git a/old_tests/ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql b/old_tests/ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql deleted file mode 100644 index 2921d9745..000000000 --- a/old_tests/ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql +++ /dev/null @@ -1,17 +0,0 @@ ---Arrange -declare - l_actual &&1 := &&2; - l_expected &&1 := &&3; - l_result integer; -begin ---Act - ut.expect(l_actual).not_to_equal(l_expected); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = &&4 then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||&&4||''', got: '''||l_result||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql b/old_tests/ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql deleted file mode 100644 index da139a647..000000000 --- a/old_tests/ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql +++ /dev/null @@ -1,20 +0,0 @@ ---Arrange -declare - l_actual &&1 := &&3; - l_expected &&2 := &&4; - l_result integer; - l_message varchar2(32767); -begin ---Act - ut.expect(l_actual).&&5.to_equal(l_expected); - l_result := ut_expectation_processor.get_status(); - l_message := ut_expectation_processor.get_failed_expectations()(1).get_result_clob; ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = ut_utils.gc_failure - and l_message like 'Actual (%) cannot be compared to Expected (%) using matcher%' then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_failure||''', got: '''||l_result||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.common.sql b/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.common.sql deleted file mode 100644 index 0632246f9..000000000 --- a/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.common.sql +++ /dev/null @@ -1,17 +0,0 @@ ---Arrange -declare - l_actual &&1 := &&2; - l_expected &&1 := &&3; - l_result integer; -begin ---Act - ut.expect(l_actual).to_equal(l_expected); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = &&4 then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||&&4||''', got: '''||l_result||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.null_value_text.common.sql b/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.null_value_text.common.sql deleted file mode 100644 index bfac42e68..000000000 --- a/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.null_value_text.common.sql +++ /dev/null @@ -1,17 +0,0 @@ ---Arrange -declare - l_actual &&1 := &&2; - l_expected &&1 := &&3; - l_result ut_expectation_result; -begin ---Act - ut.expect(l_actual).to_equal(l_expected); - l_result := ut_expectation_processor.get_failed_expectations()(1); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result.get_result_clob like '&&4' then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected text like ''&&4'', but got '''||l_result.get_result_clob||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.with_message.common.sql b/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.with_message.common.sql deleted file mode 100644 index 9b172bc8c..000000000 --- a/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.with_message.common.sql +++ /dev/null @@ -1,19 +0,0 @@ ---Arrange -declare - l_expected &&1 := &&2; - l_actual &&1 := &&3; - l_results ut_expectation_results; - l_test_description varchar2(30) := 'A test message'; -begin ---Act - ut.expect(l_actual, l_test_description ).to_equal( l_expected); - l_results := ut_expectation_processor.get_failed_expectations(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success - and treat(l_results(1) as ut_expectation_result).description like '' || l_test_description || '' then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||treat(l_results(1) as ut_expectation_result).description||''' to match ''%' || l_test_description || '%''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.with_nulls_equal.common.sql b/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.with_nulls_equal.common.sql deleted file mode 100644 index 352ceaf05..000000000 --- a/old_tests/ut_expectations/common/ut.expect.to_equal.scalar.with_nulls_equal.common.sql +++ /dev/null @@ -1,19 +0,0 @@ ---Arrange -declare - l_expected &&1 := &&2; - l_actual &&1 := &&3; - l_result integer; - l_expected_result integer := &&4; - l_nulls_are_equal boolean := &&5; -begin ---Act - ut.expect(l_actual).to_equal(l_expected, l_nulls_are_equal); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = l_expected_result then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||&&4||''', got: '''||l_result||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/ut.expect.not_to_equal.GivesFailureForEqualValues.sql b/old_tests/ut_expectations/ut.expect.not_to_equal.GivesFailureForEqualValues.sql deleted file mode 100644 index d32655480..000000000 --- a/old_tests/ut_expectations/ut.expect.not_to_equal.GivesFailureForEqualValues.sql +++ /dev/null @@ -1,15 +0,0 @@ -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'blob' 'to_blob(''Abc'')' 'to_blob(''abc'')' 'ut_utils.gc_failure'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'boolean' 'false' 'false' 'ut_utils.gc_failure'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'clob' '''Abc''' '''Abc''' 'ut_utils.gc_failure'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'date' 'sysdate' 'sysdate' 'ut_utils.gc_failure'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'number' '12345' '12345' 'ut_utils.gc_failure'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'timestamp(9)' 'to_Timestamp(''2016 123456789'',''yyyy ff'')' 'to_Timestamp(''2016 123456789'',''yyyy ff'')' 'ut_utils.gc_failure'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'timestamp(9) with local time zone' 'to_Timestamp(''2016 123456789'',''yyyy ff'')' 'to_Timestamp(''2016 123456789'',''yyyy ff'')' 'ut_utils.gc_failure'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'timestamp(9) with time zone' 'to_Timestamp(''2016 123456789'',''yyyy ff'')' 'to_Timestamp(''2016 123456789'',''yyyy ff'')' 'ut_utils.gc_failure'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'varchar2(4000)' '''Abc''' '''Abc''' 'ut_utils.gc_failure'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'interval day to second' '''2 01:00:00''' '''2 01:00:00''' 'ut_utils.gc_failure'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'interval year to month' '''1-1''' '''1-1''' 'ut_utils.gc_failure'" - - - - diff --git a/old_tests/ut_expectations/ut.expect.not_to_equal.GivesSuccessForDifferentValues.sql b/old_tests/ut_expectations/ut.expect.not_to_equal.GivesSuccessForDifferentValues.sql deleted file mode 100644 index e30b2c5e5..000000000 --- a/old_tests/ut_expectations/ut.expect.not_to_equal.GivesSuccessForDifferentValues.sql +++ /dev/null @@ -1,11 +0,0 @@ -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'blob' 'to_blob(''abc'')' 'to_blob(''abd'')' 'ut_utils.gc_success'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'boolean' 'true' 'false' 'ut_utils.gc_success'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'clob' '''Abc''' '''abc''' 'ut_utils.gc_success'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'date' 'sysdate' 'sysdate-1' 'ut_utils.gc_success'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'number' '0.1' '0.3' 'ut_utils.gc_success'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'timestamp' 'systimestamp' 'systimestamp' 'ut_utils.gc_success'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'timestamp with local time zone' 'systimestamp' 'systimestamp' 'ut_utils.gc_success'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'timestamp with time zone' 'systimestamp' 'systimestamp' 'ut_utils.gc_success'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'varchar2(4000)' '''Abc''' '''abc''' 'ut_utils.gc_success'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'interval day to second' '''2 01:00:00''' '''2 01:00:01''' 'ut_utils.gc_success'" -@@lib/RunTest.sql "ut_expectations/common/ut.expect.not_to_equal.scalar.common.sql 'interval year to month' '''1-1''' '''1-2''' 'ut_utils.gc_success'" diff --git a/old_tests/ut_expectations/ut.expect.not_to_equal.anydata.GivesFailureWhenComparingTheSameData.sql b/old_tests/ut_expectations/ut.expect.not_to_equal.anydata.GivesFailureWhenComparingTheSameData.sql deleted file mode 100644 index 9af3ed06d..000000000 --- a/old_tests/ut_expectations/ut.expect.not_to_equal.anydata.GivesFailureWhenComparingTheSameData.sql +++ /dev/null @@ -1,17 +0,0 @@ ---Arrange -declare - l_expected department$ := department$('hr'); - l_actual department$ := department$('hr'); - l_result integer; -begin ---Act - ut.expect( anydata.convertObject(l_actual) ).not_to_equal( anydata.convertObject(l_expected) ); - l_result := ut_expectation_processor.get_status(); ---Assert - if l_result = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_success||''', got: '''||l_result||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNotBoolean.sql b/old_tests/ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNotBoolean.sql deleted file mode 100644 index 58c15bffb..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNotBoolean.sql +++ /dev/null @@ -1,21 +0,0 @@ -PROMPT Gives a failre when expression evaluates to a boolean true ---Arrange -declare - l_result integer; -begin ---Act - ut.expect( 1 ).to_( be_false() ); - ut.expect( 1 ).not_to( be_true() ); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_failure||''', got: '''||l_result||'''' ); - end if; -end; -/ - - - - diff --git a/old_tests/ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNull.sql b/old_tests/ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNull.sql deleted file mode 100644 index 4b3cbbab2..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNull.sql +++ /dev/null @@ -1,21 +0,0 @@ -PROMPT Gives a failre when expression evaluates to a boolean null ---Arrange -declare - l_result integer; -begin ---Act - ut.expect( 1 = null ).to_be_false(); - ut.expect( 1 = null ).not_to_be_true(); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_failure||''', got: '''||l_result||'''' ); - end if; -end; -/ - - - - diff --git a/old_tests/ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsTrue.sql b/old_tests/ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsTrue.sql deleted file mode 100644 index 6b2357c20..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsTrue.sql +++ /dev/null @@ -1,21 +0,0 @@ -PROMPT Gives a failre when expression evaluates to a boolean true ---Arrange -declare - l_result integer; -begin ---Act - ut.expect( 1 = 1 ).to_be_false(); - ut.expect( 1 = 1 ).not_to_be_true(); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_failure||''', got: '''||l_result||'''' ); - end if; -end; -/ - - - - diff --git a/old_tests/ut_expectations/ut.expect.to_be_false.GivesSuccessWhenExpessionIsFalse.sql b/old_tests/ut_expectations/ut.expect.to_be_false.GivesSuccessWhenExpessionIsFalse.sql deleted file mode 100644 index cdee68133..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_false.GivesSuccessWhenExpessionIsFalse.sql +++ /dev/null @@ -1,21 +0,0 @@ -PROMPT Gives a success when expression evaluates to a boolean false ---Arrange -declare - l_result integer; -begin ---Act - ut.expect( 1 = 0 ).to_be_false(); - ut.expect( 1 = 0 ).not_to_be_true(); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_success||''', got: '''||l_result||'''' ); - end if; -end; -/ - - - - diff --git a/old_tests/ut_expectations/ut.expect.to_be_like.FailsForUnsupportedDatatype.sql b/old_tests/ut_expectations/ut.expect.to_be_like.FailsForUnsupportedDatatype.sql deleted file mode 100644 index 68aa1cc3a..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_like.FailsForUnsupportedDatatype.sql +++ /dev/null @@ -1,17 +0,0 @@ -declare - l_actual number := 1234; - l_pattern varchar2(32767) := '1234'; - l_escape_char varchar2(32767) := ''; - l_result integer; -begin ---Act - ut.expect( l_actual ).to_( be_like(l_pattern, l_escape_char) ); - l_result := ut_expectation_processor.get_status(); ---Assert - if l_result = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||l_actual||''', to be like '''||l_pattern||''' escape'''||l_escape_char||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenAnydataIsNull.sql b/old_tests/ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenAnydataIsNull.sql deleted file mode 100644 index a338ee2ad..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenAnydataIsNull.sql +++ /dev/null @@ -1,16 +0,0 @@ -PROMPT Gives a success when the Anydata argument is null ---Arrange -declare - l_result integer; -begin ---Act - ut.expect( cast(null as anydata) ).to_be_null(); - l_result := ut_expectation_processor.get_status(); ---Assert - if l_result = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_success||''', got: '''||l_result||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenCollectionPassedIsNull.sql b/old_tests/ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenCollectionPassedIsNull.sql deleted file mode 100644 index 29ef147fa..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenCollectionPassedIsNull.sql +++ /dev/null @@ -1,16 +0,0 @@ ---Arrange -declare - l_expected ut_varchar2_list; - l_result integer; -begin ---Act - ut.expect( anydata.convertCollection(l_expected) ).to_be_null(); - l_result := ut_expectation_processor.get_status(); ---Assert - if l_result = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_success||''', got: '''||l_result||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenObjectPassedIsNull.sql b/old_tests/ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenObjectPassedIsNull.sql deleted file mode 100644 index 970216166..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenObjectPassedIsNull.sql +++ /dev/null @@ -1,16 +0,0 @@ ---Arrange -declare - l_expected department$; - l_result integer; -begin ---Act - ut.expect( anydata.convertObject(l_expected) ).to_be_null(); - l_result := ut_expectation_processor.get_status(); ---Assert - if l_result = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_success||''', got: '''||l_result||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/ut.expect.to_be_null.refcursor.GivesSuccessWhenCursorIsNull.sql b/old_tests/ut_expectations/ut.expect.to_be_null.refcursor.GivesSuccessWhenCursorIsNull.sql deleted file mode 100644 index e5952b871..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_null.refcursor.GivesSuccessWhenCursorIsNull.sql +++ /dev/null @@ -1,17 +0,0 @@ -PROMPT Gives a success when the Cursor is null ---Arrange -declare - l_cursor sys_refcursor; - l_result integer; -begin ---Act - ut.expect( l_cursor ).to_be_null(); - l_result := ut_expectation_processor.get_status(); ---Assert - if l_result = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_success||''', got: '''||l_result||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsFalse.sql b/old_tests/ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsFalse.sql deleted file mode 100644 index 9b7459868..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsFalse.sql +++ /dev/null @@ -1,21 +0,0 @@ -PROMPT Gives a failre when expression evaluates to a boolean false ---Arrange -declare - l_result integer; -begin ---Act - ut.expect( 1 = 0 ).to_be_true(); - ut.expect( 1 = 0 ).not_to_be_false(); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_failure||''', got: '''||l_result||'''' ); - end if; -end; -/ - - - - diff --git a/old_tests/ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsNotBoolean.sql b/old_tests/ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsNotBoolean.sql deleted file mode 100644 index d099e7316..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsNotBoolean.sql +++ /dev/null @@ -1,21 +0,0 @@ -PROMPT Gives a failre when expression evaluates to a boolean false ---Arrange -declare - l_result integer; -begin ---Act - ut.expect( 1 ).to_( be_true() ); - ut.expect( 1 ).not_to( be_false() ); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_failure||''', got: '''||l_result||'''' ); - end if; -end; -/ - - - - diff --git a/old_tests/ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsNull.sql b/old_tests/ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsNull.sql deleted file mode 100644 index 4ea53dff5..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsNull.sql +++ /dev/null @@ -1,21 +0,0 @@ -PROMPT Gives a failre when expression evaluates to a boolean null ---Arrange -declare - l_result integer; -begin ---Act - ut.expect( 1 = null ).to_be_true(); - ut.expect( 1 = null ).not_to_be_false(); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_failure||''', got: '''||l_result||'''' ); - end if; -end; -/ - - - - diff --git a/old_tests/ut_expectations/ut.expect.to_be_true.GivesSuccessWhenExpessionIsTrue.sql b/old_tests/ut_expectations/ut.expect.to_be_true.GivesSuccessWhenExpessionIsTrue.sql deleted file mode 100644 index b4dc25197..000000000 --- a/old_tests/ut_expectations/ut.expect.to_be_true.GivesSuccessWhenExpessionIsTrue.sql +++ /dev/null @@ -1,21 +0,0 @@ -PROMPT Gives a success when expression evaluates to a boolean true ---Arrange -declare - l_result integer; -begin ---Act - ut.expect( 1 = 1 ).to_be_true(); - ut.expect( 1 = 1 ).not_to_be_false(); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_success||''', got: '''||l_result||'''' ); - end if; -end; -/ - - - - diff --git a/old_tests/ut_expectations/ut.expect.to_equal.cursor.UsesDefaultNLSSettingsForDatesFormatting.sql b/old_tests/ut_expectations/ut.expect.to_equal.cursor.UsesDefaultNLSSettingsForDatesFormatting.sql deleted file mode 100644 index 09e58bcf8..000000000 --- a/old_tests/ut_expectations/ut.expect.to_equal.cursor.UsesDefaultNLSSettingsForDatesFormatting.sql +++ /dev/null @@ -1,19 +0,0 @@ ---Arrange -declare - l_actual SYS_REFCURSOR; - l_expected SYS_REFCURSOR; - l_result integer; -begin ---Act - open l_actual for select sysdate as some_date from dual; - open l_expected for select to_char(sysdate) some_date from dual; - ut.expect(l_actual).to_equal(l_expected); - l_result := ut_expectation_processor.get_status(); ---Assert - if nvl(:test_result, ut_utils.gc_success) = ut_utils.gc_success and l_result = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_success||''', got: '''||l_result||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/ut.expect.to_equal.cursor.worksOnLargeDatasets.sql b/old_tests/ut_expectations/ut.expect.to_equal.cursor.worksOnLargeDatasets.sql deleted file mode 100644 index f4ad730d3..000000000 --- a/old_tests/ut_expectations/ut.expect.to_equal.cursor.worksOnLargeDatasets.sql +++ /dev/null @@ -1,21 +0,0 @@ ---Arrange -declare - l_actual sys_refcursor; - l_expected sys_refcursor; - l_result integer; -begin ---Act - open l_actual for select object_name from all_objects where rownum <=1100; - open l_expected for select object_name from all_objects where rownum <=1100; - ut.expect(l_actual).to_equal(l_expected); - ---Assert - l_result := ut_expectation_processor.get_status(); ---Assert - if l_result = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected 1 data and got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/ut.expect.to_match.FailsForUnsupportedDatatype.sql b/old_tests/ut_expectations/ut.expect.to_match.FailsForUnsupportedDatatype.sql deleted file mode 100644 index 0d8a93ac2..000000000 --- a/old_tests/ut_expectations/ut.expect.to_match.FailsForUnsupportedDatatype.sql +++ /dev/null @@ -1,17 +0,0 @@ -declare - l_actual number := 1234; - l_pattern varchar2(32767) := '^1234'; - l_modifiers varchar2(32767) := 'i'; - l_result integer; -begin ---Act - ut.expect( l_actual ).to_( match(l_pattern, l_modifiers) ); - l_result := ut_expectation_processor.get_status(); ---Assert - if l_result = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||l_actual||''', to match: '''||l_pattern||''' using modifiers:'''||l_modifiers||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_expectations/ut_data_value_object.compare.Gives0WhenComparingIdenticalObjects.sql b/old_tests/ut_expectations/ut_data_value_object.compare.Gives0WhenComparingIdenticalObjects.sql deleted file mode 100644 index d6b70de79..000000000 --- a/old_tests/ut_expectations/ut_data_value_object.compare.Gives0WhenComparingIdenticalObjects.sql +++ /dev/null @@ -1,22 +0,0 @@ ---Arrange -declare - l_expected department$ := department$('HR'); - l_actual department$ := department$('HR'); - l_result integer; -begin ---Act - l_result := - ut_data_value_object( - anydata.convertObject(l_actual) - ).compare_implementation( - ut_data_value_object( - anydata.convertObject(l_expected)) - ); ---Assert - if l_result = 0 then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line( 'Expected comparison to give 0, got '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_matchers/be_between.sql b/old_tests/ut_matchers/be_between.sql deleted file mode 100644 index 0ec54cf27..000000000 --- a/old_tests/ut_matchers/be_between.sql +++ /dev/null @@ -1,72 +0,0 @@ ---failure when value out of range -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'date' 'sysdate' 'sysdate-2' 'sysdate-1' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'number' '2.0' '1.99' '1.999' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'varchar2(1)' '''c''' '''a''' '''b''' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp' 'systimestamp+1' 'systimestamp-1' 'systimestamp' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with local time zone' 'systimestamp+1' 'systimestamp-1' 'systimestamp' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with time zone' 'systimestamp+1' 'systimestamp-1' 'systimestamp' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval year to month' '''2-2''' '''2-0''' '''2-1''' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval day to second' '''2 01:00:00''' '''2 00:59:58''' '''2 00:59:59''' 'ut_utils.gc_failure' ''" ---success when value in range -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'date' 'sysdate' 'sysdate-1' 'sysdate+1' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'number' '2.0' '1.99' '2.01' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'varchar2(1)' '''b''' '''a''' '''c''' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp' 'systimestamp' 'systimestamp-1' 'systimestamp+1' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with local time zone' 'systimestamp' 'systimestamp-1' 'systimestamp+1' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with time zone' 'systimestamp' 'systimestamp-1' 'systimestamp+1' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval year to month' '''2-1''' '''2-0''' '''2-2''' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval day to second' '''2 01:00:00''' '''2 00:59:58''' '''2 01:00:01''' 'ut_utils.gc_success' ''" ---success when value not in range -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'date' 'sysdate' 'sysdate-2' 'sysdate-1' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'number' '2.0' '1.99' '1.999' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'varchar2(1)' '''c''' '''a''' '''b''' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp' 'systimestamp+1' 'systimestamp-1' 'systimestamp' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with local time zone' 'systimestamp+1' 'systimestamp-1' 'systimestamp' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with time zone' 'systimestamp+1' 'systimestamp-1' 'systimestamp' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval year to month' '''2-2''' '''2-0''' '''2-1''' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval day to second' '''2 01:00:00''' '''2 00:59:58''' '''2 00:59:59''' 'ut_utils.gc_success' 'not_'" ---failure when value not out of range -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'date' 'sysdate' 'sysdate-1' 'sysdate+1' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'number' '2.0' '1.99' '2.01' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'varchar2(1)' '''b''' '''a''' '''c''' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp' 'systimestamp' 'systimestamp-1' 'systimestamp+1' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with local time zone' 'systimestamp' 'systimestamp-1' 'systimestamp+1' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with time zone' 'systimestamp' 'systimestamp-1' 'systimestamp+1' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval year to month' '''2-1''' '''2-0''' '''2-2''' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval day to second' '''2 01:00:00''' '''2 00:59:58''' '''2 01:00:01''' 'ut_utils.gc_failure' 'not_'" - ---failure when value is null -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'date' 'null' 'sysdate-1' 'sysdate+1' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'number' 'null' '1.99' '2.01' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'varchar2(1)' 'null' '''a''' '''c''' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp' 'null' 'systimestamp-1' 'systimestamp+1' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with local time zone' 'null' 'systimestamp-1' 'systimestamp+1' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with time zone' 'null' 'systimestamp-1' 'systimestamp+1' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval year to month' 'null' '''2-0''' '''2-2''' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval day to second' 'null' '''2 00:59:58''' '''2 01:00:01''' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'date' 'null' 'sysdate-2' 'sysdate-1' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'number' 'null' '1.99' '1.999' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'varchar2(1)' 'null' '''a''' '''b''' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp' 'null' 'systimestamp-1' 'systimestamp' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with local time zone' 'null' 'systimestamp-1' 'systimestamp' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with time zone' 'null' 'systimestamp-1' 'systimestamp' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval year to month' 'null' '''2-0''' '''2-1''' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval day to second' 'null' '''2 00:59:58''' '''2 00:59:59''' 'ut_utils.gc_failure' 'not_'" - ---failure when lower bound is null -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'date' 'sysdate' 'null' 'sysdate+1' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'number' '2.0' 'null' '2.01' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'varchar2(1)' '''b''' 'null' '''c''' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp' 'systimestamp' 'null' 'systimestamp+1' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with local time zone' 'systimestamp' 'null' 'systimestamp+1' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with time zone' 'systimestamp' 'null' 'systimestamp+1' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval year to month' '''2-1''' 'null' '''2-2''' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval day to second' '''2 01:00:00''' 'null' '''2 01:00:01''' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'date' 'sysdate' 'null' 'sysdate-1' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'number' '2.0' 'null' '1.999' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'varchar2(1)' '''b''' 'null' '''b''' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp' 'systimestamp+1' 'null' 'systimestamp' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with local time zone' 'systimestamp+1' 'null' 'systimestamp' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'timestamp with time zone' 'systimestamp+1' 'null' 'systimestamp' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval year to month' '''2-2''' 'null' '''2-1''' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.be_between.sql 'interval day to second' '''2 01:00:00''' 'null' '''2 00:59:59''' 'ut_utils.gc_failure' 'not_'" diff --git a/old_tests/ut_matchers/be_like.sql b/old_tests/ut_matchers/be_like.sql deleted file mode 100644 index 186e3e24a..000000000 --- a/old_tests/ut_matchers/be_like.sql +++ /dev/null @@ -1,19 +0,0 @@ -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'varchar2(100)' '''Stephen_King''' 'Ste__en%' '' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'varchar2(100)' '''Stephen_King''' 'Ste__en\_K%' '\' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'clob' 'rpad(''a'',32767,''a'')||''Stephen_King''' 'a%Ste__en%' '' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'clob' 'rpad(''a'',32767,''a'')||''Stephen_King''' 'a%Ste__en\_K%' '\' 'ut_utils.gc_success' ''" - -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'varchar2(100)' '''Stephen_King''' 'Ste_en%' '' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'varchar2(100)' '''Stephen_King''' 'Stephe\__%' '\' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'clob' 'rpad(''a'',32767,''a'')||''Stephen_King''' 'a%Ste_en%' '' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'clob' 'rpad(''a'',32767,''a'')||''Stephen_King''' 'a%Stephe\__%' '\' 'ut_utils.gc_failure' ''" - -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'varchar2(100)' '''Stephen_King''' 'Ste__en%' '' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'varchar2(100)' '''Stephen_King''' 'Ste__en\_K%' '\' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'clob' 'rpad(''a'',32767,''a'')||''Stephen_King''' 'a%Ste__en%' '' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'clob' 'rpad(''a'',32767,''a'')||''Stephen_King''' 'a%Ste__en\_K%' '\' 'ut_utils.gc_failure' 'not_'" - -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'varchar2(100)' '''Stephen_King''' 'Ste_en%' '' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'varchar2(100)' '''Stephen_King''' 'Stephe\__%' '\' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'clob' 'rpad(''a'',32767,''a'')||''Stephen_King''' 'a%Ste_en%' '' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_be_like.common.sql 'clob' 'rpad(''a'',32767,''a'')||''Stephen_King''' 'a%Stephe\__%' '\' 'ut_utils.gc_success' 'not_'" diff --git a/old_tests/ut_matchers/common/ut.expect.common.be_between.sql b/old_tests/ut_matchers/common/ut.expect.common.be_between.sql deleted file mode 100644 index 9a2b33ab4..000000000 --- a/old_tests/ut_matchers/common/ut.expect.common.be_between.sql +++ /dev/null @@ -1,17 +0,0 @@ ---Arrange -declare - l_value1 &&1 := &&2; - l_value_lower &&1 := &&3; - l_value_upper &&1 := &&4; -begin ---Act - ut.expect(l_value1).&&6.to_be_between(l_value_lower,l_value_upper); ---Assert - if ut_expectation_processor.get_status = &&5 then - :test_result := ut_utils.gc_success; - else - :test_result := ut_utils.gc_failure; - dbms_output.put_line('expected: '''||&&5||''', got: '''||ut_expectation_processor.get_status||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_matchers/common/ut.expect.to_be_like.common.sql b/old_tests/ut_matchers/common/ut.expect.to_be_like.common.sql deleted file mode 100644 index d76e9a530..000000000 --- a/old_tests/ut_matchers/common/ut.expect.to_be_like.common.sql +++ /dev/null @@ -1,17 +0,0 @@ -declare - l_actual &1 := &2; - l_pattern varchar2(32767) := '&3'; - l_escape_char varchar2(32767) := '&4'; - l_result integer; -begin ---Act - ut.expect( l_actual ).&&6.to_be_like(l_pattern, l_escape_char); - l_result := ut_expectation_processor.get_status(); ---Assert - if l_result = &5 then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||l_actual||''', to be like '''||l_pattern||''' escape'''||l_escape_char||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_matchers/common/ut.expect.to_match.common.sql b/old_tests/ut_matchers/common/ut.expect.to_match.common.sql deleted file mode 100644 index 441d0205f..000000000 --- a/old_tests/ut_matchers/common/ut.expect.to_match.common.sql +++ /dev/null @@ -1,17 +0,0 @@ -declare - l_actual &1 := &2; - l_pattern varchar2(32767) := '&3'; - l_modifiers varchar2(32767) := '&4'; - l_result integer; -begin ---Act - ut.expect( l_actual ).&&6.to_match(l_pattern, l_modifiers); - l_result := ut_expectation_processor.get_status(); ---Assert - if l_result = &5 then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||l_actual||''', to match: '''||l_pattern||''' using modifiers:'''||l_modifiers||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_matchers/match.sql b/old_tests/ut_matchers/match.sql deleted file mode 100644 index 29028762e..000000000 --- a/old_tests/ut_matchers/match.sql +++ /dev/null @@ -1,19 +0,0 @@ -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'varchar2(100)' '''Stephen''' '^Ste(v|ph)en$' '' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'varchar2(100)' '''sTEPHEN''' '^Ste(v|ph)en$' 'i' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'clob' 'rpad('' '',32767)||''Stephen''' 'Ste(v|ph)en$' '' 'ut_utils.gc_success' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'clob' 'rpad('' '',32767)||''sTEPHEN''' 'Ste(v|ph)en$' 'i' 'ut_utils.gc_success' ''" - -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'varchar2(100)' '''Stephen''' '^Steven$' '' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'varchar2(100)' '''sTEPHEN''' '^Steven$' 'i' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'clob' 'to_clob(rpad('' '',32767)||''Stephen'')' '^Stephen' '' 'ut_utils.gc_failure' ''" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'clob' 'to_clob(rpad('' '',32767)||''sTEPHEN'')' '^Stephen' 'i' 'ut_utils.gc_failure' ''" - -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'varchar2(100)' '''Stephen''' '^Ste(v|ph)en$' '' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'varchar2(100)' '''sTEPHEN''' '^Ste(v|ph)en$' 'i' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'clob' 'rpad('' '',32767)||''Stephen''' 'Ste(v|ph)en$' '' 'ut_utils.gc_failure' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'clob' 'rpad('' '',32767)||''sTEPHEN''' 'Ste(v|ph)en$' 'i' 'ut_utils.gc_failure' 'not_'" - -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'varchar2(100)' '''Stephen''' '^Steven$' '' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'varchar2(100)' '''sTEPHEN''' '^Steven$' 'i' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'clob' 'to_clob(rpad('' '',32767)||''Stephen'')' '^Stephen' '' 'ut_utils.gc_success' 'not_'" -@@lib/RunTest.sql "ut_matchers/common/ut.expect.to_match.common.sql 'clob' 'to_clob(rpad('' '',32767)||''sTEPHEN'')' '^Stephen' 'i' 'ut_utils.gc_success' 'not_'" diff --git a/old_tests/ut_matchers/timestamp_between.sql b/old_tests/ut_matchers/timestamp_between.sql deleted file mode 100644 index 622b8092d..000000000 --- a/old_tests/ut_matchers/timestamp_between.sql +++ /dev/null @@ -1,17 +0,0 @@ ---Arrange -declare - l_value timestamp := to_timestamp('1997-01-31 09:26:50.13','YYYY-MM-DD HH24.MI.SS.FF'); - l_value_lower timestamp := to_timestamp('1997-01-31 09:26:50.11','YYYY-MM-DD HH24.MI.SS.FF'); - l_value_upper timestamp := to_timestamp('1997-01-31 09:26:50.14','YYYY-MM-DD HH24.MI.SS.FF'); -begin - --Act - ut.expect(l_value).to_be_between(l_value_lower,l_value_upper); - --Assert - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_success||''', got: '''||ut_expectation_processor.get_status||'''' ); - end if; -end; -/ - diff --git a/old_tests/ut_matchers/timestamp_ltz_between.sql b/old_tests/ut_matchers/timestamp_ltz_between.sql deleted file mode 100644 index e4ab6b566..000000000 --- a/old_tests/ut_matchers/timestamp_ltz_between.sql +++ /dev/null @@ -1,16 +0,0 @@ ---Arrange -declare - l_value timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +02:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); - l_value_lower timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +03:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); - l_value_upper timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +01:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); -begin - --Act - ut.expect(l_value).to_be_between(l_value_lower,l_value_upper); - --Assert - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_success||''', got: '''||ut_expectation_processor.get_status||'''' ); - end if; -end; -/ diff --git a/old_tests/ut_matchers/timestamp_ltz_not_between.sql b/old_tests/ut_matchers/timestamp_ltz_not_between.sql deleted file mode 100644 index 6d7f71a62..000000000 --- a/old_tests/ut_matchers/timestamp_ltz_not_between.sql +++ /dev/null @@ -1,17 +0,0 @@ ---Arrange -declare - l_value_tlz timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +01:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); - l_value_lower_tlz timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +02:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); - l_value_upper_tlz timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +03:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); -begin - --Act - ut.expect(l_value_tlz).to_be_between(l_value_lower_tlz,l_value_upper_tlz); - --Assert - if ut_expectation_processor.get_status = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_failure||''', got: '''||ut_expectation_processor.get_status||'''' ); - end if; -end; -/ - diff --git a/old_tests/ut_matchers/timestamp_not_between.sql b/old_tests/ut_matchers/timestamp_not_between.sql deleted file mode 100644 index 7365e63ce..000000000 --- a/old_tests/ut_matchers/timestamp_not_between.sql +++ /dev/null @@ -1,17 +0,0 @@ ---Arrange -declare - l_value timestamp := to_timestamp('1997-01-31 09:26:50.13','YYYY-MM-DD HH24.MI.SS.FF'); - l_value_lower timestamp := to_timestamp('1997-01-31 09:26:50.11','YYYY-MM-DD HH24.MI.SS.FF'); - l_value_upper timestamp := to_timestamp('1997-01-31 09:26:50.12','YYYY-MM-DD HH24.MI.SS.FF'); -begin - --Act - ut.expect(l_value).to_be_between(l_value_lower,l_value_upper); - --Assert - if ut_expectation_processor.get_status = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_failure||''', got: '''||ut_expectation_processor.get_status||'''' ); - end if; -end; -/ - diff --git a/old_tests/ut_matchers/timestamp_tz_between.sql b/old_tests/ut_matchers/timestamp_tz_between.sql deleted file mode 100644 index 0c178dace..000000000 --- a/old_tests/ut_matchers/timestamp_tz_between.sql +++ /dev/null @@ -1,17 +0,0 @@ ---Arrange -declare - l_value timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +02:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); - l_value_lower timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +03:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); - l_value_upper timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +01:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); -begin - --Act - ut.expect(l_value).to_be_between(l_value_lower,l_value_upper); - --Assert - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '''||ut_utils.gc_success||''', got: '''||ut_expectation_processor.get_status||'''' ); - end if; -end; -/ - diff --git a/old_tests/ut_matchers/timestamp_tz_not_between.sql b/old_tests/ut_matchers/timestamp_tz_not_between.sql deleted file mode 100644 index 8ac3fac6d..000000000 --- a/old_tests/ut_matchers/timestamp_tz_not_between.sql +++ /dev/null @@ -1,18 +0,0 @@ ---Arrange -declare - l_value_tz timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +01:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); - l_value_lower_tz timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +02:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); - l_value_upper_tz timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +03:00','YYYY-MM-DD HH24.MI.SS.FF TZR'); -begin - --Act - ut.expect(l_value_tz).to_be_between(l_value_lower_tz,l_value_upper_tz); - --Assert - if ut_expectation_processor.get_status = ut_utils.gc_failure then - :test_result := ut_utils.gc_success; - else - :test_result := ut_utils.gc_failure; - dbms_output.put_line('expected: '''||ut_utils.gc_failure||''', got: '''||ut_expectation_processor.get_status||'''' ); - end if; -end; -/ - diff --git a/old_tests/ut_output_buffer/get_lines.RecievesALineFromBufferTableAndDeletes.sql b/old_tests/ut_output_buffer/get_lines.RecievesALineFromBufferTableAndDeletes.sql deleted file mode 100644 index 81aac7d7d..000000000 --- a/old_tests/ut_output_buffer/get_lines.RecievesALineFromBufferTableAndDeletes.sql +++ /dev/null @@ -1,33 +0,0 @@ ---Arrange -declare - l_result varchar2(4000); - l_remaining integer; - l_expected varchar2(4000); - l_output ut_output_buffer_base := ut_output_table_buffer(); -begin - --Act - l_expected := lpad('a text',4000,',a text'); - l_output.send_line(l_expected); - - select * into l_result from table(l_output.get_lines(a_timeout_sec => 0)); - select count(1) into l_remaining from ut_output_buffer_tmp where output_id = l_output.output_id; - - --Assert - ut.expect(l_result).to_equal(l_expected); - ut.expect(l_remaining).to_equal(0); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line(ut_expectation_processor.get_failed_expectations()(1).get_result_clob); - end if; - - delete from ut_output_buffer_tmp where output_id = l_output.output_id; - commit; -exception - when others then - delete from ut_output_buffer_tmp where output_id = l_output.output_id; - commit; - raise; -end; -/ diff --git a/old_tests/ut_output_buffer/get_lines.WaitsForMoreDataToAppearForSpecifiedTime.sql b/old_tests/ut_output_buffer/get_lines.WaitsForMoreDataToAppearForSpecifiedTime.sql deleted file mode 100644 index c8f343492..000000000 --- a/old_tests/ut_output_buffer/get_lines.WaitsForMoreDataToAppearForSpecifiedTime.sql +++ /dev/null @@ -1,24 +0,0 @@ ---Arrange -declare - l_result integer; - l_dummy integer; - l_output ut_output_buffer_base := ut_output_table_buffer(); - l_start_time timestamp := systimestamp; - l_wait_seconds integer := 1; -begin - --Act - l_output.send_line(lpad('a text',4000,',a text')); - - select count(*) into l_dummy from table( l_output.get_lines( a_initial_timeout => 0, a_timeout_sec => l_wait_seconds )); - l_result := round(extract(second from (systimestamp - l_start_time))); - - --Assert - ut.expect(l_result).to_equal(l_wait_seconds); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line(ut_expectation_processor.get_failed_expectations()(1).get_result_clob); - end if; -end; -/ diff --git a/old_tests/ut_output_buffer/get_lines.WaitsForTheDataToAppearForSpecifiedTime.sql b/old_tests/ut_output_buffer/get_lines.WaitsForTheDataToAppearForSpecifiedTime.sql deleted file mode 100644 index 037f6db9b..000000000 --- a/old_tests/ut_output_buffer/get_lines.WaitsForTheDataToAppearForSpecifiedTime.sql +++ /dev/null @@ -1,22 +0,0 @@ ---Arrange -declare - l_result integer; - l_dummy integer; - l_output ut_output_buffer_base := ut_output_table_buffer(); - l_start_time timestamp := systimestamp; - l_wait_seconds integer := 1; -begin - --Act - select count(1) into l_dummy from table( l_output.get_lines( a_initial_timeout => l_wait_seconds, a_timeout_sec => 0 )); - l_result := round(extract(second from (systimestamp - l_start_time))); - - --Assert - ut.expect(l_result).to_equal(l_wait_seconds); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line(ut_expectation_processor.get_failed_expectations()(1).get_result_clob); - end if; -end; -/ diff --git a/old_tests/ut_output_buffer/send_line.DoesNotSendLineIfNullTextGiven.sql b/old_tests/ut_output_buffer/send_line.DoesNotSendLineIfNullTextGiven.sql deleted file mode 100644 index 5bdbba31a..000000000 --- a/old_tests/ut_output_buffer/send_line.DoesNotSendLineIfNullTextGiven.sql +++ /dev/null @@ -1,21 +0,0 @@ ---Arrange -declare - l_result integer; - l_output ut_output_buffer_base := ut_output_table_buffer(); -begin - delete from ut_output_buffer_tmp; - --Act - l_output.send_line(null); - - select count(1) into l_result from ut_output_buffer_tmp; - - --Assert - ut.expect(l_result).to_equal(0); - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line(ut_expectation_processor.get_failed_expectations()(1).get_result_clob); - end if; - -end; -/ diff --git a/old_tests/ut_output_buffer/send_line.SendsALineIntoBufferTable.sql b/old_tests/ut_output_buffer/send_line.SendsALineIntoBufferTable.sql deleted file mode 100644 index 8c2348143..000000000 --- a/old_tests/ut_output_buffer/send_line.SendsALineIntoBufferTable.sql +++ /dev/null @@ -1,24 +0,0 @@ ---Arrange -declare - l_result varchar2(4000); - l_expected varchar2(4000); - l_output ut_output_buffer_base := ut_output_table_buffer(); -begin - --Act - l_expected := lpad('a text',4000,',a text'); - l_output.send_line(l_expected); - - select text into l_result from ut_output_buffer_tmp where output_id = l_output.output_id; - - --Assert - ut.expect(l_result).to_equal(l_expected); - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line(ut_expectation_processor.get_failed_expectations()(1).get_result_clob); - end if; - - delete from ut_output_buffer_tmp where output_id = l_output.output_id; - commit; -end; -/ diff --git a/old_tests/ut_reporters/ut_coverage_sonar_reporter.AcceptsFileMapping.sql b/old_tests/ut_reporters/ut_coverage_sonar_reporter.AcceptsFileMapping.sql deleted file mode 100644 index a27cb4ef4..000000000 --- a/old_tests/ut_reporters/ut_coverage_sonar_reporter.AcceptsFileMapping.sql +++ /dev/null @@ -1,27 +0,0 @@ -declare - l_results ut_varchar2_list; - l_clob clob; - l_expected varchar2(32767); -begin - l_expected := '%'; - select * - bulk collect into l_results - from table( - ut.run( - 'test_reporters', - ut_coverage_sonar_reporter(), - a_source_file_mappings => ut_file_mapper.build_file_mappings( user, ut_varchar2_list( - 'tests/helpers/test_reporters.pkb' ) - ) - ) - ); - l_clob := ut_utils.table_to_clob(l_results); - - if l_clob like l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line(l_clob); - end if; - -end; -/ diff --git a/old_tests/ut_reporters/ut_coverage_sonar_reporter.BuildsSonarCoverageReport.sql b/old_tests/ut_reporters/ut_coverage_sonar_reporter.BuildsSonarCoverageReport.sql deleted file mode 100644 index e76385cfa..000000000 --- a/old_tests/ut_reporters/ut_coverage_sonar_reporter.BuildsSonarCoverageReport.sql +++ /dev/null @@ -1,20 +0,0 @@ -declare - l_results ut_varchar2_list; - l_clob clob; - l_expected varchar2(32767); -begin - l_expected := '%'; - select * - bulk collect into l_results - from table(ut.run('test_reporters',ut_coverage_sonar_reporter(), a_include_objects => ut_varchar2_list('test_reporters'))); - l_clob := ut_utils.table_to_clob(l_results); - - if l_clob like l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line(l_clob); - end if; - -end; -/ - diff --git a/old_tests/ut_reporters/ut_sonar_test_reporter.AcceptsFileMapping.sql b/old_tests/ut_reporters/ut_sonar_test_reporter.AcceptsFileMapping.sql deleted file mode 100644 index 4e4bea8dc..000000000 --- a/old_tests/ut_reporters/ut_sonar_test_reporter.AcceptsFileMapping.sql +++ /dev/null @@ -1,38 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_output varchar2(32767); - l_expected varchar2(32767); -begin - l_expected := q'[ - -% - - -% -%%% -%%% -%% - -]'; - - --act - select * - bulk collect into l_output_data - from table( - ut.run( - 'test_reporters', - ut_sonar_test_reporter(), - a_test_file_mappings => ut_file_mapper.build_file_mappings( user, ut_varchar2_list('tests/helpers/test_reporters.pkb', 'tests/helpers/test_reporters_1.pkb')) - ) - ); - - l_output := ut_utils.table_to_clob(l_output_data); - - --assert - if l_output like l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('Actual:"'||l_output||'"'); - end if; -end; -/ diff --git a/old_tests/ut_reporters/ut_sonar_test_reporter.ProducesExpectedOutputs.sql b/old_tests/ut_reporters/ut_sonar_test_reporter.ProducesExpectedOutputs.sql deleted file mode 100644 index 51fd3c7c7..000000000 --- a/old_tests/ut_reporters/ut_sonar_test_reporter.ProducesExpectedOutputs.sql +++ /dev/null @@ -1,32 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_output varchar2(32767); - l_expected varchar2(32767); -begin - l_expected := q'[ - -% - - -% -%%% -%%% -%% - -]'; - - --act - select * - bulk collect into l_output_data - from table(ut.run('test_reporters',ut_sonar_test_reporter(),a_source_files=> null, a_test_files=>ut_varchar2_list('tests/helpers/test_reporters.pkb', 'tests/helpers/test_reporters_1.pkb'))); - - l_output := ut_utils.table_to_clob(l_output_data); - - --assert - if l_output like l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('Actual:"'||l_output||'"'); - end if; -end; -/ diff --git a/old_tests/ut_reporters/ut_teamcity_reporter.ProducesExpectedOutputs.sql b/old_tests/ut_reporters/ut_teamcity_reporter.ProducesExpectedOutputs.sql deleted file mode 100644 index 4a3b682ba..000000000 --- a/old_tests/ut_reporters/ut_teamcity_reporter.ProducesExpectedOutputs.sql +++ /dev/null @@ -1,52 +0,0 @@ -declare - l_output_data ut_varchar2_list; - l_output clob; - l_expected varchar2(32767); -begin - l_expected := q'{%##teamcity[testSuiteStarted timestamp='%' name='org'] -%##teamcity[testSuiteStarted timestamp='%' name='org.utplsql'] -%##teamcity[testSuiteStarted timestamp='%' name='org.utplsql.utplsql'] -%##teamcity[testSuiteStarted timestamp='%' name='org.utplsql.utplsql.test'] -%##teamcity[testSuiteStarted timestamp='%' name='A suite for testing different outcomes from reporters'] -%##teamcity[testStarted timestamp='%' captureStandardOutput='true' name='ut3.test_reporters.passing_test'] - - - - - -%##teamcity[testFinished timestamp='%' duration='%' name='ut3.test_reporters.passing_test'] -%##teamcity[testStarted timestamp='%' captureStandardOutput='true' name='ut3.test_reporters.failing_test'] - - - -%##teamcity[testFailed timestamp='%' message='Fails as values are different' name='ut3.test_reporters.failing_test'] -%##teamcity[testFinished timestamp='%' duration='%' name='ut3.test_reporters.failing_test'] -%##teamcity[testStarted timestamp='%' captureStandardOutput='true' name='ut3.test_reporters.erroring_test'] - - - -%##teamcity[testStdErr timestamp='%' name='ut3.test_reporters.erroring_test' out='Test exception:|rORA-06512: at |"UT3.TEST_REPORTERS|", line %|rORA-06512: at %|r|r'] -%##teamcity[testFailed timestamp='%' details='Test exception:|rORA-06512: at |"UT3.TEST_REPORTERS|", line %|rORA-06512: at %|r|r' message='Error occured' name='ut3.test_reporters.erroring_test'] -%##teamcity[testFinished timestamp='%' duration='%' name='ut3.test_reporters.erroring_test'] -%##teamcity[testStarted timestamp='%' captureStandardOutput='true' name='ut3.test_reporters.disabled_test'] -%##teamcity[testIgnored timestamp='%' name='ut3.test_reporters.disabled_test'] -%##teamcity[testSuiteFinished timestamp='%' name='A suite for testing different outcomes from reporters'] -%##teamcity[testSuiteFinished timestamp='%' name='org.utplsql.utplsql.test'] -%##teamcity[testSuiteFinished timestamp='%' name='org.utplsql.utplsql'] -%##teamcity[testSuiteFinished timestamp='%' name='org.utplsql'] -%##teamcity[testSuiteFinished timestamp='%' name='org']}'; - --act - select * - bulk collect into l_output_data - from table(ut.run('test_reporters',ut_teamcity_reporter())); - - l_output := ut_utils.table_to_clob(l_output_data); - --assert - if l_output like l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line(l_output); - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.DoesntFindTheSuiteWhenPackageSpecIsInvalid.sql b/old_tests/ut_suite_manager/ut_suite_manager.DoesntFindTheSuiteWhenPackageSpecIsInvalid.sql deleted file mode 100644 index dd859ad3c..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.DoesntFindTheSuiteWhenPackageSpecIsInvalid.sql +++ /dev/null @@ -1,42 +0,0 @@ -set termout off -create or replace package failing_invalid_spec as - --%suite - gv_glob_val non_existing_table.id%type := 0; - - --%beforeall - procedure before_all; - --%test - procedure test1; - --%test - procedure test2; -end; -/ -create or replace package body failing_invalid_spec as - procedure before_all is begin gv_glob_val := 1; end; - procedure test1 is begin ut.expect(1).to_equal(1); end; - procedure test2 is begin ut.expect(1).to_equal(1); end; -end; -/ -set termout on - -declare - l_objects_to_run ut_suite_items; -begin - begin - --act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list('failing_invalid_spec')); - exception - when others then - if sqlerrm like '%failing_invalid_spec%' then - :test_result := ut_utils.gc_success; - end if; - end; - - if :test_result != ut_utils.gc_success or :test_result is null then - dbms_output.put_line('Failed: Expected exception with text like ''%failing_invalid_spec%'' but got:'''||sqlerrm||''''); - end if; -end; -/ - -drop package failing_invalid_spec -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheSchema.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheSchema.sql deleted file mode 100644 index 8afb6b622..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheSchema.sql +++ /dev/null @@ -1,44 +0,0 @@ -PROMPT Prepare runner for the schema - ---Arrange -declare - c_path varchar2(100) := USER; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test2_suite ut_logical_suite; -begin - --Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - - --Assert - for i in 1 .. l_objects_to_run.count loop - if l_test0_suite is of (ut_logical_suite) then - l_test0_suite := treat(l_objects_to_run(i) as ut_logical_suite); - --assume there are only two logical suites in the test - ut.expect(l_test0_suite.name in ('tests', 'tests2')).to_be_true; - - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - case l_test0_suite.name - when 'tests' then - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(3); - l_test2_suite := treat(l_test1_suite.items(3) as ut_logical_suite); - - ut.expect(l_test2_suite.name).to_equal('test_package_2'); - ut.expect(l_test2_suite.items.count).to_equal(2); - when 'tests2' then - ut.expect(l_test1_suite.name).to_equal('test_package_3'); - ut.expect(l_test1_suite.items.count).to_equal(3); - end case; - end if; - end loop; - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByName.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByName.sql deleted file mode 100644 index 61d46b201..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByName.sql +++ /dev/null @@ -1,36 +0,0 @@ -PROMPT Prepare runner for the top 2 package by package name - ---Arrange -declare - c_path varchar2(100) := USER||'.test_package_2'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test2_suite ut_logical_suite; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(1); - l_test2_suite := treat(l_test1_suite.items(1) as ut_logical_suite); - - ut.expect(l_test2_suite.name).to_equal('test_package_2'); - ut.expect(l_test2_suite.items.count).to_equal(2); - - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByNameCurUser.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByNameCurUser.sql deleted file mode 100644 index 9762a3397..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByNameCurUser.sql +++ /dev/null @@ -1,36 +0,0 @@ -PROMPT Prepare runner for the top 2 package by package name for current user - ---Arrange -declare - c_path varchar2(100) := 'test_package_2'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test2_suite ut_logical_suite; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(1); - l_test2_suite := treat(l_test1_suite.items(1) as ut_logical_suite); - - ut.expect(l_test2_suite.name).to_equal('test_package_2'); - ut.expect(l_test2_suite.items.count).to_equal(2); - - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByPath.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByPath.sql deleted file mode 100644 index dbc6c3486..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByPath.sql +++ /dev/null @@ -1,36 +0,0 @@ -PROMPT Prepare runner for the top 2 package by path - ---Arrange -declare - c_path varchar2(100) := USER||':tests.test_package_1.test_package_2'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test2_suite ut_logical_suite; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(1); - l_test2_suite := treat(l_test1_suite.items(1) as ut_logical_suite); - - ut.expect(l_test2_suite.name).to_equal('test_package_2'); - ut.expect(l_test2_suite.items.count).to_equal(2); - - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByPathCurUser.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByPathCurUser.sql deleted file mode 100644 index 68a0443dd..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageByPathCurUser.sql +++ /dev/null @@ -1,36 +0,0 @@ -PROMPT Prepare runner for the top 2 package by path for current user - ---Arrange -declare - c_path varchar2(100) := ':tests.test_package_1.test_package_2'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test2_suite ut_logical_suite; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(1); - l_test2_suite := treat(l_test1_suite.items(1) as ut_logical_suite); - - ut.expect(l_test2_suite.name).to_equal('test_package_2'); - ut.expect(l_test2_suite.items.count).to_equal(2); - - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPath.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPath.sql deleted file mode 100644 index 7de3aab68..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPath.sql +++ /dev/null @@ -1,52 +0,0 @@ -PROMPT Prepare runner for the top 2 package procedure by path - ---Arrange -declare - c_path varchar2(100) := USER||':tests.test_package_1.test_package_2.test2'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test2_suite ut_logical_suite; - l_test_proc ut_test; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(1); - l_test2_suite := treat(l_test1_suite.items(1) as ut_logical_suite); - - ut.expect(l_test2_suite.name).to_equal('test_package_2'); - ut.expect(l_test2_suite.items.count).to_equal(1); - - l_test_proc := treat(l_test2_suite.items(1) as ut_test); - ut.expect(l_test_proc.name).to_equal('test2'); - ut.expect(l_test_proc.before_test_list.count).to_equal(1); - ut.expect(l_test_proc.after_test_list.count).to_equal(1); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line(q'[ut.expect(l_objects_to_run.count).to_equal(1);=]'||l_objects_to_run.count); - dbms_output.put_line(q'[ut.expect(l_test0_suite.name).to_equal('tests');=]'||l_test0_suite.name); - dbms_output.put_line(q'[ut.expect(l_test0_suite.items.count).to_equal(1);=]'||l_test0_suite.items.count); - dbms_output.put_line(q'[ut.expect(l_test1_suite.name).to_equal('test_package_1');=]'||l_test1_suite.name); - dbms_output.put_line(q'[ut.expect(l_test1_suite.items.count).to_equal(1);=]'||l_test1_suite.items.count); - dbms_output.put_line(q'[ut.expect(l_test2_suite.name).to_equal('test_package_2');=]'||l_test2_suite.name); - dbms_output.put_line(q'[ut.expect(l_test2_suite.items.count).to_equal(1);=]'||l_test2_suite.items.count); - dbms_output.put_line(q'[ut.expect(l_test_proc.name).to_equal('test2');=]'||l_test_proc.name); - dbms_output.put_line(q'[ut.expect(l_test_proc.before_test is not null).to_be_true;=]'||ut_utils.to_string(l_test_proc.before_test_list.count())); - dbms_output.put_line(q'[ut.expect(l_test_proc.after_test is not null).to_be_true;=]'||ut_utils.to_string(l_test_proc.after_test_list.count())); - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPathCurUser.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPathCurUser.sql deleted file mode 100644 index d476c064d..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPathCurUser.sql +++ /dev/null @@ -1,52 +0,0 @@ -PROMPT Prepare runner for the top 2 package procedure by path for current user - ---Arrange -declare - c_path varchar2(100) := ':tests.test_package_1.test_package_2.test2'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test2_suite ut_logical_suite; - l_test_proc ut_test; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(1); - l_test2_suite := treat(l_test1_suite.items(1) as ut_logical_suite); - - ut.expect(l_test2_suite.name).to_equal('test_package_2'); - ut.expect(l_test2_suite.items.count).to_equal(1); - - l_test_proc := treat(l_test2_suite.items(1) as ut_test); - ut.expect(l_test_proc.name).to_equal('test2'); - ut.expect(l_test_proc.before_test_list.count).to_equal(1); - ut.expect(l_test_proc.after_test_list.count).to_equal(1); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line(q'[ut.expect(l_objects_to_run.count).to_equal(1);=]'||l_objects_to_run.count); - dbms_output.put_line(q'[ut.expect(l_test0_suite.name).to_equal('tests');=]'||l_test0_suite.name); - dbms_output.put_line(q'[ut.expect(l_test0_suite.items.count).to_equal(1);=]'||l_test0_suite.items.count); - dbms_output.put_line(q'[ut.expect(l_test1_suite.name).to_equal('test_package_1');=]'||l_test1_suite.name); - dbms_output.put_line(q'[ut.expect(l_test1_suite.items.count).to_equal(1);=]'||l_test1_suite.items.count); - dbms_output.put_line(q'[ut.expect(l_test2_suite.name).to_equal('test_package_2');=]'||l_test2_suite.name); - dbms_output.put_line(q'[ut.expect(l_test2_suite.items.count).to_equal(1);=]'||l_test2_suite.items.count); - dbms_output.put_line(q'[ut.expect(l_test_proc.name).to_equal('test2');=]'||l_test_proc.name); - dbms_output.put_line(q'[ut.expect(l_test_proc.before_test is not null).to_be_true;=]'||ut_utils.to_string(l_test_proc.before_test_list.count())); - dbms_output.put_line(q'[ut.expect(l_test_proc.after_test is not null).to_be_true;=]'||ut_utils.to_string(l_test_proc.after_test_list.count())); - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByName.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByName.sql deleted file mode 100644 index 969524f5e..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByName.sql +++ /dev/null @@ -1,65 +0,0 @@ -PROMPT Prepare runner for the top package by package name - ---Arrange -declare - c_path varchar2(100) := USER||'.test_package_1'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_suite; - l_test2_suite ut_suite; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(3); - - ut.expect(l_test1_suite.items(1).name).to_equal('test1'); - ut.expect(l_test1_suite.items(1).description).to_equal('Test1 from test package 1'); - ut.expect(treat(l_test1_suite.items(1) as ut_test).before_test_list.count()).to_equal(0); - ut.expect(treat(l_test1_suite.items(1) as ut_test).after_test_list.count()).to_equal(0); - ut.expect(treat(l_test1_suite.items(1) as ut_test).before_each_list.count()).to_equal(1); - ut.expect(treat(l_test1_suite.items(1) as ut_test).disabled_flag).to_equal(0); - - ut.expect(l_test1_suite.items(2).name).to_equal('test2'); - ut.expect(l_test1_suite.items(2).description).to_equal('Test2 from test package 1'); - ut.expect(treat(l_test1_suite.items(2) as ut_test).before_test_list.count()).to_equal(1); - ut.expect(treat(l_test1_suite.items(2) as ut_test).after_test_list.count()).to_equal(1); - ut.expect(treat(l_test1_suite.items(2) as ut_test).before_each_list.count()).to_equal(1); - ut.expect(treat(l_test1_suite.items(2) as ut_test).disabled_flag).to_equal(0); - - -- temporary behavior. - -- decided that when executed by package, not path, only that package has to execute - l_test2_suite := treat(l_test1_suite.items(3) as ut_suite); - - ut.expect(l_test2_suite.name).to_equal('test_package_2'); - ut.expect(l_test2_suite.items.count).to_equal(2); - - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - declare - l_results ut_expectation_results; - begin - l_results := ut_expectation_processor.get_failed_expectations; - for i in 1..l_results.count loop - if l_results(i).result > ut_utils.gc_success then - dbms_output.put_line(l_results(i).get_result_clob); - end if; - end loop; - end; - - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByNameCurUser.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByNameCurUser.sql deleted file mode 100644 index c918529b5..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByNameCurUser.sql +++ /dev/null @@ -1,65 +0,0 @@ -PROMPT Prepare runner for the top package by package name for current user - ---Arrange -declare - c_path varchar2(100) := 'test_package_1'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_suite; - l_test2_suite ut_suite; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(3); - - ut.expect(l_test1_suite.items(1).name).to_equal('test1'); - ut.expect(l_test1_suite.items(1).description).to_equal('Test1 from test package 1'); - ut.expect(treat(l_test1_suite.items(1) as ut_test).before_test_list.count()).to_equal(0); - ut.expect(treat(l_test1_suite.items(1) as ut_test).after_test_list.count()).to_equal(0); - ut.expect(treat(l_test1_suite.items(1) as ut_test).before_each_list.count()).to_equal(1); - ut.expect(treat(l_test1_suite.items(1) as ut_test).disabled_flag).to_equal(0); - - ut.expect(l_test1_suite.items(2).name).to_equal('test2'); - ut.expect(l_test1_suite.items(2).description).to_equal('Test2 from test package 1'); - ut.expect(treat(l_test1_suite.items(2) as ut_test).before_test_list.count()).to_equal(1); - ut.expect(treat(l_test1_suite.items(2) as ut_test).after_test_list.count()).to_equal(1); - ut.expect(treat(l_test1_suite.items(2) as ut_test).before_each_list.count()).to_equal(1); - ut.expect(treat(l_test1_suite.items(2) as ut_test).disabled_flag).to_equal(0); - - -- temporary behavior. - -- decided that when executed by package, not path, only that package has to execute - l_test2_suite := treat(l_test1_suite.items(3) as ut_suite); - - ut.expect(l_test2_suite.name).to_equal('test_package_2'); - ut.expect(l_test2_suite.items.count).to_equal(2); - - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - else - declare - l_results ut_expectation_results; - begin - l_results := ut_expectation_processor.get_failed_expectations; - for i in 1..l_results.count loop - if l_results(i).result > ut_utils.gc_success then - dbms_output.put_line(l_results(i).get_result_clob); - end if; - end loop; - end; - - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByPath.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByPath.sql deleted file mode 100644 index 3f035c932..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByPath.sql +++ /dev/null @@ -1,36 +0,0 @@ -PROMPT Prepare runner for the top package by path - ---Arrange -declare - c_path varchar2(100) := USER||':tests'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test2_suite ut_logical_suite; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(3); - l_test2_suite := treat(l_test1_suite.items(3) as ut_logical_suite); - - ut.expect(l_test2_suite.name).to_equal('test_package_2'); - ut.expect(l_test2_suite.items.count).to_equal(2); - - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByPathCurUser.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByPathCurUser.sql deleted file mode 100644 index 28dc17442..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByPathCurUser.sql +++ /dev/null @@ -1,36 +0,0 @@ -PROMPT Prepare runner for the top package by path for current user - ---Arrange -declare - c_path varchar2(100) := ':tests'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test2_suite ut_logical_suite; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(3); - l_test2_suite := treat(l_test1_suite.items(3) as ut_logical_suite); - - ut.expect(l_test2_suite.name).to_equal('test_package_2'); - ut.expect(l_test2_suite.items.count).to_equal(2); - - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPath.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPath.sql deleted file mode 100644 index 58958881f..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPath.sql +++ /dev/null @@ -1,38 +0,0 @@ -PROMPT Prepare runner for the top package procedure by path - ---Arrange -declare - c_path varchar2(100) := USER||':tests.test_package_1.test2'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test2_suite ut_logical_suite; - l_test_proc ut_test; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(1); - l_test_proc := treat(l_test1_suite.items(1) as ut_test); - - ut.expect(l_test_proc.name).to_equal('test2'); - ut.expect(l_test_proc.description).to_equal('Test2 from test package 1'); - ut.expect(l_test_proc.before_test_list.count).to_equal(1); - ut.expect(l_test_proc.after_test_list.count).to_equal(1); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPathCurUser.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPathCurUser.sql deleted file mode 100644 index 009078767..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPathCurUser.sql +++ /dev/null @@ -1,38 +0,0 @@ -PROMPT Prepare runner for the top package procedure by path for current user - ---Arrange -declare - c_path varchar2(100) := ':tests.test_package_1.test2'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test2_suite ut_logical_suite; - l_test_proc ut_test; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_1'); - ut.expect(l_test1_suite.items.count).to_equal(1); - l_test_proc := treat(l_test1_suite.items(1) as ut_test); - - ut.expect(l_test_proc.name).to_equal('test2'); - ut.expect(l_test_proc.description).to_equal('Test2 from test package 1'); - ut.expect(l_test_proc.before_test_list.count).to_equal(1); - ut.expect(l_test_proc.after_test_list.count).to_equal(1); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureWithoutSubsuitesByName.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureWithoutSubsuitesByName.sql deleted file mode 100644 index 986b497a0..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureWithoutSubsuitesByName.sql +++ /dev/null @@ -1,36 +0,0 @@ -PROMPT Prepare runner for the top package procedure without sub-suites by package name - ---Arrange -declare - c_path varchar2(100) := USER||'.test_package_2.test2'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test_proc ut_test; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_3'); - ut.expect(l_test1_suite.items.count).to_equal(1); - - l_test_proc := treat(l_test1_suite.items(1) as ut_test); - ut.expect(l_test_proc.name).to_equal('test2'); - ut.expect(l_test_proc.before_test_list.count).to_equal(1); - ut.expect(l_test_proc.after_test_list.count).to_equal(1); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureWithoutSubsuitesByNameCurUser.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureWithoutSubsuitesByNameCurUser.sql deleted file mode 100644 index f1b536e21..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureWithoutSubsuitesByNameCurUser.sql +++ /dev/null @@ -1,36 +0,0 @@ -PROMPT Prepare runner for the top package procedure without sub-suites by package name for current user - ---Arrange -declare - c_path varchar2(100) := 'test_package_2.test2'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test_proc ut_test; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_3'); - ut.expect(l_test1_suite.items.count).to_equal(1); - - l_test_proc := treat(l_test1_suite.items(1) as ut_test); - ut.expect(l_test_proc.name).to_equal('test2'); - ut.expect(l_test_proc.before_test_list.count).to_equal(1); - ut.expect(l_test_proc.after_test_list.count).to_equal(1); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByName.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByName.sql deleted file mode 100644 index 4f95592fe..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByName.sql +++ /dev/null @@ -1,40 +0,0 @@ -PROMPT Prepare runner for the top package without sub-suites by package name - ---Arrange -declare - c_path varchar2(100) := USER||'.test_package_3'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test1 ut_test; - l_test3 ut_test; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests2'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_3'); - ut.expect(l_test1_suite.items.count).to_equal(3); - - l_test1 := treat(l_test1_suite.items(1) as ut_test); - ut.expect(l_test1.name).to_equal('test1'); - ut.expect(l_test1.disabled_flag).to_equal(0); - - l_test3 := treat(l_test1_suite.items(3) as ut_test); - ut.expect(l_test3.name).to_equal('disabled_test'); - ut.expect(l_test3.disabled_flag).to_equal(1); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByNameCurUser.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByNameCurUser.sql deleted file mode 100644 index 48da40bad..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByNameCurUser.sql +++ /dev/null @@ -1,40 +0,0 @@ -PROMPT Prepare runner for the top package without sub-suites by package name for current user - ---Arrange -declare - c_path varchar2(100) := 'test_package_3'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test1 ut_test; - l_test3 ut_test; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests2'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_3'); - ut.expect(l_test1_suite.items.count).to_equal(3); - - l_test1 := treat(l_test1_suite.items(1) as ut_test); - ut.expect(l_test1.name).to_equal('test1'); - ut.expect(l_test1.disabled_flag).to_equal(0); - - l_test3 := treat(l_test1_suite.items(3) as ut_test); - ut.expect(l_test3.name).to_equal('disabled_test'); - ut.expect(l_test3.disabled_flag).to_equal(1); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByPath.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByPath.sql deleted file mode 100644 index c5e8a3c0a..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByPath.sql +++ /dev/null @@ -1,40 +0,0 @@ -PROMPT Prepare runner for the top package without subsuites by path - ---Arrange -declare - c_path varchar2(100) := USER||':tests2.test_package_3'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test1 ut_test; - l_test3 ut_test; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests2'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_3'); - ut.expect(l_test1_suite.items.count).to_equal(3); - - l_test1 := treat(l_test1_suite.items(1) as ut_test); - ut.expect(l_test1.name).to_equal('test1'); - ut.expect(l_test1.disabled_flag).to_equal(0); - - l_test3 := treat(l_test1_suite.items(3) as ut_test); - ut.expect(l_test3.name).to_equal('disabled_test'); - ut.expect(l_test3.disabled_flag).to_equal(1); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByPathCurUser.sql b/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByPathCurUser.sql deleted file mode 100644 index ff8cd6f75..000000000 --- a/old_tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageWithoutSubsuitesByPathCurUser.sql +++ /dev/null @@ -1,40 +0,0 @@ -PROMPT Prepare runner for the top package without subsuites by path for current user - ---Arrange -declare - c_path varchar2(100) := ':tests2.test_package_3'; - l_objects_to_run ut_suite_items; - - l_test0_suite ut_logical_suite; - l_test1_suite ut_logical_suite; - l_test1 ut_test; - l_test3 ut_test; -begin ---Act - l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path)); - ---Assert - ut.expect(l_objects_to_run.count).to_equal(1); - l_test0_suite := treat(l_objects_to_run(1) as ut_logical_suite); - - ut.expect(l_test0_suite.name).to_equal('tests2'); - ut.expect(l_test0_suite.items.count).to_equal(1); - l_test1_suite := treat(l_test0_suite.items(1) as ut_logical_suite); - - ut.expect(l_test1_suite.name).to_equal('test_package_3'); - ut.expect(l_test1_suite.items.count).to_equal(3); - - l_test1 := treat(l_test1_suite.items(1) as ut_test); - ut.expect(l_test1.name).to_equal('test1'); - ut.expect(l_test1.disabled_flag).to_equal(0); - - l_test3 := treat(l_test1_suite.items(3) as ut_test); - ut.expect(l_test3.name).to_equal('disabled_test'); - ut.expect(l_test3.disabled_flag).to_equal(1); - - if ut_expectation_processor.get_status = ut_utils.gc_success then - :test_result := ut_utils.gc_success; - end if; - -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.Blob.sql b/old_tests/ut_utils/ut_utils.to_string.Blob.sql deleted file mode 100644 index 10ca127e3..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.Blob.sql +++ /dev/null @@ -1,18 +0,0 @@ ---Arrange -declare - l_text varchar2(32767) := 'A test char'; - l_value blob := utl_raw.cast_to_raw(l_text); - l_expected varchar2(32767) := ''''||rawtohex(l_value)||''''; - l_result varchar2(32767); - l_delimiter varchar2(1); -begin ---Act - l_result := ut_utils.to_String(l_value); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.Clob.sql b/old_tests/ut_utils/ut_utils.to_string.Clob.sql deleted file mode 100644 index 329059f53..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.Clob.sql +++ /dev/null @@ -1,17 +0,0 @@ ---Arrange -declare - l_value clob := 'A test char'; - l_expected varchar2(32767) := ''''||l_value||''''; - l_result varchar2(32767); - l_delimiter varchar2(1); -begin ---Act - l_result := ut_utils.to_String(l_value); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.Date.sql b/old_tests/ut_utils/ut_utils.to_string.Date.sql deleted file mode 100644 index 7d52f6cce..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.Date.sql +++ /dev/null @@ -1,16 +0,0 @@ ---Arrange -declare - l_value date := to_date('2016-12-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss'); - l_expected varchar2(100) := '2016-12-31T23:59:59'; - l_result varchar2(100); -begin ---Act - l_result := ut_utils.to_String(l_value); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.NullBlob.sql b/old_tests/ut_utils/ut_utils.to_string.NullBlob.sql deleted file mode 100644 index c49a07fc0..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.NullBlob.sql +++ /dev/null @@ -1,15 +0,0 @@ ---Arrange -declare - l_expected varchar2(100) := 'NULL'; - l_result varchar2(100); -begin ---Act - l_result := ut_utils.to_String(to_blob(NULL)); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.NullClob.sql b/old_tests/ut_utils/ut_utils.to_string.NullClob.sql deleted file mode 100644 index f2e537505..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.NullClob.sql +++ /dev/null @@ -1,15 +0,0 @@ ---Arrange -declare - l_expected varchar2(100) := 'NULL'; - l_result varchar2(100); -begin ---Act - l_result := ut_utils.to_String(to_clob(NULL)); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.NullDate.sql b/old_tests/ut_utils/ut_utils.to_string.NullDate.sql deleted file mode 100644 index e4a9758d7..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.NullDate.sql +++ /dev/null @@ -1,15 +0,0 @@ ---Arrange -declare - l_expected varchar2(100) := 'NULL'; - l_result varchar2(100); -begin ---Act - l_result := ut_utils.to_String(to_date(NULL)); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.NullNumber.sql b/old_tests/ut_utils/ut_utils.to_string.NullNumber.sql deleted file mode 100644 index b33712050..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.NullNumber.sql +++ /dev/null @@ -1,15 +0,0 @@ ---Arrange -declare - l_expected varchar2(100) := 'NULL'; - l_result varchar2(100); -begin ---Act - l_result := ut_utils.to_String(to_number(NULL)); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.NullTimestamp.sql b/old_tests/ut_utils/ut_utils.to_string.NullTimestamp.sql deleted file mode 100644 index b1c9d99a3..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.NullTimestamp.sql +++ /dev/null @@ -1,15 +0,0 @@ ---Arrange -declare - l_expected varchar2(100) := 'NULL'; - l_result varchar2(100); -begin ---Act - l_result := ut_utils.to_String(to_timestamp(NULL)); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.NullVarchar2.sql b/old_tests/ut_utils/ut_utils.to_string.NullVarchar2.sql deleted file mode 100644 index 01f2286fc..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.NullVarchar2.sql +++ /dev/null @@ -1,15 +0,0 @@ ---Arrange -declare - l_expected varchar2(100) := 'NULL'; - l_result varchar2(100); -begin ---Act - l_result := ut_utils.to_String(to_char(NULL)); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.Timestamp.sql b/old_tests/ut_utils/ut_utils.to_string.Timestamp.sql deleted file mode 100644 index 63ae8fa3b..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.Timestamp.sql +++ /dev/null @@ -1,19 +0,0 @@ ---Arrange -declare - l_value timestamp(9) := to_timestamp('2016-12-31 23:59:59.123456789', 'yyyy-mm-dd hh24:mi:ss.ff'); - l_expected varchar2(100); - l_result varchar2(100); - l_delimiter varchar2(1); -begin - select substr(value, 1, 1) into l_delimiter from nls_session_parameters t where t.parameter = 'NLS_NUMERIC_CHARACTERS'; - l_expected := '2016-12-31T23:59:59'||l_delimiter||'123456789'; ---Act - l_result := ut_utils.to_String(l_value); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.TimestampWithLocalTimeZone.sql b/old_tests/ut_utils/ut_utils.to_string.TimestampWithLocalTimeZone.sql deleted file mode 100644 index 67c21e358..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.TimestampWithLocalTimeZone.sql +++ /dev/null @@ -1,19 +0,0 @@ ---Arrange -declare - l_value timestamp(9) with local time zone:= to_timestamp('2016-12-31 23:59:59.123456789', 'yyyy-mm-dd hh24:mi:ss.ff'); - l_expected varchar2(100); - l_result varchar2(100); - l_delimiter varchar2(1); -begin - select substr(value, 1, 1) into l_delimiter from nls_session_parameters t where t.parameter = 'NLS_NUMERIC_CHARACTERS'; - l_expected := '2016-12-31T23:59:59'||l_delimiter||'123456789'; ---Act - l_result := ut_utils.to_String(l_value); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.TimestampWithTimeZone.sql b/old_tests/ut_utils/ut_utils.to_string.TimestampWithTimeZone.sql deleted file mode 100644 index 608b16dae..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.TimestampWithTimeZone.sql +++ /dev/null @@ -1,19 +0,0 @@ ---Arrange -declare - l_value timestamp(9) with time zone := to_timestamp_tz('2016-12-31 23:59:59.123456789 -8:00', 'yyyy-mm-dd hh24:mi:ss.ff tzh:tzm'); - l_expected varchar2(100); - l_result varchar2(100); - l_delimiter varchar2(1); -begin - select substr(value, 1, 1) into l_delimiter from nls_session_parameters t where t.parameter = 'NLS_NUMERIC_CHARACTERS'; - l_expected := '2016-12-31T23:59:59'||l_delimiter||'123456789 -08:00'; ---Act - l_result := ut_utils.to_String(l_value); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.Varchar2.sql b/old_tests/ut_utils/ut_utils.to_string.Varchar2.sql deleted file mode 100644 index 72e60f724..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.Varchar2.sql +++ /dev/null @@ -1,17 +0,0 @@ ---Arrange -declare - l_value varchar2(20) := 'A test char'; - l_expected varchar2(100) := ''''||l_value||''''; - l_result varchar2(100); - l_delimiter varchar2(1); -begin ---Act - l_result := ut_utils.to_String(l_value); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.veryBigBlob.sql b/old_tests/ut_utils/ut_utils.to_string.veryBigBlob.sql deleted file mode 100644 index c213a5f05..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.veryBigBlob.sql +++ /dev/null @@ -1,42 +0,0 @@ ---Arrange -declare - l_text clob := lpad('A test char',32767,'1')||lpad('1',32767,'1'); - l_value blob; - l_result varchar2(32767); - l_delimiter varchar2(1); - function clob_to_blob(p_clob clob) return blob - as - l_blob blob; - l_dest_offset integer := 1; - l_source_offset integer := 1; - l_lang_context integer := dbms_lob.default_lang_ctx; - l_warning integer := dbms_lob.warn_inconvertible_char; - begin - dbms_lob.createtemporary(l_blob, true); - dbms_lob.converttoblob( - dest_lob =>l_blob, - src_clob =>p_clob, - amount =>DBMS_LOB.LOBMAXSIZE, - dest_offset =>l_dest_offset, - src_offset =>l_source_offset, - blob_csid =>DBMS_LOB.DEFAULT_CSID, - lang_context=>l_lang_context, - warning =>l_warning - ); - return l_blob; - end; -begin - l_value := clob_to_blob(l_text); - ---Act - l_result := ut_utils.to_String(l_value); ---Assert - if length(l_result) != ut_utils.gc_max_output_string_length then - dbms_output.put_line('expected: length(l_result)='||ut_utils.gc_max_output_string_length||', got: '||length(l_result) ); - elsif l_result not like '%'||ut_utils.gc_more_data_string then - dbms_output.put_line('expected: l_result to match %'''||ut_utils.gc_more_data_string||', got: '||substr(l_result,-10) ); - else - :test_result := ut_utils.gc_success; - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.veryBigClob.sql b/old_tests/ut_utils/ut_utils.to_string.veryBigClob.sql deleted file mode 100644 index 61ebb1d3f..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.veryBigClob.sql +++ /dev/null @@ -1,18 +0,0 @@ ---Arrange -declare - l_value clob := lpad('A test char',32767,'1')||lpad('1',32767,'1'); - l_result varchar2(32767); - l_delimiter varchar2(1); -begin ---Act - l_result := ut_utils.to_String(l_value); ---Assert - if length(l_result) != ut_utils.gc_max_output_string_length then - dbms_output.put_line('expected: length(l_result)='||ut_utils.gc_max_output_string_length||', got: '||length(l_result) ); - elsif l_result not like '%'||ut_utils.gc_more_data_string then - dbms_output.put_line('expected: l_result to match %'||ut_utils.gc_more_data_string||', got: '||substr(l_result,-10) ); - else - :test_result := ut_utils.gc_success; - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.veryBigNumber.sql b/old_tests/ut_utils/ut_utils.to_string.veryBigNumber.sql deleted file mode 100644 index 02d40961d..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.veryBigNumber.sql +++ /dev/null @@ -1,16 +0,0 @@ ---Arrange -declare - l_value number := 1234567890123456789012345678901234567890; - l_expected varchar2(100) := '1234567890123456789012345678901234567890'; - l_result varchar2(100); -begin ---Act - l_result := ut_utils.to_String(l_value); ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.veryBigVarchar2.sql b/old_tests/ut_utils/ut_utils.to_string.veryBigVarchar2.sql deleted file mode 100644 index 2ef83611f..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.veryBigVarchar2.sql +++ /dev/null @@ -1,18 +0,0 @@ ---Arrange -declare - l_value varchar2(32767) := lpad('A test char',32767,'1'); - l_result varchar2(32767); - l_delimiter varchar2(1); -begin ---Act - l_result := ut_utils.to_String(l_value); ---Assert - if length(l_result) != ut_utils.gc_max_output_string_length then - dbms_output.put_line('expected: length(l_result)='||ut_utils.gc_max_output_string_length||', got: '||length(l_result) ); - elsif l_result not like '%'||ut_utils.gc_more_data_string then - dbms_output.put_line('expected: l_result to match %'||ut_utils.gc_more_data_string||', got: '||substr(l_result,-10) ); - else - :test_result := ut_utils.gc_success; - end if; -end; -/ diff --git a/old_tests/ut_utils/ut_utils.to_string.verySmallNumber.sql b/old_tests/ut_utils/ut_utils.to_string.verySmallNumber.sql deleted file mode 100644 index abc98cb3b..000000000 --- a/old_tests/ut_utils/ut_utils.to_string.verySmallNumber.sql +++ /dev/null @@ -1,21 +0,0 @@ ---Arrange -declare - l_value number := 0.123456789012345678901234567890123456789; - l_expected varchar2(100) := '.123456789012345678901234567890123456789'; - l_result varchar2(100); - l_delimiter varchar2(1); -begin ---Act - select substr(value, 1, 1) into l_delimiter from nls_session_parameters t where t.parameter = 'NLS_NUMERIC_CHARACTERS'; - l_expected := l_delimiter||'123456789012345678901234567890123456789'; - - l_result := ut_utils.to_String(l_value); - ---Assert - if l_result = l_expected then - :test_result := ut_utils.gc_success; - else - dbms_output.put_line('expected: '||l_expected||', got: '||l_result ); - end if; -end; -/ diff --git a/readme.md b/readme.md index 81bd24738..16e68d5a0 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ [![build](https://img.shields.io/travis/utPLSQL/utPLSQL/master.svg?label=master%20branch)](https://travis-ci.org/utPLSQL/utPLSQL) [![build](https://img.shields.io/travis/utPLSQL/utPLSQL/develop.svg?label=develop%20branch)](https://travis-ci.org/utPLSQL/utPLSQL) -[![sonar](https://sonarcloud.io/api/badges/gate?key=utPLSQL%3Adevelop)](https://sonarcloud.io/dashboard/index?id=utPLSQL%3Adevelop) +[![sonar](https://sonarcloud.io/api/project_badges/measure?project=utPLSQL&metric=sqale_rating)](https://sonarcloud.io/dashboard/index?id=utPLSQL) [![Coveralls coverage](https://coveralls.io/repos/github/utPLSQL/utPLSQL/badge.svg?branch=develop)](https://coveralls.io/github/utPLSQL/utPLSQL?branch=develop) ---------- @@ -45,7 +45,7 @@ Published releases are available for download on the [utPLSQL GitHub Releases Pa Full documentation of the project is automatically published on [utPLSQL github pages](https://utplsql.github.io/utPLSQL/) -[Cheat-sheet](https://www.cheatography.com/jgebal/cheat-sheets/utplsql-v3/#downloads) +[Cheat-sheets](https://www.cheatography.com/jgebal/lists/utplsql-v3-cheat-sheets/) # Installation diff --git a/sonar-project.properties b/sonar-project.properties index d9f7adabd..a2139b3fe 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,7 +2,7 @@ sonar.projectKey=utPLSQL # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. sonar.projectName=utPLSQL -sonar.projectVersion=v3.1.1 +sonar.projectVersion=v3.1.2 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # Since SonarQube 4.2, this property is optional if sonar.modules is set. @@ -19,5 +19,9 @@ sonar.projectDescription=PL/SQL Unit Testing Framework sonar.plsql.file.suffixes=sql,tab,pkb,tpb sonar.language=plsql +sonar.pullrequest.provider=github +sonar.pullrequest.github.endpoint=https://api.github.com/ +sonar.pullrequest.github.repository=utPLSQL/utPLSQL + # Encoding of the source code. Default is default system encoding #sonar.sourceEncoding=UTF-8 diff --git a/source/api/ut.pkb b/source/api/ut.pkb index 4225629b8..6fd4eab08 100644 --- a/source/api/ut.pkb +++ b/source/api/ut.pkb @@ -103,52 +103,92 @@ create or replace package body ut is raise e_package_invalidated; end if; end; - + + procedure run_autonomous( - a_paths ut_varchar2_list, a_reporter ut_reporter_base, a_color_console integer, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings, a_test_file_mappings ut_file_mappings, - a_include_objects ut_varchar2_list, a_exclude_objects ut_varchar2_list + a_paths ut_varchar2_list, + a_reporter in out nocopy ut_reporter_base, + a_color_console integer, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings, + a_test_file_mappings ut_file_mappings, + a_include_objects ut_varchar2_list, + a_exclude_objects ut_varchar2_list, + a_client_character_set varchar2 := null ) is pragma autonomous_transaction; + c_fail_on_errors constant boolean := false; begin + a_reporter := coalesce(a_reporter,ut_documentation_reporter()); ut_runner.run( - a_paths, ut_reporters(coalesce(a_reporter,ut_documentation_reporter())), - ut_utils.int_to_boolean(a_color_console), a_coverage_schemes, a_source_file_mappings, - a_test_file_mappings, a_include_objects, a_exclude_objects, false + a_paths, + ut_reporters(a_reporter), + ut_utils.int_to_boolean(a_color_console), + a_coverage_schemes, + a_source_file_mappings, + a_test_file_mappings, + a_include_objects, + a_exclude_objects, + c_fail_on_errors, + a_client_character_set ); rollback; end; procedure run_autonomous( - a_paths ut_varchar2_list, a_reporter ut_reporter_base, a_color_console integer, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list, a_exclude_objects ut_varchar2_list + a_paths ut_varchar2_list, + a_reporter in out nocopy ut_reporter_base, + a_color_console integer, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list, + a_exclude_objects ut_varchar2_list, + a_client_character_set varchar2 := null ) is pragma autonomous_transaction; + c_fail_on_errors constant boolean := false; begin + a_reporter := coalesce(a_reporter,ut_documentation_reporter()); ut_runner.run( - a_paths, ut_reporters(coalesce(a_reporter,ut_documentation_reporter())), - ut_utils.int_to_boolean(a_color_console), a_coverage_schemes, + a_paths, + ut_reporters(a_reporter), + ut_utils.int_to_boolean(a_color_console), + a_coverage_schemes, ut_file_mapper.build_file_mappings(a_source_files), ut_file_mapper.build_file_mappings(a_test_files), - a_include_objects, a_exclude_objects, false + a_include_objects, + a_exclude_objects, + c_fail_on_errors, + a_client_character_set ); rollback; end; function run( - a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined is - l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter()); - l_paths ut_varchar2_list := ut_varchar2_list(sys_context('userenv', 'current_schema')); + l_reporter ut_reporter_base := a_reporter; l_lines sys_refcursor; l_line varchar2(4000); begin run_autonomous( - l_paths, l_reporter, a_color_console, - a_coverage_schemes, a_source_file_mappings, a_test_file_mappings, a_include_objects, a_exclude_objects + ut_varchar2_list(), + l_reporter, + a_color_console, + a_coverage_schemes, + a_source_file_mappings, + a_test_file_mappings, + a_include_objects, + a_exclude_objects, + a_client_character_set ); if l_reporter is of (ut_output_reporter_base) then l_lines := treat(l_reporter as ut_output_reporter_base).get_lines_cursor(); @@ -164,18 +204,29 @@ create or replace package body ut is end; function run( - a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined is - l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter()); - l_paths ut_varchar2_list := ut_varchar2_list(sys_context('userenv', 'current_schema')); + l_reporter ut_reporter_base := a_reporter; l_lines sys_refcursor; l_line varchar2(4000); begin run_autonomous( - l_paths, l_reporter, a_color_console, a_coverage_schemes, a_source_files, a_test_files, - a_include_objects, a_exclude_objects + ut_varchar2_list(), + l_reporter, + a_color_console, + a_coverage_schemes, + a_source_files, + a_test_files, + a_include_objects, + a_exclude_objects, + a_client_character_set ); if l_reporter is of (ut_output_reporter_base) then l_lines := treat(l_reporter as ut_output_reporter_base).get_lines_cursor(); @@ -191,17 +242,30 @@ create or replace package body ut is end; function run( - a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_paths ut_varchar2_list, + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined is - l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter()); + l_reporter ut_reporter_base := a_reporter; l_lines sys_refcursor; l_line varchar2(4000); begin run_autonomous( - a_paths, l_reporter, a_color_console, a_coverage_schemes, a_source_file_mappings, a_test_file_mappings, - a_include_objects, a_exclude_objects + a_paths, + l_reporter, + a_color_console, + a_coverage_schemes, + a_source_file_mappings, + a_test_file_mappings, + a_include_objects, + a_exclude_objects, + a_client_character_set ); if l_reporter is of (ut_output_reporter_base) then l_lines := treat(l_reporter as ut_output_reporter_base).get_lines_cursor(); @@ -217,17 +281,30 @@ create or replace package body ut is end; function run( - a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_paths ut_varchar2_list, + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined is - l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter()); + l_reporter ut_reporter_base := a_reporter; l_lines sys_refcursor; l_line varchar2(4000); begin run_autonomous( - a_paths, l_reporter, a_color_console, a_coverage_schemes, a_source_files, a_test_files, - a_include_objects, a_exclude_objects + a_paths, + l_reporter, + a_color_console, + a_coverage_schemes, + a_source_files, + a_test_files, + a_include_objects, + a_exclude_objects, + a_client_character_set ); if l_reporter is of (ut_output_reporter_base) then l_lines := treat(l_reporter as ut_output_reporter_base).get_lines_cursor(); @@ -243,18 +320,30 @@ create or replace package body ut is end; function run( - a_path varchar2, a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_path varchar2, + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined is - l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter()); - l_paths ut_varchar2_list := ut_varchar2_list(coalesce(a_path, sys_context('userenv', 'current_schema'))); + l_reporter ut_reporter_base := a_reporter; l_lines sys_refcursor; l_line varchar2(4000); begin run_autonomous( - l_paths, l_reporter, a_color_console, a_coverage_schemes, a_source_file_mappings, a_test_file_mappings, - a_include_objects, a_exclude_objects + ut_varchar2_list(a_path), + l_reporter, + a_color_console, + a_coverage_schemes, + a_source_file_mappings, + a_test_file_mappings, + a_include_objects, + a_exclude_objects, + a_client_character_set ); if l_reporter is of (ut_output_reporter_base) then l_lines := treat(l_reporter as ut_output_reporter_base).get_lines_cursor(); @@ -270,18 +359,30 @@ create or replace package body ut is end; function run( - a_path varchar2, a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_path varchar2, + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined is - l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter()); - l_paths ut_varchar2_list := ut_varchar2_list(coalesce(a_path, sys_context('userenv', 'current_schema'))); + l_reporter ut_reporter_base := a_reporter; l_lines sys_refcursor; l_line varchar2(4000); begin run_autonomous( - l_paths, l_reporter, a_color_console, a_coverage_schemes, a_source_files, a_test_files, - a_include_objects, a_exclude_objects + ut_varchar2_list(a_path), + l_reporter, + a_color_console, + a_coverage_schemes, + a_source_files, + a_test_files, + a_include_objects, + a_exclude_objects, + a_client_character_set ); if l_reporter is of (ut_output_reporter_base) then l_lines := treat(l_reporter as ut_output_reporter_base).get_lines_cursor(); @@ -297,15 +398,28 @@ create or replace package body ut is end; procedure run( - a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_paths ut_varchar2_list, + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) is - l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter()); + l_reporter ut_reporter_base := a_reporter; begin run_autonomous( - a_paths, l_reporter, ut_utils.boolean_to_int(a_color_console), a_coverage_schemes, a_source_file_mappings, a_test_file_mappings, - a_include_objects, a_exclude_objects + a_paths, + l_reporter, + ut_utils.boolean_to_int(a_color_console), + a_coverage_schemes, + a_source_file_mappings, + a_test_file_mappings, + a_include_objects, + a_exclude_objects, + a_client_character_set ); if l_reporter is of (ut_output_reporter_base) then treat(l_reporter as ut_output_reporter_base).lines_to_dbms_output(); @@ -314,15 +428,28 @@ create or replace package body ut is end; procedure run( - a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_paths ut_varchar2_list, + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) is - l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter()); + l_reporter ut_reporter_base := a_reporter; begin run_autonomous( - a_paths, l_reporter, ut_utils.boolean_to_int(a_color_console), a_coverage_schemes, a_source_files, a_test_files, - a_include_objects, a_exclude_objects + a_paths, + l_reporter, + ut_utils.boolean_to_int(a_color_console), + a_coverage_schemes, + a_source_files, + a_test_files, + a_include_objects, + a_exclude_objects, + a_client_character_set ); if l_reporter is of (ut_output_reporter_base) then treat(l_reporter as ut_output_reporter_base).lines_to_dbms_output(); @@ -331,52 +458,100 @@ create or replace package body ut is end; procedure run( - a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) is begin ut.run( - ut_varchar2_list(sys_context('userenv', 'current_schema')), a_reporter, a_color_console, - a_coverage_schemes, a_source_file_mappings, a_test_file_mappings, a_include_objects, a_exclude_objects + ut_varchar2_list(), + a_reporter, + a_color_console, + a_coverage_schemes, + a_source_file_mappings, + a_test_file_mappings, + a_include_objects, + a_exclude_objects, + a_client_character_set ); end; procedure run( - a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) is begin ut.run( - ut_varchar2_list(sys_context('userenv', 'current_schema')), a_reporter, a_color_console, - a_coverage_schemes, a_source_files, a_test_files, a_include_objects, a_exclude_objects + ut_varchar2_list(), + a_reporter, + a_color_console, + a_coverage_schemes, + a_source_files, + a_test_files, + a_include_objects, + a_exclude_objects, + a_client_character_set ); end; procedure run( - a_path varchar2, a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_path varchar2, + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) is - l_paths ut_varchar2_list := ut_varchar2_list(coalesce(a_path, sys_context('userenv', 'current_schema'))); begin ut.run( - l_paths, a_reporter, a_color_console, a_coverage_schemes, a_source_file_mappings, a_test_file_mappings, - a_include_objects, a_exclude_objects + ut_varchar2_list(a_path), + a_reporter, + a_color_console, + a_coverage_schemes, + a_source_file_mappings, + a_test_file_mappings, + a_include_objects, + a_exclude_objects, + a_client_character_set ); end; procedure run( - a_path varchar2, a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_path varchar2, + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) is - l_paths ut_varchar2_list := ut_varchar2_list(coalesce(a_path, sys_context('userenv', 'current_schema'))); begin ut.run( - l_paths, a_reporter, a_color_console, a_coverage_schemes, a_source_files, a_test_files, - a_include_objects, a_exclude_objects + ut_varchar2_list(a_path), + a_reporter, + a_color_console, + a_coverage_schemes, + a_source_files, + a_test_files, + a_include_objects, + a_exclude_objects, + a_client_character_set ); end; diff --git a/source/api/ut.pks b/source/api/ut.pks index ad6ea9757..a90957fd2 100644 --- a/source/api/ut.pks +++ b/source/api/ut.pks @@ -48,75 +48,143 @@ create or replace package ut authid current_user as procedure fail(a_message in varchar2); function run( - a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined; function run( - a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined; function run( - a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_paths ut_varchar2_list, + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined; function run( - a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_paths ut_varchar2_list, + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined; function run( - a_path varchar2, a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_path varchar2, + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined; function run( - a_path varchar2, a_reporter ut_reporter_base := null, a_color_console integer := 0, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_path varchar2, + a_reporter ut_reporter_base := null, + a_color_console integer := 0, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ) return ut_varchar2_rows pipelined; procedure run( - a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ); procedure run( - a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ); procedure run( - a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_paths ut_varchar2_list, + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ); procedure run( - a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_paths ut_varchar2_list, + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ); procedure run( - a_path varchar2, a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_path varchar2, + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ); procedure run( - a_path varchar2, a_reporter ut_reporter_base := null, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null + a_path varchar2, + a_reporter ut_reporter_base := null, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_files ut_varchar2_list, + a_test_files ut_varchar2_list, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_client_character_set varchar2 := null ); /** diff --git a/source/api/ut_runner.pkb b/source/api/ut_runner.pkb index 78db64c77..ec02af30e 100644 --- a/source/api/ut_runner.pkb +++ b/source/api/ut_runner.pkb @@ -74,16 +74,32 @@ create or replace package body ut_runner is end; procedure run( - a_paths ut_varchar2_list, a_reporters ut_reporters, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_fail_on_errors boolean default false + a_paths ut_varchar2_list, + a_reporters ut_reporters, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_fail_on_errors boolean := false, + a_client_character_set varchar2 := null ) is l_run ut_run; l_coverage_schema_names ut_varchar2_rows; l_exclude_object_names ut_object_names := ut_object_names(); l_include_object_names ut_object_names; + l_paths ut_varchar2_list := ut_varchar2_list(); begin ut_event_manager.initialize(); + if a_paths is null or a_paths is empty or a_paths.count = 1 and a_paths(1) is null then + l_paths := ut_varchar2_list(sys_context('userenv', 'current_schema')); + else + for i in 1..a_paths.COUNT loop + l_paths := l_paths multiset union ut_utils.string_to_table(a_string => a_paths(i),a_delimiter => ','); + end loop; + end if; + begin ut_expectation_processor.reset_invalidation_exception(); ut_utils.save_dbms_output_to_cache(); @@ -100,7 +116,7 @@ create or replace package body ut_runner is if a_coverage_schemes is not empty then l_coverage_schema_names := ut_utils.convert_collection(a_coverage_schemes); else - l_coverage_schema_names := ut_suite_manager.get_schema_names(a_paths); + l_coverage_schema_names := ut_suite_manager.get_schema_names(l_paths); end if; if a_exclude_objects is not empty then @@ -112,13 +128,14 @@ create or replace package body ut_runner is l_include_object_names := to_ut_object_list(a_include_objects, l_coverage_schema_names); l_run := ut_run( - ut_suite_manager.configure_execution_by_path(a_paths), - a_paths, + ut_suite_manager.configure_execution_by_path(l_paths), + l_paths, l_coverage_schema_names, l_exclude_object_names, l_include_object_names, set(a_source_file_mappings), - set(a_test_file_mappings) + set(a_test_file_mappings), + a_client_character_set ); l_run.do_execute(); diff --git a/source/api/ut_runner.pks b/source/api/ut_runner.pks index ae83b2e60..b796aab9b 100644 --- a/source/api/ut_runner.pks +++ b/source/api/ut_runner.pks @@ -56,10 +56,16 @@ create or replace package ut_runner authid current_user is * schema.suite1.test2 - executes test2 procedure of suite1 suite with execution of all parent setup/teardown procedures */ procedure run( - a_paths ut_varchar2_list, a_reporters ut_reporters, a_color_console boolean := false, - a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null, - a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, - a_fail_on_errors boolean default false + a_paths ut_varchar2_list, + a_reporters ut_reporters, + a_color_console boolean := false, + a_coverage_schemes ut_varchar2_list := null, + a_source_file_mappings ut_file_mappings := null, + a_test_file_mappings ut_file_mappings := null, + a_include_objects ut_varchar2_list := null, + a_exclude_objects ut_varchar2_list := null, + a_fail_on_errors boolean := false, + a_client_character_set varchar2 := null ); /** diff --git a/source/check_object_grants.sql b/source/check_object_grants.sql new file mode 100644 index 000000000..705882bd2 --- /dev/null +++ b/source/check_object_grants.sql @@ -0,0 +1,43 @@ +declare + c_expected_grants constant dbmsoutput_linesarray := dbmsoutput_linesarray('DBMS_LOCK','DBMS_CRYPTO'); + + l_missing_grants varchar2(4000); + l_target_table varchar2(128); + l_owner_column varchar2(128); + + function get_view(a_dba_view_name varchar2) return varchar2 is + l_invalid_object_name exception; + l_result varchar2(128) := lower(a_dba_view_name); + pragma exception_init(l_invalid_object_name,-44002); + begin + l_result := dbms_assert.sql_object_name(l_result); + return l_result; + exception + when l_invalid_object_name then + return replace(l_result,'dba_','all_'); + end; + +begin + l_target_table := get_view('dba_tab_privs'); + l_owner_column := case when l_target_table like 'dba%' then 'owner' else 'table_schema' end; + execute immediate q'[ + select listagg(' - '||object_name,CHR(10)) within group(order by object_name) + from ( + select column_value as object_name + from table(:l_expected_grants) + minus + select table_name as object_name + from ]'||l_target_table||q'[ + where grantee = SYS_CONTEXT('userenv','current_schema') + and ]'||l_owner_column||q'[ = 'SYS')]' + into l_missing_grants using c_expected_grants; + if l_missing_grants is not null then + raise_application_error( + -20000 + , 'The following object grants are missing for user "'||SYS_CONTEXT('userenv','current_schema')||'" to install utPLSQL:'||CHR(10) + ||l_missing_grants||CHR(10) + ||'Please read the installation documentation at http://utplsql.org/utPLSQL/' + ); + end if; +end; +/ diff --git a/source/check_sys_grants.sql b/source/check_sys_grants.sql new file mode 100644 index 000000000..863727f00 --- /dev/null +++ b/source/check_sys_grants.sql @@ -0,0 +1,33 @@ +declare + c_expected_grants constant dbmsoutput_linesarray + := dbmsoutput_linesarray( + 'CREATE TYPE','CREATE VIEW','CREATE SYNONYM','CREATE SEQUENCE','CREATE PROCEDURE','CREATE TABLE' + ); + + l_expected_grants dbmsoutput_linesarray := c_expected_grants; + l_missing_grants varchar2(4000); +begin + if user != SYS_CONTEXT('userenv','current_schema') then + for i in 1 .. l_expected_grants.count loop + l_expected_grants(i) := replace(l_expected_grants(i),' ',' ANY '); + end loop; + end if; + select listagg(' - '||privilege,CHR(10)) within group(order by privilege) + into l_missing_grants + from ( + select column_value as privilege + from table(l_expected_grants) + minus + select privilege + from user_sys_privs + ); + if l_missing_grants is not null then + raise_application_error( + -20000 + , 'The following privileges are required for user "'||user||'" to install into schema "'||SYS_CONTEXT('userenv','current_schema')||'"'||CHR(10) + ||l_missing_grants + ||'Please read the installation documentation at http://utplsql.org/utPLSQL/' + ); + end if; +end; +/ diff --git a/source/core/annotations/ut_annotation_manager.pkb b/source/core/annotations/ut_annotation_manager.pkb index 051c3679e..c3dfb5151 100644 --- a/source/core/annotations/ut_annotation_manager.pkb +++ b/source/core/annotations/ut_annotation_manager.pkb @@ -36,8 +36,7 @@ create or replace package body ut_annotation_manager as left join ]'||l_ut_owner||q'[.ut_annotation_cache_info i on o.owner = i.object_owner and o.object_name = i.object_name and o.object_type = i.object_type where o.owner = :a_object_owner - and o.object_type = :a_object_type - and o.status = 'VALID' ]'; + and o.object_type = :a_object_type]'; open l_result for l_cursor_text using a_object_owner, a_object_type; return l_result; end; @@ -190,6 +189,7 @@ create or replace package body ut_annotation_manager as l_results ut_annotated_objects; c_object_fetch_limit constant integer := 10; begin + l_info_cursor := get_annotation_objs_info_cur(a_object_owner, a_object_type); fetch l_info_cursor bulk collect into l_info_rows; close l_info_cursor; diff --git a/source/core/events/ut_event_manager.pkb b/source/core/events/ut_event_manager.pkb index 312ddc9c3..cb556050a 100644 --- a/source/core/events/ut_event_manager.pkb +++ b/source/core/events/ut_event_manager.pkb @@ -33,7 +33,8 @@ create or replace package body ut_event_manager as procedure trigger_event( a_event_name t_event_name, a_event_object ut_event_item ) is begin if a_event_name is not null and g_event_listeners_index.exists(a_event_name) - and g_event_listeners_index(a_event_name) is not null + -- disabled due to compiler warning: PLW-06023: invocation of IS NOT NULL computes trivial value +-- and g_event_listeners_index(a_event_name) is not null then for listener_number in 1 .. g_event_listeners_index(a_event_name).count loop g_listeners(listener_number).on_event(a_event_name, a_event_object); diff --git a/source/core/types/ut_executable.tpb b/source/core/types/ut_executable.tpb index e51440408..b31322331 100644 --- a/source/core/types/ut_executable.tpb +++ b/source/core/types/ut_executable.tpb @@ -18,38 +18,17 @@ create or replace type body ut_executable is constructor function ut_executable( self in out nocopy ut_executable, a_owner varchar2, a_package varchar2, - a_procedure_name varchar2, a_associated_event_name varchar2 + a_procedure_name varchar2, a_executable_type varchar2 ) return self as result is begin self.self_type := $$plsql_unit; - self.associated_event_name := a_associated_event_name; + self.executable_type := a_executable_type; self.owner_name := a_owner; self.object_name := a_package; self.procedure_name := a_procedure_name; return; end; - member function is_valid(self in out nocopy ut_executable) return boolean is - l_result boolean := false; - l_message_part varchar2(4000) := 'Call params for ' || self.associated_event_name || ' are not valid: '; - begin - - if self.object_name is null then - self.error_stack := l_message_part || 'package is not defined'; - elsif not ut_metadata.package_valid(self.owner_name, self.object_name) then - self.error_stack := l_message_part || 'package does not exist or is invalid: ' ||upper(self.owner_name||'.'||self.object_name); - elsif self.procedure_name is null then - self.error_stack := l_message_part || 'procedure is not defined'; - elsif not ut_metadata.procedure_exists(self.owner_name, self.object_name, self.procedure_name) then - self.error_stack := l_message_part || 'procedure does not exist ' - || upper(self.owner_name || '.' || self.object_name || '.' ||self.procedure_name); - else - l_result := true; - end if; - - return l_result; - end is_valid; - member function form_name return varchar2 is begin return ut_metadata.form_name(owner_name, object_name, procedure_name); @@ -66,24 +45,57 @@ create or replace type body ut_executable is l_status number; l_cursor_number number; l_completed_without_errors boolean := true; + l_failed_with_invalid_pck boolean := true; l_start_transaction_id varchar2(250); l_end_transaction_id varchar2(250); - + + function is_defined return boolean is + l_result boolean := false; + l_message_part varchar2(4000) := 'Call params for ' || self.executable_type || ' are not valid: '; + begin + + if self.object_name is null then + self.error_stack := l_message_part || 'package is not defined'; + elsif self.procedure_name is null then + self.error_stack := l_message_part || 'procedure is not defined'; + else + l_result := true; + end if; + + return l_result; + end is_defined; + + function is_invalid return boolean is + l_result boolean := true; + l_message_part varchar2(4000) := 'Call params for ' || self.executable_type || ' are not valid: '; + begin + + if not ut_metadata.package_valid(self.owner_name, self.object_name) then + self.error_stack := l_message_part || 'package does not exist or is invalid: ' ||upper(self.owner_name||'.'||self.object_name); + elsif not ut_metadata.procedure_exists(self.owner_name, self.object_name, self.procedure_name) then + self.error_stack := l_message_part || 'procedure does not exist ' + || upper(self.owner_name || '.' || self.object_name || '.' ||self.procedure_name); + else + l_result := false; + end if; + + return l_result; + end is_invalid; + procedure save_dbms_output is l_status number; l_line varchar2(32767); begin - dbms_lob.createtemporary(self.serveroutput, true, dur => dbms_lob.session); - - loop - dbms_output.get_line(line => l_line, status => l_status); - exit when l_status = 1; + dbms_output.get_line(line => l_line, status => l_status); + if l_status != 1 then + dbms_lob.createtemporary(self.serveroutput, true, dur => dbms_lob.session); + end if; + while l_status != 1 loop if l_line is not null then - ut_utils.append_to_clob(self.serveroutput, l_line); + ut_utils.append_to_clob(self.serveroutput, l_line||chr(10)); end if; - - dbms_lob.writeappend(self.serveroutput,1,chr(10)); + dbms_output.get_line(line => l_line, status => l_status); end loop; end save_dbms_output; begin @@ -93,9 +105,9 @@ create or replace type body ut_executable is ut_utils.set_client_info(self.procedure_name); --listener - before call to executable - ut_event_manager.trigger_event('before_'||self.associated_event_name, self); + ut_event_manager.trigger_event('before_'||self.executable_type, self); - l_completed_without_errors := self.is_valid(); + l_completed_without_errors := is_defined(); if l_completed_without_errors then l_statement := 'declare' || chr(10) || @@ -103,7 +115,7 @@ create or replace type body ut_executable is ' l_error_backtrace varchar2(32767);' || chr(10) || 'begin' || chr(10) || ' begin' || chr(10) || - ' ' || ut_metadata.form_name(self.owner_name, self.object_name, self.procedure_name) || ';' || chr(10) || + ' ' || self.form_name() || ';' || chr(10) || ' exception' || chr(10) || ' when others then ' || chr(10) || ' l_error_stack := dbms_utility.format_error_stack;' || chr(10) || @@ -117,15 +129,32 @@ create or replace type body ut_executable is ut_utils.debug_log('ut_executable.do_execute l_statement: ' || l_statement); l_cursor_number := dbms_sql.open_cursor; - dbms_sql.parse(l_cursor_number, statement => l_statement, language_flag => dbms_sql.native); - dbms_sql.bind_variable(l_cursor_number, 'a_error_stack', to_char(null), 32767); - dbms_sql.bind_variable(l_cursor_number, 'a_error_backtrace', to_char(null), 32767); - - l_status := dbms_sql.execute(l_cursor_number); - dbms_sql.variable_value(l_cursor_number, 'a_error_stack', self.error_stack); - dbms_sql.variable_value(l_cursor_number, 'a_error_backtrace', self.error_backtrace); - dbms_sql.close_cursor(l_cursor_number); + /** + * The code will allow to execute once we check if packages are defined + * If it fail with 6550 (usually invalid package) it will check if because of invalid state or missing + * if for any other reason we will propagate it up as we didnt expected. + **/ + begin + dbms_sql.parse(l_cursor_number, statement => l_statement, language_flag => dbms_sql.native); + dbms_sql.bind_variable(l_cursor_number, 'a_error_stack', to_char(null), 32767); + dbms_sql.bind_variable(l_cursor_number, 'a_error_backtrace', to_char(null), 32767); + l_status := dbms_sql.execute(l_cursor_number); + dbms_sql.variable_value(l_cursor_number, 'a_error_stack', self.error_stack); + dbms_sql.variable_value(l_cursor_number, 'a_error_backtrace', self.error_backtrace); + dbms_sql.close_cursor(l_cursor_number); + exception + when ut_utils.ex_invalid_package then + l_failed_with_invalid_pck := is_invalid(); + dbms_sql.close_cursor(l_cursor_number); + if not l_failed_with_invalid_pck then + raise; + end if; + when others then + dbms_sql.close_cursor(l_cursor_number); + raise; + end; + save_dbms_output; l_completed_without_errors := (self.error_stack||self.error_backtrace) is null; @@ -135,7 +164,7 @@ create or replace type body ut_executable is end if; --listener - after call to executable - ut_event_manager.trigger_event('after_'||self.associated_event_name, self); + ut_event_manager.trigger_event('after_'||self.executable_type, self); l_end_transaction_id := dbms_transaction.local_transaction_id(); if l_start_transaction_id != l_end_transaction_id or l_end_transaction_id is null then @@ -144,6 +173,7 @@ create or replace type body ut_executable is ut_utils.set_client_info(null); return l_completed_without_errors; + end do_execute; member function get_error_stack_trace return varchar2 is diff --git a/source/core/types/ut_executable.tps b/source/core/types/ut_executable.tps index 79813c391..976ccf396 100644 --- a/source/core/types/ut_executable.tps +++ b/source/core/types/ut_executable.tps @@ -18,15 +18,14 @@ create or replace type ut_executable under ut_event_item( /** * The name of the event to be executed before and after the executable is invoked */ - associated_event_name varchar2(250 char), + executable_type varchar2(250 char), owner_name varchar2(250 char), object_name varchar2(250 char), procedure_name varchar2(250 char), error_backtrace varchar2(4000), error_stack varchar2(4000), serveroutput clob, - constructor function ut_executable( self in out nocopy ut_executable, a_owner varchar2, a_package varchar2, a_procedure_name varchar2, a_associated_event_name varchar2) return self as result, - member function is_valid(self in out nocopy ut_executable) return boolean, + constructor function ut_executable( self in out nocopy ut_executable, a_owner varchar2, a_package varchar2, a_procedure_name varchar2, a_executable_type varchar2) return self as result, member function form_name return varchar2, member procedure do_execute(self in out nocopy ut_executable, a_item in out nocopy ut_suite_item), /** diff --git a/source/core/types/ut_executable_test.tpb b/source/core/types/ut_executable_test.tpb index 9aeaa29c6..09ffab55d 100644 --- a/source/core/types/ut_executable_test.tpb +++ b/source/core/types/ut_executable_test.tpb @@ -1,11 +1,11 @@ create or replace type body ut_executable_test as constructor function ut_executable_test( self in out nocopy ut_executable_test, a_owner varchar2, a_package varchar2, - a_procedure_name varchar2, a_associated_event_name varchar2 + a_procedure_name varchar2, a_executable_type varchar2 ) return self as result is begin self.self_type := $$plsql_unit; - self.associated_event_name := a_associated_event_name; + self.executable_type := a_executable_type; self.owner_name := a_owner; self.object_name := a_package; self.procedure_name := a_procedure_name; diff --git a/source/core/types/ut_executable_test.tps b/source/core/types/ut_executable_test.tps index af3cb1923..a4963a2b9 100644 --- a/source/core/types/ut_executable_test.tps +++ b/source/core/types/ut_executable_test.tps @@ -17,7 +17,7 @@ create or replace type ut_executable_test authid current_user under ut_executabl */ constructor function ut_executable_test( self in out nocopy ut_executable_test, a_owner varchar2, a_package varchar2, - a_procedure_name varchar2, a_associated_event_name varchar2 + a_procedure_name varchar2, a_executable_type varchar2 ) return self as result, member procedure do_execute( diff --git a/source/core/types/ut_key_value_pair.tps b/source/core/types/ut_key_value_pair.tps index 45bc53157..a23df4a7b 100644 --- a/source/core/types/ut_key_value_pair.tps +++ b/source/core/types/ut_key_value_pair.tps @@ -1,4 +1,4 @@ -create or replace type ut_key_value_pair as object( +create or replace type ut_key_value_pair force as object( /* utPLSQL - Version 3 Copyright 2016 - 2017 utPLSQL Project diff --git a/source/core/types/ut_run.tpb b/source/core/types/ut_run.tpb index ccbd847fc..a282bcfdb 100644 --- a/source/core/types/ut_run.tpb +++ b/source/core/types/ut_run.tpb @@ -24,7 +24,8 @@ create or replace type body ut_run as a_exclude_objects ut_object_names := null, a_include_objects ut_object_names := null, a_project_file_mappings ut_file_mappings := null, - a_test_file_mappings ut_file_mappings := null + a_test_file_mappings ut_file_mappings := null, + a_client_character_set varchar2 := null ) return self as result is l_coverage_schema_names ut_varchar2_rows; l_coverage_options ut_coverage_options; @@ -33,6 +34,7 @@ create or replace type body ut_run as self.run_paths := a_run_paths; self.self_type := $$plsql_unit; self.items := a_items; + self.client_character_set := lower(a_client_character_set); self.results_count := ut_results_counter(); self.test_file_mappings := coalesce(a_test_file_mappings, ut_file_mappings()); self.coverage_options := ut_coverage_options( diff --git a/source/core/types/ut_run.tps b/source/core/types/ut_run.tps index 59bde318f..0f1c71ca7 100644 --- a/source/core/types/ut_run.tps +++ b/source/core/types/ut_run.tps @@ -23,6 +23,7 @@ create or replace type ut_run under ut_suite_item ( run_paths ut_varchar2_list, coverage_options ut_coverage_options, test_file_mappings ut_file_mappings, + client_character_set varchar2(100), constructor function ut_run( self in out nocopy ut_run, a_items ut_suite_items, @@ -31,7 +32,8 @@ create or replace type ut_run under ut_suite_item ( a_exclude_objects ut_object_names := null, a_include_objects ut_object_names := null, a_project_file_mappings ut_file_mappings := null, - a_test_file_mappings ut_file_mappings := null + a_test_file_mappings ut_file_mappings := null, + a_client_character_set varchar2 := null ) return self as result, overriding member procedure mark_as_skipped(self in out nocopy ut_run), overriding member function do_execute(self in out nocopy ut_run) return boolean, diff --git a/source/core/types/ut_suite.tpb b/source/core/types/ut_suite.tpb index 7b5525664..1c5663dd9 100644 --- a/source/core/types/ut_suite.tpb +++ b/source/core/types/ut_suite.tpb @@ -17,11 +17,11 @@ create or replace type body ut_suite as */ constructor function ut_suite ( - self in out nocopy ut_suite, a_object_owner varchar2, a_object_name varchar2, a_suite_name varchar2 := null + self in out nocopy ut_suite, a_object_owner varchar2, a_object_name varchar2 ) return self as result is begin self.self_type := $$plsql_unit; - self.init(a_object_owner, a_object_name, nvl(a_suite_name, a_object_name)); + self.init(a_object_owner, a_object_name, a_object_name); self.items := ut_suite_items(); before_all_list := ut_executables(); after_all_list := ut_executables(); diff --git a/source/core/types/ut_suite.tps b/source/core/types/ut_suite.tps index c80316172..866eefc80 100644 --- a/source/core/types/ut_suite.tps +++ b/source/core/types/ut_suite.tps @@ -27,10 +27,10 @@ create or replace type ut_suite under ut_logical_suite ( */ after_all_list ut_executables, constructor function ut_suite ( - self in out nocopy ut_suite, a_object_owner varchar2, a_object_name varchar2, a_suite_name varchar2 := null + self in out nocopy ut_suite, a_object_owner varchar2, a_object_name varchar2 ) return self as result, overriding member function do_execute(self in out nocopy ut_suite) return boolean, overriding member function get_error_stack_traces(self ut_suite) return ut_varchar2_list, overriding member function get_serveroutputs return clob -) +) not final / diff --git a/source/core/types/ut_suite_context.tpb b/source/core/types/ut_suite_context.tpb new file mode 100644 index 000000000..d09fb824f --- /dev/null +++ b/source/core/types/ut_suite_context.tpb @@ -0,0 +1,32 @@ +create or replace type body ut_suite_context as + /* + utPLSQL - Version 3 + Copyright 2016 - 2017 utPLSQL Project + + Licensed under the Apache License, Version 2.0 (the "License"): + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + + constructor function ut_suite_context ( + self in out nocopy ut_suite_context, a_object_owner varchar2, a_object_name varchar2, a_context_name varchar2 := null + ) return self as result is + begin + self.self_type := $$plsql_unit; + self.init(a_object_owner, a_object_name, a_context_name); + self.items := ut_suite_items(); + before_all_list := ut_executables(); + after_all_list := ut_executables(); + return; + end; + +end; +/ diff --git a/source/core/types/ut_suite_context.tps b/source/core/types/ut_suite_context.tps new file mode 100644 index 000000000..ea7d6d31c --- /dev/null +++ b/source/core/types/ut_suite_context.tps @@ -0,0 +1,22 @@ +create or replace type ut_suite_context under ut_suite ( + /* + utPLSQL - Version 3 + Copyright 2016 - 2017 utPLSQL Project + + Licensed under the Apache License, Version 2.0 (the "License"): + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + constructor function ut_suite_context ( + self in out nocopy ut_suite_context, a_object_owner varchar2, a_object_name varchar2, a_context_name varchar2 := null + ) return self as result +) +/ diff --git a/source/core/types/ut_suite_item.tpb b/source/core/types/ut_suite_item.tpb index 5325be9de..b63ed9931 100644 --- a/source/core/types/ut_suite_item.tpb +++ b/source/core/types/ut_suite_item.tpb @@ -98,7 +98,7 @@ final member procedure do_execute(self in out nocopy ut_suite_item) is return transaction_invalidators; end; - member procedure add_transaction_invalidator(a_object_name varchar2) is + member procedure add_transaction_invalidator(self in out nocopy ut_suite_item, a_object_name varchar2) is begin if a_object_name not member of transaction_invalidators then transaction_invalidators.extend(); diff --git a/source/core/types/ut_suite_item.tps b/source/core/types/ut_suite_item.tps index 6a36d88ee..5973f9bd9 100644 --- a/source/core/types/ut_suite_item.tps +++ b/source/core/types/ut_suite_item.tps @@ -61,7 +61,7 @@ create or replace type ut_suite_item force under ut_event_item ( member function create_savepoint_if_needed return varchar2, member procedure rollback_to_savepoint(self in out nocopy ut_suite_item, a_savepoint varchar2), member function get_transaction_invalidators return ut_varchar2_list, - member procedure add_transaction_invalidator(a_object_name varchar2), + member procedure add_transaction_invalidator(self in out nocopy ut_suite_item, a_object_name varchar2), /* Returns execution time in seconds (with miliseconds) */ diff --git a/source/core/ut_dbms_output_cache.sql b/source/core/ut_dbms_output_cache.sql index a81f6acbe..91aba0ba5 100644 --- a/source/core/ut_dbms_output_cache.sql +++ b/source/core/ut_dbms_output_cache.sql @@ -1,23 +1,38 @@ -create global temporary table ut_dbms_output_cache( - /* - utPLSQL - Version 3 - Copyright 2016 - 2017 utPLSQL Project - Licensed under the Apache License, Version 2.0 (the "License"): - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - /* - * This table is not a global temporary table as it needs to allow cross-session data exchange - * It is used however as a temporary table with multiple writers. - * This is why it has very high initrans and has nologging - */ - seq_no number(20,0) not null, - text varchar2(4000), - constraint ut_dbms_output_cache_pk primary key(seq_no) -) on commit preserve rows; +/* +utPLSQL - Version 3 +Copyright 2016 - 2017 utPLSQL Project +Licensed under the Apache License, Version 2.0 (the "License"): +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +/* +* This table is not a global temporary table as it needs to allow cross-session data exchange +* It is used however as a temporary table with multiple writers. +* This is why it has very high initrans and has nologging +*/ +declare + l_tab_exist number; +begin + select count(*) into l_tab_exist from + (select table_name from all_tables where table_name = 'UT_DBMS_OUTPUT_CACHE' and owner = sys_context('USERENV','CURRENT_SCHEMA') + union all + select synonym_name from all_synonyms where synonym_name = 'UT_DBMS_OUTPUT_CACHE' and owner = sys_context('USERENV','CURRENT_SCHEMA')); + if l_tab_exist = 0 then + + execute immediate q'[create global temporary table ut_dbms_output_cache + ( + seq_no number(20,0) not null, + text varchar2(4000), + constraint ut_dbms_output_cache_pk primary key(seq_no) + ) on commit preserve rows + ]'; + + end if; +end; +/ diff --git a/source/core/ut_file_mapper.pks b/source/core/ut_file_mapper.pks index 573b0528f..f16913e98 100644 --- a/source/core/ut_file_mapper.pks +++ b/source/core/ut_file_mapper.pks @@ -16,10 +16,10 @@ create or replace package ut_file_mapper authid current_user is limitations under the License. */ - gc_file_mapping_regex constant varchar2(100) := '/((\w+)\.)?(\w+)\.(\w{3})$'; + gc_file_mapping_regex constant varchar2(100) := '/(((\w|[$#])+)\.)?((\w|[$#])+)\.(\w{3})$'; gc_regex_owner_subexpression constant positive := 2; - gc_regex_name_subexpression constant positive := 3; - gc_regex_type_subexpression constant positive := 4; + gc_regex_name_subexpression constant positive := 4; + gc_regex_type_subexpression constant positive := 6; function default_file_to_obj_type_map return ut_key_value_pairs; diff --git a/source/core/ut_suite_builder.pkb b/source/core/ut_suite_builder.pkb index e39e0e33b..3a9593906 100644 --- a/source/core/ut_suite_builder.pkb +++ b/source/core/ut_suite_builder.pkb @@ -23,21 +23,58 @@ create or replace package body ut_suite_builder is gc_suite constant t_annotation_name := 'suite'; gc_suitepath constant t_annotation_name := 'suitepath'; - gc_test constant t_annotation_name := 'test'; + gc_test constant t_annotation_name := ut_utils.gc_test_execute; gc_disabled constant t_annotation_name := 'disabled'; gc_displayname constant t_annotation_name := 'displayname'; - gc_beforeall constant t_annotation_name := 'beforeall'; - gc_beforeeach constant t_annotation_name := 'beforeeach'; - gc_beforetest constant t_annotation_name := 'beforetest'; - gc_afterall constant t_annotation_name := 'afterall'; - gc_aftereach constant t_annotation_name := 'aftereach'; - gc_aftertest constant t_annotation_name := 'aftertest'; + gc_beforeall constant t_annotation_name := ut_utils.gc_before_all; + gc_beforeeach constant t_annotation_name := ut_utils.gc_before_each; + gc_beforetest constant t_annotation_name := ut_utils.gc_before_test; + gc_afterall constant t_annotation_name := ut_utils.gc_after_all; + gc_aftereach constant t_annotation_name := ut_utils.gc_after_each; + gc_aftertest constant t_annotation_name := ut_utils.gc_after_test; gc_throws constant t_annotation_name := 'throws'; gc_rollback constant t_annotation_name := 'rollback'; gc_context constant t_annotation_name := 'context'; gc_endcontext constant t_annotation_name := 'endcontext'; + type tt_annotations is table of t_annotation_name; + + gc_supported_annotations constant tt_annotations + := tt_annotations( + gc_suite, + gc_suitepath, + gc_test, + gc_disabled, + gc_displayname, + gc_beforeall, + gc_beforeeach, + gc_beforetest, + gc_afterall, + gc_aftereach, + gc_aftertest, + gc_throws, + gc_rollback, + gc_context, + gc_endcontext + ); + gc_placeholder constant varchar2(3) := '\\%'; + + gc_integer_exception constant varchar2(1) := 'I'; + gc_named_exception constant varchar2(1) := 'N'; + + type tt_executables is table of ut_executables index by t_annotation_position; + + type tt_tests is table of ut_test index by t_annotation_position; + + + type t_annotation is record( + name t_annotation_name, + text t_annotation_text, + procedure_name t_object_name + ); + + type tt_annotations_by_line is table of t_annotation index by t_annotation_position; --list of annotation texts for a given annotation indexed by annotation position: --This would hold: ('some', 'other') for a single annotation name recurring in a single procedure example @@ -47,131 +84,71 @@ create or replace package body ut_suite_builder is -- procedure some_test ... -- when you'd like to have two beforetest procedures executed in a single test type tt_annotation_texts is table of t_annotation_text index by t_annotation_position; + + type tt_annotations_by_name is table of tt_annotation_texts index by t_annotation_name; - type tt_procedure_annotations is table of tt_annotation_texts index by t_annotation_name; - - --holds information about - -- package level annotation - -- or - -- procedure and annotations associated with the procedure - type t_package_annotation is record( - text t_annotation_text, - name t_annotation_name, - procedure_name t_object_name, - procedure_annotations tt_procedure_annotations - ); - - --holds a list of package and procedure level annotations indexed (order) by position. - --procedure level annotations are grouped under procedure name - type tt_package_annotations is table of t_package_annotation index by t_annotation_position; + type tt_annotations_by_proc is table of tt_annotations_by_name index by t_object_name; - --holds all annotations for object - type t_package_annotations_info is record( - owner t_object_name, - name t_object_name, - annotations tt_package_annotations + type t_annotations_info is record ( + owner t_object_name, + name t_object_name, + by_line tt_annotations_by_line, + by_proc tt_annotations_by_proc, + by_name tt_annotations_by_name ); - --list of all package level annotation positions for a given annotaion name - type tt_package_annot_positions is table of boolean index by t_annotation_position; - --index used to lookup package level annotations by package-level annotation name - type tt_annotations_index is table of tt_package_annot_positions index by t_annotation_name; - - - ----------------------------------------------- - --- Conversion of annotations for processing - ----------------------------------------------- - function get_procedure_annotations(a_annotations ut_annotations, a_index in out nocopy binary_integer) return tt_procedure_annotations is - l_result tt_procedure_annotations; - l_index binary_integer := a_index; - l_annotation_pos binary_integer; - function is_last_annotation_for_proc(a_annotations ut_annotations, a_index binary_integer) return boolean is - begin - return a_index = a_annotations.count or a_annotations(a_index).subobject_name != nvl(a_annotations(a_index+1).subobject_name, ' '); - end; - begin - loop - l_annotation_pos := a_annotations(a_index).position; - l_result(a_annotations(a_index).name)(l_annotation_pos) := a_annotations(a_index).text; - exit when is_last_annotation_for_proc(a_annotations, a_index); - a_index := a_annotations.next(a_index); - end loop; - return l_result; - end; - - function convert_package_annotations(a_object ut_annotated_object) return t_package_annotations_info is - l_result t_package_annotations_info; - l_annotation_no binary_integer; - l_annotation_pos binary_integer; - begin - l_result.owner := a_object.object_owner; - l_result.name := a_object.object_name; - l_annotation_no := a_object.annotations.first; - while l_annotation_no is not null loop - l_annotation_pos := a_object.annotations(l_annotation_no).position; - if a_object.annotations(l_annotation_no).subobject_name is null then - l_result.annotations(l_annotation_pos).name := a_object.annotations(l_annotation_no).name; - l_result.annotations(l_annotation_pos).text := a_object.annotations(l_annotation_no).text; - else - l_result.annotations(l_annotation_pos).procedure_name := a_object.annotations(l_annotation_no).subobject_name; - l_result.annotations(l_annotation_pos).procedure_annotations := get_procedure_annotations(a_object.annotations, l_annotation_no); - end if; - l_annotation_no := a_object.annotations.next(l_annotation_no); - end loop; - return l_result; - end; - - function build_annotation_index(a_annotations tt_package_annotations ) return tt_annotations_index is - l_result tt_annotations_index; - l_annotation_pos binary_integer; - begin - l_annotation_pos := a_annotations.first; - while l_annotation_pos is not null loop - if a_annotations( l_annotation_pos ).name is not null then - l_result(a_annotations( l_annotation_pos ).name)( l_annotation_pos ) := true; - end if; - l_annotation_pos := a_annotations.next( l_annotation_pos ); - end loop; - return l_result; - end; - - procedure delete_from_annotation_index( - a_index in out nocopy tt_annotations_index, - a_start_pos t_annotation_position, - a_end_pos t_annotation_position + procedure delete_annotations_range( + a_annotations in out nocopy t_annotations_info, + a_start_pos t_annotation_position, + a_end_pos t_annotation_position ) is - l_idx t_annotation_name; + l_pos t_annotation_position := a_start_pos; + l_annotation t_annotation; begin - l_idx := a_index.first; - while l_idx is not null loop - a_index( l_idx ).delete( a_start_pos, a_end_pos); - if a_index( l_idx ).count = 0 then - a_index.delete( l_idx ); + while l_pos is not null and l_pos <= a_end_pos loop + l_annotation := a_annotations.by_line(l_pos); + if l_annotation.procedure_name is not null and a_annotations.by_proc.exists(l_annotation.procedure_name) then + a_annotations.by_proc.delete(l_annotation.procedure_name); + elsif a_annotations.by_name.exists(l_annotation.name) then + a_annotations.by_name(l_annotation.name).delete(l_pos); + if a_annotations.by_name(l_annotation.name).count = 0 then + a_annotations.by_name.delete(l_annotation.name); + end if; end if; - l_idx := a_index.next( l_idx ); + l_pos := a_annotations.by_line.next( l_pos ); end loop; + a_annotations.by_line.delete(a_start_pos, a_end_pos); end; ----------------------------------------------- -- Processing annotations ----------------------------------------------- - procedure add_annotation_warning( + function get_qualified_object_name( + a_suite ut_suite_item, a_procedure_name t_object_name + ) return varchar2 is + l_result varchar2(1000); + begin + if a_suite is not null then + l_result := upper( a_suite.object_owner || '.' || a_suite.object_name ); + if a_procedure_name is not null then + l_result := l_result || upper( '.' || a_procedure_name ); + end if; + end if; + return l_result; + end; + + procedure add_annotation_ignored_warning( a_suite in out nocopy ut_suite_item, a_annotation t_annotation_name, a_message varchar2, a_line_no binary_integer, a_procedure_name t_object_name := null ) is - l_object_name varchar2(1000); begin - l_object_name := upper( a_suite.object_owner || '.' || a_suite.object_name ); - if a_procedure_name is not null then - l_object_name := l_object_name || upper( '.' || a_procedure_name ); - end if; a_suite.put_warning( replace(a_message,'%%%','"--%'||a_annotation||'"') || ' Annotation ignored.' - || chr( 10 ) || 'at "' || l_object_name || '", line ' || a_line_no + || chr( 10 ) || 'at "' || get_qualified_object_name(a_suite, a_procedure_name) || '", line ' || a_line_no ); end; @@ -186,70 +163,224 @@ create or replace package body ut_suite_builder is return l_rollback_type; end; - function build_exception_numbers_list(a_annotation_text in varchar2) return ut_integer_list is - l_throws_list ut_varchar2_list; - l_exception_number_list ut_integer_list := ut_integer_list(); - l_regexp_for_excep_nums varchar2(30) := '^-?[[:digit:]]{1,5}$'; - begin - /*the a_expected_error_codes is converted to a ut_varchar2_list after that is trimmed and filtered to left only valid exception numbers*/ - l_throws_list := ut_utils.string_to_table(a_annotation_text, ',', 'Y'); - l_throws_list := ut_utils.filter_list( ut_utils.trim_list_elements(l_throws_list), l_regexp_for_excep_nums); - l_exception_number_list.extend(l_throws_list.count); - for i in 1 .. l_throws_list.count loop - l_exception_number_list(i) := l_throws_list(i); - end loop; - return l_exception_number_list; - end; - procedure add_to_throws_numbers_list( - a_list in out nocopy ut_integer_list, + a_suite in out nocopy ut_suite, + a_list in out nocopy ut_integer_list, + a_procedure_name t_object_name, a_throws_ann_text tt_annotation_texts ) is l_annotation_pos binary_integer; + + function is_valid_qualified_name (a_name varchar2) return boolean is + l_name varchar2(500); + begin + l_name := dbms_assert.qualified_sql_name(a_name); + return true; + exception when others then + return false; + end; + + function check_exception_type(a_exception_name in varchar2) return varchar2 is + l_exception_type varchar2(50); + begin + --check if it is a predefined exception + begin + execute immediate 'begin null; exception when '||a_exception_name||' then null; end;'; + l_exception_type := gc_named_exception; + exception + when others then + if dbms_utility.format_error_stack() like '%PLS-00485%' then + begin + execute immediate 'declare x positiven := -('||a_exception_name||'); begin null; end;'; + l_exception_type := gc_integer_exception; + exception + when others then + --invalid exception number (positive) + --TODO add warning for this value + null; + end; + end if; + end; + return l_exception_type; + end; + + function get_exception_number (a_exception_var in varchar2) return integer is + l_exc_no integer; + l_exc_type varchar2(50); + l_sql varchar2(32767); + function remap_no_data_found (a_number integer) return integer is + begin + return case a_number when 100 then -1403 else a_number end; + end; + begin + l_exc_type := check_exception_type(a_exception_var); + + if l_exc_type is not null then + + execute immediate + case l_exc_type + when gc_integer_exception then + 'declare + l_exception number; + begin + :l_exception := '||a_exception_var||'; ' + when gc_named_exception then + 'begin + raise '||a_exception_var||'; + exception + when others then + :l_exception := sqlcode; ' + end || + 'end;' + using out l_exc_no; + + end if; + return remap_no_data_found(l_exc_no); + end; + + function build_exception_numbers_list( + a_suite in out nocopy ut_suite, + a_procedure_name t_object_name, + a_line_no integer, + a_annotation_text in varchar2 + ) return ut_integer_list is + l_throws_list ut_varchar2_list; + l_exception_number integer; + l_exception_number_list ut_integer_list := ut_integer_list(); + c_regexp_for_exception_no constant varchar2(30) := '^-?[[:digit:]]{1,5}$'; + begin + /*the a_expected_error_codes is converted to a ut_varchar2_list after that is trimmed and filtered to left only valid exception numbers*/ + l_throws_list := ut_utils.trim_list_elements(ut_utils.string_to_table(a_annotation_text, ',', 'Y')); + + for i in 1 .. l_throws_list.count + loop + /** + * Check if its a valid qualified name and if so try to resolve name to an exception number + */ + if is_valid_qualified_name(l_throws_list(i)) then + l_exception_number := get_exception_number(l_throws_list(i)); + elsif regexp_like(l_throws_list(i), c_regexp_for_exception_no) then + l_exception_number := l_throws_list(i); + end if; + + if l_exception_number is null then + a_suite.put_warning( + 'Invalid parameter value "'||l_throws_list(i)||'" for "--%throws" annotation. Parameter ignored.' + || chr( 10 ) || 'at "' || get_qualified_object_name(a_suite, a_procedure_name) || '", line ' || a_line_no + ); + else + l_exception_number_list.extend; + l_exception_number_list(l_exception_number_list.last) := l_exception_number; + end if; + l_exception_number := null; + end loop; + + return l_exception_number_list; + end; + begin a_list := ut_integer_list(); l_annotation_pos := a_throws_ann_text.first; while l_annotation_pos is not null loop - a_list := a_list multiset union build_exception_numbers_list( a_throws_ann_text(l_annotation_pos)); + if a_throws_ann_text(l_annotation_pos) is null then + a_suite.put_warning( + '"--%throws" annotation requires a parameter. Annotation ignored.' + || chr( 10 ) || 'at "' || get_qualified_object_name(a_suite, a_procedure_name) || '", line ' || l_annotation_pos + ); + else + a_list := + a_list multiset union + build_exception_numbers_list( + a_suite, + a_procedure_name, + l_annotation_pos, + a_throws_ann_text(l_annotation_pos) + ); + end if; l_annotation_pos := a_throws_ann_text.next(l_annotation_pos); end loop; end; - procedure add_to_list( - a_executables in out nocopy ut_executables, - a_owner varchar2, - a_package_name varchar2, - a_procedure_name varchar2, - a_executable_type ut_utils.t_executable_type - ) is + function convert_list( + a_list tt_executables + ) return ut_executables is + l_result ut_executables := ut_executables(); + l_pos t_annotation_position := a_list.first; begin - if a_executables is null then - a_executables := ut_executables(); - end if; - a_executables.extend; - a_executables(a_executables.last) := ut_executable(a_owner, a_package_name, a_procedure_name, a_executable_type); - end; + while l_pos is not null loop + l_result := l_result multiset union all a_list(l_pos); + l_pos := a_list.next(l_pos); + end loop; + return l_result; + end; - procedure add_all_to_list( - a_executables in out nocopy ut_executables, - a_owner varchar2, - a_package_name varchar2, - a_annotation_texts tt_annotation_texts, - a_event_name ut_utils.t_event_name - ) is - l_annotation_pos binary_integer; + function convert_list( + a_list tt_tests + ) return ut_suite_items is + l_result ut_suite_items := ut_suite_items(); + l_pos t_annotation_position := a_list.first; begin - l_annotation_pos := a_annotation_texts.first; - while l_annotation_pos is not null loop - add_to_list(a_executables, a_owner, a_package_name, a_annotation_texts(l_annotation_pos), a_event_name ); - l_annotation_pos := a_annotation_texts.next( l_annotation_pos); + while l_pos is not null loop + l_result.extend; + l_result(l_result.last) := a_list(l_pos); + l_pos := a_list.next(l_pos); end loop; + return l_result; end; + function add_executables( + a_owner t_object_name, + a_package_name t_object_name, + a_annotation_texts tt_annotation_texts, + a_event_name ut_utils.t_event_name + ) return tt_executables is + l_executables ut_executables; + l_result tt_executables; + l_annotation_pos binary_integer; + l_procedures_list ut_varchar2_list; + l_procedures_pos binary_integer; + l_components_list ut_varchar2_list; + begin + l_annotation_pos := a_annotation_texts.first; + while l_annotation_pos is not null loop + l_procedures_list := + ut_utils.filter_list( + ut_utils.trim_list_elements( + ut_utils.string_to_table(a_annotation_texts(l_annotation_pos), ',') + ) + , '[[:alpha:]]+' + ); + + l_procedures_pos := l_procedures_list.first; + l_executables := ut_executables(); + while l_procedures_pos is not null loop + l_components_list := ut_utils.string_to_table(l_procedures_list(l_procedures_pos), '.'); + + l_executables.extend; + l_executables(l_executables.last) := + case(l_components_list.count()) + when 1 then + ut_executable(a_owner, a_package_name, l_components_list(1), a_event_name) + when 2 then + ut_executable(a_owner,l_components_list(1), l_components_list(2), a_event_name) + when 3 then + ut_executable(l_components_list(1), l_components_list(2), l_components_list(3), a_event_name) + else + null + end; + l_procedures_pos := l_procedures_list.next(l_procedures_pos); + end loop; + l_result(l_annotation_pos) := l_executables; + l_annotation_pos := a_annotation_texts.next(l_annotation_pos); + end loop; + return l_result; + end; + procedure warning_on_duplicate_annot( a_suite in out nocopy ut_suite_item, - a_annotations tt_annotations_index, - a_for_annotation varchar2 + a_annotations tt_annotations_by_name, + a_for_annotation varchar2, + a_procedure_name t_object_name := null ) is l_annotation_name t_annotation_name; l_line_no binary_integer; @@ -259,38 +390,17 @@ create or replace package body ut_suite_builder is --start from second occurrence of annotation l_line_no := a_annotations(a_for_annotation).next( a_annotations(a_for_annotation).first ); while l_line_no is not null loop - add_annotation_warning( a_suite, a_for_annotation, 'Duplicate annotation %%%.', l_line_no ); + add_annotation_ignored_warning( a_suite, a_for_annotation, 'Duplicate annotation %%%.', l_line_no, a_procedure_name ); l_line_no := a_annotations(a_for_annotation).next( l_line_no ); end loop; end if; end if; end; - procedure warning_on_duplicate_annot( - a_suite in out nocopy ut_suite_item, - a_procedure_name t_object_name, - a_annotations tt_procedure_annotations, - a_for_annotation varchar2 - ) is - l_annotation_name t_annotation_name; - l_line_no binary_integer; - begin - if a_annotations.exists(a_for_annotation) then - if a_annotations(a_for_annotation).count > 1 then - --start from second occurrence of annotation - l_line_no := a_annotations(a_for_annotation).next( a_annotations(a_for_annotation).first ); - while l_line_no is not null loop - add_annotation_warning( a_suite, a_for_annotation, 'Duplicate annotation %%%.', l_line_no, a_procedure_name ); - l_line_no := a_annotations(a_for_annotation).next( l_line_no ); - end loop; - end if; - end if; - end; - procedure warning_bad_annot_combination( a_suite in out nocopy ut_suite_item, a_procedure_name t_object_name, - a_proc_annotations tt_procedure_annotations, + a_proc_annotations tt_annotations_by_name, a_for_annotation varchar2, a_invalid_annotations ut_varchar2_list ) is @@ -298,72 +408,90 @@ create or replace package body ut_suite_builder is l_warning varchar2(32767); l_line_no binary_integer; begin - l_annotation_name := a_proc_annotations.first; - while l_annotation_name is not null loop - if l_annotation_name member of a_invalid_annotations then - l_line_no := a_proc_annotations(l_annotation_name).first; - while l_line_no is not null loop - add_annotation_warning( - a_suite, l_annotation_name, 'Annotation %%% cannot be used with "--%'|| a_for_annotation || '".', - l_line_no, a_procedure_name - ); - l_line_no := a_proc_annotations(l_annotation_name).next(l_line_no); - end loop; - end if; - l_annotation_name := a_proc_annotations.next(l_annotation_name); - end loop; + if a_proc_annotations.exists(a_for_annotation) then + l_annotation_name := a_proc_annotations.first; + while l_annotation_name is not null loop + if l_annotation_name member of a_invalid_annotations then + l_line_no := a_proc_annotations(l_annotation_name).first; + while l_line_no is not null loop + add_annotation_ignored_warning( + a_suite, l_annotation_name, 'Annotation %%% cannot be used with "--%'|| a_for_annotation || '".', + l_line_no, a_procedure_name + ); + l_line_no := a_proc_annotations(l_annotation_name).next(l_line_no); + end loop; + end if; + l_annotation_name := a_proc_annotations.next(l_annotation_name); + end loop; + end if; end; procedure add_test( - a_suite in out nocopy ut_suite, - a_procedure_name varchar2, - a_annotations tt_procedure_annotations + a_suite in out nocopy ut_suite, + a_tests in out nocopy tt_tests, + a_procedure_name t_object_name, + a_proc_annotations tt_annotations_by_name ) is l_test ut_test; l_annotation_texts tt_annotation_texts; l_annotation_pos binary_integer; begin + if not a_proc_annotations.exists(gc_test) then + return; + end if; + warning_on_duplicate_annot(a_suite, a_proc_annotations, gc_test, a_procedure_name); + warning_on_duplicate_annot(a_suite, a_proc_annotations, gc_displayname, a_procedure_name); + warning_on_duplicate_annot(a_suite, a_proc_annotations, gc_rollback, a_procedure_name); + warning_bad_annot_combination( + a_suite, a_procedure_name, a_proc_annotations, gc_test, + ut_varchar2_list(gc_beforeeach, gc_aftereach, gc_beforeall, gc_afterall) + ); + l_test := ut_test(a_suite.object_owner, a_suite.object_name, a_procedure_name); - if a_annotations.exists(gc_displayname) then - l_annotation_texts := a_annotations(gc_displayname); + if a_proc_annotations.exists(gc_displayname) then + l_annotation_texts := a_proc_annotations(gc_displayname); --take the last definition if more than one was provided l_test.description := l_annotation_texts(l_annotation_texts.first); --TODO if more than one - warning else - l_test.description := a_annotations(gc_test)(a_annotations(gc_test).first); + l_test.description := a_proc_annotations(gc_test)(a_proc_annotations(gc_test).first); end if; l_test.path := a_suite.path ||'.'||a_procedure_name; - if a_annotations.exists(gc_rollback) then - l_annotation_texts := a_annotations(gc_rollback); + if a_proc_annotations.exists(gc_rollback) then + l_annotation_texts := a_proc_annotations(gc_rollback); l_test.rollback_type := get_rollback_type(l_annotation_texts(l_annotation_texts.first)); if l_test.rollback_type is null then - add_annotation_warning( + add_annotation_ignored_warning( a_suite, gc_rollback, 'Annotation %%% must be provided with one of values: "auto" or "manual".', l_annotation_texts.first, a_procedure_name ); end if; end if; - if a_annotations.exists(gc_beforetest) then - add_all_to_list( l_test.before_test_list, l_test.object_owner, l_test.object_name, a_annotations(gc_beforetest), ut_utils.gc_before_test ); + if a_proc_annotations.exists(gc_beforetest) then + l_test.before_test_list := convert_list( + add_executables( l_test.object_owner, l_test.object_name, a_proc_annotations( gc_beforetest ), gc_beforetest ) + ); end if; - if a_annotations.exists(gc_aftertest) then - add_all_to_list( l_test.after_test_list, l_test.object_owner, l_test.object_name, a_annotations(gc_aftertest), ut_utils.gc_after_test ); + if a_proc_annotations.exists(gc_aftertest) then + l_test.after_test_list := convert_list( + add_executables( l_test.object_owner, l_test.object_name, a_proc_annotations( gc_aftertest ), gc_aftertest ) + ); end if; - if a_annotations.exists(gc_throws) then - add_to_throws_numbers_list(l_test.expected_error_codes, a_annotations(gc_throws)); + if a_proc_annotations.exists(gc_throws) then + add_to_throws_numbers_list(a_suite, l_test.expected_error_codes, a_procedure_name, a_proc_annotations(gc_throws)); end if; - l_test.disabled_flag := ut_utils.boolean_to_int(a_annotations.exists(gc_disabled)); + l_test.disabled_flag := ut_utils.boolean_to_int(a_proc_annotations.exists(gc_disabled)); - a_suite.add_item(l_test); + a_tests(a_proc_annotations(gc_test).first) := l_test; end; - procedure update_before_after_list( + procedure update_before_after_each( a_suite in out nocopy ut_logical_suite, - a_before_each_list ut_executables, - a_after_each_list ut_executables + a_before_each_list tt_executables, + a_after_each_list tt_executables ) is l_test ut_test; l_context ut_logical_suite; @@ -372,303 +500,319 @@ create or replace package body ut_suite_builder is for i in 1 .. a_suite.items.count loop if a_suite.items(i) is of (ut_test) then l_test := treat( a_suite.items(i) as ut_test); - l_test.before_each_list := coalesce(a_before_each_list,ut_executables()) multiset union all l_test.before_each_list; - l_test.after_each_list := l_test.after_each_list multiset union all coalesce(a_after_each_list,ut_executables()); + l_test.before_each_list := coalesce(convert_list(a_before_each_list),ut_executables()) multiset union all l_test.before_each_list; + l_test.after_each_list := l_test.after_each_list multiset union all coalesce(convert_list(a_after_each_list),ut_executables()); a_suite.items(i) := l_test; elsif a_suite.items(i) is of (ut_logical_suite) then l_context := treat(a_suite.items(i) as ut_logical_suite); - update_before_after_list(l_context, a_before_each_list, a_after_each_list); + update_before_after_each(l_context, a_before_each_list, a_after_each_list); a_suite.items(i) := l_context; end if; end loop; end if; end; - procedure add_annotated_procedure( + procedure process_before_after_annot( + a_list in out nocopy tt_executables, + a_annotation_name t_annotation_name, a_procedure_name t_object_name, - a_proc_annotations tt_procedure_annotations, - a_suite in out nocopy ut_suite, - a_before_each_list in out nocopy ut_executables, - a_after_each_list in out nocopy ut_executables - ) is + a_proc_annotations tt_annotations_by_name, + a_suite in out nocopy ut_suite + ) is begin - warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, gc_test); - warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, gc_displayname); - warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, gc_rollback); - warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, gc_beforeall); - warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, gc_beforeeach); - warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, gc_afterall); - warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, gc_aftereach); - - if a_proc_annotations.exists(gc_test) then - add_test( a_suite, a_procedure_name, a_proc_annotations); - - warning_bad_annot_combination( - a_suite, a_procedure_name, a_proc_annotations, gc_test, - ut_varchar2_list(gc_beforeeach, gc_aftereach, gc_beforeall, gc_afterall) - ); - - else - if a_proc_annotations.exists(gc_beforeeach) then - add_to_list( a_before_each_list, a_suite.object_owner, a_suite.object_name, a_procedure_name, ut_utils.gc_before_each ); - --TODO add warning if annotation has text - text ignored - end if; - if a_proc_annotations.exists(gc_aftereach) then - add_to_list( a_after_each_list, a_suite.object_owner, a_suite.object_name, a_procedure_name, ut_utils.gc_after_each ); - --TODO add warning if annotation has text - text ignored - end if; - if a_proc_annotations.exists(gc_beforeall) then - add_to_list( a_suite.before_all_list, a_suite.object_owner, a_suite.object_name, a_procedure_name, ut_utils.gc_before_all ); - --TODO add warning if annotation has text - text ignored - end if; - if a_proc_annotations.exists(gc_afterall) then - add_to_list( a_suite.after_all_list, a_suite.object_owner, a_suite.object_name, a_procedure_name, ut_utils.gc_after_all ); - --TODO add warning if annotation has text - text ignored - end if; + if a_proc_annotations.exists(a_annotation_name) and not a_proc_annotations.exists(gc_test) then + a_list( a_proc_annotations(a_annotation_name).first ) := ut_executables(ut_executable(a_suite.object_owner, a_suite.object_name, a_procedure_name, a_annotation_name)); + warning_on_duplicate_annot(a_suite, a_proc_annotations, a_annotation_name, a_procedure_name); + --TODO add warning if annotation has text - text ignored end if; end; procedure add_annotated_procedures( - a_annotations tt_package_annotations, - a_suite in out nocopy ut_suite, - a_before_each_list out ut_executables, - a_after_each_list out ut_executables + a_proc_annotations tt_annotations_by_proc, + a_suite in out nocopy ut_suite, + a_before_each_list in out nocopy tt_executables, + a_after_each_list in out nocopy tt_executables, + a_before_all_list in out nocopy tt_executables, + a_after_all_list in out nocopy tt_executables ) is - l_position t_annotation_position; + l_procedure_name t_object_name; + l_tests tt_tests; begin - a_before_each_list := ut_executables(); - a_after_each_list := ut_executables(); - l_position := a_annotations.first; - while l_position is not null loop - if a_annotations(l_position).procedure_name is not null then - add_annotated_procedure( - a_annotations(l_position).procedure_name, - a_annotations(l_position).procedure_annotations, - a_suite, - a_before_each_list, - a_after_each_list - ); - end if; - l_position := a_annotations.next( l_position); + l_procedure_name := a_proc_annotations.first; + while l_procedure_name is not null loop + add_test( a_suite, l_tests, l_procedure_name, a_proc_annotations(l_procedure_name) ); + process_before_after_annot(a_before_each_list, gc_beforeeach, l_procedure_name, a_proc_annotations(l_procedure_name), a_suite); + process_before_after_annot(a_after_each_list, gc_aftereach, l_procedure_name, a_proc_annotations(l_procedure_name), a_suite); + process_before_after_annot(a_before_all_list, gc_beforeall, l_procedure_name, a_proc_annotations(l_procedure_name), a_suite); + process_before_after_annot(a_after_all_list, gc_afterall, l_procedure_name, a_proc_annotations(l_procedure_name), a_suite); + l_procedure_name := a_proc_annotations.next( l_procedure_name ); end loop; + a_suite.items := a_suite.items multiset union all convert_list(l_tests); end; - procedure populate_suite_contents( + procedure build_suitepath( a_suite in out nocopy ut_suite, - a_annotations tt_package_annotations, - a_package_ann_index tt_annotations_index, - a_context_name t_object_name := null + a_annotations t_annotations_info ) is - l_before_each_list ut_executables; - l_after_each_list ut_executables; - l_rollback_type ut_utils.t_rollback_type; - l_annotation_text varchar2(32767); - l_object_name t_object_name; + l_annotation_text t_annotation_text; begin - if a_context_name is not null then - l_object_name := a_suite.object_name||'.'||a_context_name; - else - l_object_name := a_suite.object_name; - end if; - if a_package_ann_index.exists(gc_suitepath) then - l_annotation_text := trim(a_annotations(a_package_ann_index(gc_suitepath).first).text); + if a_annotations.by_name.exists(gc_suitepath) then + l_annotation_text := trim(a_annotations.by_name(gc_suitepath)(a_annotations.by_name(gc_suitepath).first)); if l_annotation_text is not null then if regexp_like(l_annotation_text,'^((\w|[$#])+\.)*(\w|[$#])+$') then - a_suite.path := l_annotation_text||'.'||l_object_name; + a_suite.path := l_annotation_text||'.'||a_suite.object_name; else - add_annotation_warning( - a_suite, gc_suitepath||'('||l_annotation_text||')', - 'Invalid path value in annotation %%%.', a_package_ann_index(gc_suitepath).first + add_annotation_ignored_warning( + a_suite, gc_suitepath||'('||l_annotation_text||')', + 'Invalid path value in annotation %%%.', a_annotations.by_name(gc_suitepath).first ); end if; else - add_annotation_warning( - a_suite, gc_suitepath, '%%% annotation requires a non-empty parameter value.', - a_package_ann_index(gc_suitepath).first + add_annotation_ignored_warning( + a_suite, gc_suitepath, '%%% annotation requires a non-empty parameter value.', + a_annotations.by_name(gc_suitepath).first ); end if; - warning_on_duplicate_annot(a_suite, a_package_ann_index, gc_suitepath); + warning_on_duplicate_annot(a_suite, a_annotations.by_name, gc_suitepath); end if; - a_suite.path := lower(coalesce(a_suite.path, l_object_name)); + a_suite.path := lower(coalesce(a_suite.path, a_suite.object_name)); + end; - if a_package_ann_index.exists(gc_displayname) then - l_annotation_text := trim(a_annotations(a_package_ann_index(gc_displayname).first).text); + procedure populate_suite_contents( + a_suite in out nocopy ut_suite, + a_annotations t_annotations_info + ) is + l_before_each_list tt_executables; + l_after_each_list tt_executables; + l_before_all_list tt_executables; + l_after_all_list tt_executables; + l_executables ut_executables; + l_rollback_type ut_utils.t_rollback_type; + l_annotation_text t_annotation_text; + begin + if a_annotations.by_name.exists(gc_displayname) then + l_annotation_text := trim(a_annotations.by_name(gc_displayname)(a_annotations.by_name(gc_displayname).first)); if l_annotation_text is not null then a_suite.description := l_annotation_text; else - add_annotation_warning( + add_annotation_ignored_warning( a_suite, gc_displayname, '%%% annotation requires a non-empty parameter value.', - a_package_ann_index(gc_displayname).first + a_annotations.by_name(gc_displayname).first ); end if; - warning_on_duplicate_annot(a_suite, a_package_ann_index, gc_displayname); + warning_on_duplicate_annot(a_suite, a_annotations.by_name, gc_displayname); end if; - if a_package_ann_index.exists(gc_rollback) then - l_rollback_type := get_rollback_type(a_annotations(a_package_ann_index(gc_rollback).first).text); + if a_annotations.by_name.exists(gc_rollback) then + l_rollback_type := get_rollback_type(a_annotations.by_name(gc_rollback)(a_annotations.by_name(gc_rollback).first)); if l_rollback_type is null then - add_annotation_warning( + add_annotation_ignored_warning( a_suite, gc_rollback, '%%% annotation requires one of values as parameter: "auto" or "manual".', - a_package_ann_index(gc_rollback).first + a_annotations.by_name(gc_rollback).first ); end if; - warning_on_duplicate_annot(a_suite, a_package_ann_index, gc_rollback); + warning_on_duplicate_annot(a_suite, a_annotations.by_name, gc_rollback); + end if; + if a_annotations.by_name.exists(gc_beforeall) then + l_before_all_list := add_executables( a_suite.object_owner, a_suite.object_name, a_annotations.by_name(gc_beforeall), gc_beforeall ); + end if; + if a_annotations.by_name.exists(gc_afterall) then + l_after_all_list := add_executables( a_suite.object_owner, a_suite.object_name, a_annotations.by_name(gc_afterall), gc_afterall ); + end if; + + if a_annotations.by_name.exists(gc_beforeeach) then + l_before_each_list := add_executables( a_suite.object_owner, a_suite.object_name, a_annotations.by_name(gc_beforeeach), gc_beforeeach ); + end if; + if a_annotations.by_name.exists(gc_aftereach) then + l_after_each_list := add_executables( a_suite.object_owner, a_suite.object_name, a_annotations.by_name(gc_aftereach), gc_aftereach ); end if; - a_suite.disabled_flag := ut_utils.boolean_to_int(a_package_ann_index.exists(gc_disabled)); + a_suite.disabled_flag := ut_utils.boolean_to_int(a_annotations.by_name.exists(gc_disabled)); --process procedure annotations for suite - add_annotated_procedures(a_annotations, a_suite, l_before_each_list, l_after_each_list); + add_annotated_procedures(a_annotations.by_proc, a_suite, l_before_each_list, l_after_each_list, l_before_all_list, l_after_all_list); a_suite.set_rollback_type(l_rollback_type); - update_before_after_list(a_suite, l_before_each_list, l_after_each_list); + update_before_after_each(a_suite, l_before_each_list, l_after_each_list); + a_suite.before_all_list := convert_list(l_before_all_list); + a_suite.after_all_list := convert_list(l_after_all_list); end; procedure add_suite_contexts( a_suite in out nocopy ut_suite, - a_annotations in out nocopy tt_package_annotations, - a_package_ann_index in out nocopy tt_annotations_index + a_annotations in out nocopy t_annotations_info ) is l_context_pos t_annotation_position; l_end_context_pos t_annotation_position; - l_package_ann_index tt_annotations_index; - l_annotations tt_package_annotations; - l_suite ut_suite; + l_context_name t_object_name; + l_ctx_annotations t_annotations_info; + l_context ut_suite_context; l_context_no binary_integer := 1; function get_endcontext_position( - a_context_ann_pos t_annotation_position, - a_package_ann_index in out nocopy tt_annotations_index + a_context_ann_pos t_annotation_position, + a_package_annotations in out nocopy tt_annotations_by_name ) return t_annotation_position is l_result t_annotation_position; begin - if a_package_ann_index.exists(gc_endcontext) then - l_result := a_package_ann_index(gc_endcontext).first; + if a_package_annotations.exists(gc_endcontext) then + l_result := a_package_annotations(gc_endcontext).first; while l_result <= a_context_ann_pos loop - --remove invalid endcontext - delete_from_annotation_index(a_package_ann_index, l_result, l_result); - --remove the bad endcontext from index - l_result := a_package_ann_index(gc_endcontext).next(l_result); + l_result := a_package_annotations(gc_endcontext).next(l_result); end loop; end if; return l_result; end; function get_annotations_in_context( - a_annotations tt_package_annotations, + a_annotations t_annotations_info, a_context_pos t_annotation_position, a_end_context_pos t_annotation_position - ) return tt_package_annotations is - l_annotations tt_package_annotations; - l_position t_annotation_position; + ) return t_annotations_info is + l_result t_annotations_info; + l_position t_annotation_position; + l_procedure_name t_object_name; + l_annotation_name t_annotation_name; + l_annotation_text t_annotation_text; begin l_position := a_context_pos; + l_result.owner := a_annotations.owner; + l_result.name := a_annotations.name; while l_position is not null and l_position <= a_end_context_pos loop - l_annotations(l_position) := a_annotations(l_position); - l_position := a_annotations.next(l_position); + l_result.by_line(l_position) := a_annotations.by_line(l_position); + l_procedure_name := l_result.by_line(l_position).procedure_name; + l_annotation_name := l_result.by_line(l_position).name; + l_annotation_text := l_result.by_line(l_position).text; + if l_procedure_name is not null then + l_result.by_proc(l_procedure_name)(l_annotation_name)(l_position) := l_annotation_text; + else + l_result.by_name(l_annotation_name)(l_position) := l_annotation_text; + end if; + l_position := a_annotations.by_line.next(l_position); end loop; - return l_annotations; + return l_result; end; begin - if not a_package_ann_index.exists(gc_context) then + if not a_annotations.by_name.exists(gc_context) then return; end if; - l_context_pos := a_package_ann_index(gc_context).first; + + l_context_pos := a_annotations.by_name( gc_context).first; + while l_context_pos is not null loop - l_end_context_pos := get_endcontext_position(l_context_pos, a_package_ann_index); + l_end_context_pos := get_endcontext_position(l_context_pos, a_annotations.by_name ); if l_end_context_pos is null then exit; end if; --create a sub-set of annotations to process as sub-suite (context) - l_annotations := get_annotations_in_context(a_annotations, l_context_pos, l_end_context_pos); - l_package_ann_index := build_annotation_index(l_annotations); + l_ctx_annotations := get_annotations_in_context( a_annotations, l_context_pos, l_end_context_pos); - l_suite := ut_suite(a_suite.object_owner, a_suite.object_name, gc_context||'_'||l_context_no); + l_context_name := coalesce( + l_ctx_annotations.by_line( l_context_pos ).text + , gc_context||'_'||l_context_no + ); + + l_context := ut_suite_context(a_suite.object_owner, a_suite.object_name, l_context_name ); - l_suite.description := l_annotations(l_package_ann_index(gc_context).first).text; - l_suite.description := l_annotations(l_context_pos).text; - warning_on_duplicate_annot( l_suite, l_package_ann_index, gc_suite ); + l_context.path := a_suite.path||'.'||l_context_name; + l_context.description := l_ctx_annotations.by_line( l_context_pos ).text; - populate_suite_contents( l_suite, l_annotations, l_package_ann_index, gc_context||'_'||l_context_no ); + warning_on_duplicate_annot( l_context, l_ctx_annotations.by_name, gc_context ); - a_suite.add_item(l_suite); + populate_suite_contents( l_context, l_ctx_annotations ); + + a_suite.add_item(l_context); -- remove annotations within context after processing them - a_annotations.delete(l_context_pos, l_end_context_pos); - delete_from_annotation_index(a_package_ann_index, l_context_pos, l_end_context_pos); + delete_annotations_range(a_annotations, l_context_pos, l_end_context_pos); - if a_package_ann_index.exists(gc_context) then - l_context_pos := a_package_ann_index(gc_context).next(l_context_pos); - else - l_context_pos := null; - end if; + exit when not a_annotations.by_name.exists( gc_context); + + l_context_pos := a_annotations.by_name( gc_context).next( l_context_pos); l_context_no := l_context_no + 1; end loop; end; procedure warning_on_incomplete_context( a_suite in out nocopy ut_suite, - a_annotations tt_package_annotations, - a_package_ann_index tt_annotations_index + a_package_ann_index tt_annotations_by_name ) is l_annotation_pos t_annotation_position; - begin - if a_package_ann_index.exists(gc_context) then - l_annotation_pos := a_package_ann_index(gc_context).first; - while l_annotation_pos is not null loop - add_annotation_warning( - a_suite, gc_context, 'Invalid annotation %%%. Cannot find following "--%endcontext".', - l_annotation_pos - ); - l_annotation_pos := a_package_ann_index(gc_context).next(l_annotation_pos); - end loop; - end if; - if a_package_ann_index.exists(gc_endcontext) then - l_annotation_pos := a_package_ann_index(gc_endcontext).first; - while l_annotation_pos is not null loop - add_annotation_warning( - a_suite, gc_endcontext, 'Invalid annotation %%%. Cannot find preceding "--%context".', - l_annotation_pos - ); - l_annotation_pos := a_package_ann_index(gc_endcontext).next(l_annotation_pos); - end loop; + begin + if a_package_ann_index.exists(gc_context) then + l_annotation_pos := a_package_ann_index(gc_context).first; + while l_annotation_pos is not null loop + add_annotation_ignored_warning( + a_suite, gc_context, 'Invalid annotation %%%. Cannot find following "--%endcontext".', + l_annotation_pos + ); + l_annotation_pos := a_package_ann_index(gc_context).next(l_annotation_pos); + end loop; + end if; + if a_package_ann_index.exists(gc_endcontext) then + l_annotation_pos := a_package_ann_index(gc_endcontext).first; + while l_annotation_pos is not null loop + add_annotation_ignored_warning( + a_suite, gc_endcontext, 'Invalid annotation %%%. Cannot find preceding "--%context".', + l_annotation_pos + ); + l_annotation_pos := a_package_ann_index(gc_endcontext).next(l_annotation_pos); + end loop; + end if; + end; + + procedure warning_on_unknown_annotations( + a_suite in out nocopy ut_suite_item, + a_annotations tt_annotations_by_line + ) is + l_line_no t_annotation_position := a_annotations.first; + begin + while l_line_no is not null loop + if a_annotations(l_line_no).name not member of (gc_supported_annotations) then + add_annotation_ignored_warning( + a_suite, + a_annotations(l_line_no).name, + 'Unsupported annotation %%%.', + l_line_no, + a_annotations(l_line_no).procedure_name + ); end if; - end; + l_line_no := a_annotations.next(l_line_no); + end loop; + end; function create_suite( - a_package_annotations t_package_annotations_info + a_annotations t_annotations_info ) return ut_logical_suite is - l_annotations tt_package_annotations := a_package_annotations.annotations; - l_package_ann_index tt_annotations_index; - l_suite ut_suite; + l_annotations t_annotations_info := a_annotations; + l_annotation_pos t_annotation_position; + l_suite ut_suite; begin - l_package_ann_index := build_annotation_index(l_annotations); - if l_package_ann_index.exists(gc_suite) then + if l_annotations.by_name.exists( gc_suite) then --create an incomplete suite - l_suite := ut_suite(a_package_annotations.owner, a_package_annotations.name); + l_suite := ut_suite(l_annotations.owner, l_annotations.name); + l_annotation_pos := l_annotations.by_name( gc_suite).first; + l_suite.description := l_annotations.by_name( gc_suite)( l_annotation_pos); + warning_on_unknown_annotations(l_suite, l_annotations.by_line); - l_suite.description := l_annotations(l_package_ann_index(gc_suite).first).text; - warning_on_duplicate_annot(l_suite, l_package_ann_index, gc_suite); + warning_on_duplicate_annot( l_suite, l_annotations.by_name, gc_suite ); - add_suite_contexts( l_suite, l_annotations, l_package_ann_index ); + build_suitepath( l_suite, l_annotations ); + + add_suite_contexts( l_suite, l_annotations ); --by this time all contexts were consumed and l_annotations should not have any context/endcontext annotation in it. - warning_on_incomplete_context( l_suite, l_annotations, l_package_ann_index ); + warning_on_incomplete_context( l_suite, l_annotations.by_name ); - populate_suite_contents( l_suite, l_annotations, l_package_ann_index ); + populate_suite_contents( l_suite, l_annotations ); end if; return l_suite; end; - function create_suite(a_object ut_annotated_object) return ut_logical_suite is - begin - return create_suite( convert_package_annotations(a_object) ); - end create_suite; - function build_suites_hierarchy(a_suites_by_path tt_schema_suites) return tt_schema_suites is l_result tt_schema_suites; l_suite_path varchar2(4000 char); @@ -717,12 +861,38 @@ create or replace package body ut_suite_builder is l_annotated_objects ut_annotated_objects; l_all_suites tt_schema_suites; l_result t_schema_suites_info; + + function convert_package_annotations(a_object ut_annotated_object) return t_annotations_info is + l_result t_annotations_info; + l_annotation t_annotation; + l_annotation_no binary_integer; + l_annotation_pos binary_integer; + begin + l_result.owner := a_object.object_owner; + l_result.name := lower(trim(a_object.object_name)); + l_annotation_no := a_object.annotations.first; + while l_annotation_no is not null loop + l_annotation_pos := a_object.annotations(l_annotation_no).position; + l_annotation.name := a_object.annotations(l_annotation_no).name; + l_annotation.text := a_object.annotations(l_annotation_no).text; + l_annotation.procedure_name := lower(trim(a_object.annotations(l_annotation_no).subobject_name)); + l_result.by_line( l_annotation_pos) := l_annotation; + if l_annotation.procedure_name is null then + l_result.by_name( l_annotation.name)( l_annotation_pos) := l_annotation.text; + else + l_result.by_proc(l_annotation.procedure_name)(l_annotation.name)(l_annotation_pos) := l_annotation.text; + end if; + l_annotation_no := a_object.annotations.next(l_annotation_no); + end loop; + return l_result; + end; + begin fetch a_annotated_objects bulk collect into l_annotated_objects; close a_annotated_objects; for i in 1 .. l_annotated_objects.count loop - l_suite := create_suite(l_annotated_objects(i)); + l_suite := create_suite(convert_package_annotations(l_annotated_objects(i))); if l_suite is not null then l_all_suites(l_suite.path) := l_suite; l_result.suite_paths(l_suite.object_name) := l_suite.path; diff --git a/source/core/ut_suite_manager.pkb b/source/core/ut_suite_manager.pkb index 4a8927496..dccd745d2 100644 --- a/source/core/ut_suite_manager.pkb +++ b/source/core/ut_suite_manager.pkb @@ -213,26 +213,64 @@ create or replace package body ut_suite_manager is end; procedure filter_suite_by_path(a_suite in out nocopy ut_suite_item, a_path varchar2) is - c_root constant varchar2(32767) := lower(regexp_substr(a_path, '[A-Za-z0-9$#_]+')); - c_rest_path constant varchar2(32767) := regexp_substr(a_path, '\.(.+)', subexpression => 1); - l_suite ut_logical_suite; - l_item ut_suite_item; - l_items ut_suite_items := ut_suite_items(); - begin - if a_path is not null and a_suite is not null and a_suite is of (ut_logical_suite) then - l_suite := treat(a_suite as ut_logical_suite); + c_item_name constant varchar2(32767) := lower(regexp_substr(a_path, '[A-Za-z0-9$#_]+')); + c_child_filter_path constant varchar2(32767) := regexp_substr(a_path, '\.(.+)', subexpression => 1); + l_suite ut_logical_suite; + l_item ut_suite_item; + l_items ut_suite_items := ut_suite_items(); - for i in 1 .. l_suite.items.count loop - l_item := l_suite.items(i); - if lower(l_item.name) = c_root then - filter_suite_by_path(l_item, c_rest_path); - l_items.extend; - l_items(l_items.count) := l_item; + function find_item_in_suite(a_suite ut_logical_suite, a_item_name varchar2) return ut_suite_item is + l_item_index binary_integer; + begin + l_item_index := a_suite.items.first; + while l_item_index is not null loop + if lower(a_suite.items(l_item_index).name) = a_item_name then + return a_suite.items(l_item_index); end if; + l_item_index := a_suite.items.next(l_item_index); end loop; + return null; + end; - if l_items.count = 0 then - raise_application_error(-20203, 'Suite not found'); + function find_item_in_suite_contexts(a_suite ut_logical_suite, a_item_name varchar2) return ut_suite_item is + l_item_index binary_integer; + l_context ut_suite_context; + l_item ut_suite_item; + begin + l_item_index := a_suite.items.first; + while l_item_index is not null loop + if a_suite.items(l_item_index) is of (ut_suite_context) then + l_item := find_item_in_suite( + treat(a_suite.items(l_item_index) as ut_suite_context) + , a_item_name + ); + end if; + + if l_item is not null then + l_context := treat(a_suite.items(l_item_index) as ut_suite_context); + l_context.items := ut_suite_items(l_item); + exit; + end if; + l_item_index := a_suite.items.next(l_item_index); + end loop; + return l_context; + end; + begin + if a_suite is of (ut_logical_suite) then + l_suite := treat(a_suite as ut_logical_suite); + + l_item := coalesce( + find_item_in_suite(l_suite, c_item_name) + , find_item_in_suite_contexts(l_suite, c_item_name) + ); + if l_item is not null then + if c_child_filter_path is not null then + filter_suite_by_path(l_item, c_child_filter_path); + end if; + l_items.extend; + l_items(l_items.count) := l_item; + else + raise_application_error(-20203, 'Suite item '||c_item_name||' not found'); end if; l_suite.items := l_items; @@ -241,12 +279,15 @@ create or replace package body ut_suite_manager is end filter_suite_by_path; function get_suite_filtered_by_path(a_path varchar2, a_schema_suites tt_schema_suites) return ut_logical_suite is - l_suite ut_logical_suite; - c_suite_path constant varchar2(4000) := regexp_substr(a_path, ':(.+)', subexpression => 1); - c_root_suite_name constant varchar2(4000) := regexp_substr(c_suite_path, '^[A-Za-z0-9$#_]+'); + l_suite ut_logical_suite; + c_suite_path constant varchar2(32767) := regexp_substr(a_path, ':(.+)', subexpression => 1); + c_root_suite_name constant varchar2(32767) := regexp_substr(c_suite_path, '^[A-Za-z0-9$#_]+'); + c_child_filter_path constant varchar2(32767) := regexp_substr(c_suite_path, '\.(.+)', subexpression => 1); begin l_suite := a_schema_suites(c_root_suite_name); - filter_suite_by_path(l_suite, regexp_substr(c_suite_path, '\.(.+)', subexpression => 1)); + if c_child_filter_path is not null then + filter_suite_by_path(l_suite, c_child_filter_path); + end if; return l_suite; exception when no_data_found then @@ -293,7 +334,7 @@ create or replace package body ut_suite_manager is l_index varchar2(4000 char); l_suite ut_logical_suite; l_objects_to_run ut_suite_items; - l_schema_paths t_schema_paths; + l_schema_paths t_schema_paths; begin --resolve schema names from paths and group paths by schema name resolve_schema_names(l_paths); diff --git a/source/core/ut_suite_manager.pks b/source/core/ut_suite_manager.pks index 8b1b34335..f35ddb4b3 100644 --- a/source/core/ut_suite_manager.pks +++ b/source/core/ut_suite_manager.pks @@ -17,7 +17,7 @@ create or replace package ut_suite_manager authid current_user is */ /** - * Reads database source code, parses it and returns annotations + * Resposible for building hierarhy of sutes from individual suites created by suite_builder */ /** diff --git a/source/core/ut_utils.pkb b/source/core/ut_utils.pkb index 438d32c60..7130ff6c5 100644 --- a/source/core/ut_utils.pkb +++ b/source/core/ut_utils.pkb @@ -107,8 +107,10 @@ create or replace package body ut_utils is l_len integer := coalesce(dbms_lob.getlength(a_value), 0); l_result varchar2(32767); begin - if l_len = 0 then + if a_value is null then l_result := gc_null_string; + elsif l_len = 0 then + l_result := gc_empty_string; elsif l_len <= gc_max_input_string_length then l_result := surround_with(a_value,a_qoute_char); else @@ -121,8 +123,10 @@ create or replace package body ut_utils is l_len integer := coalesce(dbms_lob.getlength(a_value), 0); l_result varchar2(32767); begin - if l_len = 0 then + if a_value is null then l_result := gc_null_string; + elsif l_len = 0 then + l_result := gc_empty_string; elsif l_len <= gc_max_input_string_length then l_result := surround_with(rawtohex(a_value),a_qoute_char); else @@ -437,17 +441,16 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab, procedure save_dbms_output_to_cache is l_status number; l_line varchar2(32767); - l_line_no integer := 1; + l_offset integer := 0; l_lines ut_varchar2_rows := ut_varchar2_rows(); c_lines_limit constant integer := 100; pragma autonomous_transaction; - procedure flush_lines is + procedure flush_lines(a_lines ut_varchar2_rows, a_offset integer) is begin insert into ut_dbms_output_cache (seq_no,text) - select rownum, column_value - from table(l_lines); - l_lines.delete; + select rownum+a_offset, column_value + from table(a_lines); end; begin loop @@ -455,10 +458,12 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab, exit when l_status = 1; l_lines := l_lines multiset union all ut_utils.convert_collection(ut_utils.clob_to_table(l_line||chr(7),4000)); if l_lines.count > c_lines_limit then - flush_lines(); + flush_lines(l_lines, l_offset); + l_offset := l_offset + l_lines.count; + l_lines.delete; end if; end loop; - flush_lines(); + flush_lines(l_lines, l_offset); commit; end; @@ -506,6 +511,17 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab, return to_char(a_value, gc_number_format, 'NLS_NUMERIC_CHARACTERS=''. '''); end; + function get_xml_header(a_encoding varchar2) return varchar2 is + begin + return + ''; + end; + function trim_list_elements(a_list IN ut_varchar2_list, a_regexp_to_trim in varchar2 default '[:space:]') return ut_varchar2_list is l_trimmed_list ut_varchar2_list; l_index integer; @@ -524,7 +540,7 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab, return l_trimmed_list; end; - function filter_list(a_list IN ut_varchar2_list, a_regexp_filter in varchar2) return ut_varchar2_list is + function filter_list(a_list in ut_varchar2_list, a_regexp_filter in varchar2) return ut_varchar2_list is l_filtered_list ut_varchar2_list; l_index integer; begin @@ -570,10 +586,6 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab, l_newlines_count binary_integer; l_offset binary_integer := 1; l_length binary_integer := coalesce(dbms_lob.getlength(a_source), 0); - function is_before(a_x binary_integer, a_y binary_integer) return boolean is - begin - return a_x < a_y or a_y = 0; - end; begin l_ml_comment_start := instr(a_source,'/*'); l_comment_start := instr(a_source,'--'); diff --git a/source/core/ut_utils.pks b/source/core/ut_utils.pks index 166ce01ec..847c57fd8 100644 --- a/source/core/ut_utils.pks +++ b/source/core/ut_utils.pks @@ -21,38 +21,38 @@ create or replace package ut_utils authid definer is * */ - gc_version constant varchar2(50) := 'v3.1.1.1865'; + gc_version constant varchar2(50) := 'v3.1.2.2130'; /* Constants: Event names */ subtype t_event_name is varchar2(30); gc_before_run constant t_event_name := 'before_run'; gc_before_suite constant t_event_name := 'before_suite'; - gc_before_before_all constant t_event_name := 'before_before_all'; - gc_before_before_each constant t_event_name := 'before_before_each'; - gc_before_before_test constant t_event_name := 'before_before_test'; - gc_before_test_execute constant t_event_name := 'before_test_execute'; - gc_before_after_test constant t_event_name := 'before_after_test'; - gc_before_after_each constant t_event_name := 'before_after_each'; - gc_before_after_all constant t_event_name := 'before_after_all'; + gc_before_before_all constant t_event_name := 'before_beforeall'; + gc_before_before_each constant t_event_name := 'before_beforeeach'; + gc_before_before_test constant t_event_name := 'before_beforetest'; + gc_before_test_execute constant t_event_name := 'before_test'; + gc_before_after_test constant t_event_name := 'before_aftertest'; + gc_before_after_each constant t_event_name := 'before_aftereach'; + gc_before_after_all constant t_event_name := 'before_afterall'; gc_after_run constant t_event_name := 'after_run'; gc_after_suite constant t_event_name := 'after_suite'; - gc_after_before_all constant t_event_name := 'after_before_all'; - gc_after_before_each constant t_event_name := 'after_before_each'; - gc_after_before_test constant t_event_name := 'after_before_test'; - gc_after_test_execute constant t_event_name := 'after_test_execute'; - gc_after_after_test constant t_event_name := 'after_after_test'; - gc_after_after_each constant t_event_name := 'after_after_each'; - gc_after_after_all constant t_event_name := 'after_after_all'; + gc_after_before_all constant t_event_name := 'after_beforeall'; + gc_after_before_each constant t_event_name := 'after_beforeeach'; + gc_after_before_test constant t_event_name := 'after_beforetest'; + gc_after_test_execute constant t_event_name := 'after_test'; + gc_after_after_test constant t_event_name := 'after_aftertest'; + gc_after_after_each constant t_event_name := 'after_aftereach'; + gc_after_after_all constant t_event_name := 'after_afterall'; gc_finalize constant t_event_name := 'finalize'; subtype t_executable_type is varchar2(30); - gc_before_all constant t_executable_type := 'before_all'; - gc_before_each constant t_executable_type := 'before_each'; - gc_before_test constant t_executable_type := 'before_test'; - gc_test_execute constant t_executable_type := 'test_execute'; - gc_after_test constant t_executable_type := 'after_test'; - gc_after_each constant t_executable_type := 'after_each'; - gc_after_all constant t_executable_type := 'after_all'; + gc_before_all constant t_executable_type := 'beforeall'; + gc_before_each constant t_executable_type := 'beforeeach'; + gc_before_test constant t_executable_type := 'beforetest'; + gc_test_execute constant t_executable_type := 'test'; + gc_after_test constant t_executable_type := 'aftertest'; + gc_after_each constant t_executable_type := 'aftereach'; + gc_after_all constant t_executable_type := 'afterall'; /* Constants: Test Results */ subtype t_test_result is binary_integer range 0 .. 3; @@ -110,6 +110,10 @@ create or replace package ut_utils authid definer is gc_invalid_version_no constant pls_integer := -20214; pragma exception_init(ex_invalid_version_no, -20214); + ex_invalid_package exception; + gc_invalid_package constant pls_integer := -6550; + pragma exception_init(ex_invalid_package, -6550); + gc_max_storage_varchar2_len constant integer := 4000; gc_max_output_string_length constant integer := 4000; gc_max_input_string_length constant integer := gc_max_output_string_length - 2; --we need to remove 2 chars for quotes around string @@ -120,6 +124,7 @@ create or replace package ut_utils authid definer is gc_timestamp_format constant varchar2(100) := 'yyyy-mm-dd"T"hh24:mi:ssxff'; gc_timestamp_tz_format constant varchar2(100) := 'yyyy-mm-dd"T"hh24:mi:ssxff tzh:tzm'; gc_null_string constant varchar2(4) := 'NULL'; + gc_empty_string constant varchar2(5) := 'EMPTY'; type t_version is record( major natural, @@ -316,6 +321,13 @@ create or replace package ut_utils authid definer is */ function to_xml_number_format(a_value number) return varchar2; + + /** + * Returns xml header. If a_encoding is not null, header will include encoding attribute with provided value + */ + function get_xml_header(a_encoding varchar2) return varchar2; + + /*It takes a collection of type ut_varchar2_list and it trims the characters passed as arguments for every element*/ function trim_list_elements(a_list IN ut_varchar2_list, a_regexp_to_trim in varchar2 default '[:space:]') return ut_varchar2_list; diff --git a/source/create_synonyms_and_grants_for_public.sql b/source/create_synonyms_and_grants_for_public.sql index 235c6806a..e2cc450f5 100644 --- a/source/create_synonyms_and_grants_for_public.sql +++ b/source/create_synonyms_and_grants_for_public.sql @@ -31,6 +31,8 @@ whenever oserror exit failure rollback alter session set current_schema = &&ut3_owner; +grant execute on &&ut3_owner..ut_expectation to public; +grant execute on &&ut3_owner..ut_expectation_compound to public; grant execute on &&ut3_owner..ut_be_between to public; grant execute on &&ut3_owner..ut_be_empty to public; grant execute on &&ut3_owner..ut_be_false to public; @@ -101,6 +103,8 @@ end; prompt Creating synonyms for UTPLSQL objects in &&ut3_owner schema to PUBLIC +create public synonym ut_expectation for &&ut3_owner..ut_expectation; +create public synonym ut_expectation_compound for &&ut3_owner..ut_expectation_compound; create public synonym be_between for &&ut3_owner..ut_be_between; create public synonym be_empty for &&ut3_owner..ut_be_empty; create public synonym be_false for &&ut3_owner..ut_be_false; @@ -142,8 +146,6 @@ create public synonym ut_file_mapping for &&ut3_owner..ut_file_mapping; create public synonym ut_file_mapper for &&ut3_owner..ut_file_mapper; create public synonym ut_key_value_pairs for &&ut3_owner..ut_key_value_pairs; create public synonym ut_key_value_pair for &&ut3_owner..ut_key_value_pair; -create public synonym ut_compound_data_tmp for &&ut3_owner..ut_compound_data_tmp; -create public synonym ut_compound_data_diff_tmp for &&ut3_owner..ut_compound_data_diff_tmp; create public synonym ut_sonar_test_reporter for &&ut3_owner..ut_sonar_test_reporter; begin $if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then diff --git a/source/create_user_grants.sql b/source/create_user_grants.sql new file mode 100644 index 000000000..112317027 --- /dev/null +++ b/source/create_user_grants.sql @@ -0,0 +1,122 @@ +/* + utPLSQL - Version 3 + Copyright 2016 - 2017 utPLSQL Project + + Licensed under the Apache License, Version 2.0 (the "License"): + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Create all necessary grant for the user who owns test packages and want to execute utPLSQL framework +*/ + +@@define_ut3_owner_param.sql + +column 2 new_value 2 noprint +select null as "2" from dual where 1=0; +spool params.sql.tmp +select + case + when '&&2' is null then q'[ACCEPT ut3_user CHAR PROMPT 'Provide schema to which should be granted the utPLSQL v3 ']' + else 'define ut3_user=&&2' + end +from dual; +spool off +set termout on +@params.sql.tmp +set termout off +/* cleanup temporary sql files */ +--try running on windows +$ del params.sql.tmp +--try running on linux/unix +! rm params.sql.tmp +set termout on + +set echo off +set feedback on +set heading off +set verify off + +prompt Granting privileges on UTPLSQL objects in &&ut3_owner schema to user &&ut3_user + +whenever sqlerror exit failure rollback +whenever oserror exit failure rollback + +alter session set current_schema = &&ut3_owner; + +grant execute on &&ut3_owner..ut_expectation to &ut3_user; +grant execute on &&ut3_owner..ut_expectation_compound to &ut3_user; +grant execute on &&ut3_owner..ut_be_between to &ut3_user; +grant execute on &&ut3_owner..ut_be_empty to &ut3_user; +grant execute on &&ut3_owner..ut_be_false to &ut3_user; +grant execute on &&ut3_owner..ut_be_greater_or_equal to &ut3_user; +grant execute on &&ut3_owner..ut_be_greater_than to &ut3_user; +grant execute on &&ut3_owner..ut_be_less_or_equal to &ut3_user; +grant execute on &&ut3_owner..ut_be_less_than to &ut3_user; +grant execute on &&ut3_owner..ut_be_like to &ut3_user; +grant execute on &&ut3_owner..ut_be_not_null to &ut3_user; +grant execute on &&ut3_owner..ut_be_null to &ut3_user; +grant execute on &&ut3_owner..ut_be_true to &ut3_user; +grant execute on &&ut3_owner..ut_equal to &ut3_user; +grant execute on &&ut3_owner..ut_have_count to &ut3_user; +grant execute on &&ut3_owner..ut_match to &ut3_user; +grant execute on &&ut3_owner..ut to &ut3_user; +grant execute on &&ut3_owner..ut_runner to &ut3_user; +grant execute on &&ut3_owner..ut_teamcity_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_xunit_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_junit_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_tfs_junit_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_documentation_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_html_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_sonar_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_coveralls_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_cobertura_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_reporters to &ut3_user; +grant execute on &&ut3_owner..ut_varchar2_list to &ut3_user; +grant execute on &&ut3_owner..ut_varchar2_rows to &ut3_user; +grant execute on &&ut3_owner..ut_integer_list to &ut3_user; +grant execute on &&ut3_owner..ut_reporter_base to &ut3_user; +grant execute on &&ut3_owner..ut_output_reporter_base to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_reporter_base to &ut3_user; +grant execute on &&ut3_owner..ut_console_reporter_base to &ut3_user; +grant execute on &&ut3_owner..ut_coverage to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_options to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_helper to &ut3_user; +grant execute on &&ut3_owner..ut_output_buffer_base to &ut3_user; +grant execute on &&ut3_owner..ut_output_table_buffer to &ut3_user; +grant execute on &&ut3_owner..ut_file_mappings to &ut3_user; +grant execute on &&ut3_owner..ut_file_mapping to &ut3_user; +grant execute on &&ut3_owner..ut_file_mapper to &ut3_user; +grant execute on &&ut3_owner..ut_key_value_pairs to &ut3_user; +grant execute on &&ut3_owner..ut_key_value_pair to &ut3_user; +grant select, insert, delete on &&ut3_owner..ut_compound_data_tmp to &ut3_user; +grant select, insert, delete on &&ut3_owner..ut_compound_data_diff_tmp to &ut3_user; +grant execute on &&ut3_owner..ut_sonar_test_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_annotations to &ut3_user; +grant execute on &&ut3_owner..ut_annotation to &ut3_user; +grant execute on &&ut3_owner..ut_annotation_manager to &ut3_user; +grant execute on &&ut3_owner..ut_annotated_object to &ut3_user; +grant execute on &&ut3_owner..ut_annotated_objects to &ut3_user; +grant select on &&ut3_owner..ut_annotation_cache_info to &ut3_user; +grant select on &&ut3_owner..ut_annotation_cache to &ut3_user; +grant execute on &&ut3_owner..ut_annotation_cache_manager to &ut3_user; +grant execute on &&ut3_owner..ut_annotation_parser to &ut3_user; +grant execute on &&ut3_owner..ut_annotation_objs_cache_info to &ut3_user; +grant execute on &&ut3_owner..ut_annotation_obj_cache_info to &ut3_user; +begin + $if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then + execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_blocks to &ut3_user'; + execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_runs to &ut3_user'; + execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_units to &ut3_user'; + $else + null; + $end +end; +/ diff --git a/source/create_synonyms_and_grants_for_user.sql b/source/create_user_synonyms.sql similarity index 58% rename from source/create_synonyms_and_grants_for_user.sql rename to source/create_user_synonyms.sql index 3044cb32f..b16b0683c 100644 --- a/source/create_synonyms_and_grants_for_user.sql +++ b/source/create_user_synonyms.sql @@ -51,77 +51,10 @@ whenever oserror exit failure rollback alter session set current_schema = &&ut3_owner; -grant execute on &&ut3_owner..ut_be_between to &ut3_user; -grant execute on &&ut3_owner..ut_be_empty to &ut3_user; -grant execute on &&ut3_owner..ut_be_false to &ut3_user; -grant execute on &&ut3_owner..ut_be_greater_or_equal to &ut3_user; -grant execute on &&ut3_owner..ut_be_greater_than to &ut3_user; -grant execute on &&ut3_owner..ut_be_less_or_equal to &ut3_user; -grant execute on &&ut3_owner..ut_be_less_than to &ut3_user; -grant execute on &&ut3_owner..ut_be_like to &ut3_user; -grant execute on &&ut3_owner..ut_be_not_null to &ut3_user; -grant execute on &&ut3_owner..ut_be_null to &ut3_user; -grant execute on &&ut3_owner..ut_be_true to &ut3_user; -grant execute on &&ut3_owner..ut_equal to &ut3_user; -grant execute on &&ut3_owner..ut_have_count to &ut3_user; -grant execute on &&ut3_owner..ut_match to &ut3_user; -grant execute on &&ut3_owner..ut to &ut3_user; -grant execute on &&ut3_owner..ut_runner to &ut3_user; -grant execute on &&ut3_owner..ut_teamcity_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_xunit_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_junit_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_tfs_junit_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_documentation_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_html_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_sonar_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_coveralls_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_cobertura_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_reporters to &ut3_user; -grant execute on &&ut3_owner..ut_varchar2_list to &ut3_user; -grant execute on &&ut3_owner..ut_varchar2_rows to &ut3_user; -grant execute on &&ut3_owner..ut_integer_list to &ut3_user; -grant execute on &&ut3_owner..ut_reporter_base to &ut3_user; -grant execute on &&ut3_owner..ut_output_reporter_base to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_reporter_base to &ut3_user; -grant execute on &&ut3_owner..ut_console_reporter_base to &ut3_user; -grant execute on &&ut3_owner..ut_coverage to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_options to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_helper to &ut3_user; -grant execute on &&ut3_owner..ut_output_buffer_base to &ut3_user; -grant execute on &&ut3_owner..ut_output_table_buffer to &ut3_user; -grant execute on &&ut3_owner..ut_file_mappings to &ut3_user; -grant execute on &&ut3_owner..ut_file_mapping to &ut3_user; -grant execute on &&ut3_owner..ut_file_mapper to &ut3_user; -grant execute on &&ut3_owner..ut_key_value_pairs to &ut3_user; -grant execute on &&ut3_owner..ut_key_value_pair to &ut3_user; -grant select, insert, delete on &&ut3_owner..ut_compound_data_tmp to &ut3_user; -grant select, insert, delete on &&ut3_owner..ut_compound_data_diff_tmp to &ut3_user; -grant execute on &&ut3_owner..ut_sonar_test_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_annotations to &ut3_user; -grant execute on &&ut3_owner..ut_annotation to &ut3_user; -grant execute on &&ut3_owner..ut_annotation_manager to &ut3_user; -grant execute on &&ut3_owner..ut_annotated_object to &ut3_user; -grant execute on &&ut3_owner..ut_annotated_objects to &ut3_user; -grant select on &&ut3_owner..ut_annotation_cache_info to &ut3_user; -grant select on &&ut3_owner..ut_annotation_cache to &ut3_user; -grant execute on &&ut3_owner..ut_annotation_cache_manager to &ut3_user; -grant execute on &&ut3_owner..ut_annotation_parser to &ut3_user; -grant execute on &&ut3_owner..ut_annotation_objs_cache_info to &ut3_user; -grant execute on &&ut3_owner..ut_annotation_obj_cache_info to &ut3_user; -begin - $if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then - execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_blocks to &ut3_user'; - execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_runs to &ut3_user'; - execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_units to &ut3_user'; - $else - null; - $end -end; -/ - - prompt Creating synonyms for UTPLSQL objects in &&ut3_owner schema to user &&ut3_user +create or replace synonym &ut3_user..ut_expectation for &&ut3_owner..ut_expectation; +create or replace synonym &ut3_user..ut_expectation_compound for &&ut3_owner..ut_expectation_compound; create or replace synonym &ut3_user..be_between for &&ut3_owner..be_between; create or replace synonym &ut3_user..be_empty for &&ut3_owner..be_empty; create or replace synonym &ut3_user..be_false for &&ut3_owner..be_false; @@ -164,7 +97,6 @@ create or replace synonym &ut3_user..ut_file_mapper for &&ut3_owner..ut_file_map create or replace synonym &ut3_user..ut_key_value_pairs for &&ut3_owner..ut_key_value_pairs; create or replace synonym &ut3_user..ut_key_value_pair for &&ut3_owner..ut_key_value_pair; create or replace synonym &ut3_user..ut_compound_data_tmp for &&ut3_owner..ut_cursor_data; -create or replace synonym &ut3_user..ut_compound_data_diff_tmp for &&ut3_owner..ut_compound_data_diff_tmp; create or replace synonym &ut3_user..ut_sonar_test_reporter for &&ut3_owner..ut_sonar_test_reporter; begin $if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then diff --git a/source/expectations/data_values/ut_compound_data_diff_tmp.sql b/source/expectations/data_values/ut_compound_data_diff_tmp.sql index 881cc8082..27f95907b 100644 --- a/source/expectations/data_values/ut_compound_data_diff_tmp.sql +++ b/source/expectations/data_values/ut_compound_data_diff_tmp.sql @@ -14,5 +14,13 @@ create global temporary table ut_compound_data_diff_tmp( */ diff_id raw(128), item_no integer, - constraint ut_compound_data_diff_tmp_pk primary key(diff_id,item_no) + pk_hash raw(128), + item_hash raw(128), + duplicate_no integer, + constraint ut_compound_data_diff_tmp_uk1 unique (diff_id,duplicate_no,item_no,item_hash, pk_hash), + constraint ut_compound_data_diff_tmp_chk check( + item_no is not null and pk_hash is null and duplicate_no is null + or item_no is null and item_hash is not null and duplicate_no is not null + or item_no is null and pk_hash is not null and duplicate_no is not null + ) ) on commit preserve rows; diff --git a/source/expectations/data_values/ut_compound_data_helper.pkb b/source/expectations/data_values/ut_compound_data_helper.pkb index a69741aa8..bde359738 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pkb +++ b/source/expectations/data_values/ut_compound_data_helper.pkb @@ -16,55 +16,25 @@ create or replace package body ut_compound_data_helper is limitations under the License. */ - type t_type_name_map is table of varchar2(100) index by binary_integer; - g_type_name_map t_type_name_map; - - function get_column_type(a_desc_rec dbms_sql.desc_rec3) return varchar2 is - l_result varchar2(500) := 'unknown datatype'; - begin - if g_type_name_map.exists(a_desc_rec.col_type) then - l_result := g_type_name_map(a_desc_rec.col_type); - elsif a_desc_rec.col_schema_name is not null and a_desc_rec.col_type_name is not null then - l_result := a_desc_rec.col_schema_name||'.'||a_desc_rec.col_type_name; - end if; - return l_result; - end; - - function get_columns_info(a_columns_tab dbms_sql.desc_tab3, a_columns_count integer) return ut_key_value_pairs is - l_result ut_key_value_pairs := ut_key_value_pairs(); - begin - for i in 1 .. a_columns_count loop - l_result.extend; - l_result(l_result.last) := ut_key_value_pair(a_columns_tab(i).col_name, get_column_type(a_columns_tab(i))); - end loop; - return l_result; - end; - - function get_columns_info(a_cursor in out nocopy sys_refcursor) return xmltype is - l_cursor_number integer; - l_columns_count pls_integer; - l_columns_desc dbms_sql.desc_tab3; - l_result xmltype; - l_columns_tab ut_key_value_pairs; - begin - if a_cursor is null or not a_cursor%isopen then - return null; - end if; - l_cursor_number := dbms_sql.to_cursor_number( a_cursor ); - dbms_sql.describe_columns3( l_cursor_number, l_columns_count, l_columns_desc ); - a_cursor := dbms_sql.to_refcursor( l_cursor_number ); - l_columns_tab := get_columns_info( l_columns_desc, l_columns_count); - - select - XMLELEMENT("ROW", xmlagg(xmlelement(evalname ut_utils.xmlgen_escaped_string(key), - XMLATTRIBUTES(key AS "xml_valid_name"), - value))) - into l_result - from table(l_columns_tab ); - - return l_result; - end; - + g_user_defined_type pls_integer := dbms_sql.user_defined_type; + + function get_column_info_xml(a_column_details ut_key_anyval_pair) return xmltype is + l_result varchar2(4000); + l_res xmltype; + l_data ut_data_value := a_column_details.value; + l_key varchar2(4000) := ut_utils.xmlgen_escaped_string(a_column_details.KEY); + begin + l_result := '<'||l_key||' xml_valid_name="'||l_key||'">'; + if l_data is of(ut_data_value_xmltype) then + l_result := l_result || (treat(l_data as ut_data_value_xmltype).to_string); + else + l_result := l_result || ut_utils.xmlgen_escaped_string((treat(l_data as ut_data_value_varchar2).data_value)); + end if; + + l_result := l_result ||''; + return xmltype(l_result); + end; + function get_columns_filter( a_exclude_xpath varchar2, a_include_xpath varchar2, a_table_alias varchar2 := 'ucd', a_column_alias varchar2 := 'item_data' @@ -86,6 +56,32 @@ create or replace package body ut_compound_data_helper is end if; return l_filter; end; + + /** + * Current get column filter shaving off ROW tag during extract, this not working well with include and XMLTABLE option + * so when there is extract we artificially inject removed tag + **/ + function get_columns_row_filter( + a_exclude_xpath varchar2, a_include_xpath varchar2, + a_table_alias varchar2 := 'ucd', a_column_alias varchar2 := 'item_data' + ) return varchar2 is + l_filter varchar2(32767); + l_source_column varchar2(500) := a_table_alias||'.'||a_column_alias; + begin + -- this SQL statement is constructed in a way that we always get the same number and ordering of substitution variables + -- That is, we always get: l_exclude_xpath, l_include_xpath + -- regardless if the variables are NULL (not to be used) or NOT NULL and will be used for filtering + if a_exclude_xpath is null and a_include_xpath is null then + l_filter := ':l_exclude_xpath, :l_include_xpath, '||l_source_column||' as '||a_column_alias; + elsif a_exclude_xpath is not null and a_include_xpath is null then + l_filter := 'deletexml( '||l_source_column||', :l_exclude_xpath ) as '||a_column_alias||', :l_include_xpath'; + elsif a_exclude_xpath is null and a_include_xpath is not null then + l_filter := ':l_exclude_xpath, xmlelement("ROW",extract( '||l_source_column||', :l_include_xpath )) as '||a_column_alias; + elsif a_exclude_xpath is not null and a_include_xpath is not null then + l_filter := 'xmlelement("ROW",extract( deletexml( '||l_source_column||', :l_exclude_xpath ), :l_include_xpath )) as '||a_column_alias; + end if; + return l_filter; + end; function get_columns_diff( a_expected xmltype, a_actual xmltype, a_exclude_xpath varchar2, a_include_xpath varchar2 @@ -94,7 +90,7 @@ create or replace package body ut_compound_data_helper is l_sql varchar2(32767); l_results tt_column_diffs; begin - l_column_filter := get_columns_filter(a_exclude_xpath, a_include_xpath); + l_column_filter := get_columns_row_filter(a_exclude_xpath, a_include_xpath); l_sql := q'[ with expected_cols as ( select :a_expected as item_data from dual ), @@ -157,6 +153,133 @@ create or replace package body ut_compound_data_helper is execute immediate l_sql bulk collect into l_results using a_expected, a_actual, a_exclude_xpath, a_include_xpath, a_exclude_xpath, a_include_xpath; + + return l_results; + end; + + function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return clob is + l_pk_value clob; + begin + select replace((extract(a_item_data,a_join_by_xpath).getclobval()),chr(10)) into l_pk_value from dual; + return l_pk_value; + end; + + function get_rows_diff( + a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw, + a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2, + a_join_by_xpath varchar2 + ) return tt_row_diffs is + l_column_filter varchar2(32767); + l_results tt_row_diffs; + begin + l_column_filter := get_columns_row_filter(a_exclude_xpath,a_include_xpath); + + /** + * Since its unordered search we cannot select max rows from diffs as we miss some comparision records + * We will restrict output on higher level of select + * NO_MERGE hint was introduced to prevent optimizer from merging views and rewriting query which in some cases + * lead to second value being null depend on execution plan that been chosen + **/ + execute immediate q'[ + with diff_info as (select item_hash,pk_hash,duplicate_no from ut_compound_data_diff_tmp ucdc where diff_id = :diff_guid) + select rn,diff_type,diffed_row,pk_value from + ( + select + diff_type, diffed_row, + dense_rank() over (order by case when diff_type in ('Extra','Missing') then diff_type end, + case when diff_type in ('Actual','Expected') then pk_hash end, + case when diff_type in ('Extra','Missing') then pk_hash end, + case when diff_type in ('Actual','Expected') then diff_type end) rn, + pk_value, pk_hash + from + ( + select diff_type,diffed_row,pk_hash,pk_value from + (select diff_type,data_item diffed_row,pk_hash,pk_value + from + (select /*+NO_MERGE*/ nvl(exp.pk_hash, act.pk_hash) pk_hash,nvl(exp.pk_value, act.pk_value) pk_value, + xmlserialize(content exp.row_data no indent) exp_item, + xmlserialize(content act.row_data no indent) act_item + from + (select ucd.* + from + (select ucd.column_value row_data, + r.item_hash row_hash, + r.pk_hash , + r.duplicate_no, + ucd.column_value.getclobval() col_val, + ucd.column_value.getRootElement() col_name, + ut_compound_data_helper.get_pk_value(:join_xpath,r.item_data) pk_value + from + (select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_hash, i.pk_hash, i.duplicate_no + from ut_compound_data_tmp ucd, + diff_info i + where ucd.data_id = :self_guid + and ucd.item_hash = i.item_hash + ) r, + table( xmlsequence( extract(r.item_data,'/*/*') ) ) ucd + ) ucd + ) exp + join ( + select ucd.* + from + (select ucd.column_value row_data, + r.item_hash row_hash, + r.pk_hash , + r.duplicate_no, + ucd.column_value.getclobval() col_val, + ucd.column_value.getRootElement() col_name, + ut_compound_data_helper.get_pk_value(:join_xpath,r.item_data) pk_value + from + (select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_hash, i.pk_hash, i.duplicate_no + from ut_compound_data_tmp ucd, + diff_info i + where ucd.data_id = :other_guid + and ucd.item_hash = i.item_hash + ) r, + table( xmlsequence( extract(r.item_data,'/*/*') ) ) ucd + ) ucd + ) act + on exp.pk_hash = act.pk_hash and exp.col_name = act.col_name + and exp.duplicate_no = act.duplicate_no + where dbms_lob.compare(exp.col_val, act.col_val) != 0 + ) + unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:') ) + ) + union all + select case when exp.pk_hash is null then 'Extra' else 'Missing' end as diff_type, + xmlserialize(content nvl(exp.item_data, act.item_data) no indent) diffed_row, + coalesce(exp.pk_hash,act.pk_hash) pk_hash, + coalesce(exp.pk_value,act.pk_value) pk_value + from (select extract(deletexml(ucd.item_data, :join_by),'/*/*') item_data,i.pk_hash, + ut_compound_data_helper.get_pk_value(:join_by,item_data) pk_value + from ut_compound_data_tmp ucd, + diff_info i + where ucd.data_id = :self_guid + and ucd.item_hash = i.item_hash + ) exp + full outer join ( + select extract(deletexml(ucd.item_data, :join_by),'/*/*') item_data,i.pk_hash, + ut_compound_data_helper.get_pk_value(:join_by,item_data) pk_value + from ut_compound_data_tmp ucd, + diff_info i + where ucd.data_id = :other_guid + and ucd.item_hash = i.item_hash + )act + on exp.pk_hash = act.pk_hash + where exp.pk_hash is null or act.pk_hash is null + ) + ) where rn <= :max_rows + order by rn, pk_hash, diff_type + ]' + bulk collect into l_results + using a_diff_id, + a_join_by_xpath, + a_exclude_xpath, a_include_xpath, a_expected_dataset_guid, + a_join_by_xpath, + a_exclude_xpath, a_include_xpath, a_actual_dataset_guid, + a_join_by_xpath,a_join_by_xpath,a_expected_dataset_guid,a_join_by_xpath,a_join_by_xpath, a_actual_dataset_guid, + a_max_rows; + return l_results; end; @@ -170,9 +293,12 @@ create or replace package body ut_compound_data_helper is l_column_filter := get_columns_filter(a_exclude_xpath,a_include_xpath); execute immediate q'[ with - diff_info as (select item_no from ut_compound_data_diff_tmp ucdc where diff_id = :diff_guid and rownum <= :max_rows) + diff_info as ( select item_no + from + (select item_no from ut_compound_data_diff_tmp ucdc where diff_id = :diff_guid order by item_no asc) + where rownum <= :max_rows) select * - from (select rn, diff_type, xmlserialize(content data_item no indent) diffed_row + from (select rn, diff_type, xmlserialize(content data_item no indent) diffed_row, null pk_value from (select nvl(exp.rn, act.rn) rn, xmlagg(exp.col order by exp.col_no) exp_item, xmlagg(act.col order by act.col_no) act_item @@ -180,9 +306,10 @@ create or replace package body ut_compound_data_helper is s.column_value.getRootElement() col_name, s.column_value.getclobval() col_val from (select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_data item_data_no_filter - from ut_compound_data_tmp ucd + from ut_compound_data_tmp ucd, + diff_info i where ucd.data_id = :self_guid - and ucd.item_no in (select i.item_no from diff_info i) + and ucd.item_no = i.item_no ) r, table( xmlsequence( extract(r.item_data,'/*/*') ) ) s ) exp @@ -191,9 +318,10 @@ create or replace package body ut_compound_data_helper is s.column_value.getRootElement() col_name, s.column_value.getclobval() col_val from (select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_data item_data_no_filter - from ut_compound_data_tmp ucd + from ut_compound_data_tmp ucd, + diff_info i where ucd.data_id = :other_guid - and ucd.item_no in (select i.item_no from diff_info i) + and ucd.item_no = i.item_no ) r, table( xmlsequence( extract(r.item_data,'/*/*') ) ) s ) act @@ -206,7 +334,8 @@ create or replace package body ut_compound_data_helper is union all select nvl(exp.item_no, act.item_no) rn, case when exp.item_no is null then 'Extra:' else 'Missing:' end as diff_type, - xmlserialize(content nvl(exp.item_data, act.item_data) no indent) diffed_row + xmlserialize(content nvl(exp.item_data, act.item_data) no indent) diffed_row, + null pk_value from (select ucd.item_no, extract(ucd.item_data,'/*/*') item_data from ut_compound_data_tmp ucd where ucd.data_id = :self_guid @@ -217,12 +346,10 @@ create or replace package body ut_compound_data_helper is from ut_compound_data_tmp ucd where ucd.data_id = :other_guid and ucd.item_no in (select i.item_no from diff_info i) - )act on exp.item_no = act.item_no where exp.item_no is null or act.item_no is null - order by 1, 2 -]' + order by 1, 2]' bulk collect into l_results using a_diff_id, a_max_rows, a_exclude_xpath, a_include_xpath, a_expected_dataset_guid, @@ -231,6 +358,116 @@ create or replace package body ut_compound_data_helper is return l_results; end; + function get_rows_diff_unordered( + a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw, + a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2 + ) return tt_row_diffs is + l_column_filter varchar2(32767); + l_results tt_row_diffs; + begin + l_column_filter := get_columns_filter(a_exclude_xpath,a_include_xpath); + + /** + * Since its unordered search we cannot select max rows from diffs as we miss some comparision records + * We will restrict output on higher level of select + */ + + execute immediate q'[with + diff_info as (select item_hash,duplicate_no from ut_compound_data_diff_tmp ucdc where diff_id = :diff_guid) + select duplicate_no, + diffed_type, + diffed_row, + null pk_value + from + (select + coalesce(exp.duplicate_no,act.duplicate_no) duplicate_no, + case + when act.row_hash is null then + 'Missing:' + else 'Extra:' + end diffed_type, + case when exp.row_hash is null then + xmlserialize(content act.row_data no indent) + when act.row_hash is null then + xmlserialize(content exp.row_data no indent) + end diffed_row + from (select ucd.* + from (select ucd.column_value row_data, + r.item_hash row_hash, + r.duplicate_no + from (select ]'||l_column_filter||q'[, ucd.item_no, i.item_hash, i.duplicate_no + from ut_compound_data_tmp ucd, + diff_info i + where ucd.data_id = :self_guid + and ucd.item_hash = i.item_hash + ) r, + table( xmlsequence( extract(r.item_data,'/*') ) ) ucd + ) ucd + ) exp + full outer join + (select ucd.* + from (select ucd.column_value row_data, + r.item_hash row_hash, + r.duplicate_no + from (select ]'||l_column_filter||q'[, ucd.item_no, i.item_hash, i.duplicate_no + from ut_compound_data_tmp ucd, + diff_info i + where ucd.data_id = :other_guid + and ucd.item_hash = i.item_hash + ) r, + table( xmlsequence( extract(r.item_data,'/*') ) ) ucd + ) ucd + ) act + on exp.row_hash = act.row_hash + and exp.duplicate_no = act.duplicate_no + where exp.row_hash is null or act.row_hash is null + order by diffed_type, coalesce(exp.row_hash,act.row_hash), duplicate_no + ) + where rownum < :max_rows ]' + bulk collect into l_results + using a_diff_id, + a_exclude_xpath, a_include_xpath, a_expected_dataset_guid, + a_exclude_xpath, a_include_xpath, a_actual_dataset_guid, + a_max_rows; + + return l_results; + + end; + + function compare_type(a_join_by_xpath in varchar2,a_unordered boolean) return varchar2 is + begin + case + when a_join_by_xpath is not null then + return gc_compare_join_by; + when a_unordered then + return gc_compare_unordered; + else + return gc_compare_normal; + end case; + end; + + function get_rows_diff( + a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw, + a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2, + a_join_by_xpath varchar2,a_unorderdered boolean + ) return tt_row_diffs is + l_results tt_row_diffs; + l_compare_type varchar2(10):= compare_type(a_join_by_xpath,a_unorderdered); + begin + case + when l_compare_type = gc_compare_join_by then + return get_rows_diff(a_expected_dataset_guid, a_actual_dataset_guid, a_diff_id, + a_max_rows, a_exclude_xpath, a_include_xpath ,a_join_by_xpath); + when l_compare_type = gc_compare_unordered then + return get_rows_diff_unordered(a_expected_dataset_guid, a_actual_dataset_guid, a_diff_id, + a_max_rows, a_exclude_xpath, a_include_xpath); + else + return get_rows_diff(a_expected_dataset_guid, a_actual_dataset_guid, a_diff_id, + a_max_rows, a_exclude_xpath, a_include_xpath); + end case; + + end; + function get_hash(a_data raw, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash is begin return dbms_crypto.hash(a_data, a_hash_type); @@ -258,26 +495,47 @@ create or replace package body ut_compound_data_helper is return l_cols_hash; end; -begin - g_type_name_map( dbms_sql.binary_bouble_type ) := 'BINARY_DOUBLE'; - g_type_name_map( dbms_sql.bfile_type ) := 'BFILE'; - g_type_name_map( dbms_sql.binary_float_type ) := 'BINARY_FLOAT'; - g_type_name_map( dbms_sql.blob_type ) := 'BLOB'; - g_type_name_map( dbms_sql.long_raw_type ) := 'LONG RAW'; - g_type_name_map( dbms_sql.char_type ) := 'CHAR'; - g_type_name_map( dbms_sql.clob_type ) := 'CLOB'; - g_type_name_map( dbms_sql.long_type ) := 'LONG'; - g_type_name_map( dbms_sql.date_type ) := 'DATE'; - g_type_name_map( dbms_sql.interval_day_to_second_type ) := 'INTERVAL DAY TO SECOND'; - g_type_name_map( dbms_sql.interval_year_to_month_type ) := 'INTERVAL YEAR TO MONTH'; - g_type_name_map( dbms_sql.raw_type ) := 'RAW'; - g_type_name_map( dbms_sql.timestamp_type ) := 'TIMESTAMP'; - g_type_name_map( dbms_sql.timestamp_with_tz_type ) := 'TIMESTAMP WITH TIME ZONE'; - g_type_name_map( dbms_sql.timestamp_with_local_tz_type ) := 'TIMESTAMP WITH LOCAL TIME ZONE'; - g_type_name_map( dbms_sql.varchar2_type ) := 'VARCHAR2'; - g_type_name_map( dbms_sql.number_type ) := 'NUMBER'; - g_type_name_map( dbms_sql.rowid_type ) := 'ROWID'; - g_type_name_map( dbms_sql.urowid_type ) := 'UROWID'; - + function is_pk_exists(a_expected_cursor xmltype,a_actual_cursor xmltype, a_exclude_xpath varchar2, a_include_xpath varchar2,a_join_by_xpath varchar2) + return tt_missing_pk is + l_pk_xpath_tabs ut_varchar2_list := ut_varchar2_list(); + l_column_filter varchar2(32767); + l_no_missing_keys tt_missing_pk := tt_missing_pk(); + + begin + if a_join_by_xpath is not null then + l_pk_xpath_tabs := ut_utils.string_to_table(a_join_by_xpath,'|'); + l_column_filter := get_columns_row_filter(a_exclude_xpath, a_include_xpath); + + execute immediate q'[ + with xpaths_tab as (select column_value xpath from table(:xpath_tabs)), + expected_column_info as ( select :expected as item_data from dual ), + actual_column_info as ( select :actual as item_data from dual ) + select REGEXP_SUBSTR (xpath,'[^(/\*/)](.+)$'),diif_type from + ( + (select xpath,'e' diif_type from xpaths_tab + minus + select xpath,'e' diif_type + from ( select ]'||l_column_filter||q'[ from expected_column_info ucd) x + ,xpaths_tab + where xmlexists (xpaths_tab.xpath passing x.item_data) + ) + union all + (select xpath,'a' diif_type from xpaths_tab + minus + select xpath,'a' diif_type + from ( select ]'||l_column_filter||q'[ from actual_column_info ucd) x + ,xpaths_tab + where xmlexists (xpaths_tab.xpath passing x.item_data) + ) + )]' bulk collect into l_no_missing_keys + using l_pk_xpath_tabs,a_expected_cursor,a_actual_cursor, + a_exclude_xpath, a_include_xpath, + a_exclude_xpath, a_include_xpath; + + end if; + + return l_no_missing_keys; + end; + end; -/ \ No newline at end of file +/ diff --git a/source/expectations/data_values/ut_compound_data_helper.pks b/source/expectations/data_values/ut_compound_data_helper.pks index d49db160c..da2863667 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pks +++ b/source/expectations/data_values/ut_compound_data_helper.pks @@ -16,6 +16,10 @@ create or replace package ut_compound_data_helper authid definer is limitations under the License. */ + gc_compare_join_by constant varchar2(10):='join_by'; + gc_compare_unordered constant varchar2(10):='unordered'; + gc_compare_normal constant varchar2(10):='normal'; + type t_column_diffs is record( diff_type varchar2(1), expected_name varchar2(250), @@ -28,15 +32,23 @@ create or replace package ut_compound_data_helper authid definer is type tt_column_diffs is table of t_column_diffs; + type t_missing_pk is record( + missingxpath varchar2(250), + diff_type varchar2(1) + ); + + type tt_missing_pk is table of t_missing_pk; + type t_row_diffs is record( rn integer, diff_type varchar2(250), - diffed_row clob + diffed_row clob, + pk_value varchar2(4000) ); type tt_row_diffs is table of t_row_diffs; - function get_columns_info(a_cursor in out nocopy sys_refcursor) return xmltype; + function get_column_info_xml(a_column_details ut_key_anyval_pair) return xmltype; function get_columns_filter( a_exclude_xpath varchar2, a_include_xpath varchar2, @@ -47,9 +59,14 @@ create or replace package ut_compound_data_helper authid definer is a_expected xmltype, a_actual xmltype, a_exclude_xpath varchar2, a_include_xpath varchar2 ) return tt_column_diffs; - function get_rows_diff( + function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return clob; + + function compare_type(a_join_by_xpath in varchar2,a_unordered boolean) return varchar2; + + function get_rows_diff( a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw, - a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2 + a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2, + a_join_by_xpath varchar2,a_unorderdered boolean ) return tt_row_diffs; subtype t_hash is raw(128); @@ -60,6 +77,9 @@ create or replace package ut_compound_data_helper authid definer is a_data_value_cursor ut_data_value_refcursor, a_exclude_xpath varchar2, a_include_xpath varchar2, a_hash_type binary_integer := dbms_crypto.hash_sh1 ) return t_hash; + + function is_pk_exists(a_expected_cursor xmltype, a_actual_cursor xmltype, a_exclude_xpath varchar2, a_include_xpath varchar2,a_join_by_xpath varchar2) + return tt_missing_pk; end; / diff --git a/source/expectations/data_values/ut_compound_data_tmp.sql b/source/expectations/data_values/ut_compound_data_tmp.sql index 300b0fd38..827ab9066 100644 --- a/source/expectations/data_values/ut_compound_data_tmp.sql +++ b/source/expectations/data_values/ut_compound_data_tmp.sql @@ -15,5 +15,8 @@ create global temporary table ut_compound_data_tmp( data_id raw(32), item_no integer, item_data xmltype, - constraint ut_compound_data_tmp_pk primary key(data_id, item_no) + item_hash raw(128), + pk_hash raw(128), + duplicate_no integer, + constraint ut_cmp_data_tmp_hash_pk unique (data_id,item_no, item_hash , duplicate_no) ) on commit preserve rows; diff --git a/source/expectations/data_values/ut_compound_data_value.tpb b/source/expectations/data_values/ut_compound_data_value.tpb index b7c43d2d8..2d7f5ff65 100644 --- a/source/expectations/data_values/ut_compound_data_value.tpb +++ b/source/expectations/data_values/ut_compound_data_value.tpb @@ -31,14 +31,9 @@ create or replace type body ut_compound_data_value as return true; end; - member function is_empty return boolean is - begin - return self.elements_count = 0; - end; - overriding member function is_multi_line return boolean is begin - return not self.is_null() and not self.is_empty(); + return not self.is_null(); end; overriding member function compare_implementation(a_other ut_data_value) return integer is @@ -71,17 +66,18 @@ create or replace type body ut_compound_data_value as return l_result_string; end; - overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2 ) return varchar2 is + overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean := false ) return varchar2 is l_result clob; - l_result_string varchar2(32767); + l_result_string varchar2(32767); begin - l_result := get_data_diff(a_other, a_exclude_xpath, a_include_xpath); + l_result := get_data_diff(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath,a_unordered); l_result_string := ut_utils.to_string(l_result,null); dbms_lob.freetemporary(l_result); return l_result_string; end; - - member function get_data_diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2 ) return clob is + + member function get_data_diff(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, + a_join_by_xpath varchar2, a_unordered boolean) return clob is c_max_rows constant integer := 20; l_result clob; l_results ut_utils.t_clob_tab := ut_utils.t_clob_tab(); @@ -91,6 +87,19 @@ create or replace type body ut_compound_data_value as l_actual ut_compound_data_value; l_diff_id ut_compound_data_helper.t_hash; l_row_diffs ut_compound_data_helper.tt_row_diffs; + l_compare_type varchar2(10); + + function get_diff_message (a_row_diff ut_compound_data_helper.t_row_diffs,a_compare_type varchar2) return varchar2 is + begin + if a_compare_type = ut_compound_data_helper.gc_compare_join_by and a_row_diff.pk_value is not null then + return ' PK '||a_row_diff.pk_value||' - '||rpad(a_row_diff.diff_type,10)||a_row_diff.diffed_row; + elsif a_compare_type = ut_compound_data_helper.gc_compare_join_by or a_compare_type = ut_compound_data_helper.gc_compare_normal then + return ' Row No. '||a_row_diff.rn||' - '||rpad(a_row_diff.diff_type,10)||a_row_diff.diffed_row; + elsif a_compare_type = ut_compound_data_helper.gc_compare_unordered then + return rpad(a_row_diff.diff_type,10)||a_row_diff.diffed_row; + end if; + end; + begin if not a_other is of (ut_compound_data_value) then raise value_error; @@ -101,13 +110,16 @@ create or replace type body ut_compound_data_value as --diff rows and row elements l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_actual.data_id); + -- First tell how many rows are different - execute immediate 'select count(*) from ' || l_ut_owner || '.ut_compound_data_diff_tmp where diff_id = :diff_id' into l_diff_row_count using l_diff_id; + execute immediate 'select count('||case when a_join_by_xpath is not null then 'distinct pk_hash' else '*' end||') from ' + || l_ut_owner || '.ut_compound_data_diff_tmp + where diff_id = :diff_id' into l_diff_row_count using l_diff_id; if l_diff_row_count > 0 then + l_compare_type := ut_compound_data_helper.compare_type(a_join_by_xpath,a_unordered); l_row_diffs := ut_compound_data_helper.get_rows_diff( - self.data_id, l_actual.data_id, l_diff_id, c_max_rows, a_exclude_xpath, a_include_xpath - ); + self.data_id, l_actual.data_id, l_diff_id, c_max_rows, a_exclude_xpath, a_include_xpath, a_join_by_xpath, a_unordered); l_message := chr(10) ||'Rows: [ ' || l_diff_row_count ||' differences' || case when l_diff_row_count > c_max_rows and l_row_diffs.count > 0 then ', showing first '||c_max_rows end @@ -117,13 +129,14 @@ create or replace type body ut_compound_data_value as ut_utils.append_to_clob( l_result, l_message ); for i in 1 .. l_row_diffs.count loop l_results.extend; - l_results(l_results.last) := ' Row No. '||l_row_diffs(i).rn||' - '||rpad(l_row_diffs(i).diff_type,10)||l_row_diffs(i).diffed_row; + l_results(l_results.last) := get_diff_message(l_row_diffs(i),l_compare_type); end loop; ut_utils.append_to_clob(l_result,l_results); end if; return l_result; end; + member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer is l_other ut_compound_data_value; l_ut_owner varchar2(250) := ut_utils.ut_owner; @@ -132,6 +145,7 @@ create or replace type body ut_compound_data_value as l_result integer; --the XML stylesheet is applied on XML representation of data to exclude column names from comparison --column names and data-types are compared separately + --user CHR(38) instead of ampersand to eliminate define request when installing through some IDEs l_xml_data_fmt constant xmltype := xmltype( q'[ @@ -139,7 +153,7 @@ create or replace type body ut_compound_data_value as - + '||CHR(38)||'#xD; , @@ -171,7 +185,103 @@ create or replace type body ut_compound_data_value as ') != 0' using in l_diff_id, a_exclude_xpath, a_include_xpath, self.data_id, a_exclude_xpath, a_include_xpath, l_other.data_id, l_xml_data_fmt, l_xml_data_fmt; + --result is OK only if both are same + if sql%rowcount = 0 and self.elements_count = l_other.elements_count then + l_result := 0; + else + l_result := 1; + end if; + return l_result; + end; + member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean ) return integer is + l_other ut_compound_data_value; + l_ut_owner varchar2(250) := ut_utils.ut_owner; + l_column_filter varchar2(32767); + l_diff_id ut_compound_data_helper.t_hash; + l_result integer; + l_row_diffs ut_compound_data_helper.tt_row_diffs; + c_max_rows constant integer := 20; + + function get_column_pk_hash(a_join_by_xpath varchar2) return varchar2 is + l_column varchar2(32767); + begin + /* due to possibility of key being to columns we cannot use xmlextractvalue + usage of xmlagg is possible however it greatly complicates code and performance is impacted. + xpath to be looked at or regex + */ + if a_join_by_xpath is not null then + l_column := l_ut_owner ||'.ut_compound_data_helper.get_hash(extract(ucd.item_data,:join_by_xpath).GetClobVal()) pk_hash'; + else + l_column := ':join_by_xpath pk_hash'; + end if; + return l_column; + end; + + begin + if not a_other is of (ut_compound_data_value) then + raise value_error; + end if; + + l_other := treat(a_other as ut_compound_data_value); + + l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_other.data_id); + l_column_filter := ut_compound_data_helper.get_columns_filter(a_exclude_xpath, a_include_xpath); + + /** + * Due to incompatibility issues in XML between 11 and 12.2 and 12.1 versions we will prepopulate pk_hash upfront to + * avoid optimizer incorrectly rewrite and causing NULL error or ORA-600 + **/ + execute immediate 'merge into ' || l_ut_owner || '.ut_compound_data_tmp tgt + using ( + select '||l_ut_owner ||'.ut_compound_data_helper.get_hash(ucd.item_data.getclobval()) item_hash, + pk_hash, ucd.item_no, ucd.data_id + from + ( + select '||l_column_filter||','||get_column_pk_hash(a_join_by_xpath)||', item_no, data_id + from ' || l_ut_owner || q'[.ut_compound_data_tmp ucd + where data_id = :self_guid or data_id = :other_guid + ) ucd + ) src + on (tgt.item_no = src.item_no and tgt.data_id = src.data_id) + when matched then update + set tgt.item_hash = src.item_hash, + tgt.pk_hash = src.pk_hash ]' + using a_exclude_xpath, a_include_xpath,a_join_by_xpath,self.data_id, l_other.data_id; + + /* Peform minus on two sets two get diffrences that will be used later on to print results */ + execute immediate 'insert into ' || l_ut_owner || '.ut_compound_data_diff_tmp ( diff_id,item_hash,pk_hash,duplicate_no) + with source_data as + ( select t.data_id,t.item_hash,row_number() over (partition by t.pk_hash,t.item_hash,t.data_id order by 1,2) duplicate_no, + pk_hash + from ' || l_ut_owner || '.ut_compound_data_tmp t + where data_id = :self_guid or data_id = :other_guid + ) + select distinct :diff_id,tmp.item_hash,tmp.pk_hash,tmp.duplicate_no + from( + ( + select t.item_hash,t. duplicate_no,t.pk_hash + from source_data t + where t.data_id = :self_guid + minus + select t.item_hash,t. duplicate_no,t.pk_hash + from source_data t + where t.data_id = :other_guid + ) + union all + ( + select t.item_hash,t. duplicate_no,t.pk_hash + from source_data t + where t.data_id = :other_guid + minus + select t.item_hash,t. duplicate_no,t.pk_hash + from source_data t + where t.data_id = :self_guid + ))tmp' + using self.data_id, l_other.data_id, + l_diff_id, + self.data_id, l_other.data_id, + l_other.data_id,self.data_id; --result is OK only if both are same if sql%rowcount = 0 and self.elements_count = l_other.elements_count then l_result := 0; diff --git a/source/expectations/data_values/ut_compound_data_value.tps b/source/expectations/data_values/ut_compound_data_value.tps index e06848a1e..f95fa478c 100644 --- a/source/expectations/data_values/ut_compound_data_value.tps +++ b/source/expectations/data_values/ut_compound_data_value.tps @@ -1,4 +1,4 @@ -create or replace type ut_compound_data_value under ut_data_value( +create or replace type ut_compound_data_value force under ut_data_value( /* utPLSQL - Version 3 Copyright 2016 - 2017 utPLSQL Project @@ -38,12 +38,12 @@ create or replace type ut_compound_data_value under ut_data_value( overriding member function get_object_info return varchar2, overriding member function is_null return boolean, overriding member function is_diffable return boolean, - member function is_empty return boolean, overriding member function to_string return varchar2, overriding member function is_multi_line return boolean, overriding member function compare_implementation(a_other ut_data_value) return integer, - overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2 ) return varchar2, - member function get_data_diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2 ) return clob, - member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer + overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean := false ) return varchar2, + member function get_data_diff(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean) return clob, + member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer, + member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean ) return integer ) not final not instantiable / diff --git a/source/expectations/data_values/ut_curr_usr_compound_helper.pkb b/source/expectations/data_values/ut_curr_usr_compound_helper.pkb new file mode 100644 index 000000000..b610ee13c --- /dev/null +++ b/source/expectations/data_values/ut_curr_usr_compound_helper.pkb @@ -0,0 +1,244 @@ +create or replace package body ut_curr_usr_compound_helper is + + type t_type_name_map is table of varchar2(100) index by binary_integer; + g_type_name_map t_type_name_map; + g_anytype_name_map t_type_name_map; + g_anytype_collection_name t_type_name_map; + g_user_defined_type pls_integer := dbms_sql.user_defined_type; + g_is_collection boolean := false; + + procedure set_collection_state(a_is_collection boolean) is + begin + --Make sure that we set a g_is_collection only once so we dont reset from true to false. + if not g_is_collection then + g_is_collection := a_is_collection; + end if; + end; + + function get_column_type(a_desc_rec dbms_sql.desc_rec3, a_desc_user_types boolean := false) return ut_key_anyval_pair is + l_data ut_data_value; + l_result ut_key_anyval_pair; + l_data_type varchar2(500) := 'unknown datatype'; + + function is_collection (a_owner varchar2,a_type_name varchar2) return boolean is + l_type_view varchar2(200) := ut_metadata.get_dba_view('dba_types'); + l_typecode varchar2(100); + begin + execute immediate 'select typecode from '||l_type_view ||' + where owner = :owner and type_name = :typename' + into l_typecode using a_owner,a_type_name; + + return l_typecode = 'COLLECTION'; + end; + + begin + if g_type_name_map.exists(a_desc_rec.col_type) then + l_data := ut_data_value_varchar2(g_type_name_map(a_desc_rec.col_type)); + /*If its a collection regardless is we want to describe user defined types we will return just a name + and capture that name */ + elsif a_desc_rec.col_type = g_user_defined_type and is_collection(a_desc_rec.col_schema_name,a_desc_rec.col_type_name) then + l_data := ut_data_value_varchar2(a_desc_rec.col_schema_name||'.'||a_desc_rec.col_type_name); + set_collection_state(true); + elsif a_desc_rec.col_type = g_user_defined_type and a_desc_user_types then + l_data :=ut_data_value_xmltype(get_user_defined_type(a_desc_rec.col_schema_name,a_desc_rec.col_type_name)); + elsif a_desc_rec.col_schema_name is not null and a_desc_rec.col_type_name is not null then + l_data := ut_data_value_varchar2(a_desc_rec.col_schema_name||'.'||a_desc_rec.col_type_name); + end if; + return ut_key_anyval_pair(a_desc_rec.col_name,l_data); + end; + + function get_columns_info( + a_columns_tab dbms_sql.desc_tab3, a_columns_count integer, a_desc_user_types boolean := false + ) return ut_key_anyval_pairs is + l_result ut_key_anyval_pairs := ut_key_anyval_pairs(); + begin + for i in 1 .. a_columns_count loop + l_result.extend; + l_result(l_result.last) := get_column_type(a_columns_tab(i),a_desc_user_types); + end loop; + return l_result; + end; + + procedure get_descr_cursor( + a_cursor in out nocopy sys_refcursor, + a_columns_tab in out nocopy ut_key_anyval_pairs, + a_join_by_tab in out nocopy ut_key_anyval_pairs + ) is + l_cursor_number integer; + l_columns_count pls_integer; + l_columns_desc dbms_sql.desc_tab3; + begin + if a_cursor is null or not a_cursor%isopen then + a_columns_tab := null; + a_join_by_tab := null; + end if; + l_cursor_number := dbms_sql.to_cursor_number( a_cursor ); + dbms_sql.describe_columns3( l_cursor_number, l_columns_count, l_columns_desc ); + a_cursor := dbms_sql.to_refcursor( l_cursor_number ); + a_columns_tab := get_columns_info( l_columns_desc, l_columns_count, false); + a_join_by_tab := get_columns_info( l_columns_desc, l_columns_count, true); + end; + + procedure get_columns_info( + a_cursor in out nocopy sys_refcursor, + a_columns_info out nocopy xmltype, + a_join_by_info out nocopy xmltype, + a_contains_collection out nocopy number + ) is + l_columns_info xmltype; + l_join_by_info xmltype; + l_result_tmp xmltype; + l_columns_tab ut_key_anyval_pairs; + l_join_by_tab ut_key_anyval_pairs; + begin + + get_descr_cursor(a_cursor,l_columns_tab,l_join_by_tab); + + for i in 1..l_columns_tab.COUNT + loop + l_result_tmp := ut_compound_data_helper.get_column_info_xml(l_columns_tab(i)); + select xmlconcat(l_columns_info,l_result_tmp) into l_columns_info from dual; + end loop; + + for i in 1..l_join_by_tab.COUNT + loop + l_result_tmp := ut_compound_data_helper.get_column_info_xml(l_join_by_tab(i)); + select xmlconcat(l_join_by_info,l_result_tmp) into l_join_by_info from dual; + end loop; + + select XMLELEMENT("ROW",l_columns_info ),XMLELEMENT("ROW",l_join_by_info ) + into a_columns_info,a_join_by_info from dual; + + a_contains_collection := ut_utils.boolean_to_int(g_is_collection); + end; + + function get_anytype_attribute_count (a_anytype anytype) return pls_integer is + l_attribute_typecode pls_integer; + l_schema_name varchar2(32767); + l_version varchar2(32767); + l_type_name varchar2(32767); + l_attributes pls_integer; + l_prec pls_integer; + l_scale pls_integer; + l_len pls_integer; + l_csid pls_integer; + l_csfrm pls_integer; + begin + l_attribute_typecode := a_anytype.getinfo( + prec => l_prec, + scale => l_scale, + len => l_len, + csid => l_csid, + csfrm => l_csfrm, + schema_name => l_schema_name, + type_name => l_type_name, + version => l_version, + numelems => l_attributes); + return l_attributes; + end; + + function get_anytype_attributes_info (a_anytype anytype) return ut_key_value_pairs is + l_result ut_key_value_pairs := ut_key_value_pairs(); + l_attribute_typecode pls_integer; + l_aname varchar2(32767); + l_prec pls_integer; + l_scale pls_integer; + l_len pls_integer; + l_csid pls_integer; + l_csfrm pls_integer; + l_attr_elt_type anytype; + begin + for i in 1..get_anytype_attribute_count(a_anytype) loop + l_attribute_typecode := a_anytype.getAttrElemInfo( + pos => i, --First attribute + prec => l_prec, + scale => l_scale, + len => l_len, + csid => l_csid, + csfrm => l_csfrm, + attr_elt_type => l_attr_elt_type, + aname => l_aname); + + l_result.extend; + l_result(l_result.last) := ut_key_value_pair(l_aname, g_anytype_name_map(l_attribute_typecode)); + --check for collection + if g_anytype_collection_name.exists(l_attribute_typecode) then + set_collection_state(true); + end if; + end loop; + return l_result; + end; + + function get_user_defined_type(a_owner varchar2,a_type_name varchar2) return xmltype is + l_anydata anydata; + l_anytype anytype; + l_typecode pls_integer; + l_result xmltype; + l_columns_tab ut_key_value_pairs := ut_key_value_pairs(); + + begin + execute immediate 'declare + l_v '||a_owner||'.'||a_type_name||'; + begin + :anydata := anydata.convertobject(l_v); + end;' USING IN OUT l_anydata; + + l_typecode := l_anydata.gettype(l_anytype); + l_columns_tab := get_anytype_attributes_info(l_anytype); + + select xmlagg(xmlelement(evalname key,value)) + into l_result from table(l_columns_tab); + + return l_result; + + end; + + begin + g_anytype_name_map(dbms_types.typecode_date) :=' DATE'; + g_anytype_name_map(dbms_types.typecode_number) := 'NUMBER'; + g_anytype_name_map(dbms_types.typecode_raw) := 'RAW'; + g_anytype_name_map(dbms_types.typecode_char) := 'CHAR'; + g_anytype_name_map(dbms_types.typecode_varchar2) := 'VARCHAR2'; + g_anytype_name_map(dbms_types.typecode_varchar) := 'VARCHAR'; + g_anytype_name_map(dbms_types.typecode_blob) := 'BLOB'; + g_anytype_name_map(dbms_types.typecode_bfile) := 'BFILE'; + g_anytype_name_map(dbms_types.typecode_clob) := 'CLOB'; + g_anytype_name_map(dbms_types.typecode_timestamp) := 'TIMESTAMP'; + g_anytype_name_map(dbms_types.typecode_timestamp_tz) := 'TIMESTAMP WITH TIME ZONE'; + g_anytype_name_map(dbms_types.typecode_timestamp_ltz) := 'TIMESTAMP WITH LOCAL TIME ZONE'; + g_anytype_name_map(dbms_types.typecode_interval_ym) := 'INTERVAL YEAR TO MONTH'; + g_anytype_name_map(dbms_types.typecode_interval_ds) := 'INTERVAL DAY TO SECOND'; + g_anytype_name_map(dbms_types.typecode_bfloat) := 'BINARY_FLOAT'; + g_anytype_name_map(dbms_types.typecode_bdouble) := 'BINARY_DOUBLE'; + g_anytype_name_map(dbms_types.typecode_urowid) := 'UROWID'; + g_anytype_name_map(dbms_types.typecode_varray) := 'VARRRAY'; + g_anytype_name_map(dbms_types.typecode_table) := 'TABLE'; + g_anytype_name_map(dbms_types.typecode_namedcollection) := 'NAMEDCOLLECTION'; + + g_anytype_collection_name(dbms_types.typecode_varray) := 'VARRRAY'; + g_anytype_collection_name(dbms_types.typecode_table) := 'TABLE'; + g_anytype_collection_name(dbms_types.typecode_namedcollection) := 'NAMEDCOLLECTION'; + + + g_type_name_map( dbms_sql.binary_bouble_type ) := 'BINARY_DOUBLE'; + g_type_name_map( dbms_sql.bfile_type ) := 'BFILE'; + g_type_name_map( dbms_sql.binary_float_type ) := 'BINARY_FLOAT'; + g_type_name_map( dbms_sql.blob_type ) := 'BLOB'; + g_type_name_map( dbms_sql.long_raw_type ) := 'LONG RAW'; + g_type_name_map( dbms_sql.char_type ) := 'CHAR'; + g_type_name_map( dbms_sql.clob_type ) := 'CLOB'; + g_type_name_map( dbms_sql.long_type ) := 'LONG'; + g_type_name_map( dbms_sql.date_type ) := 'DATE'; + g_type_name_map( dbms_sql.interval_day_to_second_type ) := 'INTERVAL DAY TO SECOND'; + g_type_name_map( dbms_sql.interval_year_to_month_type ) := 'INTERVAL YEAR TO MONTH'; + g_type_name_map( dbms_sql.raw_type ) := 'RAW'; + g_type_name_map( dbms_sql.timestamp_type ) := 'TIMESTAMP'; + g_type_name_map( dbms_sql.timestamp_with_tz_type ) := 'TIMESTAMP WITH TIME ZONE'; + g_type_name_map( dbms_sql.timestamp_with_local_tz_type ) := 'TIMESTAMP WITH LOCAL TIME ZONE'; + g_type_name_map( dbms_sql.varchar2_type ) := 'VARCHAR2'; + g_type_name_map( dbms_sql.number_type ) := 'NUMBER'; + g_type_name_map( dbms_sql.rowid_type ) := 'ROWID'; + g_type_name_map( dbms_sql.urowid_type ) := 'UROWID'; + +end; +/ diff --git a/source/expectations/data_values/ut_curr_usr_compound_helper.pks b/source/expectations/data_values/ut_curr_usr_compound_helper.pks new file mode 100644 index 000000000..d662f51f9 --- /dev/null +++ b/source/expectations/data_values/ut_curr_usr_compound_helper.pks @@ -0,0 +1,13 @@ +create or replace package ut_curr_usr_compound_helper authid current_user is + + procedure get_columns_info( + a_cursor in out nocopy sys_refcursor, + a_columns_info out nocopy xmltype, + a_join_by_info out nocopy xmltype, + a_contains_collection out nocopy number + ); + + function get_user_defined_type(a_owner varchar2, a_type_name varchar2) return xmltype; + +end; +/ diff --git a/source/expectations/data_values/ut_data_value.tpb b/source/expectations/data_values/ut_data_value.tpb index 605f492f3..db7d29763 100644 --- a/source/expectations/data_values/ut_data_value.tpb +++ b/source/expectations/data_values/ut_data_value.tpb @@ -25,7 +25,12 @@ create or replace type body ut_data_value as return false; end; - member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2 ) return varchar2 is + member function is_empty return boolean is + begin + raise value_error; + end; + + member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean :=false ) return varchar2 is begin return null; end; diff --git a/source/expectations/data_values/ut_data_value.tps b/source/expectations/data_values/ut_data_value.tps index fba0ed3c4..e9ad68bba 100644 --- a/source/expectations/data_values/ut_data_value.tps +++ b/source/expectations/data_values/ut_data_value.tps @@ -1,4 +1,4 @@ -create or replace type ut_data_value authid current_user as object ( +create or replace type ut_data_value force authid current_user as object ( /* utPLSQL - Version 3 Copyright 2016 - 2017 utPLSQL Project @@ -24,7 +24,8 @@ create or replace type ut_data_value authid current_user as object ( final member function to_string_report(a_add_new_line_for_multi_line boolean := false, a_with_object_info boolean := true) return varchar2, order member function compare( a_other ut_data_value ) return integer, member function is_diffable return boolean, - member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2 ) return varchar2, + member function is_empty return boolean, + member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean := false ) return varchar2, not instantiable member function compare_implementation( a_other ut_data_value ) return integer ) not final not instantiable / diff --git a/source/expectations/data_values/ut_data_value_blob.tpb b/source/expectations/data_values/ut_data_value_blob.tpb index cd66f43fe..0f7f1d758 100644 --- a/source/expectations/data_values/ut_data_value_blob.tpb +++ b/source/expectations/data_values/ut_data_value_blob.tpb @@ -29,6 +29,15 @@ create or replace type body ut_data_value_blob as return (self.data_value is null); end; + overriding member function is_empty return boolean is + l_result boolean := false; + begin + if self.data_value is not null and dbms_lob.compare( self.data_value, empty_blob()) = 0 then + l_result := true; + end if; + return l_result; + end; + overriding member function to_string return varchar2 is begin return ut_utils.to_string(self.data_value); diff --git a/source/expectations/data_values/ut_data_value_blob.tps b/source/expectations/data_values/ut_data_value_blob.tps index ce8376cb3..8ebfffc3e 100644 --- a/source/expectations/data_values/ut_data_value_blob.tps +++ b/source/expectations/data_values/ut_data_value_blob.tps @@ -18,6 +18,7 @@ create or replace type ut_data_value_blob under ut_data_value( data_value blob, constructor function ut_data_value_blob(self in out nocopy ut_data_value_blob, a_value blob) return self as result, overriding member function is_null return boolean, + overriding member function is_empty return boolean, overriding member function to_string return varchar2, overriding member function is_multi_line return boolean, overriding member function compare_implementation(a_other ut_data_value) return integer diff --git a/source/expectations/data_values/ut_data_value_clob.tpb b/source/expectations/data_values/ut_data_value_clob.tpb index c8004ce83..289a3a73c 100644 --- a/source/expectations/data_values/ut_data_value_clob.tpb +++ b/source/expectations/data_values/ut_data_value_clob.tpb @@ -29,6 +29,15 @@ create or replace type body ut_data_value_clob as return (self.data_value is null); end; + overriding member function is_empty return boolean is + l_result boolean := false; + begin + if self.data_value is not null and dbms_lob.compare( self.data_value, empty_clob()) = 0 then + l_result := true; + end if; + return l_result; + end; + overriding member function to_string return varchar2 is begin return ut_utils.to_string(self.data_value); diff --git a/source/expectations/data_values/ut_data_value_clob.tps b/source/expectations/data_values/ut_data_value_clob.tps index 14735ed19..d72e05926 100644 --- a/source/expectations/data_values/ut_data_value_clob.tps +++ b/source/expectations/data_values/ut_data_value_clob.tps @@ -18,6 +18,7 @@ create or replace type ut_data_value_clob under ut_data_value( data_value clob, constructor function ut_data_value_clob(self in out nocopy ut_data_value_clob, a_value clob) return self as result, overriding member function is_null return boolean, + overriding member function is_empty return boolean, overriding member function to_string return varchar2, overriding member function is_multi_line return boolean, overriding member function compare_implementation(a_other ut_data_value) return integer diff --git a/source/expectations/data_values/ut_data_value_collection.tpb b/source/expectations/data_values/ut_data_value_collection.tpb index 156b5a73d..fa91a1fb4 100644 --- a/source/expectations/data_values/ut_data_value_collection.tpb +++ b/source/expectations/data_values/ut_data_value_collection.tpb @@ -36,9 +36,9 @@ create or replace type body ut_data_value_collection as return; end; - overriding member function is_multi_line return boolean is + overriding member function is_empty return boolean is begin - return not self.is_null(); + return self.elements_count = 0; end; end; diff --git a/source/expectations/data_values/ut_data_value_collection.tps b/source/expectations/data_values/ut_data_value_collection.tps index 243de3c64..e375e27d0 100644 --- a/source/expectations/data_values/ut_data_value_collection.tps +++ b/source/expectations/data_values/ut_data_value_collection.tps @@ -17,6 +17,7 @@ create or replace type ut_data_value_collection under ut_data_value_anydata( */ constructor function ut_data_value_collection(self in out nocopy ut_data_value_collection, a_value anydata) return self as result, - overriding member function is_multi_line return boolean + overriding member function is_empty return boolean + ) / diff --git a/source/expectations/data_values/ut_data_value_object.tpb b/source/expectations/data_values/ut_data_value_object.tpb index a683336c6..c3c26f4bc 100644 --- a/source/expectations/data_values/ut_data_value_object.tpb +++ b/source/expectations/data_values/ut_data_value_object.tpb @@ -28,10 +28,5 @@ create or replace type body ut_data_value_object as return self.data_type; end; - overriding member function is_multi_line return boolean is - begin - return not self.is_null(); - end; - end; / diff --git a/source/expectations/data_values/ut_data_value_object.tps b/source/expectations/data_values/ut_data_value_object.tps index 4457186a4..3cc6ee051 100644 --- a/source/expectations/data_values/ut_data_value_object.tps +++ b/source/expectations/data_values/ut_data_value_object.tps @@ -16,7 +16,6 @@ create or replace type ut_data_value_object under ut_data_value_anydata( limitations under the License. */ constructor function ut_data_value_object(self in out nocopy ut_data_value_object, a_value anydata) return self as result, - overriding member function get_object_info return varchar2, - overriding member function is_multi_line return boolean + overriding member function get_object_info return varchar2 ) / diff --git a/source/expectations/data_values/ut_data_value_refcursor.tpb b/source/expectations/data_values/ut_data_value_refcursor.tpb index ccebdb99e..701b01d3c 100644 --- a/source/expectations/data_values/ut_data_value_refcursor.tpb +++ b/source/expectations/data_values/ut_data_value_refcursor.tpb @@ -15,7 +15,7 @@ create or replace type body ut_data_value_refcursor as See the License for the specific language governing permissions and limitations under the License. */ - + constructor function ut_data_value_refcursor(self in out nocopy ut_data_value_refcursor, a_value sys_refcursor) return self as result is begin init(a_value); @@ -28,8 +28,8 @@ create or replace type body ut_data_value_refcursor as l_ctx number; l_xml xmltype; l_current_date_format varchar2(4000); - l_ut_owner varchar2(250) := ut_utils.ut_owner; cursor_not_open exception; + l_ut_owner varchar2(250) := ut_utils.ut_owner; begin self.is_data_null := ut_utils.boolean_to_int(a_value is null); self.self_type := $$plsql_unit; @@ -37,7 +37,11 @@ create or replace type body ut_data_value_refcursor as self.data_type := 'refcursor'; if l_cursor is not null then if l_cursor%isopen then - self.columns_info := ut_compound_data_helper.get_columns_info(l_cursor); + --Get some more info regarding cursor, including if it containts collection columns and what is their name + + ut_curr_usr_compound_helper.get_columns_info(l_cursor,self.columns_info,self.key_info, + self.contain_collection); + self.elements_count := 0; -- We use DBMS_XMLGEN in order to: -- 1) be able to process data in bulks (set of rows) @@ -58,8 +62,8 @@ create or replace type body ut_data_value_refcursor as loop l_xml := dbms_xmlgen.getxmltype(l_ctx); - - execute immediate + + execute immediate 'insert into ' || l_ut_owner || '.ut_compound_data_tmp(data_id, item_no, item_data) ' || 'select :self_guid, :self_row_count + rownum, value(a) ' || ' from table( xmlsequence( extract(:l_xml,''ROWSET/*'') ) ) a' @@ -69,7 +73,7 @@ create or replace type body ut_data_value_refcursor as self.elements_count := self.elements_count + sql%rowcount; end loop; - + ut_expectation_processor.reset_nls_params(); if l_cursor%isopen then close l_cursor; @@ -108,14 +112,15 @@ create or replace type body ut_data_value_refcursor as return l_result_string; end; - overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2 ) return varchar2 is + overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean := false ) return varchar2 is l_result clob; l_results ut_utils.t_clob_tab := ut_utils.t_clob_tab(); l_result_string varchar2(32767); l_actual ut_data_value_refcursor; l_column_diffs ut_compound_data_helper.tt_column_diffs := ut_compound_data_helper.tt_column_diffs(); l_exclude_xpath varchar2(32767) := a_exclude_xpath; - + l_missing_pk ut_compound_data_helper.tt_missing_pk := ut_compound_data_helper.tt_missing_pk(); + function get_col_diff_text(a_col ut_compound_data_helper.t_column_diffs) return varchar2 is begin return @@ -130,7 +135,20 @@ create or replace type body ut_data_value_refcursor as ' Column <'||a_col.actual_name||'> is misplaced. Expected position: '||a_col.expected_pos||',' ||' actual position: '||a_col.actual_pos||'.' end; end; + + function get_missing_key_message(a_missing_keys ut_compound_data_helper.t_missing_pk) return varchar2 is + l_message varchar2(200); + begin + + if a_missing_keys.diff_type = 'a' then + l_message := ' Join key '||a_missing_keys.missingxpath||' does not exists in actual'; + elsif a_missing_keys.diff_type = 'e' then + l_message := ' Join key '||a_missing_keys.missingxpath||' does not exists in expected'; + end if; + return l_message; + end; + function add_incomparable_cols_to_xpath( a_column_diffs ut_compound_data_helper.tt_column_diffs, a_exclude_xpath varchar2 ) return varchar2 is @@ -151,6 +169,7 @@ create or replace type body ut_data_value_refcursor as end if; return l_result; end; + begin if not a_other is of (ut_data_value_refcursor) then raise value_error; @@ -174,34 +193,75 @@ create or replace type body ut_data_value_refcursor as ut_utils.append_to_clob(l_result, l_results); l_exclude_xpath := add_incomparable_cols_to_xpath(l_column_diffs, a_exclude_xpath); end if; - - --diff rows and row elements - ut_utils.append_to_clob(l_result, self.get_data_diff(a_other, l_exclude_xpath, a_include_xpath)); - + + --check for missing pk + if (a_join_by_xpath is not null) then + l_missing_pk := ut_compound_data_helper.is_pk_exists(self.key_info, l_actual.key_info, a_exclude_xpath, a_include_xpath,a_join_by_xpath); + end if; + + --diff rows and row elements if the pk is not missing + if l_missing_pk.count = 0 then + ut_utils.append_to_clob(l_result, self.get_data_diff(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath, a_unordered)); + else + ut_utils.append_to_clob(l_result,chr(10) || 'Unable to join sets:' || chr(10)); + for i in 1 .. l_missing_pk.count loop + l_results.extend; + ut_utils.append_to_clob(l_result, get_missing_key_message(l_missing_pk(i))|| chr(10)); + end loop; + + if ut_utils.int_to_boolean(self.contain_collection) or ut_utils.int_to_boolean(l_actual.contain_collection) then + ut_utils.append_to_clob(l_result,' Please make sure that your join clause is not refferring to collection element'|| chr(10)); + end if; + + end if; + l_result_string := ut_utils.to_string(l_result,null); dbms_lob.freetemporary(l_result); return l_result_string; end; - overriding member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer is + overriding member function compare_implementation (a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean) return integer is l_result integer := 0; l_other ut_data_value_refcursor; + function is_pk_missing (a_pk_missing_tab ut_compound_data_helper.tt_missing_pk) return integer is + begin + return case when a_pk_missing_tab.count > 0 then 1 else 0 end; + end; begin if not a_other is of (ut_data_value_refcursor) then raise value_error; end if; l_other := treat(a_other as ut_data_value_refcursor); - - --if column names/types are not equal - build a diff of column names and types - if ut_compound_data_helper.columns_hash( self, a_exclude_xpath, a_include_xpath ) - != ut_compound_data_helper.columns_hash( l_other, a_exclude_xpath, a_include_xpath ) - then - l_result := 1; + + --if we join by key and key is missing fail and report error + if a_join_by_xpath is not null then + l_result := is_pk_missing(ut_compound_data_helper.is_pk_exists(self.key_info, l_other.key_info, a_exclude_xpath, a_include_xpath,a_join_by_xpath)); + end if; + + if l_result = 0 then + --if column names/types are not equal - build a diff of column names and types + if ut_compound_data_helper.columns_hash( self, a_exclude_xpath, a_include_xpath ) + != ut_compound_data_helper.columns_hash( l_other, a_exclude_xpath, a_include_xpath ) + then + l_result := 1; + end if; + + if a_unordered then + l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath, a_unordered); + else + l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath); + end if; end if; - l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath); + return l_result; end; + overriding member function is_empty return boolean is + begin + return self.elements_count = 0; + end; + + end; / diff --git a/source/expectations/data_values/ut_data_value_refcursor.tps b/source/expectations/data_values/ut_data_value_refcursor.tps index c59bf2662..27f4a4d7c 100644 --- a/source/expectations/data_values/ut_data_value_refcursor.tps +++ b/source/expectations/data_values/ut_data_value_refcursor.tps @@ -24,16 +24,28 @@ create or replace type ut_data_value_refcursor under ut_compound_data_value( * Determines if the cursor is null */ is_cursor_null integer, - + + /** + * hold information if the cursor contains collection object + */ + contain_collection number(1,0), + /** * Holds information about column names and column data-types */ columns_info xmltype, - + + /** + * Holds more detailed information regarding the pk joins + */ + key_info xmltype, + constructor function ut_data_value_refcursor(self in out nocopy ut_data_value_refcursor, a_value sys_refcursor) return self as result, member procedure init(self in out nocopy ut_data_value_refcursor, a_value sys_refcursor), overriding member function to_string return varchar2, - overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2 ) return varchar2, - overriding member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer + overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean := false ) return varchar2, + overriding member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean) return integer, + overriding member function is_empty return boolean + ) / diff --git a/source/expectations/data_values/ut_data_value_xmltype.tpb b/source/expectations/data_values/ut_data_value_xmltype.tpb new file mode 100644 index 000000000..237a7e592 --- /dev/null +++ b/source/expectations/data_values/ut_data_value_xmltype.tpb @@ -0,0 +1,50 @@ +create or replace type body ut_data_value_xmltype as + /* + utPLSQL - Version 3 + Copyright 2016 - 2017 utPLSQL Project + + Licensed under the Apache License, Version 2.0 (the "License"): + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + + constructor function ut_data_value_xmltype(self in out nocopy ut_data_value_xmltype, a_value xmltype) return self as result is + begin + self.data_value := a_value; + self.self_type := $$plsql_unit; + self.data_type := 'xmltype'; + return; + end; + + overriding member function is_null return boolean is + begin + return (self.data_value is null); + end; + + overriding member function to_string return varchar2 is + begin + return ut_utils.to_string(self.data_value.getClobVal()); + end; + + overriding member function compare_implementation(a_other ut_data_value) return integer is + l_result integer; + l_other ut_data_value_xmltype; + begin + if a_other is of (ut_data_value_xmltype) then + l_other := treat(a_other as ut_data_value_xmltype); + l_result := dbms_lob.compare(self.data_value.getClobVal(),l_other.data_value.getClobVal()); + end if; + + return l_result; + end; + +end; +/ diff --git a/source/expectations/data_values/ut_data_value_xmltype.tps b/source/expectations/data_values/ut_data_value_xmltype.tps new file mode 100644 index 000000000..2bc4ae985 --- /dev/null +++ b/source/expectations/data_values/ut_data_value_xmltype.tps @@ -0,0 +1,24 @@ +create or replace type ut_data_value_xmltype under ut_data_value( + /* + utPLSQL - Version 3 + Copyright 2016 - 2017 utPLSQL Project + + Licensed under the Apache License, Version 2.0 (the "License"): + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + data_value xmltype, + constructor function ut_data_value_xmltype(self in out nocopy ut_data_value_xmltype, a_value xmltype) return self as result, + overriding member function is_null return boolean, + overriding member function to_string return varchar2, + overriding member function compare_implementation(a_other ut_data_value) return integer +) +/ diff --git a/source/expectations/data_values/ut_key_anyval_pair.tps b/source/expectations/data_values/ut_key_anyval_pair.tps new file mode 100644 index 000000000..8fb4831c0 --- /dev/null +++ b/source/expectations/data_values/ut_key_anyval_pair.tps @@ -0,0 +1,21 @@ +create or replace type ut_key_anyval_pair force as object( + /* + utPLSQL - Version 3 + Copyright 2016 - 2017 utPLSQL Project + + Licensed under the Apache License, Version 2.0 (the "License"): + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + key varchar2(4000), + value ut_data_value +) not final +/ diff --git a/source/expectations/data_values/ut_key_anyval_pairs.tps b/source/expectations/data_values/ut_key_anyval_pairs.tps new file mode 100644 index 000000000..ccf4ce047 --- /dev/null +++ b/source/expectations/data_values/ut_key_anyval_pairs.tps @@ -0,0 +1,19 @@ +create or replace type ut_key_anyval_pairs as + /* + utPLSQL - Version 3 + Copyright 2016 - 2017 utPLSQL Project + + Licensed under the Apache License, Version 2.0 (the "License"): + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + table of ut_key_anyval_pair +/ diff --git a/source/expectations/matchers/ut_be_empty.tpb b/source/expectations/matchers/ut_be_empty.tpb index c5ab2261a..7bf9bdd84 100644 --- a/source/expectations/matchers/ut_be_empty.tpb +++ b/source/expectations/matchers/ut_be_empty.tpb @@ -30,14 +30,10 @@ create or replace type body ut_be_empty as overriding member function run_matcher(self in out nocopy ut_be_empty, a_actual ut_data_value) return boolean is l_result boolean; begin - if a_actual is of(ut_data_value_refcursor) then - l_result := treat(a_actual as ut_data_value_refcursor).is_empty; - elsif a_actual is of(ut_data_value_collection) then - l_result := treat(a_actual as ut_data_value_collection).is_empty; - else - l_result := (self as ut_matcher).run_matcher(a_actual); - end if; - return l_result; + return a_actual.is_empty(); + exception + when value_error then + return (self as ut_matcher).run_matcher(a_actual); end; end; diff --git a/source/expectations/matchers/ut_equal.tpb b/source/expectations/matchers/ut_equal.tpb index 29b8f511d..3a163e9c9 100644 --- a/source/expectations/matchers/ut_equal.tpb +++ b/source/expectations/matchers/ut_equal.tpb @@ -23,6 +23,7 @@ create or replace type body ut_equal as self.expected := a_expected; self.include_list := ut_varchar2_list(); self.exclude_list := ut_varchar2_list(); + self.join_columns := ut_varchar2_list(); end; member function equal_with_nulls(a_assert_result boolean, a_actual ut_data_value) return boolean is @@ -182,6 +183,29 @@ create or replace type body ut_equal as return l_result; end; + member function unordered return ut_equal is + l_result ut_equal := self; + begin + l_result.is_unordered := ut_utils.boolean_to_int(true); + return l_result; + end; + + member function join_by(a_columns varchar2) return ut_equal is + l_result ut_equal := self; + begin + l_result.is_unordered := ut_utils.boolean_to_int(true); + ut_utils.append_to_list(l_result.join_columns, a_columns); + return l_result; + end; + + member function join_by(a_columns ut_varchar2_list) return ut_equal is + l_result ut_equal := self; + begin + l_result.is_unordered := ut_utils.boolean_to_int(true); + l_result.join_columns := l_result.join_columns multiset union all coalesce(a_columns,ut_varchar2_list()); + return l_result; + end; + member function get_include_xpath return varchar2 is begin return ut_utils.to_xpath( coalesce(include_list, ut_varchar2_list()) ); @@ -192,6 +216,16 @@ create or replace type body ut_equal as return ut_utils.to_xpath( coalesce(exclude_list, ut_varchar2_list()) ); end; + member function get_unordered return boolean is + begin + return ut_utils.int_to_boolean(nvl(is_unordered,0)); + end; + + member function get_join_by_xpath return varchar2 is + begin + return ut_utils.to_xpath( coalesce(join_columns, ut_varchar2_list()) ); + end; + overriding member function run_matcher(self in out nocopy ut_equal, a_actual ut_data_value) return boolean is l_result boolean; begin @@ -199,7 +233,7 @@ create or replace type body ut_equal as if self.expected is of (ut_data_value_anydata) then l_result := 0 = treat(self.expected as ut_data_value_anydata).compare_implementation(a_actual, get_exclude_xpath(), get_include_xpath()); elsif self.expected is of (ut_data_value_refcursor) then - l_result := 0 = treat(self.expected as ut_data_value_refcursor).compare_implementation(a_actual, get_exclude_xpath(), get_include_xpath()); + l_result := 0 = treat(self.expected as ut_data_value_refcursor).compare_implementation(a_actual, get_exclude_xpath(), get_include_xpath(), get_join_by_xpath(), get_unordered()); else l_result := equal_with_nulls((self.expected = a_actual), a_actual); end if; @@ -216,7 +250,7 @@ create or replace type body ut_equal as if self.expected.data_type = a_actual.data_type and self.expected.is_diffable then l_result := 'Actual: '||a_actual.get_object_info()||' '||self.description()||': '||self.expected.get_object_info() - || chr(10) || 'Diff:' || expected.diff(a_actual, get_exclude_xpath(), get_include_xpath()); + || chr(10) || 'Diff:' || expected.diff(a_actual, get_exclude_xpath(), get_include_xpath(), get_join_by_xpath(), get_unordered()); else l_result := (self as ut_matcher).failure_message(a_actual) || ': '|| self.expected.to_string_report(); end if; diff --git a/source/expectations/matchers/ut_equal.tps b/source/expectations/matchers/ut_equal.tps index 710b23f7f..01b1d2e1e 100644 --- a/source/expectations/matchers/ut_equal.tps +++ b/source/expectations/matchers/ut_equal.tps @@ -25,7 +25,17 @@ create or replace type ut_equal under ut_comparison_matcher( * Holds (list of columns/attributes) to incude when comparing compound types */ include_list ut_varchar2_list, + + /** + * Holds value if comparision on refcursor to be performed as unordered set + */ + is_unordered number(1,0), + /** + * Holds list of columns to be used as a join PK on sys_refcursor comparision + */ + join_columns ut_varchar2_list, + member procedure init(self in out nocopy ut_equal, a_expected ut_data_value, a_nulls_are_equal boolean), member function equal_with_nulls( self in ut_equal, a_assert_result boolean, a_actual ut_data_value) return boolean, constructor function ut_equal(self in out nocopy ut_equal, a_expected anydata, a_nulls_are_equal boolean := null) return self as result, @@ -49,8 +59,13 @@ create or replace type ut_equal under ut_comparison_matcher( member function include(a_items ut_varchar2_list) return ut_equal, member function exclude(a_items varchar2) return ut_equal, member function exclude(a_items ut_varchar2_list) return ut_equal, + member function unordered return ut_equal, + member function join_by(a_columns varchar2) return ut_equal, + member function join_by(a_columns ut_varchar2_list) return ut_equal, member function get_include_xpath return varchar2, member function get_exclude_xpath return varchar2, + member function get_unordered return boolean, + member function get_join_by_xpath return varchar2, overriding member function run_matcher(self in out nocopy ut_equal, a_actual ut_data_value) return boolean, overriding member function failure_message(a_actual ut_data_value) return varchar2, overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2 diff --git a/source/expectations/ut_expectation_compound.tpb b/source/expectations/ut_expectation_compound.tpb index 8665af265..dea146bd2 100644 --- a/source/expectations/ut_expectation_compound.tpb +++ b/source/expectations/ut_expectation_compound.tpb @@ -146,6 +146,59 @@ create or replace type body ut_expectation_compound as self.to_( treat(matcher as ut_equal).exclude(a_items) ); end if; end; + + member function unordered return ut_expectation_compound is + l_result ut_expectation_compound; + begin + l_result := self; + l_result.matcher := treat(l_result.matcher as ut_equal).unordered; + return l_result; + end; + + member procedure unordered(self in ut_expectation_compound) is + begin + + if ut_utils.int_to_boolean(negated) then + self.not_to( treat(matcher as ut_equal).unordered ); + else + self.to_( treat(matcher as ut_equal).unordered ); + end if; + end; + + member function join_by(a_columns varchar2) return ut_expectation_compound is + l_result ut_expectation_compound; + begin + l_result := self; + l_result.matcher := treat(l_result.matcher as ut_equal).join_by(a_columns); + return l_result; + end; + + member function join_by(a_columns ut_varchar2_list) return ut_expectation_compound is + l_result ut_expectation_compound; + begin + l_result := self; + l_result.matcher := treat(l_result.matcher as ut_equal).join_by(a_columns); + return l_result; + end; + + member procedure join_by(self in ut_expectation_compound, a_columns varchar2) is + begin + if ut_utils.int_to_boolean(negated) then + self.not_to( treat(matcher as ut_equal).join_by(a_columns) ); + else + self.to_( treat(matcher as ut_equal).join_by(a_columns) ); + end if; + end; + + member procedure join_by(self in ut_expectation_compound, a_columns ut_varchar2_list) is + begin + + if ut_utils.int_to_boolean(negated) then + self.not_to( treat(matcher as ut_equal).join_by(a_columns) ); + else + self.to_( treat(matcher as ut_equal).join_by(a_columns) ); + end if; + end; end; / diff --git a/source/expectations/ut_expectation_compound.tps b/source/expectations/ut_expectation_compound.tps index 66dcb91af..967706a21 100644 --- a/source/expectations/ut_expectation_compound.tps +++ b/source/expectations/ut_expectation_compound.tps @@ -36,8 +36,13 @@ create or replace type ut_expectation_compound under ut_expectation( member function exclude(a_items varchar2) return ut_expectation_compound, member function exclude(a_items ut_varchar2_list) return ut_expectation_compound, member procedure exclude(self in ut_expectation_compound, a_items varchar2), - member procedure exclude(self in ut_expectation_compound, a_items ut_varchar2_list) - + member procedure exclude(self in ut_expectation_compound, a_items ut_varchar2_list), + member function unordered return ut_expectation_compound, + member procedure unordered(self in ut_expectation_compound), + member function join_by(a_columns varchar2) return ut_expectation_compound, + member function join_by(a_columns ut_varchar2_list) return ut_expectation_compound, + member procedure join_by(self in ut_expectation_compound, a_columns varchar2), + member procedure join_by(self in ut_expectation_compound, a_columns ut_varchar2_list) ) final -/ +/ \ No newline at end of file diff --git a/source/install.sql b/source/install.sql index 4054086a6..07227c316 100644 --- a/source/install.sql +++ b/source/install.sql @@ -29,6 +29,9 @@ whenever oserror exit failure rollback prompt Switching current schema to &&ut3_owner prompt &&line_separator alter session set current_schema = &&ut3_owner; + +@@check_object_grants.sql +@@check_sys_grants.sql --set define off --dbms_output buffer cache table @@ -68,6 +71,7 @@ alter session set current_schema = &&ut3_owner; @@install_component.sql 'core/types/ut_test.tps' @@install_component.sql 'core/types/ut_logical_suite.tps' @@install_component.sql 'core/types/ut_suite.tps' +@@install_component.sql 'core/types/ut_suite_context.tps' @@install_component.sql 'core/types/ut_file_mapping.tps' @@install_component.sql 'core/types/ut_file_mappings.tps' @@install_component.sql 'core/types/ut_coverage_options.tps' @@ -151,6 +155,7 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema @@install_component.sql 'core/types/ut_test.tpb' @@install_component.sql 'core/types/ut_logical_suite.tpb' @@install_component.sql 'core/types/ut_suite.tpb' +@@install_component.sql 'core/types/ut_suite_context.tpb' @@install_component.sql 'core/types/ut_run.tpb' @@install_component.sql 'core/types/ut_expectation_result.tpb' @@install_component.sql 'core/types/ut_reporter_base.tpb' @@ -166,7 +171,6 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema @@install_component.sql 'expectations/data_values/ut_compound_data_diff_tmp.sql' @@install_component.sql 'expectations/data_values/ut_data_value.tps' @@install_component.sql 'expectations/data_values/ut_compound_data_value.tps' -@@install_component.sql 'expectations/data_values/ut_compound_data_helper.pks' @@install_component.sql 'expectations/data_values/ut_data_value_anydata.tps' @@install_component.sql 'expectations/data_values/ut_data_value_collection.tps' @@install_component.sql 'expectations/data_values/ut_data_value_object.tps' @@ -182,6 +186,11 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema @@install_component.sql 'expectations/data_values/ut_data_value_timestamp_ltz.tps' @@install_component.sql 'expectations/data_values/ut_data_value_varchar2.tps' @@install_component.sql 'expectations/data_values/ut_data_value_yminterval.tps' +@@install_component.sql 'expectations/data_values/ut_data_value_xmltype.tps' +@@install_component.sql 'expectations/data_values/ut_key_anyval_pair.tps' +@@install_component.sql 'expectations/data_values/ut_key_anyval_pairs.tps' +@@install_component.sql 'expectations/data_values/ut_compound_data_helper.pks' +@@install_component.sql 'expectations/data_values/ut_curr_usr_compound_helper.pks' @@install_component.sql 'expectations/matchers/ut_matcher.tps' @@install_component.sql 'expectations/matchers/ut_comparison_matcher.tps' @@install_component.sql 'expectations/matchers/ut_be_false.tps' @@ -203,6 +212,7 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema @@install_component.sql 'expectations/data_values/ut_data_value.tpb' @@install_component.sql 'expectations/data_values/ut_compound_data_value.tpb' @@install_component.sql 'expectations/data_values/ut_compound_data_helper.pkb' +@@install_component.sql 'expectations/data_values/ut_curr_usr_compound_helper.pkb' @@install_component.sql 'expectations/data_values/ut_data_value_anydata.tpb' @@install_component.sql 'expectations/data_values/ut_data_value_object.tpb' @@install_component.sql 'expectations/data_values/ut_data_value_collection.tpb' @@ -218,6 +228,7 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema @@install_component.sql 'expectations/data_values/ut_data_value_timestamp_ltz.tpb' @@install_component.sql 'expectations/data_values/ut_data_value_varchar2.tpb' @@install_component.sql 'expectations/data_values/ut_data_value_yminterval.tpb' +@@install_component.sql 'expectations/data_values/ut_data_value_xmltype.tpb' @@install_component.sql 'expectations/matchers/ut_matcher.tpb' @@install_component.sql 'expectations/matchers/ut_comparison_matcher.tpb' @@install_component.sql 'expectations/matchers/ut_be_false.tpb' diff --git a/source/install_component.sql b/source/install_component.sql index 1248c872f..5a9fc7e56 100644 --- a/source/install_component.sql +++ b/source/install_component.sql @@ -18,5 +18,6 @@ set heading off set feedback off exec dbms_output.put_line('Installing component '||upper(regexp_substr('&&1','\/(\w*)\.',1,1,'i',1))); @@&&1 +show errors exec dbms_output.put_line('&&line_separator'); diff --git a/source/reporters/ut_coverage_cobertura_reporter.tpb b/source/reporters/ut_coverage_cobertura_reporter.tpb index 82d085604..cce2224df 100644 --- a/source/reporters/ut_coverage_cobertura_reporter.tpb +++ b/source/reporters/ut_coverage_cobertura_reporter.tpb @@ -66,25 +66,27 @@ create or replace type body ut_coverage_cobertura_reporter is end; function get_coverage_xml( - a_coverage_data ut_coverage.t_coverage + a_coverage_data ut_coverage.t_coverage, + a_run ut_run ) return clob is - l_file_part varchar2(32767); - l_result clob; - l_unit ut_coverage.t_full_name; - l_obj_name ut_coverage.t_object_name; - c_coverage_def constant varchar2(200) := ''||CHR(10)||''||chr(10); + l_file_part varchar2(32767); + l_result clob; + l_unit ut_coverage.t_full_name; + l_obj_name ut_coverage.t_object_name; + c_coverage_def constant varchar2(200) := ''||chr(10); c_file_footer constant varchar2(30) := ''||chr(10); c_coverage_footer constant varchar2(30) := ''; c_sources_footer constant varchar2(30) := ''||chr(10); - c_packages_footer constant varchar2(30) := ''||chr(10); + c_packages_footer constant varchar2(30) := ''||chr(10); c_package_footer constant varchar2(30) := ''||chr(10); - c_class_footer constant varchar2(30) := ''||chr(10); - c_lines_footer constant varchar2(30) := ''||chr(10); - l_epoch varchar2(50) := (sysdate - to_date('01-01-1970 00:00:00', 'dd-mm-yyyy hh24:mi:ss')) * 24 * 60 * 60; + c_class_footer constant varchar2(30) := ''||chr(10); + c_lines_footer constant varchar2(30) := ''||chr(10); + l_epoch varchar2(50) := (sysdate - to_date('01-01-1970 00:00:00', 'dd-mm-yyyy hh24:mi:ss')) * 24 * 60 * 60; begin dbms_lob.createtemporary(l_result,true); + ut_utils.append_to_clob(l_result, ut_utils.get_xml_header(a_run.client_character_set)||chr(10)); ut_utils.append_to_clob(l_result, c_coverage_def); --write header @@ -138,7 +140,7 @@ create or replace type body ut_coverage_cobertura_reporter is l_coverage_data := ut_coverage.get_coverage_data(a_run.coverage_options); - self.print_clob( get_coverage_xml( l_coverage_data ) ); + self.print_clob( get_coverage_xml( l_coverage_data, a_run ) ); (self as ut_reporter_base).after_calling_run(a_run); end; diff --git a/source/reporters/ut_coverage_html_reporter.tpb b/source/reporters/ut_coverage_html_reporter.tpb index d1a9dd473..08069ff65 100644 --- a/source/reporters/ut_coverage_html_reporter.tpb +++ b/source/reporters/ut_coverage_html_reporter.tpb @@ -35,7 +35,14 @@ create or replace type body ut_coverage_html_reporter is ut_coverage.coverage_stop(); l_coverage_data := ut_coverage.get_coverage_data(a_run.coverage_options); - self.print_clob( ut_coverage_report_html_helper.get_index( a_coverage_data => l_coverage_data,a_assets_path => self.assets_path, a_project_name=> self.project_name )); + self.print_clob( + ut_coverage_report_html_helper.get_index( + a_coverage_data => l_coverage_data, + a_assets_path => self.assets_path, + a_project_name => self.project_name, + a_charset => a_run.client_character_set + ) + ); end; diff --git a/source/reporters/ut_coverage_report_html_helper.pkb b/source/reporters/ut_coverage_report_html_helper.pkb index 4ea8c6eb1..6b310e1f8 100644 --- a/source/reporters/ut_coverage_report_html_helper.pkb +++ b/source/reporters/ut_coverage_report_html_helper.pkb @@ -241,7 +241,7 @@ function get_details_file_content(a_object_id varchar2, a_unit ut_object_name, a '' || executions_per_line(a_coverage.executions, a_coverage.uncovered_lines + a_coverage.covered_lines) - || ' hits/line)' || '' || '
' || + || ' hits/line)' || '' || '
' || a_coverage.objects.count || ' files in total.
' || '' || (a_coverage.uncovered_lines + a_coverage.covered_lines) || ' relevant lines. ' || '' || a_coverage.covered_lines || @@ -277,8 +277,13 @@ function get_details_file_content(a_object_id varchar2, a_unit ut_object_name, a /* * public definitions */ - function get_index(a_coverage_data ut_coverage.t_coverage, a_assets_path varchar2, a_project_name varchar2 := null, a_command_line varchar2 := null) - return clob is + function get_index( + a_coverage_data ut_coverage.t_coverage, + a_assets_path varchar2, + a_project_name varchar2 := null, + a_command_line varchar2 := null, + a_charset varchar2 := null + ) return clob is l_file_part varchar2(32767); l_result clob; @@ -287,10 +292,12 @@ function get_details_file_content(a_object_id varchar2, a_unit ut_object_name, a l_time_str varchar2(50); l_using varchar2(1000); l_unit ut_coverage.t_full_name; + l_charset varchar2(1000); begin - l_coverage_pct := coverage_pct(a_coverage_data.covered_lines, a_coverage_data.uncovered_lines); + l_charset := coalesce(upper(a_charset),'UTF-8'); + l_coverage_pct := coverage_pct(a_coverage_data.covered_lines, a_coverage_data.uncovered_lines); - l_time_str := ut_utils.to_string(sysdate); + l_time_str := to_char(sysdate,'yyyy-mm-dd"T"hh24:mi:ss'); l_using := case when a_command_line is not null then '
using ' || dbms_xmlgen.convert(a_command_line) @@ -305,10 +312,10 @@ function get_details_file_content(a_object_id varchar2, a_unit ut_object_name, a end; --TODO - build main file containing total run data and per schema data l_file_part := '' || '' || l_title || - '' || '' || - '' || + '' || '' || + '' || '' || + 'application.css'' media=''screen, print'' rel=''stylesheet'' type=''text/css''/>' || '' || '' || '' || @@ -339,7 +346,7 @@ function get_details_file_content(a_object_id varchar2, a_unit ut_object_name, a l_unit := a_coverage_data.objects.next(l_unit); end loop; - l_file_part := '
'; + l_file_part := ''; ut_utils.append_to_clob(l_result, l_file_part); return l_result; diff --git a/source/reporters/ut_coverage_report_html_helper.pks b/source/reporters/ut_coverage_report_html_helper.pks index e718f9fed..8970a235e 100644 --- a/source/reporters/ut_coverage_report_html_helper.pks +++ b/source/reporters/ut_coverage_report_html_helper.pks @@ -31,7 +31,13 @@ create or replace package ut_coverage_report_html_helper authid current_user is function line_hits_css_class(a_line_hist number) return varchar2; - function get_index(a_coverage_data ut_coverage.t_coverage, a_assets_path varchar2, a_project_name varchar2 := null, a_command_line varchar2 := null) return clob; + function get_index( + a_coverage_data ut_coverage.t_coverage, + a_assets_path varchar2, + a_project_name varchar2 := null, + a_command_line varchar2 := null, + a_charset varchar2 := null + ) return clob; end; / diff --git a/source/reporters/ut_coverage_sonar_reporter.tpb b/source/reporters/ut_coverage_sonar_reporter.tpb index a82097061..29d3d351d 100644 --- a/source/reporters/ut_coverage_sonar_reporter.tpb +++ b/source/reporters/ut_coverage_sonar_reporter.tpb @@ -59,7 +59,8 @@ create or replace type body ut_coverage_sonar_reporter is return l_result; end; function get_coverage_xml( - a_coverage_data ut_coverage.t_coverage + a_coverage_data ut_coverage.t_coverage, + a_run ut_run ) return clob is l_file_part varchar2(32767); l_result clob; @@ -70,6 +71,7 @@ create or replace type body ut_coverage_sonar_reporter is begin dbms_lob.createtemporary(l_result,true); + ut_utils.append_to_clob(l_result, ut_utils.get_xml_header(a_run.client_character_set)||chr(10)); ut_utils.append_to_clob(l_result, c_coverage_header); l_unit := a_coverage_data.objects.first; while l_unit is not null loop @@ -90,7 +92,7 @@ create or replace type body ut_coverage_sonar_reporter is l_coverage_data := ut_coverage.get_coverage_data(a_run.coverage_options); - self.print_clob( get_coverage_xml( l_coverage_data ) ); + self.print_clob( get_coverage_xml( l_coverage_data, a_run ) ); end; overriding member function get_description return varchar2 as diff --git a/source/reporters/ut_coveralls_reporter.tpb b/source/reporters/ut_coveralls_reporter.tpb index f19d1f3ce..96df05483 100644 --- a/source/reporters/ut_coveralls_reporter.tpb +++ b/source/reporters/ut_coveralls_reporter.tpb @@ -40,22 +40,21 @@ create or replace type body ut_coveralls_reporter is l_last_line_no := a_unit_coverage.lines.last; if l_last_line_no is null then - l_last_line_no := a_unit_coverage.total_lines - 1; - for i in 1 .. l_last_line_no loop - ut_utils.append_to_clob(l_result, '0,'); - end loop; - ut_utils.append_to_clob(l_result, '0'); + ut_utils.append_to_clob( + l_result + , rpad( to_clob( '0' ), ( a_unit_coverage.total_lines * 3 ) - 2, ','||chr(10)||'0' ) + ); else for line_no in 1 .. l_last_line_no loop if a_unit_coverage.lines.exists(line_no) then l_file_part := to_char(a_unit_coverage.lines(line_no).executions); - else + else l_file_part := c_null; end if; if line_no < l_last_line_no then l_file_part := l_file_part ||','; end if; - ut_utils.append_to_clob(l_result, l_file_part); + ut_utils.append_to_clob(l_result, l_file_part||chr(10)); end loop; end if; ut_utils.append_to_clob(l_result, ']'); diff --git a/source/reporters/ut_junit_reporter.tpb b/source/reporters/ut_junit_reporter.tpb index e1a6d7dca..204a39fb4 100644 --- a/source/reporters/ut_junit_reporter.tpb +++ b/source/reporters/ut_junit_reporter.tpb @@ -53,17 +53,15 @@ create or replace type body ut_junit_reporter is self.print_text(''); elsif a_test.result > ut_utils.gc_success then self.print_text(''); - self.print_text(c_cddata_tag_start); for i in 1 .. a_test.failed_expectations.count loop l_lines := a_test.failed_expectations(i).get_result_lines(); for j in 1 .. l_lines.count loop - self.print_text(l_lines(j)); + self.print_text(dbms_xmlgen.convert(l_lines(j))); end loop; - self.print_text(a_test.failed_expectations(i).caller_info); + self.print_text(dbms_xmlgen.convert(a_test.failed_expectations(i).caller_info)); end loop; - self.print_text(c_cddata_tag_end); self.print_text(''); end if; -- TODO - decide if we need/want to use the tag too @@ -137,6 +135,7 @@ create or replace type body ut_junit_reporter is end; begin l_suite_id := 0; + self.print_text(ut_utils.get_xml_header(a_run.client_character_set)); self.print_text(''); for i in 1 .. a_run.items.count loop print_suite_elements(treat(a_run.items(i) as ut_logical_suite), l_suite_id); diff --git a/source/reporters/ut_sonar_test_reporter.tpb b/source/reporters/ut_sonar_test_reporter.tpb index 66d82fedc..a410480ae 100644 --- a/source/reporters/ut_sonar_test_reporter.tpb +++ b/source/reporters/ut_sonar_test_reporter.tpb @@ -56,14 +56,12 @@ create or replace type body ut_sonar_test_reporter is self.print_text(''); elsif a_test.result > ut_utils.gc_success then self.print_text(''); - self.print_text(''); self.print_text(''); end if; self.print_text(''); @@ -89,6 +87,7 @@ create or replace type body ut_sonar_test_reporter is end; begin + self.print_text(ut_utils.get_xml_header(a_run.client_character_set)); self.print_text(''); for i in 1 .. a_run.items.count loop print_suite_results(treat(a_run.items(i) as ut_logical_suite), a_run.test_file_mappings); diff --git a/source/reporters/ut_tfs_junit_reporter.tpb b/source/reporters/ut_tfs_junit_reporter.tpb index 42da37f05..dbcd558a6 100644 --- a/source/reporters/ut_tfs_junit_reporter.tpb +++ b/source/reporters/ut_tfs_junit_reporter.tpb @@ -76,15 +76,13 @@ create or replace type body ut_tfs_junit_reporter is -- Do not count error as failure elsif a_test.result = ut_utils.gc_failure then self.print_text(''); - self.print_text(''); self.print_text(''); end if; @@ -143,6 +141,7 @@ create or replace type body ut_tfs_junit_reporter is begin l_suite_id := 0; + self.print_text(ut_utils.get_xml_header(a_run.client_character_set)); self.print_text(''); for i in 1 .. a_run.items.count loop print_suite_results(treat(a_run.items(i) as ut_logical_suite), l_suite_id); diff --git a/source/uninstall.sql b/source/uninstall.sql index 6da0e4fd9..0991d9245 100644 --- a/source/uninstall.sql +++ b/source/uninstall.sql @@ -25,287 +25,11 @@ prompt Uninstalling UTPLSQL v3 framework prompt &&line_separator alter session set current_schema = &&ut3_owner; -set echo on -drop synonym be_between; -drop synonym have_count; +@@uninstall_objects.sql -drop synonym match; +@@uninstall_synonyms.sql -drop synonym be_false; - -drop synonym be_empty; - -drop synonym be_greater_or_equal; - -drop synonym be_greater_than; - -drop synonym be_less_or_equal; - -drop synonym be_less_than; - -drop synonym be_like; - -drop synonym be_not_null; - -drop synonym be_null; - -drop synonym be_true; - -drop synonym equal; - -drop type ut_coveralls_reporter force; - -drop type ut_coverage_sonar_reporter force; - -drop type ut_coverage_cobertura_reporter force; - -drop package ut_coverage_report_html_helper; - -drop type ut_coverage_html_reporter force; - -drop type ut_sonar_test_reporter force; - -drop package ut_coverage; - -drop package ut_coverage_helper; - -drop view ut_coverage_sources_tmp; - -drop table ut_coverage_sources_tmp$; - -drop package ut_teamcity_reporter_helper; - -drop package ut_runner; - -drop package ut_suite_manager; - -drop package ut_suite_builder; - -drop package ut; - -drop table ut_dbms_output_cache; - -drop type ut_expectation_compound force; - -drop type ut_expectation force; - -drop package ut_expectation_processor; - -drop type ut_match force; - -drop type ut_be_between force; - -drop type ut_equal force; - -drop type ut_be_true force; - -drop type ut_be_null force; - -drop type ut_be_not_null force; - -drop type ut_be_like force; - -drop type ut_be_greater_or_equal force; - -drop type ut_be_empty force; - -drop type ut_be_greater_than force; - -drop type ut_be_less_or_equal force; - -drop type ut_be_less_than force; - -drop type ut_be_false force; - -drop type ut_comparison_matcher force; - -drop type ut_matcher force; - -drop type ut_data_value_yminterval force; - -drop type ut_data_value_varchar2 force; - -drop type ut_data_value_timestamp_tz force; - -drop type ut_data_value_timestamp_ltz force; - -drop type ut_data_value_timestamp force; - -drop type ut_data_value_number force; - -drop type ut_data_value_refcursor force; - -drop type ut_data_value_dsinterval force; - -drop type ut_data_value_date force; - -drop type ut_data_value_clob force; - -drop type ut_data_value_boolean force; - -drop type ut_data_value_blob force; - -drop type ut_data_value_object force; - -drop type ut_data_value_collection force; - -drop type ut_data_value_anydata force; - -drop type ut_data_value force; - -drop table ut_compound_data_tmp; - -drop table ut_compound_data_diff_tmp; - -drop package ut_annotation_manager; - -drop package ut_annotation_parser; - -drop package ut_annotation_cache_manager; - -drop table ut_annotation_cache cascade constraints; - -drop table ut_annotation_cache_info cascade constraints; - -drop sequence ut_annotation_cache_seq; - -drop type ut_annotation_objs_cache_info force; - -drop type ut_annotation_obj_cache_info force; - -drop type ut_annotated_objects force; - -drop type ut_annotated_object force; - -drop type ut_annotations force; - -drop type ut_annotation force; - -drop package ut_file_mapper; - -drop package ut_metadata; - -drop package ut_ansiconsole_helper; - -drop package ut_utils; - -drop type ut_documentation_reporter force; - -drop type ut_teamcity_reporter force; - -drop type ut_xunit_reporter force; - -drop type ut_junit_reporter force; - -drop type ut_tfs_junit_reporter force; - -drop type ut_event_listener force; - -drop type ut_output_reporter_base force; - -drop type ut_coverage_reporter_base force; - -drop type ut_reporters force; - -drop type ut_reporter_base force; - -drop type ut_run force; - -drop type ut_coverage_options force; - -drop type ut_file_mappings force; - -drop type ut_file_mapping force; - -drop type ut_suite force; - -drop type ut_logical_suite force; - -drop type ut_test force; - -drop type ut_console_reporter_base force; - -drop type ut_executable_test force; - -drop type ut_executables force; - -drop type ut_executable force; - -drop type ut_suite_items force; - -drop type ut_suite_item force; - -drop type ut_output_table_buffer force; - -drop type ut_output_buffer_base force; - -drop view ut_output_buffer_tmp; - -drop table ut_output_buffer_tmp$; - -drop view ut_output_buffer_info_tmp; - -drop table ut_output_buffer_info_tmp$; - -drop sequence ut_message_id_seq; - -drop type ut_results_counter force; - -drop type ut_expectation_results force; - -drop type ut_expectation_result force; - -drop package ut_event_manager; - -drop type ut_event_listener force; - -drop type ut_event_item force; - -drop type ut_key_value_pairs force; - -drop type ut_key_value_pair force; - -drop type ut_object_names force; - -drop type ut_object_name force; - -drop type ut_integer_list force; - -drop type ut_varchar2_list force; - -drop type ut_varchar2_rows force; - -set echo off -set feedback off -declare - i integer := 0; -begin - dbms_output.put_line('Dropping synonyms pointing to non-existing objects in schema '||upper('&&ut3_owner')); - for syn in ( - select - case when owner = 'PUBLIC' - then 'public synonym ' - else 'synonym ' || owner || '.' end || synonym_name as syn_name, - table_owner||'.'||table_name as for_object - from all_synonyms s - where table_owner = upper('&&ut3_owner') and table_owner != owner - and not exists (select 1 from all_objects o where o.owner = s.table_owner and o.object_name = s.table_name) - ) - loop - i := i + 1; - begin - execute immediate 'drop '||syn.syn_name; - dbms_output.put_line('Dropped '||syn.syn_name||' for object '||syn.for_object); - exception - when others then - dbms_output.put_line('FAILED to drop '||syn.syn_name||' for object '||syn.for_object); - end; - end loop; - dbms_output.put_line('&&line_separator'); - dbms_output.put_line(i||' synonyms dropped'); -end; -/ begin dbms_output.put_line('&&line_separator'); dbms_output.put_line('Uninstall complete'); diff --git a/source/uninstall_all.sql b/source/uninstall_all.sql new file mode 100644 index 000000000..21b567d0e --- /dev/null +++ b/source/uninstall_all.sql @@ -0,0 +1,45 @@ +/* + utPLSQL - Version 3 + Copyright 2016 - 2017 utPLSQL Project + + Licensed under the Apache License, Version 2.0 (the "License"): + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +@@define_ut3_owner_param.sql + +set feedback on + +spool uninstall.log + +prompt &&line_separator +prompt Uninstalling UTPLSQL v3 framework +prompt &&line_separator + +alter session set current_schema = &&ut3_owner; + +@@uninstall_objects.sql + +@@uninstall_coverage_tables.sql + +@@uninstall_synonyms.sql + +begin + dbms_output.put_line('&&line_separator'); + dbms_output.put_line('Uninstall complete'); + dbms_output.put_line('&&line_separator'); +end; +/ + +spool off + +exit; + diff --git a/source/uninstall_coverage_tables.sql b/source/uninstall_coverage_tables.sql new file mode 100644 index 000000000..8de75b51e --- /dev/null +++ b/source/uninstall_coverage_tables.sql @@ -0,0 +1,33 @@ +set echo off +set feedback off +begin + for to_be_dopped in ( + select table_name + from all_tables + where table_name in ( + 'PLSQL_PROFILER_RUNS','PLSQL_PROFILER_UNITS','PLSQL_PROFILER_DATA', + 'DBMSPCC_BLOCKS','DBMSPCC_RUNS','DBMSPCC_UNITS' + ) + and owner = sys_context( 'USERENV', 'CURRENT_SCHEMA' ) + ) + loop + execute immediate 'drop table '||to_be_dopped.table_name||' cascade constraints'; + dbms_output.put_line('Table '||to_be_dopped.table_name||' dropped'); + end loop; +end; +/ + +declare + l_seq_exist number; +begin + select count(*) into l_seq_exist + from all_sequences + where sequence_name = 'PLSQL_PROFILER_RUNNUMBER' + and sequence_owner = sys_context('USERENV','CURRENT_SCHEMA'); + if l_seq_exist = 1 then + execute immediate 'drop sequence plsql_profiler_runnumber'; + dbms_output.put_line('Sequence PLSQL_PROFILER_RUNNUMBER dropped'); + end if; +end; +/ + diff --git a/source/uninstall_objects.sql b/source/uninstall_objects.sql new file mode 100644 index 000000000..cf8b3905f --- /dev/null +++ b/source/uninstall_objects.sql @@ -0,0 +1,301 @@ +set echo on +drop synonym be_between; + +drop synonym have_count; + +drop synonym match; + +drop synonym be_false; + +drop synonym be_empty; + +drop synonym be_greater_or_equal; + +drop synonym be_greater_than; + +drop synonym be_less_or_equal; + +drop synonym be_less_than; + +drop synonym be_like; + +drop synonym be_not_null; + +drop synonym be_null; + +drop synonym be_true; + +drop synonym equal; + +drop type ut_coveralls_reporter force; + +drop type ut_coverage_sonar_reporter force; + +drop type ut_coverage_cobertura_reporter force; + +drop package ut_coverage_report_html_helper; + +drop type ut_coverage_html_reporter force; + +drop type ut_sonar_test_reporter force; + +drop package ut_coverage; + +drop package ut_coverage_helper; + +drop view ut_coverage_sources_tmp; + +drop table ut_coverage_sources_tmp$; + +drop package ut_teamcity_reporter_helper; + +drop package ut_runner; + +drop package ut_suite_manager; + +drop package ut_suite_builder; + +drop package ut; + +drop table ut_dbms_output_cache; + +drop type ut_expectation_compound force; + +drop type ut_expectation force; + +drop package ut_expectation_processor; + +drop type ut_match force; + +drop type ut_be_between force; + +drop type ut_equal force; + +drop type ut_be_true force; + +drop type ut_be_null force; + +drop type ut_be_not_null force; + +drop type ut_be_like force; + +drop type ut_be_greater_or_equal force; + +drop type ut_be_empty force; + +drop type ut_be_greater_than force; + +drop type ut_be_less_or_equal force; + +drop type ut_be_less_than force; + +drop type ut_be_false force; + +drop type ut_comparison_matcher force; + +drop type ut_matcher force; + +drop type ut_data_value_yminterval force; + +drop type ut_data_value_varchar2 force; + +drop type ut_data_value_timestamp_tz force; + +drop type ut_data_value_timestamp_ltz force; + +drop type ut_data_value_timestamp force; + +drop type ut_data_value_number force; + +drop type ut_data_value_refcursor force; + +drop type ut_data_value_dsinterval force; + +drop type ut_data_value_date force; + +drop type ut_data_value_clob force; + +drop type ut_data_value_boolean force; + +drop type ut_data_value_blob force; + +drop type ut_data_value_object force; + +drop type ut_data_value_collection force; + +drop type ut_data_value_anydata force; + +drop type ut_data_value_xmltype force; + +drop type ut_data_value force; + +drop table ut_compound_data_tmp; + +drop table ut_compound_data_diff_tmp; + +drop package ut_annotation_manager; + +drop package ut_annotation_parser; + +drop package ut_annotation_cache_manager; + +drop table ut_annotation_cache cascade constraints; + +drop table ut_annotation_cache_info cascade constraints; + +drop sequence ut_annotation_cache_seq; + +drop type ut_annotation_objs_cache_info force; + +drop type ut_annotation_obj_cache_info force; + +drop type ut_annotated_objects force; + +drop type ut_annotated_object force; + +drop type ut_annotations force; + +drop type ut_annotation force; + +drop package ut_file_mapper; + +drop package ut_metadata; + +drop package ut_ansiconsole_helper; + +drop package ut_utils; + +drop type ut_documentation_reporter force; + +drop type ut_teamcity_reporter force; + +drop type ut_xunit_reporter force; + +drop type ut_junit_reporter force; + +drop type ut_tfs_junit_reporter force; + +drop type ut_event_listener force; + +drop type ut_output_reporter_base force; + +drop type ut_coverage_reporter_base force; + +drop type ut_reporters force; + +drop type ut_reporter_base force; + +drop type ut_run force; + +drop type ut_coverage_options force; + +drop type ut_file_mappings force; + +drop type ut_file_mapping force; + +drop type ut_suite_context force; + +drop type ut_suite force; + +drop type ut_logical_suite force; + +drop type ut_test force; + +drop type ut_console_reporter_base force; + +drop type ut_executable_test force; + +drop type ut_executables force; + +drop type ut_executable force; + +drop type ut_suite_items force; + +drop type ut_suite_item force; + +drop type ut_output_table_buffer force; + +drop type ut_output_buffer_base force; + +drop view ut_output_buffer_tmp; + +drop table ut_output_buffer_tmp$ purge; + +drop view ut_output_buffer_info_tmp; + +drop table ut_output_buffer_info_tmp$; + +drop sequence ut_message_id_seq; + +drop type ut_results_counter force; + +drop type ut_expectation_results force; + +drop type ut_expectation_result force; + +drop package ut_event_manager; + +drop type ut_event_item force; + +drop type ut_key_anyval_pair force; + +drop type ut_key_anyval_pairs force; + +drop type ut_key_value_pairs force; + +drop type ut_key_value_pair force; + +drop type ut_object_names force; + +drop type ut_object_name force; + +drop type ut_integer_list force; + +drop type ut_varchar2_list force; + +drop type ut_varchar2_rows force; + +drop package ut_coverage_profiler; + +drop package ut_compound_data_helper; + +drop package ut_curr_usr_compound_helper; + +drop package ut_coverage_helper_profiler; + +drop type ut_have_count; + +drop type ut_compound_data_value; + +set echo off +set feedback off +declare + i integer := 0; +begin + dbms_output.put_line('Dropping packages created for 12.2+ ' || upper('&&ut3_owner')); + for pkg in ( + select object_name, owner + from all_objects + where 1 = 1 + and owner = upper('&&ut3_owner') + and object_type = 'PACKAGE' + and object_name in ('UT_COVERAGE_HELPER_BLOCK','UT_COVERAGE_BLOCK')) + loop + + begin + + execute immediate 'drop package ' || pkg.owner || '.' || pkg.object_name; + dbms_output.put_line('Dropped '|| pkg.object_name); + i := i + 1; + + exception + when others then + dbms_output.put_line('FAILED to drop ' || pkg.object_name); + end; + + end loop; + + dbms_output.put_line('&&line_separator'); + dbms_output.put_line(i || ' packages dropped'); +end; +/ diff --git a/source/uninstall_synonyms.sql b/source/uninstall_synonyms.sql new file mode 100644 index 000000000..569e5057d --- /dev/null +++ b/source/uninstall_synonyms.sql @@ -0,0 +1,64 @@ +set echo off +set feedback off +declare + i integer := 0; +begin + dbms_output.put_line('Dropping synonyms pointing to non-existing objects in schema '||upper('&&ut3_owner')); + for syn in ( + select + case when owner = 'PUBLIC' + then 'public synonym ' + else 'synonym ' || owner || '.' end || synonym_name as syn_name, + table_owner||'.'||table_name as for_object + from all_synonyms s + where table_owner = upper('&&ut3_owner') and table_owner != owner + and not exists (select 1 from all_objects o where o.owner = s.table_owner and o.object_name = s.table_name) + ) + loop + i := i + 1; + begin + execute immediate 'drop '||syn.syn_name; + dbms_output.put_line('Dropped '||syn.syn_name||' for object '||syn.for_object); + exception + when others then + dbms_output.put_line('FAILED to drop '||syn.syn_name||' for object '||syn.for_object); + end; + end loop; + dbms_output.put_line('&&line_separator'); + dbms_output.put_line(i||' synonyms dropped'); +end; +/ + +declare + i integer := 0; +begin + dbms_output.put_line('Dropping synonyms pointing to PL/SQL code coverage objects on 12.2 ' || upper('&&ut3_owner')); + for syn in ( + select + case when owner = 'PUBLIC' then 'public synonym ' + else 'synonym ' || owner || '.' + end || synonym_name as syn_name, + table_owner || '.' || table_name as for_object + from all_synonyms s + where 1 = 1 + and table_owner = upper('&&ut3_owner') + and synonym_name in ('DBMSPCC_BLOCKS','DBMSPCC_RUNS','DBMSPCC_UNITS') + ) + loop + + begin + + execute immediate 'drop '||syn.syn_name; + dbms_output.put_line('Dropped '||syn.syn_name||' for object '||syn.for_object); + i := i + 1; + + exception + when others then + dbms_output.put_line('FAILED to drop '||syn.syn_name||' for object '||syn.for_object); + end; + + end loop; + dbms_output.put_line('&&line_separator'); + dbms_output.put_line(i||' synonyms dropped'); +end; +/ diff --git a/test/api/test_ut_run.pkb b/test/api/test_ut_run.pkb index 503239307..807f38696 100644 --- a/test/api/test_ut_run.pkb +++ b/test/api/test_ut_run.pkb @@ -1,5 +1,518 @@ create or replace package body test_ut_run is + --%test(ut.version() returns version of the framework) + procedure ut_version is + begin + ut.expect(ut3.ut.version()).to_match('^v\d+\.\d+\.\d+\.\d+(-\w+)?$'); + end; + + --%test(ut.fail() marks test as failed) + procedure ut_fail is + begin + --Act + ut3.ut.fail('Testing failure message'); + --Assert + ut.expect( + xmltype(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).getClobVal() + ).to_be_like('%2%Testing failure message%'); + --Cleanup + ut3.ut_expectation_processor.clear_expectations(); + end; + + + function get_dbms_output_as_clob return clob is + l_status number; + l_line varchar2(32767); + l_result clob; + begin + + dbms_output.get_line(line => l_line, status => l_status); + if l_status != 1 then + dbms_lob.createtemporary(l_result, true, dur => dbms_lob.session); + end if; + while l_status != 1 loop + if l_line is not null then + ut3.ut_utils.append_to_clob(l_result, l_line||chr(10)); + end if; + dbms_output.get_line(line => l_line, status => l_status); + end loop; + return l_result; + end; + + procedure create_ut3$user#_tests is + pragma autonomous_transaction; + begin + execute immediate q'[create or replace package ut3$user#.test_package_1 is + --%suite + --%suitepath(tests) + + --%test(Test1 from test package 1) + procedure test1; + + --%test(Test2 from test package 1) + procedure test2; + + procedure run(a_reporter ut3.ut_reporter_base := null); + procedure run(a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base); + procedure run(a_path varchar2, a_reporter ut3.ut_reporter_base := null); + procedure run(a_path varchar2, a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base); + procedure run(a_paths ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base := null); + procedure run(a_paths ut3.ut_varchar2_list, a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base); + function run(a_reporter ut3.ut_reporter_base := null) return ut3.ut_varchar2_list; + function run(a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base) return ut3.ut_varchar2_list; + function run(a_path varchar2, a_reporter ut3.ut_reporter_base := null) return ut3.ut_varchar2_list; + function run(a_path varchar2, a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base) return ut3.ut_varchar2_list; + function run(a_paths ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base := null) return ut3.ut_varchar2_list; + function run(a_paths ut3.ut_varchar2_list, a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base) return ut3.ut_varchar2_list; + + end test_package_1; + ]'; + execute immediate q'[create or replace package body ut3$user#.test_package_1 is + procedure test1 is + begin + dbms_output.put_line('test_package_1.test1 executed'); + end; + procedure test2 is + begin + dbms_output.put_line('test_package_1.test2 executed'); + end; + + procedure run(a_reporter ut3.ut_reporter_base := null) is + begin + ut3.ut.run(a_reporter); + end; + procedure run(a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base) is + begin + ut3.ut.run( + a_reporter, a_source_files => ut3.ut_varchar2_list(), + a_test_files => a_test_files + ); + end; + procedure run(a_path varchar2, a_reporter ut3.ut_reporter_base := null) is + begin + ut3.ut.run(a_path, a_reporter); + end; + procedure run(a_path varchar2, a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base) is + begin + ut3.ut.run( + a_path, + a_reporter, a_source_files => ut3.ut_varchar2_list(), + a_test_files => a_test_files + ); + end; + procedure run(a_paths ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base := null) is + begin + ut3.ut.run(a_paths, a_reporter); + end; + procedure run(a_paths ut3.ut_varchar2_list, a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base) is + begin + ut3.ut.run( + a_paths, + a_reporter, a_source_files => ut3.ut_varchar2_list(), + a_test_files => a_test_files + ); + end; + + function run(a_reporter ut3.ut_reporter_base := null) return ut3.ut_varchar2_list is + l_results ut3.ut_varchar2_list; + begin + select * bulk collect into l_results from table (ut3.ut.run(a_reporter)); + return l_results; + end; + function run(a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base) return ut3.ut_varchar2_list is + l_results ut3.ut_varchar2_list; + begin + select * bulk collect into l_results from table ( + ut3.ut.run( + a_reporter, a_source_files => ut3.ut_varchar2_list(), + a_test_files => a_test_files + )); + return l_results; + end; + function run(a_path varchar2, a_reporter ut3.ut_reporter_base := null) return ut3.ut_varchar2_list is + l_results ut3.ut_varchar2_list; + begin + select * bulk collect into l_results from table (ut3.ut.run(a_path, a_reporter)); + return l_results; + end; + function run(a_path varchar2, a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base) return ut3.ut_varchar2_list is + l_results ut3.ut_varchar2_list; + begin + select * bulk collect into l_results from table ( + ut3.ut.run( + a_path, + a_reporter, a_source_files => ut3.ut_varchar2_list(), + a_test_files => a_test_files + )); + return l_results; + end; + function run(a_paths ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base := null) return ut3.ut_varchar2_list is + l_results ut3.ut_varchar2_list; + begin + select * bulk collect into l_results from table (ut3.ut.run(a_paths, a_reporter)); + return l_results; + end; + function run(a_paths ut3.ut_varchar2_list, a_test_files ut3.ut_varchar2_list, a_reporter ut3.ut_reporter_base) return ut3.ut_varchar2_list is + l_results ut3.ut_varchar2_list; + begin + select * bulk collect into l_results from table ( + ut3.ut.run( + a_paths, + a_reporter, a_source_files => ut3.ut_varchar2_list(), + a_test_files => a_test_files + )); + return l_results; + end; + end test_package_1; + ]'; + + execute immediate q'[create or replace package ut3$user#.test_package_2 is + --%suite + --%suitepath(tests.test_package_1) + + --%test + procedure test1; + + --%test + procedure test2; + + end test_package_2; + ]'; + execute immediate q'[create or replace package body ut3$user#.test_package_2 is + procedure test1 is + begin + dbms_output.put_line('test_package_2.test1 executed'); + end; + procedure test2 is + begin + dbms_output.put_line('test_package_2.test2 executed'); + end; + end test_package_2; + ]'; + + execute immediate q'[create or replace package ut3$user#.test_package_3 is + --%suite + --%suitepath(tests2) + + --%test + procedure test1; + + --%test + procedure test2; + + end test_package_3; + ]'; + execute immediate q'[create or replace package body ut3$user#.test_package_3 is + procedure test1 is + begin + dbms_output.put_line('test_package_3.test1 executed'); + end; + procedure test2 is + begin + dbms_output.put_line('test_package_3.test2 executed'); + end; + end test_package_3; + ]'; + end; + + procedure drop_ut3$user#_tests is + pragma autonomous_transaction; + begin + execute immediate q'[drop package ut3$user#.test_package_1]'; + execute immediate q'[drop package ut3$user#.test_package_2]'; + execute immediate q'[drop package ut3$user#.test_package_3]'; + end; + + procedure run_proc_no_params is + l_results clob; + begin + execute immediate 'begin ut3$user#.test_package_1.run(); end;'; + l_results := get_dbms_output_as_clob(); + --Assert + ut.expect( l_results ).to_be_like( '%test_package_1%test_package_2%test_package_3%' ); + end; + + procedure run_proc_specific_reporter is + l_results clob; + begin + --Act + execute immediate 'begin ut3$user#.test_package_1.run(:a_reporter); end;' + using in ut3.ut_documentation_reporter(); + l_results := get_dbms_output_as_clob(); + --Assert + ut.expect( l_results ).to_be_like( '%test_package_1%test_package_2%test_package_3%' ); + end; + + procedure run_proc_cov_file_list is + l_results clob; + begin + --Act + execute immediate 'begin ut3$user#.test_package_1.run(a_test_files=>:a_test_files, a_reporter=>:a_reporter); end;' + using + in ut3.ut_varchar2_list('tests/ut3$user#.test_package_1.pkb','tests/ut3$user#.test_package_2.pkb','tests/ut3$user#.test_package_3.pkb'), + in ut3.ut_sonar_test_reporter(); + l_results := get_dbms_output_as_clob(); + --Assert + ut.expect( l_results ).to_be_like( '%tests/ut3$user#.test_package_2.pkb%tests/ut3$user#.test_package_1.pkb%tests/ut3$user#.test_package_3.pkb%' ); + end; + + procedure run_proc_pkg_name is + l_results clob; + begin + execute immediate 'begin ut3$user#.test_package_1.run(:a_path); end;' + using in 'test_package_1'; + l_results := get_dbms_output_as_clob(); + --Assert + ut.expect( l_results ).to_be_like( '%test_package_1%' ); + ut.expect( l_results ).not_to_be_like( '%test_package_2%' ); + ut.expect( l_results ).not_to_be_like( '%test_package_3%' ); + end; + + procedure run_proc_pkg_name_file_list is + l_results clob; + begin + execute immediate 'begin ut3$user#.test_package_1.run(:a_path, :a_test_files, :a_reporter); end;' + using + in 'test_package_3', + in ut3.ut_varchar2_list('tests/ut3$user#.test_package_1.pkb','tests/ut3$user#.test_package_2.pkb','tests/ut3$user#.test_package_3.pkb'), + in ut3.ut_sonar_test_reporter(); + l_results := get_dbms_output_as_clob(); + --Assert + ut.expect( l_results ).to_be_like( '%tests/ut3$user#.test_package_3.pkb%' ); + ut.expect( l_results ).not_to_be_like( '%tests/ut3$user#.test_package_1.pkb%' ); + ut.expect( l_results ).not_to_be_like( '%tests/ut3$user#.test_package_2.pkb%' ); + end; + + procedure run_proc_path_list is + l_results clob; + begin + execute immediate 'begin ut3$user#.test_package_1.run(:a_paths); end;' + using in ut3.ut_varchar2_list(':tests.test_package_1',':tests'); + l_results := get_dbms_output_as_clob(); + --Assert + ut.expect( l_results ).to_be_like( '%test_package_1%' ); + ut.expect( l_results ).to_be_like( '%test_package_2%' ); + ut.expect( l_results ).not_to_be_like( '%test_package_3%' ); + end; + + procedure run_proc_path_list_file_list is + l_results clob; + begin + execute immediate 'begin ut3$user#.test_package_1.run(:a_paths, :a_test_files, :a_reporter); end;' + using + in ut3.ut_varchar2_list(':tests.test_package_1',':tests'), + in ut3.ut_varchar2_list('tests/ut3$user#.test_package_1.pkb','tests/ut3$user#.test_package_2.pkb','tests/ut3$user#.test_package_3.pkb'), + in ut3.ut_sonar_test_reporter(); + l_results := get_dbms_output_as_clob(); + --Assert + ut.expect( l_results ).to_be_like( '%tests/ut3$user#.test_package_1.pkb%' ); + ut.expect( l_results ).to_be_like( '%tests/ut3$user#.test_package_2.pkb%' ); + ut.expect( l_results ).not_to_be_like( '%tests/ut3$user#.test_package_3.pkb%' ); + end; + + procedure run_proc_null_reporter is + l_results clob; + begin + --Act + execute immediate 'begin ut3$user#.test_package_1.run(:a_reporter); end;' + using in cast(null as ut3.ut_reporter_base); + l_results := get_dbms_output_as_clob(); + --Assert + ut.expect( l_results ).to_be_like( '%tests%test_package_1%test_package_2%tests2%test_package_3%' ); + end; + + procedure run_proc_null_path is + l_results clob; + begin + --Act + execute immediate 'begin ut3$user#.test_package_1.run(:a_path); end;' + using in cast(null as varchar2); + l_results := get_dbms_output_as_clob(); + --Assert + ut.expect( l_results ).to_be_like( '%test_package_1%test_package_2%test_package_3%' ); + end; + + procedure run_proc_null_path_list is + l_results clob; + l_paths ut3.ut_varchar2_list; + begin + --Act + execute immediate 'begin ut3$user#.test_package_1.run(:a_paths); end;' + using in l_paths; + l_results := get_dbms_output_as_clob(); + --Assert + ut.expect( l_results ).to_be_like( '%test_package_1%test_package_2%test_package_3%' ); + end; + + procedure run_proc_empty_path_list is + l_results clob; + begin + --Act + execute immediate 'begin ut3$user#.test_package_1.run(:a_paths); end;' + using in ut3.ut_varchar2_list(); + l_results := get_dbms_output_as_clob(); + --Assert + ut.expect( l_results ).to_be_like( '%test_package_1%test_package_2%test_package_3%' ); + end; + + procedure run_func_no_params is + l_results ut3.ut_varchar2_list; + begin + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(); end;' using out l_results; + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%test_package_1%test_package_2%test_package_3%' ); + end; + + procedure run_func_specific_reporter is + l_results ut3.ut_varchar2_list; + begin + --Act + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(:a_reporter); end;' + using out l_results, in ut3.ut_documentation_reporter(); + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%test_package_1%test_package_2%test_package_3%' ); + end; + + procedure run_func_cov_file_list is + l_results ut3.ut_varchar2_list; + begin + --Act + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(a_test_files=>:a_test_files, a_reporter=>:a_reporter); end;' + using out l_results, + in ut3.ut_varchar2_list('tests/ut3$user#.test_package_1.pkb','tests/ut3$user#.test_package_2.pkb','tests/ut3$user#.test_package_3.pkb'), + in ut3.ut_sonar_test_reporter(); + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%tests/ut3$user#.test_package_2.pkb%tests/ut3$user#.test_package_1.pkb%tests/ut3$user#.test_package_3.pkb%' ); + end; + + procedure run_func_pkg_name is + l_results ut3.ut_varchar2_list; + begin + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(:a_path); end;' + using out l_results, in 'test_package_1'; + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%test_package_bal%' ); + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).not_to_be_like( '%test_package_2%' ); + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).not_to_be_like( '%test_package_3%' ); + end; + + procedure run_func_pkg_name_file_list is + l_results ut3.ut_varchar2_list; + begin + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(:a_path, :a_test_files, :a_reporter); end;' + using out l_results, + in 'test_package_3', + in ut3.ut_varchar2_list('tests/ut3$user#.test_package_1.pkb','tests/ut3$user#.test_package_2.pkb','tests/ut3$user#.test_package_3.pkb'), + in ut3.ut_sonar_test_reporter(); + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%tests/ut3$user#.test_package_3.pkb%' ); + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).not_to_be_like( '%tests/ut3$user#.test_package_1.pkb%' ); + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).not_to_be_like( '%tests/ut3$user#.test_package_2.pkb%' ); + end; + + procedure run_func_path_list is + l_results ut3.ut_varchar2_list; + begin + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(:a_paths); end;' + using out l_results, in ut3.ut_varchar2_list(':tests.test_package_1',':tests'); + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%test_package_1%' ); + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%test_package_2%' ); + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).not_to_be_like( '%test_package_3%' ); + end; + + procedure run_func_path_list_file_list is + l_results ut3.ut_varchar2_list; + begin + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(:a_paths, :a_test_files, :a_reporter); end;' + using out l_results, + in ut3.ut_varchar2_list(':tests.test_package_1',':tests'), + in ut3.ut_varchar2_list('tests/ut3$user#.test_package_1.pkb','tests/ut3$user#.test_package_2.pkb','tests/ut3$user#.test_package_3.pkb'), + in ut3.ut_sonar_test_reporter(); + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%tests/ut3$user#.test_package_1.pkb%' ); + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%tests/ut3$user#.test_package_2.pkb%' ); + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).not_to_be_like( '%tests/ut3$user#.test_package_3.pkb%' ); + end; + + procedure run_func_null_reporter is + l_results ut3.ut_varchar2_list; + begin + --Act + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(:a_reporter); end;' + using out l_results, in cast(null as ut3.ut_reporter_base); + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%tests%test_package_1%test_package_2%tests2%test_package_3%' ); + end; + + procedure run_func_null_path is + l_results ut3.ut_varchar2_list; + begin + --Act + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(:a_path); end;' + using out l_results, in cast(null as varchar2); + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%test_package_1%test_package_2%test_package_3%' ); + end; + + procedure run_func_null_path_list is + l_results ut3.ut_varchar2_list; + l_paths ut3.ut_varchar2_list; + begin + --Act + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(:a_paths); end;' + using out l_results, in l_paths; + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%test_package_1%test_package_2%test_package_3%' ); + end; + + procedure run_func_empty_path_list is + l_results ut3.ut_varchar2_list; + begin + --Act + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(:a_paths); end;' + using out l_results, in ut3.ut_varchar2_list(); + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%test_package_1%test_package_2%test_package_3%' ); + end; + + procedure run_func_cov_file_lst_null_rep is + l_results ut3.ut_varchar2_list; + begin + --Act + execute immediate 'begin :l_results := ut3$user#.test_package_1.run(a_test_files=>:a_test_files, a_reporter=>:a_reporter); end;' + using out l_results, + in ut3.ut_varchar2_list('tests/ut3$user#.test_package_1.pkb','tests/ut3$user#.test_package_2.pkb','tests/ut3$user#.test_package_3.pkb'), + in cast(null as ut3.ut_reporter_base); + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( '%test_package_1%test_package_2%test_package_3%' ); + end; + + procedure run_func_empty_suite is + l_results ut3.ut_varchar2_list; + l_expected varchar2(32767); + pragma autonomous_transaction; + begin + --Arrange + execute immediate q'[create or replace package empty_suite as + -- %suite + + procedure not_a_test; + end;]'; + execute immediate q'[create or replace package body empty_suite as + procedure not_a_test is begin null; end; + end;]'; + l_expected := '%empty_suite%0 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%'; + --Act + select * bulk collect into l_results from table(ut3.ut.run('empty_suite')); + + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( l_expected ); + + --Cleanup + execute immediate q'[drop package empty_suite]'; + end; + procedure create_test_suite is pragma autonomous_transaction; begin @@ -14,37 +527,22 @@ create or replace package body test_ut_run is --%suitepath(test_state) --%test - procedure stateful_success; - - --%test - --%beforetest(recompile_in_background) + --%beforetest(acquire_state,recompile_in_background) procedure failing_stateful_test; procedure recompile_in_background; - - --%test - procedure dummy_success; + procedure acquire_state; end; ]'; execute immediate q'{ create or replace package body test_stateful as - procedure stateful_success is - begin - ut3.ut.expect(stateful_package.g_state).to_equal('A'); - end; - procedure failing_stateful_test is begin ut3.ut.expect(stateful_package.g_state).to_equal('abc'); end; - procedure dummy_success is - begin - ut3.ut.expect(1).to_equal(1); - end; - procedure recompile_in_background is l_job_name varchar2(30) := 'recreate_stateful_package'; l_cnt integer := 1; @@ -60,18 +558,22 @@ create or replace package body test_ut_run is g_state varchar2(3) := 'abc'; end;]'; end;/', - start_date => sysdate, + start_date => localtimestamp, enabled => TRUE, auto_drop => TRUE, comments => 'one-time job' ); - dbms_lock.sleep(0.2); + dbms_lock.sleep(1); while l_cnt > 0 loop select count(1) into l_cnt from dba_scheduler_running_jobs srj where srj.job_name = l_job_name; end loop; end; + procedure acquire_state is + begin + dbms_output.put_line('stateful_package.g_state='||stateful_package.g_state); + end; end; }'; @@ -84,21 +586,21 @@ create or replace package body test_ut_run is --Arrange l_expected := 'test_state test_stateful - stateful_success [% sec] - failing_stateful_test [% sec] (FAILED - 1) - dummy_success [% sec]% + failing_stateful_test [% sec] (FAILED - 1)% Failures:% 1) failing_stateful_test ORA-04061: existing state of package "UT3_TESTER.STATEFUL_PACKAGE" has been invalidated ORA-04065: not executed, altered or dropped package "UT3_TESTER.STATEFUL_PACKAGE" ORA-06508: PL/SQL: could not find program unit being called: "UT3_TESTER.STATEFUL_PACKAGE" - ORA-06512: at "UT3_TESTER.TEST_STATEFUL", line 10% + ORA-06512: at "UT3_TESTER.TEST_STATEFUL", line 5% ORA-06512: at line 6% -3 tests, 0 failed, 1 errored, 0 disabled, 0 warning(s)%'; +1 tests, 0 failed, 1 errored, 0 disabled, 0 warning(s)%'; --Act select * bulk collect into l_results from table(ut3.ut.run('test_stateful')); + --Assert + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( l_expected ); ut.fail('Expected exception but nothing was raised'); exception when others then @@ -113,5 +615,110 @@ Failures:% execute immediate 'drop package test_stateful'; end; + procedure run_in_invalid_state is + l_results ut3.ut_varchar2_list; + l_actual clob; + l_expected varchar2(32767); + begin + select * bulk collect into l_results from table(ut3.ut.run('failing_invalid_spec')); + + l_actual := ut3.ut_utils.table_to_clob(l_results); + ut.expect(l_actual).to_be_like('%Call params for % are not valid: package does not exist or is invalid: %FAILING_INVALID_SPEC%'); + + end; + + procedure compile_invalid_package is + ex_compilation_error exception; + pragma exception_init(ex_compilation_error,-24344); + pragma autonomous_transaction; + begin + begin + execute immediate q'[ + create or replace package failing_invalid_spec as + --%suite + gv_glob_val non_existing_table.id%type := 0; + + --%test + procedure test1; + end;]'; + exception when ex_compilation_error then null; + end; + begin + execute immediate q'[ + create or replace package body failing_invalid_spec as + procedure test1 is begin ut.expect(1).to_equal(1); end; + end;]'; + exception when ex_compilation_error then null; + end; + end; + procedure drop_invalid_package is + pragma autonomous_transaction; + begin + execute immediate 'drop package failing_invalid_spec'; + end; + + procedure run_and_revalidate_specs is + l_results ut3.ut_varchar2_list; + l_actual clob; + l_is_invalid number; + begin + execute immediate q'[select count(1) from all_objects o where o.owner = :object_owner and o.object_type = 'PACKAGE' + and o.status = 'INVALID' and o.object_name= :object_name]' into l_is_invalid + using user,'INVALID_PCKAG_THAT_REVALIDATES'; + + select * bulk collect into l_results from table(ut3.ut.run('invalid_pckag_that_revalidates')); + + l_actual := ut3.ut_utils.table_to_clob(l_results); + ut.expect(1).to_equal(l_is_invalid); + ut.expect(l_actual).to_be_like('%invalid_pckag_that_revalidates%invalidspecs [% sec]% +%Finished in % seconds% +%1 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%'); + + end; + + procedure generate_invalid_spec is + ex_compilation_error exception; + pragma exception_init(ex_compilation_error,-24344); + pragma autonomous_transaction; + begin + + execute immediate q'[ + create or replace package parent_specs as + c_test constant varchar2(1) := 'Y'; + end;]'; + + execute immediate q'[ + create or replace package invalid_pckag_that_revalidates as + --%suite + g_var varchar2(1) := parent_specs.c_test; + + --%test(invalidspecs) + procedure test1; + end;]'; + + execute immediate q'[ + create or replace package body invalid_pckag_that_revalidates as + procedure test1 is begin ut.expect('Y').to_equal(g_var); end; + end;]'; + + -- That should invalidate test package and we can then revers + execute immediate q'[ + create or replace package parent_specs as + c_test_error constant varchar2(1) := 'Y'; + end;]'; + + execute immediate q'[ + create or replace package parent_specs as + c_test constant varchar2(1) := 'Y'; + end;]'; + + end; + procedure drop_invalid_spec is + pragma autonomous_transaction; + begin + execute immediate 'drop package invalid_pckag_that_revalidates'; + execute immediate 'drop package parent_specs'; + end; + end; / diff --git a/test/api/test_ut_run.pks b/test/api/test_ut_run.pks index 1bc3555a4..cd4a78ff3 100644 --- a/test/api/test_ut_run.pks +++ b/test/api/test_ut_run.pks @@ -1,12 +1,106 @@ create or replace package test_ut_run is - --%suite(ut_run) + --%suite(ut.run) + --%suitepath(utplsql.api) + + + --%test(ut.version() returns version of the framework) + procedure ut_version; + + --%test(ut.fail() marks test as failed) + procedure ut_fail; + + procedure create_ut3$user#_tests; + procedure drop_ut3$user#_tests; + + --%context(ut_run_procedure) + --%displayname(ut.run() procedure options) + --%beforeall(create_ut3$user#_tests) + --%afterall(drop_ut3$user#_tests) + + --%test(Runs all tests in current schema with default reporter when no parameters given) + procedure run_proc_no_params; + --%test(Runs all tests in current schema with specified reporter) + procedure run_proc_specific_reporter; + --%test(Runs all tests in current schema with coverage file list) + procedure run_proc_cov_file_list; + + --%disabled(TODO - currently it executes the package and all child packages) + --%test(Runs given package only with package name given as path) + procedure run_proc_pkg_name; + --%test(Runs all from given package with package name given as path and coverage file list) + procedure run_proc_pkg_name_file_list; + --%test(Runs tests from given paths only with paths list) + procedure run_proc_path_list; + --%test(Runs tests from given paths only with paths list and coverage file list) + procedure run_proc_path_list_file_list; + --%test(Runs all tests in current schema using default reporter when null reporter given) + procedure run_proc_null_reporter; + --%test(Runs all tests in current schema with null path provided) + procedure run_proc_null_path; + --%test(Runs all tests in current schema with null path list given) + procedure run_proc_null_path_list; + --%test(Runs all tests in current schema with empty path list given) + procedure run_proc_empty_path_list; + + --%endcontext - procedure create_test_suite; - procedure drop_test_suite; + + --%context(ut_run_function) + --%displayname(ut.run() function options) + --%beforeall(create_ut3$user#_tests) + --%afterall(drop_ut3$user#_tests) + + --%test(Runs all tests in current schema with default reporter when no parameters given) + procedure run_func_no_params; + --%test(Runs all tests in current schema with specified reporter) + procedure run_func_specific_reporter; + --%test(Runs all tests in current schema with coverage file list) + procedure run_func_cov_file_list; + + --%disabled(TODO - currently it executes the package and all child packages) + --%test(Runs given package only with package name given as path) + procedure run_func_pkg_name; + --%test(Runs all from given package with package name given as path and coverage file list) + procedure run_func_pkg_name_file_list; + --%test(Runs tests from given paths with paths list) + procedure run_func_path_list; + --%test(Runs tests from given paths with paths list and coverage file list) + procedure run_func_path_list_file_list; + --%test(Runs all tests in current schema using default reporter when null reporter given) + procedure run_func_null_reporter; + --%test(Runs all tests in current schema with null path provided) + procedure run_func_null_path; + --%test(Runs all tests in current schema with null path list given) + procedure run_func_null_path_list; + --%test(Runs all tests in current schema with empty path list given) + procedure run_func_empty_path_list; + --%test(Runs all tests in current schema with coverage file list and default reporter) + procedure run_func_cov_file_lst_null_rep; + --%test(Executes successfully an empty suite) + procedure run_func_empty_suite; --%test(ut.run - raises after completing all tests if a test fails with ORA-04068 or ORA-04061) --%beforetest(create_test_suite) --%aftertest(drop_test_suite) procedure raise_in_invalid_state; + procedure create_test_suite; + procedure drop_test_suite; + + --%test(ut.run - Does not execute suite when specified package is not valid) + --%beforetest(compile_invalid_package) + --%aftertest(drop_invalid_package) + procedure run_in_invalid_state; + procedure compile_invalid_package; + procedure drop_invalid_package; + + --%test(Invalidate package specs via rebuild but still execute package) + --%beforetest(generate_invalid_spec) + --%aftertest(drop_invalid_spec) + procedure run_and_revalidate_specs; + procedure generate_invalid_spec; + procedure drop_invalid_spec; + + --%endcontext + end; / diff --git a/test/api/test_ut_runner.pkb b/test/api/test_ut_runner.pkb index e957d3719..3a8f6f670 100644 --- a/test/api/test_ut_runner.pkb +++ b/test/api/test_ut_runner.pkb @@ -180,25 +180,35 @@ end;'; procedure run_keep_dbms_output_buffer is l_expected dbmsoutput_linesarray; l_actual dbmsoutput_linesarray; - l_lines number := 100; + l_results ut3.ut_varchar2_list; + l_lines number := 10000; begin --Arrange create_test_spec(); create_test_body(0); + l_expected := dbmsoutput_linesarray( 'A text placed into DBMS_OUTPUT', 'Another line', lpad('A very long line',10000,'a') ); - dbms_output.put_line(l_expected(1)); - dbms_output.put_line(l_expected(2)); - dbms_output.put_line(l_expected(3)); + for i in 1 .. 300 loop + l_expected.extend; + l_expected(l_expected.last) := 'line '||i; + end loop; + + for i in 1 .. l_expected.count loop + dbms_output.put_line(l_expected(i)); + end loop; + --Act - ut3.ut.run('test_cache'); + select * + bulk collect into l_results + from table(ut3.ut.run('test_cache')); --Assert dbms_output.get_lines(lines => l_actual, numlines => l_lines); - for i in 1 .. l_expected.count loop + for i in 1 .. l_lines loop ut.expect(l_actual(i)).to_equal(l_expected(i)); end loop; drop_test_package(); @@ -351,5 +361,175 @@ end;'; ut.expect(dbms_utility.format_error_stack||dbms_utility.format_error_backtrace).not_to_be_like('%ORA-02055%'); end; + procedure create_test_csl_packages is + pragma autonomous_transaction; + begin + execute immediate q'[ + create or replace package test_csl_names1 as + --%suite + --%suitepath(test_csl_names) + + --%test + procedure one_is_one; + + --%test + procedure two_is_two; + + end; + ]'; + + execute immediate q'{ + create or replace package body test_csl_names1 as + + procedure one_is_one is + begin + ut3.ut.expect(1).to_equal(1); + end; + + procedure two_is_two is + begin + ut3.ut.expect(2).to_equal(2); + end; + + end; + }'; + + execute immediate q'[ + create or replace package test_csl_names2 as + --%suite + --%suitepath(test_csl_names) + + --%test + procedure one_is_one; + + --%test + procedure two_is_two; + + end; + ]'; + + execute immediate q'{ + create or replace package body test_csl_names2 as + + procedure one_is_one is + begin + ut3.ut.expect(1).to_equal(1); + end; + + procedure two_is_two is + begin + ut3.ut.expect(2).to_equal(2); + end; + + end; + }'; + + end; + + procedure drop_test_csl_packages is + pragma autonomous_transaction; + begin + execute immediate 'drop package test_csl_names1'; + execute immediate 'drop package test_csl_names2'; + end; + + procedure pass_varchar2_name_list is + l_results ut3.ut_varchar2_list; + l_actual clob; + begin + select * + bulk collect into l_results + from table(ut3.ut.run(ut3.ut_varchar2_list('test_csl_names1','test_csl_names2'))); + + l_actual := ut3.ut_utils.table_to_clob(l_results); + ut.expect(l_actual).to_be_like('%Finished in % seconds +%4 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%'); + end; + + procedure pass_varchar2_name is + l_results ut3.ut_varchar2_list; + l_actual clob; + begin + select * + bulk collect into l_results + from table(ut3.ut.run('test_csl_names1')); + + l_actual := ut3.ut_utils.table_to_clob(l_results); + ut.expect(l_actual).to_be_like('%Finished in % seconds +%2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%'); + end; + + procedure pass_varchar2_suite_csl is + l_results ut3.ut_varchar2_list; + l_actual clob; + begin + select * + bulk collect into l_results + from table(ut3.ut.run('test_csl_names1,test_csl_names2')); + + l_actual := ut3.ut_utils.table_to_clob(l_results); + ut.expect(l_actual).to_be_like('%Finished in % seconds +%4 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%'); + end; + + procedure pass_varchar2_test_csl is + l_results ut3.ut_varchar2_list; + l_actual clob; + begin + select * + bulk collect into l_results + from table(ut3.ut.run('test_csl_names1.one_is_one,test_csl_names2.one_is_one')); + + l_actual := ut3.ut_utils.table_to_clob(l_results); + ut.expect(l_actual).to_be_like('%Finished in % seconds +%2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%'); + end; + + procedure pass_varch_test_csl_spc is + l_results ut3.ut_varchar2_list; + l_actual clob; + begin + select * + bulk collect into l_results + from table(ut3.ut.run('test_csl_names1.one_is_one, test_csl_names2.one_is_one')); + + l_actual := ut3.ut_utils.table_to_clob(l_results); + ut.expect(l_actual).to_be_like('%Finished in % seconds +%2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%'); + end; + + procedure pass_csl_with_srcfile is + l_results ut3.ut_varchar2_list; + l_actual clob; + begin + + select * + bulk collect into l_results + from table( + ut3.ut.run( + a_path => 'test_csl_names1.one_is_one,test_csl_names2.one_is_one', + a_source_files => ut3.ut_varchar2_list('ut3.ut'), + a_test_files => ut3.ut_varchar2_list('ut3_tester.test_csl_names2') + ) + ); + + l_actual := ut3.ut_utils.table_to_clob(l_results); + ut.expect(l_actual).to_be_like('%Finished in % seconds +%2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%'); + end; + + procedure pass_csl_within_var2list is + l_results ut3.ut_varchar2_list; + l_actual clob; + begin + select * + bulk collect into l_results + from table(ut3.ut.run(ut3.ut_varchar2_list('test_csl_names1.one_is_one,test_csl_names2.one_is_one'))); + + l_actual := ut3.ut_utils.table_to_clob(l_results); + ut.expect(l_actual).to_be_like('%Finished in % seconds +%2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%'); + end; + end; / diff --git a/test/api/test_ut_runner.pks b/test/api/test_ut_runner.pks index 7b22fd4f1..74c93dbae 100644 --- a/test/api/test_ut_runner.pks +++ b/test/api/test_ut_runner.pks @@ -61,5 +61,35 @@ create or replace package test_ut_runner is --%aftertest(db_link_cleanup) procedure raises_20213_on_fail_link; + procedure create_test_csl_packages; + procedure drop_test_csl_packages; + + --%context(ut_run_coma_sep_list) + --%beforeall(create_test_csl_packages) + --%afterall(drop_test_csl_packages) + + --%test( Pass name of tests as varchar2_list ) + procedure pass_varchar2_name_list; + + --%test( Pass single test name as varchar2 ) + procedure pass_varchar2_name; + + --%test( Pass coma separated list of suite names ) + procedure pass_varchar2_suite_csl; + + --%test( Pass coma separated list of test names ) + procedure pass_varchar2_test_csl; + + --%test( Pass coma separated list of test names with spaces ) + procedure pass_varch_test_csl_spc; + + --%test( Pass coma separated list and source and test files ) + procedure pass_csl_with_srcfile; + + --%test( Pass coma separated list in varchar2list ) + procedure pass_csl_within_var2list; + + --%endcontext + end; / diff --git a/test/core/annotations/test_annot_throws_exception.pkb b/test/core/annotations/test_annot_throws_exception.pkb index 26dbc6613..2c8c3be2c 100644 --- a/test/core/annotations/test_annot_throws_exception.pkb +++ b/test/core/annotations/test_annot_throws_exception.pkb @@ -7,8 +7,25 @@ is l_package_spec varchar2(32737); l_package_body varchar2(32737); + l_exception_spec varchar2(32737); l_test_results ut3.ut_varchar2_list; begin + l_exception_spec := q'[ + create or replace package exc_pkg is + c_e_single_exc constant number := -20200; + c_e_dummy constant varchar2(10) := 'dummy'; + c_e_varch_exc constant varchar2(10) := '-20201'; + c_e_list_1 number := -20202; + c_e_list_2 constant number := -20203; + c_e_diff_exc constant number := -20204; + c_e_mix_list constant number := -20205; + c_e_mix_missin constant number := -20206; + + e_some_exception exception; + pragma exception_init(e_some_exception, -20207); + + end;]'; + l_package_spec := ' create package annotated_package_with_throws is --%suite(Dummy package to test annotation throws) @@ -45,9 +62,58 @@ is --%throws(7894562, operaqk, -=1, -1, pow74d, posdfk3) procedure one_valid_exception_number; - --%test(Givess failure when a exception is expected and nothing is thrown) + --%test(Gives failure when a exception is expected and nothing is thrown) --%throws(-20459, -20136, -20145) procedure nothing_thrown; + + --%test(Single exception defined as a constant number in package) + --%throws(exc_pkg.c_e_single_exc) + procedure single_exc_const_pkg; + + --%test(Gives success when one of annotated exception using constant is thrown) + --%throws(exc_pkg.c_e_list_1,exc_pkg.c_e_list_2) + procedure list_of_exc_constant; + + --%test(Gives failure when the raised exception is different that the annotated one using variable) + --%throws(exc_pkg.c_e_diff_exc) + procedure fail_not_match_exc; + + --%test(Success when one of exception from mixed list of number and constant is thrown) + --%throws(exc_pkg.c_e_mix_list,-20105) + procedure mixed_exc_list; + + --%test(Success when match exception even if other variable on list dont exists) + --%throws(exc_pkg.c_e_mix_missin,utter_rubbish) + procedure mixed_list_notexi; + + --%test(Success resolve and match named exception defined in pragma exception init) + --%throws(exc_pkg.e_some_exception) + procedure named_exc_pragma; + + --%test(Success resolve and match oracle named exception) + --%throws(NO_DATA_FOUND) + procedure named_exc_ora; + + --%test(Success resolve and match oracle named exception dup val index) + --%throws(DUP_VAL_ON_INDEX) + procedure named_exc_ora_dup_ind; + + --%test(Success map no data 100 to -1403) + --%throws(-1403) + procedure nodata_exc_ora; + + --%test(Success for exception defined as varchar) + --%throws(exc_pkg.c_e_varch_exc) + procedure defined_varchar_exc; + + --%test(Non existing constant exception) + --%throws(dummy.c_dummy); + procedure non_existing_const; + + --%test(Bad exception constant) + --%throws(exc_pkg.c_e_dummy); + procedure bad_exc_const; + end; '; @@ -98,12 +164,75 @@ is begin null; end; + + procedure single_exc_const_pkg is + begin + raise_application_error(exc_pkg.c_e_single_exc,''Test''); + end; + + procedure list_of_exc_constant is + begin + raise_application_error(exc_pkg.c_e_list_1,''Test''); + end; + + procedure fail_not_match_exc is + begin + raise NO_DATA_FOUND; + end; + + procedure mixed_exc_list is + begin + raise_application_error(exc_pkg.c_e_mix_list,''Test''); + end; + + procedure mixed_list_notexi is + begin + raise_application_error(exc_pkg.c_e_mix_missin,''Test''); + end; + + procedure named_exc_pragma is + begin + raise exc_pkg.e_some_exception; + end; + + procedure named_exc_ora is + begin + raise NO_DATA_FOUND; + end; + + procedure named_exc_ora_dup_ind is + begin + raise DUP_VAL_ON_INDEX; + end; + + procedure nodata_exc_ora is + begin + raise NO_DATA_FOUND; + end; + + procedure defined_varchar_exc is + begin + raise_application_error(exc_pkg.c_e_varch_exc,''Test''); + end; + + procedure non_existing_const is + begin + raise_application_error(-20143, ''Test error''); + end; + + procedure bad_exc_const is + begin + raise_application_error(-20143, ''Test error''); + end; + end; '; + execute immediate l_exception_spec; execute immediate l_package_spec; execute immediate l_package_body; + select * bulk collect into l_test_results from table(ut3.ut.run(('annotated_package_with_throws'))); g_tests_results := ut3.ut_utils.table_to_clob(l_test_results); @@ -159,15 +288,87 @@ is procedure nothing_thrown is begin - ut.expect(g_tests_results).to_match('^\s*Givess failure when a exception is expected and nothing is thrown \[[\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); + ut.expect(g_tests_results).to_match('^\s*Gives failure when a exception is expected and nothing is thrown \[[\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); ut.expect(g_tests_results).to_match('nothing_thrown\s*Expected one of exceptions \(-20459, -20136, -20145\) but nothing was raised.'); end; + procedure single_exc_const_pkg is + begin + ut.expect(g_tests_results).to_match('^\s*Single exception defined as a constant number in package \[[\.0-9]+ sec\]\s*$','m'); + ut.expect(g_tests_results).not_to_match('single_exc_const_pkg'); + end; + + procedure list_of_exc_constant is + begin + ut.expect(g_tests_results).to_match('^\s*Gives success when one of annotated exception using constant is thrown \[[\.0-9]+ sec\]\s*$','m'); + ut.expect(g_tests_results).not_to_match('list_of_exc_constant'); + end; + + procedure fail_not_match_exc is + begin + ut.expect(g_tests_results).to_match('^\s*Gives failure when the raised exception is different that the annotated one using variable \[[\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); + ut.expect(g_tests_results).to_match('fail_not_match_exc\s+Actual: -1403 was expected to equal: -20204\s+ORA-01403: no data found\s+ORA-06512: at "UT3_TESTER.ANNOTATED_PACKAGE_WITH_THROWS"'); + end; + + procedure mixed_exc_list is + begin + ut.expect(g_tests_results).to_match('^\s*Success when one of exception from mixed list of number and constant is thrown \[[\.0-9]+ sec\]\s*$','m'); + ut.expect(g_tests_results).not_to_match('mixed_exc_list'); + end; + + procedure mixed_list_notexi is + begin + ut.expect(g_tests_results).to_match('^\s*Success when match exception even if other variable on list dont exists \[[\.0-9]+ sec\]\s*$','m'); + ut.expect(g_tests_results).not_to_match('mixed_list_notexi'); + end; + procedure named_exc_pragma is + begin + ut.expect(g_tests_results).to_match('^\s*Success resolve and match named exception defined in pragma exception init \[[\.0-9]+ sec\]\s*$','m'); + ut.expect(g_tests_results).not_to_match('mixed_list_notexi'); + end; + + procedure named_exc_ora is + begin + ut.expect(g_tests_results).to_match('^\s*Success resolve and match oracle named exception \[[\.0-9]+ sec\]\s*$','m'); + ut.expect(g_tests_results).not_to_match('named_exc_ora'); + end; + + procedure named_exc_ora_dup_ind is + begin + ut.expect(g_tests_results).to_match('^\s*Success resolve and match oracle named exception dup val index \[[\.0-9]+ sec\]\s*$','m'); + ut.expect(g_tests_results).not_to_match('named_exc_ora_dup_ind'); + end; + + procedure nodata_exc_ora is + begin + ut.expect(g_tests_results).to_match('^\s*Success map no data 100 to -1403 \[[\.0-9]+ sec\]\s*$','m'); + ut.expect(g_tests_results).not_to_match('nodata_exc_ora'); + end; + + procedure defined_varchar_exc is + begin + ut.expect(g_tests_results).to_match('^\s*Success for exception defined as varchar \[[\.0-9]+ sec\]\s*$','m'); + ut.expect(g_tests_results).not_to_match('defined_varchar_exc'); + end; + + procedure non_existing_const is + begin + ut.expect(g_tests_results).to_match('^\s*Non existing constant exception \[[\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); + ut.expect(g_tests_results).to_match('non_existing_const\s*ORA-20143: Test error\s*ORA-06512: at "UT3_TESTER.ANNOTATED_PACKAGE_WITH_THROWS"'); + end; + + procedure bad_exc_const is + begin + ut.expect(g_tests_results).to_match('^\s*Bad exception constant \[[\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); + ut.expect(g_tests_results).to_match('bad_exc_const\s*ORA-20143: Test error\s*ORA-06512: at "UT3_TESTER.ANNOTATED_PACKAGE_WITH_THROWS"'); + end; + procedure drop_test_package is pragma autonomous_transaction; begin execute immediate 'drop package annotated_package_with_throws'; + execute immediate 'drop package exc_pkg'; end; end; diff --git a/test/core/annotations/test_annot_throws_exception.pks b/test/core/annotations/test_annot_throws_exception.pks index 272f89252..54e814b55 100644 --- a/test/core/annotations/test_annot_throws_exception.pks +++ b/test/core/annotations/test_annot_throws_exception.pks @@ -30,9 +30,45 @@ is --%test(Detects a valid exception number within many invalid ones) procedure one_valid_exception_number; - --%test(Givess failure when a exception is expected and nothing is thrown) + --%test(Gives failure when a exception is expected and nothing is thrown) procedure nothing_thrown; + --%test(Single exception defined as a constant number in package) + procedure single_exc_const_pkg; + + --%test(Gives success when one of annotated exception using constant is thrown) + procedure list_of_exc_constant; + + --%test(Gives failure when the raised exception is different that the annotated one using variable) + procedure fail_not_match_exc; + + --%test(Success when one of exception from mixed list of number and constant is thrown) + procedure mixed_exc_list; + + --%test(Success when match exception even if other variable on list dont exists) + procedure mixed_list_notexi; + + --%test(Success resolve and match named exception defined in pragma exception init) + procedure named_exc_pragma; + + --%test(Success resolve and match oracle named exception no data) + procedure named_exc_ora; + + --%test(Success resolve and match oracle named exception dup val index) + procedure named_exc_ora_dup_ind; + + --%test(Success map no data 100 to -1403) + procedure nodata_exc_ora; + + --%test(Success for exception defined as varchar) + procedure defined_varchar_exc; + + --%test(Non existing constant exception) + procedure non_existing_const; + + --%test(Bad exception constant) + procedure bad_exc_const; + --%afterall procedure drop_test_package; diff --git a/test/core/annotations/test_before_after_test_annotation.pkb b/test/core/annotations/test_before_after_test_annotation.pkb new file mode 100644 index 000000000..06871a335 --- /dev/null +++ b/test/core/annotations/test_before_after_test_annotation.pkb @@ -0,0 +1,311 @@ +create or replace package body test_before_after_annotations is + + type t_executed_procedures is table of t_procedures index by t_procedure_name; + g_tests_results clob; + g_executed_procedures t_executed_procedures; + + + procedure set_procs_called(a_for_procedure t_procedure_name, a_procedures t_procedures) is + begin + g_executed_procedures(a_for_procedure) := a_procedures; + end; + + function get_procs_called(a_for_procedure varchar2) return t_procedures pipelined is + begin + if g_executed_procedures.exists(a_for_procedure) then + for i in 1 .. g_executed_procedures(a_for_procedure).count loop + pipe row (g_executed_procedures(a_for_procedure)(i)); + end loop; + end if; + return; + end; + + procedure create_tests_results is + pragma autonomous_transaction; + + + l_dummy_utility_pkg_spec varchar2(32737); + l_dummy_utility_pkg_body varchar2(32737); + l_test_package_spec varchar2(32737); + l_test_package_body varchar2(32737); + l_test_results ut3.ut_varchar2_list; + + begin + l_dummy_utility_pkg_spec := q'[ + create or replace package shared_test_package is + + procedure before_test; + + procedure set_proc_called(a_procedure_name varchar2); + + function get_procs_called return test_before_after_annotations.t_procedures; + + procedure reset_proc_called; + + end; + ]'; + + l_dummy_utility_pkg_body := q'[ + create or replace package body shared_test_package is + + g_called_procedures test_before_after_annotations.t_procedures := test_before_after_annotations.t_procedures(); + + procedure set_proc_called(a_procedure_name varchar2) is + begin + g_called_procedures.extend; + g_called_procedures(g_called_procedures.last) := a_procedure_name; + end; + + function get_procs_called return test_before_after_annotations.t_procedures is + begin + return g_called_procedures; + end; + + procedure reset_proc_called is + begin + g_called_procedures.delete; + end; + + procedure before_test is + begin + set_proc_called('shared_test_package.before_test'); + end; + + end; + ]'; + + l_test_package_spec := q'[ + create or replace package dummy_before_after_test is + --%suite(Package to test annotations beforetest and aftertest) + + --%aftereach + procedure clean_global_variables; + + --%test(Executes Beforetest call to procedure inside package) + --%beforetest(before_test) + procedure beforetest_local_procedure; + + --%test(Executes beforetest procedure defined in the package when specified with package name) + --%beforetest(dummy_before_after_test.before_test) + procedure beforetest_local_proc_with_pkg; + + --%test(Executes Beforetest procedure twice when defined twice) + --%beforetest(before_test, before_test) + procedure beforetest_twice; + + --%test(Executes Beforetest procedure from external package) + --%beforetest(shared_test_package.before_test) + procedure beforetest_one_ext_procedure; + + --%test(Executed external and internal Beforetest procedures) + --%beforetest(shared_test_package.before_test, before_test) + procedure beforetest_multi_ext_procedure; + + --%test(Stops execution at first non-existing Beforetest procedure and marks test as errored) + --%beforetest(shared_test_package.before_test, non_existent_procedure, before_test) + procedure beforetest_missing_procedure; + + --%test(Stops execution at first erroring Beforetest procedure and marks test as errored) + --%beforetest(shared_test_package.before_test, before_test_erroring, before_test) + procedure beforetest_one_err_procedure; + + procedure before_test; + + procedure before_test_erroring; + + end; + ]'; + + l_test_package_body := q'[ + create or replace package body dummy_before_after_test is + + procedure clean_global_variables is + begin + shared_test_package.reset_proc_called; + end; + + procedure beforetest_local_procedure is + begin + test_before_after_annotations.set_procs_called( + 'beforetest_local_procedure', + shared_test_package.get_procs_called() + ); + end; + + procedure beforetest_local_proc_with_pkg is + begin + test_before_after_annotations.set_procs_called( + 'beforetest_local_proc_with_pkg', + shared_test_package.get_procs_called() + ); + end; + + procedure beforetest_twice is + begin + test_before_after_annotations.set_procs_called( + 'beforetest_twice', + shared_test_package.get_procs_called() + ); + end; + + procedure beforetest_one_ext_procedure is + begin + test_before_after_annotations.set_procs_called( + 'beforetest_one_ext_procedure', + shared_test_package.get_procs_called() + ); + end; + + procedure beforetest_multi_ext_procedure is + begin + test_before_after_annotations.set_procs_called( + 'beforetest_multi_ext_procedure', + shared_test_package.get_procs_called() + ); + end; + + procedure beforetest_missing_procedure is + begin + test_before_after_annotations.set_procs_called( + 'beforetest_missing_procedure', + shared_test_package.get_procs_called() + ); + end; + + procedure beforetest_one_err_procedure is + begin + test_before_after_annotations.set_procs_called( + 'beforetest_one_err_procedure', + shared_test_package.get_procs_called() + ); + end; + + procedure before_test is + begin + shared_test_package.set_proc_called('dummy_before_after_test.before_test'); + end; + + procedure before_test_erroring is + begin + shared_test_package.set_proc_called('dummy_before_after_test.before_test_erroring'); + raise program_error; + end; + + end; + ]'; + + execute immediate l_dummy_utility_pkg_spec; + execute immediate l_dummy_utility_pkg_body; + execute immediate l_test_package_spec; + execute immediate l_test_package_body; + + --Execute the tests and collect the results + select * bulk collect into l_test_results from table(ut3.ut.run(('dummy_before_after_test'))); + + execute immediate 'drop package dummy_before_after_test'; + execute immediate 'drop package shared_test_package'; + + g_tests_results := ut3.ut_utils.table_to_clob(l_test_results); + end; + + procedure beforetest_local_procedure is + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + open l_expected for + select 'dummy_before_after_test.before_test' as column_value from dual; + open l_actual for + select * from table(test_before_after_annotations.get_procs_called('beforetest_local_procedure')); + ut.expect(l_actual).to_equal(l_expected); + end; + + procedure beforetest_local_proc_with_pkg is + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + open l_expected for + select 'dummy_before_after_test.before_test' as column_value from dual; + open l_actual for + select * from table(test_before_after_annotations.get_procs_called('beforetest_local_procedure')); + ut.expect(l_actual).to_equal(l_expected); + end; + + procedure beforetest_twice is + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + open l_expected for + select 'dummy_before_after_test.before_test' as column_value from dual union all + select 'dummy_before_after_test.before_test' as column_value from dual; + + open l_actual for + select * from table(test_before_after_annotations.get_procs_called('beforetest_twice')); + ut.expect(l_actual).to_equal(l_expected); + end; + + procedure beforetest_one_ext_procedure is + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + open l_expected for + select 'shared_test_package.before_test' as column_value from dual; + + open l_actual for + select * from table(test_before_after_annotations.get_procs_called('beforetest_one_ext_procedure')); + ut.expect(l_actual).to_equal(l_expected); + end; + + procedure beforetest_multi_ext_procedure is + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + open l_expected for + select 'shared_test_package.before_test' as column_value from dual union all + select 'dummy_before_after_test.before_test' as column_value from dual; + + open l_actual for + select * from table(test_before_after_annotations.get_procs_called('beforetest_multi_ext_procedure')); + ut.expect(l_actual).to_equal(l_expected); + end; + + procedure beforetest_missing_procedure is + l_actual sys_refcursor; + begin + open l_actual for + select * from table(test_before_after_annotations.get_procs_called('beforetest_missing_procedure')); + + ut.expect(l_actual).to_be_empty; + + ut.expect(g_tests_results).to_match( + '^\s*Stops execution at first non-existing Beforetest procedure and marks test as errored \[[\.0-9]+ sec\] \(FAILED - 1\)\s*$' + ,'m' + ); + ut.expect(g_tests_results).to_match( + '1\) beforetest_missing_procedure\s+' || + 'Call params for beforetest are not valid: procedure does not exist ' || + 'UT3_TESTER.DUMMY_BEFORE_AFTER_TEST.NON_EXISTENT_PROCEDURE' + ,'m' + ); + end; + + procedure beforetest_one_err_procedure is + l_actual sys_refcursor; + begin + open l_actual for + select * from table(test_before_after_annotations.get_procs_called('beforetest_one_err_procedure')); + + ut.expect(l_actual).to_be_empty; + + ut.expect(g_tests_results).to_match( + '^\s*Stops execution at first non-existing Beforetest procedure and marks test as errored \[[\.0-9]+ sec\] \(FAILED - 1\)\s*$' + ,'m' + ); + ut.expect(g_tests_results).to_match( + '2\) beforetest_one_err_procedure\s+' || + 'ORA-06501: PL/SQL: program error' + ,'m' + ); + end; + +end; +/ \ No newline at end of file diff --git a/test/core/annotations/test_before_after_test_annotation.pks b/test/core/annotations/test_before_after_test_annotation.pks new file mode 100644 index 000000000..a4ce52727 --- /dev/null +++ b/test/core/annotations/test_before_after_test_annotation.pks @@ -0,0 +1,38 @@ +create or replace package test_before_after_annotations is + + --%suite(annotations - beforetest and aftertest) + --%suitepath(utplsql.core.annotations) + + subtype t_procedure_name is varchar2(250) not null; + type t_procedures is table of t_procedure_name; + + procedure set_procs_called(a_for_procedure t_procedure_name, a_procedures t_procedures); + + function get_procs_called(a_for_procedure varchar2) return t_procedures pipelined; + + --%beforeall + procedure create_tests_results; + + --%test(Executes Beforetest call to procedure inside package) + procedure beforetest_local_procedure; + + --%test(Executes beforetest procedure defined in the package when specified with package name) + procedure beforetest_local_proc_with_pkg; + + --%test(Executes Beforetest procedure twice when defined twice) + procedure beforetest_twice; + + --%test(Executes Beforetest procedure from external package) + procedure beforetest_one_ext_procedure; + + --%test(Executed external and internal Beforetest procedures) + procedure beforetest_multi_ext_procedure; + + --%test(Stops execution at first non-existing Beforetest procedure and marks test as errored) + procedure beforetest_missing_procedure; + + --%test(Stops execution at first erroring Beforetest procedure and marks test as errored) + procedure beforetest_one_err_procedure; + +end; +/ \ No newline at end of file diff --git a/test/core/expectations/scalar_data/binary/test_be_greater_or_equal.pkb b/test/core/expectations/binary/test_be_greater_or_equal.pkb similarity index 97% rename from test/core/expectations/scalar_data/binary/test_be_greater_or_equal.pkb rename to test/core/expectations/binary/test_be_greater_or_equal.pkb index 7e82adde7..f41878643 100644 --- a/test/core/expectations/scalar_data/binary/test_be_greater_or_equal.pkb +++ b/test/core/expectations/binary/test_be_greater_or_equal.pkb @@ -251,5 +251,13 @@ create or replace package body test_be_greater_or_equal is ut.expect( expectations.failed_expectations_data( ) ).not_to_be_empty( ); end; + procedure actual_clob is + begin + --Act + ut3.ut.expect(to_clob('3')).to_( ut3.be_greater_or_equal(3) ); + --Assert + ut.expect( expectations.failed_expectations_data( ) ).not_to_be_empty( ); + end; + end; / diff --git a/test/core/expectations/scalar_data/binary/test_be_greater_or_equal.pks b/test/core/expectations/binary/test_be_greater_or_equal.pks similarity index 96% rename from test/core/expectations/scalar_data/binary/test_be_greater_or_equal.pks rename to test/core/expectations/binary/test_be_greater_or_equal.pks index a9f0e0c75..077dff59c 100644 --- a/test/core/expectations/scalar_data/binary/test_be_greater_or_equal.pks +++ b/test/core/expectations/binary/test_be_greater_or_equal.pks @@ -1,7 +1,7 @@ create or replace package test_be_greater_or_equal is --%suite((not)to_be_greater_or_equal) - --%suitepath(utplsql.core.expectations.scalar_data.binary) + --%suitepath(utplsql.core.expectations.binary) --%aftereach procedure cleanup_expectations; @@ -90,5 +90,8 @@ create or replace package test_be_greater_or_equal is --%test(Negated - Gives failure when actual timestamp with local time zone is greater than expected) procedure not_actual_timestamp_ltz_gretr; + --%test(Gives failure when running against CLOB) + procedure actual_clob; + end; / diff --git a/test/core/expectations/scalar_data/binary/test_be_greater_than.pkb b/test/core/expectations/binary/test_be_greater_than.pkb similarity index 97% rename from test/core/expectations/scalar_data/binary/test_be_greater_than.pkb rename to test/core/expectations/binary/test_be_greater_than.pkb index 688200707..5863b11b1 100644 --- a/test/core/expectations/scalar_data/binary/test_be_greater_than.pkb +++ b/test/core/expectations/binary/test_be_greater_than.pkb @@ -251,5 +251,13 @@ create or replace package body test_be_greater_than is ut.expect( expectations.failed_expectations_data( ) ).not_to_be_empty( ); end; + procedure actual_clob is + begin + --Act + ut3.ut.expect(to_clob('3')).to_( ut3.be_greater_than(2) ); + --Assert + ut.expect( expectations.failed_expectations_data( ) ).not_to_be_empty( ); + end; + end; / diff --git a/test/core/expectations/scalar_data/binary/test_be_greater_than.pks b/test/core/expectations/binary/test_be_greater_than.pks similarity index 96% rename from test/core/expectations/scalar_data/binary/test_be_greater_than.pks rename to test/core/expectations/binary/test_be_greater_than.pks index 6563addd0..6a1dfcc3e 100644 --- a/test/core/expectations/scalar_data/binary/test_be_greater_than.pks +++ b/test/core/expectations/binary/test_be_greater_than.pks @@ -1,7 +1,7 @@ create or replace package test_be_greater_than is --%suite((not)to_be_greater_than) - --%suitepath(utplsql.core.expectations.scalar_data.binary) + --%suitepath(utplsql.core.expectations.binary) --%aftereach procedure cleanup_expectations; @@ -90,5 +90,8 @@ create or replace package test_be_greater_than is --%test(Negated - Gives failure when actual timestamp with local time zone is greater than expected) procedure not_actual_timestamp_ltz_gretr; + --%test(Gives failure when running against CLOB) + procedure actual_clob; + end; / diff --git a/test/core/expectations/scalar_data/binary/test_be_less_or_equal.pkb b/test/core/expectations/binary/test_be_less_or_equal.pkb similarity index 97% rename from test/core/expectations/scalar_data/binary/test_be_less_or_equal.pkb rename to test/core/expectations/binary/test_be_less_or_equal.pkb index f3ee4bc47..c72e0039b 100644 --- a/test/core/expectations/scalar_data/binary/test_be_less_or_equal.pkb +++ b/test/core/expectations/binary/test_be_less_or_equal.pkb @@ -251,5 +251,13 @@ create or replace package body test_be_less_or_equal is ut.expect( expectations.failed_expectations_data( ) ).to_be_empty(); end; + procedure actual_clob is + begin + --Act + ut3.ut.expect(to_clob('3')).to_( ut3.be_less_or_equal(3) ); + --Assert + ut.expect( expectations.failed_expectations_data( ) ).not_to_be_empty( ); + end; + end; / diff --git a/test/core/expectations/scalar_data/binary/test_be_less_or_equal.pks b/test/core/expectations/binary/test_be_less_or_equal.pks similarity index 96% rename from test/core/expectations/scalar_data/binary/test_be_less_or_equal.pks rename to test/core/expectations/binary/test_be_less_or_equal.pks index 4cfdd0af6..a6ab01664 100644 --- a/test/core/expectations/scalar_data/binary/test_be_less_or_equal.pks +++ b/test/core/expectations/binary/test_be_less_or_equal.pks @@ -1,7 +1,7 @@ create or replace package test_be_less_or_equal is --%suite((not)to_be_less_or_equal) - --%suitepath(utplsql.core.expectations.scalar_data.binary) + --%suitepath(utplsql.core.expectations.binary) --%aftereach procedure cleanup_expectations; @@ -90,5 +90,8 @@ create or replace package test_be_less_or_equal is --%test(Negated - Gives success when actual timestamp with local time zone is greater than expected) procedure not_actual_timestamp_ltz_gretr; + --%test(Gives failure when running against CLOB) + procedure actual_clob; + end; / diff --git a/test/core/expectations/scalar_data/binary/test_equal.pkb b/test/core/expectations/binary/test_equal.pkb similarity index 97% rename from test/core/expectations/scalar_data/binary/test_equal.pkb rename to test/core/expectations/binary/test_equal.pkb index 0e5ab2fdf..dd7dd7a82 100644 --- a/test/core/expectations/scalar_data/binary/test_equal.pkb +++ b/test/core/expectations/binary/test_equal.pkb @@ -95,6 +95,8 @@ create or replace package body test_equal is procedure equal_fail_on_type_diff is begin + test_to_equal_fail('boolean', 'integer', 'true', '1'); + test_to_equal_fail('integer', 'boolean', '1', 'true'); test_to_equal_fail('blob', 'clob', 'to_blob(''ABC'')', '''ABC'''); test_to_equal_fail('clob', 'blob', '''ABC''', 'to_blob(''ABC'')'); test_to_equal_fail('clob', 'anydata', '''ABC''', 'null'); @@ -115,6 +117,8 @@ create or replace package body test_equal is procedure not_equal_fail_on_type_diff is begin + test_not_to_equal_fail('boolean', 'integer', 'true', '1'); + test_not_to_equal_fail('integer', 'boolean', '1', 'true'); test_not_to_equal_fail('blob', 'clob', 'to_blob(''ABC'')', '''ABC'''); test_not_to_equal_fail('clob', 'blob', '''ABC''', 'to_blob(''ABC'')'); test_not_to_equal_fail('clob', 'anydata', '''ABC''', 'null'); @@ -136,6 +140,7 @@ create or replace package body test_equal is procedure failure_on_data_diff is begin test_to_equal_fail('blob', 'to_blob(''abc'')', 'to_blob(''abd'')'); + test_to_equal_fail('boolean', 'false', 'true'); test_to_equal_fail('boolean', 'true', 'false'); test_to_equal_fail('clob', '''Abc''', '''abc'''); test_to_equal_fail('date', 'sysdate', 'sysdate-1'); diff --git a/test/core/expectations/scalar_data/binary/test_equal.pks b/test/core/expectations/binary/test_equal.pks similarity index 95% rename from test/core/expectations/scalar_data/binary/test_equal.pks rename to test/core/expectations/binary/test_equal.pks index 80b00eefb..c0280c288 100644 --- a/test/core/expectations/scalar_data/binary/test_equal.pks +++ b/test/core/expectations/binary/test_equal.pks @@ -1,7 +1,7 @@ create or replace package test_equal is --%suite((not)to_be_equal) - --%suitepath(utplsql.core.expectations.scalar_data.binary) + --%suitepath(utplsql.core.expectations.binary) procedure reset_nulls_equal; diff --git a/test/core/expectations/scalar_data/binary/test_expect_to_be_less_than.pkb b/test/core/expectations/binary/test_expect_to_be_less_than.pkb similarity index 97% rename from test/core/expectations/scalar_data/binary/test_expect_to_be_less_than.pkb rename to test/core/expectations/binary/test_expect_to_be_less_than.pkb index 987cbf9cd..8f1278db4 100644 --- a/test/core/expectations/scalar_data/binary/test_expect_to_be_less_than.pkb +++ b/test/core/expectations/binary/test_expect_to_be_less_than.pkb @@ -251,5 +251,13 @@ create or replace package body test_expect_to_be_less_than is ut.expect( expectations.failed_expectations_data( ) ).to_be_empty( ); end; + procedure actual_clob is + begin + --Act + ut3.ut.expect(to_clob('3')).to_( ut3.be_less_than(4) ); + --Assert + ut.expect( expectations.failed_expectations_data( ) ).not_to_be_empty( ); + end; + end; / diff --git a/test/core/expectations/scalar_data/binary/test_expect_to_be_less_than.pks b/test/core/expectations/binary/test_expect_to_be_less_than.pks similarity index 96% rename from test/core/expectations/scalar_data/binary/test_expect_to_be_less_than.pks rename to test/core/expectations/binary/test_expect_to_be_less_than.pks index 555de2fb4..67e6b8776 100644 --- a/test/core/expectations/scalar_data/binary/test_expect_to_be_less_than.pks +++ b/test/core/expectations/binary/test_expect_to_be_less_than.pks @@ -1,7 +1,7 @@ create or replace package test_expect_to_be_less_than is --%suite((not)to_be_less_than) - --%suitepath(utplsql.core.expectations.scalar_data.binary) + --%suitepath(utplsql.core.expectations.binary) --%aftereach procedure cleanup_expectations; @@ -90,5 +90,8 @@ create or replace package test_expect_to_be_less_than is --%test(Negated - Gives success when actual timestamp with local time zone is greater than expected) procedure not_actual_timestamp_ltz_gretr; + --%test(Gives failure when running against CLOB) + procedure actual_clob; + end; / diff --git a/test/core/expectations/compound_data/test_expectations_cursor.pkb b/test/core/expectations/compound_data/test_expectations_cursor.pkb deleted file mode 100644 index b805105e6..000000000 --- a/test/core/expectations/compound_data/test_expectations_cursor.pkb +++ /dev/null @@ -1,1045 +0,0 @@ -create or replace package body test_expectations_cursor is - - gc_blob blob := to_blob('123'); - gc_clob clob := to_clob('abc'); - gc_date date := sysdate; - gc_ds_int interval day(9) to second(9) := numtodsinterval(1.12345678912, 'day'); - gc_num number := 123456789.1234567890123456789; - gc_ts timestamp(9) := to_timestamp_tz('2017-03-30 00:21:12.123456789 cet','yyyy-mm-dd hh24:mi:ss.ff9 tzr'); - gc_ts_tz timestamp(9) with time zone := to_timestamp_tz('2017-03-30 00:21:12.123456789 cet','yyyy-mm-dd hh24:mi:ss.ff9 tzr'); - gc_ts_ltz timestamp(9) with local time zone := to_timestamp_tz('2017-03-30 00:21:12.123456789 cet','yyyy-mm-dd hh24:mi:ss.ff9 tzr'); - gc_varchar varchar2(4000) := 'a varchar2'; - gc_ym_int interval year(9) to month := numtoyminterval(1.1, 'year'); - - procedure cleanup_expectations is - begin - expectations.cleanup_expectations( ); - end; - - procedure setup_temp_table_test - as - pragma autonomous_transaction; - begin - execute immediate 'create global temporary table gtt_test_table ( - value varchar2(250) - ) on commit delete rows'; - - end; - - procedure cleanup_temp_table_test - as - pragma autonomous_transaction; - begin - execute immediate 'drop table gtt_test_table'; - end; - - procedure with_temp_table - as - pragma autonomous_transaction; - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - -- Arrange - execute immediate 'insert into gtt_test_table ( value ) ' || - 'select ''Test-entry'' from dual union all ' || - 'select ''Other test entry'' from dual'; - open l_expected for - select 'Test-entry' as value from dual union all - select 'Other test entry' as value from dual; - open l_actual for 'select * from gtt_test_table'; - --Act - execute the expectation on cursor opened on GTT - ut3.ut.expect( l_actual ).to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - --Cleanup - rollback; - end; - - - procedure success_on_same_data - as - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - -- Arrange - open l_expected for - select 1 as my_num, - 'This is my test string' as my_string, - to_clob('This is an even longer test clob') as my_clob, - to_date('1984-09-05', 'YYYY-MM-DD') as my_date - from dual; - open l_actual for - select 1 as my_num, - 'This is my test string' as my_string, - to_clob('This is an even longer test clob') as my_clob, - to_date('1984-09-05', 'YYYY-MM-DD') as my_date - from dual; - --Act - ut3.ut.expect( l_actual ).to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure success_on_empty - as - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - -- Arrange - open l_expected for select * from dual where 1=0; - open l_actual for select * from dual where 1=0; - --Act - ut3.ut.expect( l_actual ).to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure success_on_both_null - as - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - --Act - ut3.ut.expect( l_actual ).to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure success_to_be_null - as - l_actual sys_refcursor; - begin - --Act - ut3.ut.expect( l_actual ).to_be_null(); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure success_not_to_be_not_null - as - l_actual sys_refcursor; - begin - --Act - ut3.ut.expect( l_actual ).not_to_be_not_null(); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure success_not_to_be_null - as - l_actual sys_refcursor; - begin - --Arrange - open l_actual for select * from dual; - --Act - ut3.ut.expect( l_actual ).to_be_not_null(); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure success_to_be_not_null - as - l_actual sys_refcursor; - begin - --Arrange - open l_actual for select * from dual; - --Act - ut3.ut.expect( l_actual ).to_be_not_null(); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure success_is_empty - as - l_actual sys_refcursor; - begin - --Arrange - open l_actual for select * from dual where 0=1; - --Act - ut3.ut.expect( l_actual ).to_be_empty(); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure success_is_not_empty - as - l_actual sys_refcursor; - begin - --Arrange - open l_actual for select * from dual; - --Act - ut3.ut.expect( l_actual ).not_to_be_empty(); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure failure_is_null - as - l_actual sys_refcursor; - begin - --Arrange - open l_actual for select * from dual; - --Act - ut3.ut.expect( l_actual ).to_be_null(); - --Assert - ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); - end; - - procedure failure_is_not_null - as - l_actual sys_refcursor; - begin - --Act - ut3.ut.expect( l_actual ).not_to_be_null(); - --Assert - ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); - end; - - procedure failure_is_empty - as - l_actual sys_refcursor; - begin - --Arrange - open l_actual for select * from dual; - --Act - ut3.ut.expect( l_actual ).to_be_empty(); - --Assert - ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); - end; - - procedure failure_is_not_empty - as - l_actual sys_refcursor; - begin - --Arrange - open l_actual for select * from dual where 0=1; - --Act - ut3.ut.expect( l_actual ).not_to_be_empty(); - --Assert - ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); - end; - - procedure fail_null_vs_empty - as - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - --Arrange - open l_expected for select * from dual where 1=0; - --Act - ut3.ut.expect( l_actual ).not_to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure fail_on_difference - as - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - --Arrange - open l_expected for select to_clob('This is an even longer test clob') as my_clob from dual; - open l_actual for select to_clob('Another totally different story') as my_clob from dual; - --Act - ut3.ut.expect( l_actual ).to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); - end; - - procedure fail_on_expected_missing - as - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - --Arrange - open l_expected for select 1 as my_num from dual; - open l_actual for select 1 as my_num from dual union all select 1 as my_num from dual; - --Act - ut3.ut.expect( l_actual ).to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); - end; - - procedure fail_on_actual_missing - as - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - --Arrange - open l_expected for select 1 as my_num from dual union all select 1 as my_num from dual; - open l_actual for select 1 as my_num from dual; - --Act - ut3.ut.expect( l_actual ).to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); - end; - - procedure fail_on_different_column_name - as - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - --Arrange - open l_expected for select 1 as col_1 from dual; - open l_actual for select 1 as col_2 from dual; - --Act - ut3.ut.expect( l_actual ).to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); - end; - - - procedure fail_on_different_column_order - as - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - --Arrange - open l_expected for select 1 as col_1, 2 as col_2 from dual; - open l_actual for select 2 as col_2, 1 as col_1 from dual; - --Act - ut3.ut.expect( l_actual ).to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); - end; - - procedure fail_on_different_row_order - as - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - --Arrange - open l_expected for select 1 as my_num from dual union all select 2 as my_num from dual; - open l_actual for select 2 as my_num from dual union all select 1 as my_num from dual; - --Act - ut3.ut.expect( l_actual ).to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); - end; - - procedure include_time_in_date_with_nls - as - l_expected sys_refcursor; - l_actual sys_refcursor; - l_date date := sysdate; - l_second number := 1/24/60/60; - begin - --Arrange - ut.set_nls; - open l_actual for select l_date as some_date from dual; - open l_expected for select l_date-l_second some_date from dual; - ut.reset_nls; - --Act - ut3.ut.expect( l_actual ).to_equal( l_expected ); - --Assert - ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); - end; - - procedure uses_default_nls_for_date - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select sysdate as some_date from dual; - open l_expected for select to_date(to_char(sysdate)) as some_date from dual; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure exclude_columns_as_list - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; - open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>ut3.ut_varchar2_list('A_COLUMN','Some_Col')); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure exclude_columns_as_csv - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; - open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>'A_COLUMN,Some_Col'); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure exclude_columns_as_mixed_list is - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; - open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>ut3.ut_varchar2_list('A_COLUMN','/ROW/Some_Col')); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure exclude_columns_as_mix_csv_lst is - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; - open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>'A_COLUMN,/ROW/Some_Col'); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure exclude_columns_xpath_invalid - as - l_actual SYS_REFCURSOR; - l_expected SYS_REFCURSOR; - l_error_code integer := -31011; --xpath_error - begin - --Arrange - open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; - open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; - begin - --Act - ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>'/ROW/A_COLUMN,\\//Some_Col'); - --Assert - ut.fail('Expected '||l_error_code||' but nothing was raised'); - exception - when others then - ut.expect(sqlcode).to_equal(l_error_code); - end; - end; - - procedure exclude_columns_xpath - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual; - open l_expected for select 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>'/ROW/A_COLUMN|/ROW/Some_Col'); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure exclude_ignores_invalid_column - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select rownum as rn, 'c' as A_COLUMN from dual a connect by level < 4; - open l_expected for select rownum as rn, 'd' as A_COLUMN from dual a connect by level < 4; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>ut3.ut_varchar2_list('A_COLUMN','non_existing_column')); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure include_columns_as_list - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; - open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected).include(ut3.ut_varchar2_list('RN','//A_Column','SOME_COL')); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure include_columns_as_csv - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; - open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected).include('RN,//A_Column,SOME_COL'); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure include_columns_xpath_invalid - as - l_actual SYS_REFCURSOR; - l_expected SYS_REFCURSOR; - begin - --Arrange - open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; - open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; - begin - --Act - ut3.ut.expect(l_actual).to_equal(l_expected).include('/ROW/RN,\\//A_Column,//SOME_COL'); - --Assert - ut.fail('Expected exception but nothing was raised'); - exception - when others then - ut.expect(sqlcode).to_be_between(-31013,-31011); - end; - end; - - procedure include_columns_xpath - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual connect by level < 4; - open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual connect by level < 4; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected).include('/ROW/RN|//A_Column|//SOME_COL'); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure include_ignores_invalid_column - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select rownum as rn, 'c' as A_COLUMN from dual a connect by level < 4; - open l_expected for select rownum as rn, 'd' as A_COLUMN from dual a connect by level < 4; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected).include(ut3.ut_varchar2_list('RN','non_existing_column')); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure include_exclude_col_csv_xpath - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual connect by level < 4; - open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual connect by level < 4; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected).exclude('Some_Col').include('/ROW/RN|//Some_Col'); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure include_exclude_columns_list - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual connect by level < 4; - open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual connect by level < 4; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected).exclude(ut3.ut_varchar2_list('A_COLUMN')).include(ut3.ut_varchar2_list('RN','A_Column','A_COLUMN')); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure data_diff_on_rows_mismatch - as - l_actual sys_refcursor; - l_expected sys_refcursor; - l_actual_message varchar2(32767); - l_expected_message varchar2(32767); - begin - --Arrange - open l_actual for select 1 rn from dual union all select 6 rn from dual; - open l_expected for select rownum rn from dual connect by level <=3; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - - l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 3 ] -Diff: -Rows: [ 2 differences ] - Row No. 2 - Actual: 6 - Row No. 2 - Expected: 2 - Row No. 3 - Missing: 3]'; - l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); - end; - - procedure char_and_varchar2_col_is_equal is - l_expected sys_refcursor; - l_actual sys_refcursor; - l_actual_message varchar2(32767); - l_expected_message varchar2(32767); - begin - --Arrange - open l_actual for select cast('a' as char(1)) a_column, 1 as id from dual; - open l_expected for select cast('a' as varchar2(10)) a_column from dual; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - l_expected_message := q'[Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = 1 ] -Diff: -Columns: - Column [position: 2, data-type: NUMBER] is not expected in results. -Rows: [ 1 differences ] - All rows are different as the columns are not matching.]'; - l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); - end; - - procedure column_diff_on_data_type_diff is - l_actual sys_refcursor; - l_expected sys_refcursor; - l_actual_message varchar2(32767); - l_expected_message varchar2(32767); - begin - --Arrange - open l_actual for select to_char(rownum) rn, rownum another_rn from dual connect by level <=2; - open l_expected for select rownum rn, rownum another_rn from dual connect by level <=2; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - - l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ] -Diff: -Columns: - Column data-type is invalid. Expected: NUMBER, actual: VARCHAR2.]'; - l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); - end; - - procedure column_diff_on_col_name_diff is - l_actual sys_refcursor; - l_expected sys_refcursor; - l_actual_message varchar2(32767); - l_expected_message varchar2(32767); - begin - --Arrange - open l_actual for select rownum rn, rownum bad_column_name from dual connect by level <=2; - open l_expected for select rownum rn, rownum expected_column_name from dual connect by level <=2; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - - l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ] -Diff: -Columns:% - Column [data-type: NUMBER] is missing. Expected column position: 2.% - Column [position: 2, data-type: NUMBER] is not expected in results.%]'; - l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); - end; - - --%test(Reports column diff on cusror with different column positions) - procedure column_diff_on_col_position is - l_actual sys_refcursor; - l_expected sys_refcursor; - l_actual_message varchar2(32767); - l_expected_message varchar2(32767); - begin - --Arrange - open l_actual for select rownum+1 col_1, rownum+2 col_2, rownum+3 col_3, rownum+4 col_4 from dual connect by level <=2; - open l_expected for select rownum+1 col_1, rownum+4 col_4, rownum+2 col_2, rownum+3 col_3 from dual connect by level <=2; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - - l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ] -Diff: -Columns: - Column is misplaced. Expected position: 2, actual position: 4. - Column is misplaced. Expected position: 3, actual position: 2. - Column is misplaced. Expected position: 4, actual position: 3. -Rows: [ 2 differences ] - All rows are different as the columns are not matching.]'; - l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); - end; - - - --%test(Reports only mismatched columns on column data mismatch) - procedure data_diff_on_col_data_mismatch is - l_actual sys_refcursor; - l_expected sys_refcursor; - l_actual_message varchar2(32767); - l_expected_message varchar2(32767); - begin - --Arrange - open l_actual for select rownum good_col, -rownum bad_col from dual connect by level <=2; - open l_expected for select rownum good_col, rownum bad_col from dual connect by level <=2; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - - l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ] -Diff: -Rows: [ 2 differences ] - Row No. 1 - Actual: -1 - Row No. 1 - Expected: 1 - Row No. 2 - Actual: -2 - Row No. 2 - Expected: 2]'; - l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); - end; - - procedure data_diff_on_20_rows_only is - l_actual sys_refcursor; - l_expected sys_refcursor; - l_actual_message varchar2(32767); - l_expected_message varchar2(32767); - begin - --Arrange - open l_actual for - select rownum - * case when mod(rownum,2) = 0 then -1 else 1 end bad_col, - rownum good_col - from dual connect by level <=100; - open l_expected for select rownum bad_col, rownum good_col from dual connect by level <=110; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - - l_expected_message := q'[Actual: refcursor [ count = 100 ] was expected to equal: refcursor [ count = 110 ] -Diff: -Rows: [ 60 differences, showing first 20 ] - Row No. 2 - Actual: -2 - Row No. 2 - Expected: 2 - Row No. 4 - Actual: -4 - Row No. 4 - Expected: 4 - Row No. 6 - Actual: -6 - Row No. 6 - Expected: 6 - Row No. 8 - Actual: -8 - Row No. 8 - Expected: 8 - % - Row No. 38 - Actual: -38 - Row No. 38 - Expected: 38 - Row No. 40 - Actual: -40 - Row No. 40 - Expected: 40]'; - l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); - end; - - procedure column_and_data_diff is - l_actual sys_refcursor; - l_expected sys_refcursor; - l_actual_message varchar2(32767); - l_expected_message varchar2(32767); - begin - --Arrange - open l_expected for - select 1 as ID, 'JACK' as FIRST_NAME, 'SPARROW' AS LAST_NAME, 10000 AS SALARY from dual union all - select 2 as ID, 'LUKE' as FIRST_NAME, 'SKYWALKER' AS LAST_NAME, 1000 AS SALARY from dual union all - select 3 as ID, 'TONY' as FIRST_NAME, 'STARK' AS LAST_NAME, 100000 AS SALARY from dual; - open l_actual for - select 'M' AS GENDER, 'JACK' as FIRST_NAME, 'SPARROW' AS LAST_NAME, 1 as ID, '25000' AS SALARY from dual union all - select 'M' AS GENDER, 'TONY' as FIRST_NAME, 'STARK' AS LAST_NAME, 3 as ID, '100000' AS SALARY from dual union all - select 'F' AS GENDER, 'JESSICA' as FIRST_NAME, 'JONES' AS LAST_NAME, 4 as ID, '2345' AS SALARY from dual union all - select 'M' AS GENDER, 'LUKE' as FIRST_NAME, 'SKYWALKER' AS LAST_NAME, 2 as ID, '1000' AS SALARY from dual; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - l_expected_message := q'[Actual: refcursor [ count = 4 ] was expected to equal: refcursor [ count = 3 ] -Diff: -Columns: - Column is misplaced. Expected position: 1, actual position: 4. - Column data-type is invalid. Expected: NUMBER, actual: VARCHAR2. - Column [position: 1, data-type: CHAR] is not expected in results. -Rows: [ 4 differences ] - Row No. 1 - Actual: 25000 - Row No. 1 - Expected: 10000 - Row No. 2 - Actual: TONYSTARK3100000 - Row No. 2 - Expected: 2LUKESKYWALKER1000 - Row No. 3 - Actual: JESSICAJONES42345 - Row No. 3 - Expected: 3TONYSTARK100000 - Row No. 4 - Extra: MLUKESKYWALKER21000]'; - l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); - end; - - procedure prepare_table - as - pragma autonomous_transaction; - begin - execute immediate - 'create table test_table_for_cursors ( - some_blob blob, - some_clob clob, - some_date date, - some_ds_interval interval day(9) to second(9), - some_nummber number, - some_timestamp timestamp(9), - some_timestamp_tz timestamp(9) with time zone, - some_timestamp_ltz timestamp(9) with local time zone, - some_varchar2 varchar2(4000), - some_ym_interval interval year(9) to month - )'; - execute immediate q'[ - insert into test_table_for_cursors - values( :gc_blob, :gc_clob, :gc_date, :gc_ds_int, :gc_num, :gc_ts, :gc_ts_tz, :gc_ts_ltz, :gc_varchar, :gc_ym_int - ) -]' using gc_blob, gc_clob, gc_date, gc_ds_int, gc_num, gc_ts, gc_ts_tz, gc_ts_ltz, gc_varchar, gc_ym_int; - commit; - end; - - procedure cleanup_table - as - pragma autonomous_transaction; - begin - execute immediate 'drop table test_table_for_cursors'; - end; - - procedure compares_sql_and_plsql_types is - l_expected sys_refcursor; - l_actual sys_refcursor; - begin - --Arrange - open l_expected for - select gc_blob some_blob, - gc_clob some_clob, - gc_date some_date, - gc_ds_int some_ds_interval, - gc_num some_nummber, - gc_ts some_timestamp, - gc_ts_tz some_timestamp_tz, - gc_ts_ltz some_timestamp_ltz , - gc_varchar some_varchar2, - gc_ym_int some_ym_interval - from dual; - open l_actual for q'[select * from test_table_for_cursors]'; - --Act - ut3.ut.expect(l_expected).to_equal(l_actual); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - procedure closes_cursor_after_use - as - l_actual sys_refcursor; - begin - --Arrange - open l_actual for select 1 as value from dual; - --Act - ut3.ut.expect(l_actual).to_be_empty(); - --Assert - ut.expect(l_actual%isopen).to_be_false(); - end; - - procedure closes_cursor_after_use_on_err - as - l_actual sys_refcursor; - begin - --Arrange - open l_actual for select 1/0 as value from dual; - --Act - begin - ut3.ut.expect(l_actual).to_be_empty(); - exception - when others then - null; - end; - --Assert - ut.expect(l_actual%isopen).to_be_false(); - end; - - procedure reports_on_exception_in_cursor - as - l_actual sys_refcursor; - l_error_code integer := -19202; --Error occurred in XML processing - begin - --Act - open l_actual for select 1/0 as error_column from dual connect by level < 10; - begin - ut3.ut.expect(l_actual).to_be_empty(); - --Assert - ut.fail('Expected '||l_error_code||' but nothing was raised'); - exception - when others then - ut.expect(sqlcode).to_equal(l_error_code); - end; - end; - - procedure exception_when_closed_cursor - is - l_actual sys_refcursor; - l_error_code constant integer := -20155; - begin - --Arrange - open l_actual for select * from dual; - close l_actual; - --Act - ut3.ut.expect( l_actual ).not_to_be_null; - exception - when others then - --Assert - ut.expect(sqlcode).to_equal(l_error_code); - end; - - procedure compares_over_1000_rows - as - l_actual sys_refcursor; - l_expected sys_refcursor; - begin - --Arrange - open l_actual for select object_name from all_objects where rownum <=1100; - open l_expected for select object_name from all_objects where rownum <=1100; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - function get_cursor return sys_refcursor is - l_cursor sys_refcursor; - begin - open l_cursor for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; - return l_cursor; - end; - - procedure deprec_to_equal_excl_varch is - begin - --Act - ut3.ut.expect(get_cursor()).to_equal(get_cursor(), a_exclude => 'A_COLUMN,Some_Col'); - --Assert - ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); - ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); - end; - - procedure deprec_to_equal_excl_list is - begin - --Act - ut3.ut.expect(get_cursor()).to_equal(get_cursor(), a_exclude => ut3.ut_varchar2_list('A_COLUMN','Some_Col')); - --Assert - ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); - ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); - end; - - procedure deprec_not_to_equal_excl_varch is - begin - --Act - ut3.ut.expect(get_cursor()).not_to_equal(get_cursor(), a_exclude => 'A_COLUMN,Some_Col'); - --Assert - ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); - ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); - end; - - procedure deprec_not_to_equal_excl_list is - begin - --Act - ut3.ut.expect(get_cursor()).not_to_equal(get_cursor(), a_exclude => ut3.ut_varchar2_list('A_COLUMN','Some_Col')); - --Assert - ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); - ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); - end; - - procedure deprec_equal_excl_varch is - begin - --Act - ut3.ut.expect(get_cursor()).to_(ut3.equal(get_cursor(), a_exclude => 'A_COLUMN,Some_Col')); - --Assert - ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); - ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); - end; - - procedure deprec_equal_excl_list is - begin - --Act - ut3.ut.expect(get_cursor()).to_(ut3.equal(get_cursor(), a_exclude => ut3.ut_varchar2_list('A_COLUMN','Some_Col'))); - --Assert - ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); - ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); - end; - - procedure col_diff_on_col_name_implicit is - l_actual SYS_REFCURSOR; - l_expected SYS_REFCURSOR; - l_actual_message varchar2(32767); - l_expected_message varchar2(32767); - begin - --Arrange - open l_actual for select '1' , '2' from dual connect by level <=2; - open l_expected for select rownum , rownum expected_column_name from dual connect by level <=2; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - - l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]% -Diff:% -Columns:% - Column [data-type: NUMBER] is missing. Expected column position: 1.% - Column [data-type: NUMBER] is missing. Expected column position: 2.% - Column <%1%> [position: 1, data-type: CHAR] is not expected in results.% - Column <%2%> [position: 2, data-type: CHAR] is not expected in results.% -Rows: [ 2 differences ]% - All rows are different as the columns are not matching.%]'; - l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); - end; - - procedure col_mtch_on_col_name_implicit is - l_actual SYS_REFCURSOR; - l_expected SYS_REFCURSOR; - l_actual_message varchar2(32767); - l_expected_message varchar2(32767); - begin - --Arrange - open l_actual for select '1' , rownum from dual connect by level <=2; - open l_expected for select '1' , rownum from dual connect by level <=2; - --Act - ut3.ut.expect(l_actual).to_equal(l_expected); - --Assert - ut.expect(expectations.failed_expectations_data()).to_be_empty(); - end; - - - procedure include_col_name_implicit is - l_actual SYS_REFCURSOR; - l_expected SYS_REFCURSOR; - begin - --Arrange - open l_actual for select rownum as rn, 'a', 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; - open l_expected for select rownum as rn, 'a', 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; - begin - --Act - ut3.ut.expect(l_actual).to_equal(l_expected).include(q'!/ROW/RN,'a',//SOME_COL!'); - --Assert - ut.fail('Expected exception but nothing was raised'); - exception - when others then - ut.expect(sqlcode).to_be_between(-31013,-31011); - end; - end; - - procedure exclude_col_name_implicit is - l_actual SYS_REFCURSOR; - l_expected SYS_REFCURSOR; - begin - --Arrange - open l_actual for select rownum as rn, 'a', 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; - open l_expected for select rownum as rn, 'a', 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; - begin - --Act - ut3.ut.expect(l_actual).to_equal(l_expected).exclude(q'!/ROW/RN,'a',//SOME_COL!'); - --Assert - ut.fail('Expected exception but nothing was raised'); - exception - when others then - ut.expect(sqlcode).to_be_between(-31013,-31011); - end; - end; - -end; -/ diff --git a/test/core/expectations/scalar_data/unary/test_expect_to_be_null.pks b/test/core/expectations/scalar_data/unary/test_expect_to_be_null.pks deleted file mode 100644 index d6cc6433d..000000000 --- a/test/core/expectations/scalar_data/unary/test_expect_to_be_null.pks +++ /dev/null @@ -1,97 +0,0 @@ -create or replace package test_expect_to_be_null -is - --%suite(to_be_null) - --%suitepath(utplsql.core.expectations.scalar_data.unary) - - --%aftereach - procedure cleanup_expectations; - - --%beforeall - procedure create_types; - - --%afterall - procedure drop_types; - - --%test(Gives success with null blob) - procedure null_blob; - - --%test(Gives success with null boolean) - procedure null_boolean; - - --%test(Gives success with null clob) - procedure null_clob; - - --%test(Gives success with null date) - procedure null_date; - - --%test(Gives success with null number) - procedure null_number; - - --%test(Gives success null timestamp) - procedure null_timestamp; - - --%test(Gives success with null timestamp with local time zone) - procedure null_timestamp_with_ltz; - - --%test(Gives success with null timestamp with time zone) - procedure null_timestamp_with_tz; - - --%test(Gives success with null varchar2) - procedure null_varchar2; - - --%test(Gives success with null anydata) - procedure null_anydata; - - --%test(Gives success with uninitialized object within anydata) - procedure uninit_object_in_anydata; - - --%test(Gives success with uninitialized nested table within anydata) - procedure uninit_nested_table_in_anydata; - - --%test(Gives success with uninitialized varray within anydata) - procedure uninit_varray_in_anydata; - - --%test(Gives failure for not null blob) - procedure blob_not_null; - - --%test(Gives failure for blob with length 0) - procedure blob_0_length; - - --%test(Gives failure for not null boolean) - procedure boolean_not_null; - - --%test(Gives failure for not null clob) - procedure clob_not_null; - - --%test(Gives failure for clob with length 0) - procedure clob_0_length; - - --%test(Gives failure for not null date) - procedure date_not_null; - - --%test(Gives failure for not null number) - procedure number_not_null; - - --%test(Gives failure for not null timestamp) - procedure timestamp_not_null; - - --%test(Gives failure for not null timestamp with local time zone) - procedure timestamp_with_ltz_not_null; - - --%test(Gives failure for not null timestamp with time zone) - procedure timestamp_with_tz_not_null; - - --%test(Gives failure for not null varchar2) - procedure varchar2_not_null; - - --%test(Gives failure for initialized object within anydata) - procedure initialized_object; - - --%test(Gives failure for initialized nested table within anydata) - procedure initialized_nested_table; - - --%test(Gives failure for initialized varray within anydata) - procedure initialized_varray; - -end test_expect_to_be_null; -/ diff --git a/test/core/expectations/compound_data/test_expectation_anydata.pkb b/test/core/expectations/test_expectation_anydata.pkb similarity index 100% rename from test/core/expectations/compound_data/test_expectation_anydata.pkb rename to test/core/expectations/test_expectation_anydata.pkb diff --git a/test/core/expectations/compound_data/test_expectation_anydata.pks b/test/core/expectations/test_expectation_anydata.pks similarity index 98% rename from test/core/expectations/compound_data/test_expectation_anydata.pks rename to test/core/expectations/test_expectation_anydata.pks index 95df59512..fedec586c 100644 --- a/test/core/expectations/compound_data/test_expectation_anydata.pks +++ b/test/core/expectations/test_expectation_anydata.pks @@ -1,7 +1,7 @@ create or replace package test_expectation_anydata is --%suite(equal on anydata) - --%suitepath(utplsql.core.expectations.compound_data) + --%suitepath(utplsql.core.expectations) --%aftereach procedure cleanup; diff --git a/test/core/expectations/test_expectation_processor.pkb b/test/core/expectations/test_expectation_processor.pkb new file mode 100644 index 000000000..17ffbec3c --- /dev/null +++ b/test/core/expectations/test_expectation_processor.pkb @@ -0,0 +1,71 @@ +create or replace package body test_expectation_processor is + + procedure who_called_expectation is + l_stack_trace varchar2(4000); + l_source_line varchar2(4000); + begin + l_stack_trace := q'[----- PL/SQL Call Stack ----- + object line object + handle number name +34f88e4420 124 package body SCH_TEST.UT_EXPECTATION_PROCESSOR +353dfeb2f8 26 SCH_TEST.UT_EXPECTATION_RESULT +cba249ce0 112 SCH_TEST.UT_EXPECTATION +3539881cf0 21 SCH_TEST.UT_EXPECTATION_NUMBER +351a608008 28 package body SCH_TEST.TPKG_PRIOR_YEAR_GENERATION +351a6862b8 6 anonymous block +351fe31010 1825 package body SYS.DBMS_SQL +20befbe4d8 129 SCH_TEST.UT_EXECUTABLE +20befbe4d8 65 SCH_TEST.UT_EXECUTABLE +34f8ab7cd8 80 SCH_TEST.UT_TEST +34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM +34f8ab9b10 74 SCH_TEST.UT_SUITE +34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM +cba24bfd0 75 SCH_TEST.UT_LOGICAL_SUITE +353dfecf30 59 SCH_TEST.UT_RUN +34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM +357f5421e8 77 package body SCH_TEST.UT_RUNNER +357f5421e8 111 package body SCH_TEST.UT_RUNNER +20be951ab0 292 package body SCH_TEST.UT +20be951ab0 320 package body SCH_TEST.UT +]'; + ut.expect( + ut3.ut_expectation_processor.who_called_expectation(l_stack_trace) + ).to_be_like('at "SCH_TEST.TPKG_PRIOR_YEAR_GENERATION", line 28 %'); + end; + + + procedure who_called_expectation_0x is + l_stack_trace varchar2(4000); + l_source_line varchar2(4000); + begin + l_stack_trace := q'[----- PL/SQL Call Stack ----- + object line object + handle number name +34f88e4420 124 package body SCH_TEST.UT_EXPECTATION_PROCESSOR +353dfeb2f8 26 SCH_TEST.UT_EXPECTATION_RESULT +cba249ce0 112 SCH_TEST.UT_EXPECTATION +3539881cf0 21 SCH_TEST.UT_EXPECTATION_NUMBER +351a608008 28 package body SCH_TEST.TPKG_PRIOR_YEAR_GENERATION +351a6862b8 6 anonymous block +351fe31010 1825 package body SYS.DBMS_SQL +20befbe4d8 129 SCH_TEST.UT_EXECUTABLE +20befbe4d8 65 SCH_TEST.UT_EXECUTABLE +34f8ab7cd8 80 SCH_TEST.UT_TEST +34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM +34f8ab9b10 74 SCH_TEST.UT_SUITE +34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM +cba24bfd0 75 SCH_TEST.UT_LOGICAL_SUITE +353dfecf30 59 SCH_TEST.UT_RUN +34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM +357f5421e8 77 package body SCH_TEST.UT_RUNNER +357f5421e8 111 package body SCH_TEST.UT_RUNNER +20be951ab0 292 package body SCH_TEST.UT +20be951ab0 320 package body SCH_TEST.UT +]'; + ut.expect( + ut3.ut_expectation_processor.who_called_expectation(l_stack_trace) + ).to_be_like('at "SCH_TEST.TPKG_PRIOR_YEAR_GENERATION", line 28 %'); + end; + +end; +/ diff --git a/test/core/expectations/test_expectation_processor.pks b/test/core/expectations/test_expectation_processor.pks new file mode 100644 index 000000000..ecde48153 --- /dev/null +++ b/test/core/expectations/test_expectation_processor.pks @@ -0,0 +1,17 @@ +create or replace package test_expectation_processor is + + --%suite(expectation_processor) + --%suitepath(utplsql.core.expectations) + + --%context(who_called_expectation) + + --%test(parses stack trace and returns object and line that called expectation) + procedure who_called_expectation; + + --%test(parses stack trace containing 0x and returns object and line that called expectation) + procedure who_called_expectation_0x; + + --%endcontext + +end; +/ diff --git a/test/core/expectations/test_expectations_cursor.pkb b/test/core/expectations/test_expectations_cursor.pkb new file mode 100644 index 000000000..d18cef5fb --- /dev/null +++ b/test/core/expectations/test_expectations_cursor.pkb @@ -0,0 +1,1991 @@ +create or replace package body test_expectations_cursor is + + gc_blob blob := to_blob('123'); + gc_clob clob := to_clob('abc'); + gc_date date := sysdate; + gc_ds_int interval day(9) to second(9) := numtodsinterval(1.12345678912, 'day'); + gc_num number := 123456789.1234567890123456789; + gc_ts timestamp(9) := to_timestamp_tz('2017-03-30 00:21:12.123456789 cet','yyyy-mm-dd hh24:mi:ss.ff9 tzr'); + gc_ts_tz timestamp(9) with time zone := to_timestamp_tz('2017-03-30 00:21:12.123456789 cet','yyyy-mm-dd hh24:mi:ss.ff9 tzr'); + gc_ts_ltz timestamp(9) with local time zone := to_timestamp_tz('2017-03-30 00:21:12.123456789 cet','yyyy-mm-dd hh24:mi:ss.ff9 tzr'); + gc_varchar varchar2(4000) := 'a varchar2'; + gc_ym_int interval year(9) to month := numtoyminterval(1.1, 'year'); + + procedure cleanup_expectations is + begin + expectations.cleanup_expectations( ); + end; + + procedure setup_temp_table_test + as + pragma autonomous_transaction; + begin + execute immediate 'create global temporary table gtt_test_table ( + value varchar2(250) + ) on commit delete rows'; + + end; + + procedure cleanup_temp_table_test + as + pragma autonomous_transaction; + begin + execute immediate 'drop table gtt_test_table'; + end; + + procedure with_temp_table + as + pragma autonomous_transaction; + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + -- Arrange + execute immediate 'insert into gtt_test_table ( value ) ' || + 'select ''Test-entry'' from dual union all ' || + 'select ''Other test entry'' from dual'; + open l_expected for + select 'Test-entry' as value from dual union all + select 'Other test entry' as value from dual; + open l_actual for 'select * from gtt_test_table'; + --Act - execute the expectation on cursor opened on GTT + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + --Cleanup + rollback; + end; + + + procedure success_on_same_data + as + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + -- Arrange + open l_expected for + select 1 as my_num, + 'This is my test string' as my_string, + to_clob('This is an even longer test clob') as my_clob, + to_date('1984-09-05', 'YYYY-MM-DD') as my_date + from dual; + open l_actual for + select 1 as my_num, + 'This is my test string' as my_string, + to_clob('This is an even longer test clob') as my_clob, + to_date('1984-09-05', 'YYYY-MM-DD') as my_date + from dual; + --Act + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure success_on_empty + as + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + -- Arrange + open l_expected for select * from dual where 1=0; + open l_actual for select * from dual where 1=0; + --Act + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure success_on_both_null + as + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + --Act + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure success_to_be_null + as + l_actual sys_refcursor; + begin + --Act + ut3.ut.expect( l_actual ).to_be_null(); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure success_not_to_be_not_null + as + l_actual sys_refcursor; + begin + --Act + ut3.ut.expect( l_actual ).not_to_be_not_null(); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure success_not_to_be_null + as + l_actual sys_refcursor; + begin + --Arrange + open l_actual for select * from dual; + --Act + ut3.ut.expect( l_actual ).to_be_not_null(); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure success_to_be_not_null + as + l_actual sys_refcursor; + begin + --Arrange + open l_actual for select * from dual; + --Act + ut3.ut.expect( l_actual ).to_be_not_null(); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure success_is_empty + as + l_actual sys_refcursor; + begin + --Arrange + open l_actual for select * from dual where 0=1; + --Act + ut3.ut.expect( l_actual ).to_be_empty(); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure success_is_not_empty + as + l_actual sys_refcursor; + begin + --Arrange + open l_actual for select * from dual; + --Act + ut3.ut.expect( l_actual ).not_to_be_empty(); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure failure_is_null + as + l_actual sys_refcursor; + begin + --Arrange + open l_actual for select * from dual; + --Act + ut3.ut.expect( l_actual ).to_be_null(); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure failure_is_not_null + as + l_actual sys_refcursor; + begin + --Act + ut3.ut.expect( l_actual ).not_to_be_null(); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure failure_is_empty + as + l_actual sys_refcursor; + begin + --Arrange + open l_actual for select * from dual; + --Act + ut3.ut.expect( l_actual ).to_be_empty(); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure failure_is_not_empty + as + l_actual sys_refcursor; + begin + --Arrange + open l_actual for select * from dual where 0=1; + --Act + ut3.ut.expect( l_actual ).not_to_be_empty(); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure fail_null_vs_empty + as + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + --Arrange + open l_expected for select * from dual where 1=0; + --Act + ut3.ut.expect( l_actual ).not_to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure fail_on_difference + as + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + --Arrange + open l_expected for select to_clob('This is an even longer test clob') as my_clob from dual; + open l_actual for select to_clob('Another totally different story') as my_clob from dual; + --Act + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure fail_on_expected_missing + as + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + --Arrange + open l_expected for select 1 as my_num from dual; + open l_actual for select 1 as my_num from dual union all select 1 as my_num from dual; + --Act + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure fail_on_actual_missing + as + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + --Arrange + open l_expected for select 1 as my_num from dual union all select 1 as my_num from dual; + open l_actual for select 1 as my_num from dual; + --Act + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure fail_on_different_column_name + as + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + --Arrange + open l_expected for select 1 as col_1 from dual; + open l_actual for select 1 as col_2 from dual; + --Act + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + + procedure fail_on_different_column_order + as + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + --Arrange + open l_expected for select 1 as col_1, 2 as col_2 from dual; + open l_actual for select 2 as col_2, 1 as col_1 from dual; + --Act + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure fail_on_different_row_order + as + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + --Arrange + open l_expected for select 1 as my_num from dual union all select 2 as my_num from dual; + open l_actual for select 2 as my_num from dual union all select 1 as my_num from dual; + --Act + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure include_time_in_date_with_nls + as + l_expected sys_refcursor; + l_actual sys_refcursor; + l_date date := sysdate; + l_second number := 1/24/60/60; + begin + --Arrange + ut3.ut.set_nls; + open l_actual for select l_date as some_date from dual; + open l_expected for select l_date-l_second some_date from dual; + ut3.ut.reset_nls; + --Act + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure uses_default_nls_for_date + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select sysdate as some_date from dual; + open l_expected for select to_date(to_char(sysdate)) as some_date from dual; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure exclude_columns_as_list + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>ut3.ut_varchar2_list('A_COLUMN','Some_Col')); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure exclude_columns_as_csv + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>'A_COLUMN,Some_Col'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure exclude_columns_as_mixed_list is + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>ut3.ut_varchar2_list('A_COLUMN','/ROW/Some_Col')); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure exclude_columns_as_mix_csv_lst is + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>'A_COLUMN,/ROW/Some_Col'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure exclude_columns_xpath_invalid + as + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_error_code integer := -31011; --xpath_error + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + begin + --Act + ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>'/ROW/A_COLUMN,\\//Some_Col'); + --Assert + ut.fail('Expected '||l_error_code||' but nothing was raised'); + exception + when others then + ut.expect(sqlcode).to_equal(l_error_code); + end; + end; + + procedure exclude_columns_xpath + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual; + open l_expected for select 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>'/ROW/A_COLUMN|/ROW/Some_Col'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure exclude_ignores_invalid_column + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'c' as A_COLUMN from dual a connect by level < 4; + open l_expected for select rownum as rn, 'd' as A_COLUMN from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>ut3.ut_varchar2_list('A_COLUMN','non_existing_column')); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure include_columns_as_list + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).include(ut3.ut_varchar2_list('RN','//A_Column','SOME_COL')); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure include_columns_as_csv + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).include('RN,//A_Column,SOME_COL'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure include_columns_xpath_invalid + as + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + begin + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).include('/ROW/RN,\\//A_Column,//SOME_COL'); + --Assert + ut.fail('Expected exception but nothing was raised'); + exception + when others then + ut.expect(sqlcode).to_be_between(-31013,-31011); + end; + end; + + procedure include_columns_xpath + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).include('/ROW/RN|//A_Column|//SOME_COL'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure include_ignores_invalid_column + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'c' as A_COLUMN from dual a connect by level < 4; + open l_expected for select rownum as rn, 'd' as A_COLUMN from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).include(ut3.ut_varchar2_list('RN','non_existing_column')); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure include_exclude_col_csv_xpath + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).exclude('Some_Col').include('/ROW/RN|//Some_Col'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure include_exclude_columns_list + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).exclude(ut3.ut_varchar2_list('A_COLUMN')).include(ut3.ut_varchar2_list('RN','A_Column','A_COLUMN')); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure data_diff_on_rows_mismatch + as + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select 1 rn from dual union all select 6 rn from dual; + open l_expected for select rownum rn from dual connect by level <=3; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + + l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 3 ] +Diff: +Rows: [ 2 differences ] + Row No. 2 - Actual: 6 + Row No. 2 - Expected: 2 + Row No. 3 - Missing: 3]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure char_and_varchar2_col_is_equal is + l_expected sys_refcursor; + l_actual sys_refcursor; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select cast('a' as char(1)) a_column, 1 as id from dual; + open l_expected for select cast('a' as varchar2(10)) a_column from dual; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + l_expected_message := q'[Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = 1 ] +Diff: +Columns: + Column [position: 2, data-type: NUMBER] is not expected in results. +Rows: [ 1 differences ] + All rows are different as the columns are not matching.]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure column_diff_on_data_type_diff is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select to_char(rownum) rn, rownum another_rn from dual connect by level <=2; + open l_expected for select rownum rn, rownum another_rn from dual connect by level <=2; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + + l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ] +Diff: +Columns: + Column data-type is invalid. Expected: NUMBER, actual: VARCHAR2.]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure column_diff_on_col_name_diff is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select rownum rn, rownum bad_column_name from dual connect by level <=2; + open l_expected for select rownum rn, rownum expected_column_name from dual connect by level <=2; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + + l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ] +Diff: +Columns:% + Column [data-type: NUMBER] is missing. Expected column position: 2.% + Column [position: 2, data-type: NUMBER] is not expected in results.%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + --%test(Reports column diff on cusror with different column positions) + procedure column_diff_on_col_position is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select rownum+1 col_1, rownum+2 col_2, rownum+3 col_3, rownum+4 col_4 from dual connect by level <=2; + open l_expected for select rownum+1 col_1, rownum+4 col_4, rownum+2 col_2, rownum+3 col_3 from dual connect by level <=2; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + + l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ] +Diff: +Columns: + Column is misplaced. Expected position: 2, actual position: 4. + Column is misplaced. Expected position: 3, actual position: 2. + Column is misplaced. Expected position: 4, actual position: 3. +Rows: [ 2 differences ] + All rows are different as the columns are not matching.]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + + --%test(Reports only mismatched columns on column data mismatch) + procedure data_diff_on_col_data_mismatch is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select rownum good_col, -rownum bad_col from dual connect by level <=2; + open l_expected for select rownum good_col, rownum bad_col from dual connect by level <=2; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + + l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ] +Diff: +Rows: [ 2 differences ] + Row No. 1 - Actual: -1 + Row No. 1 - Expected: 1 + Row No. 2 - Actual: -2 + Row No. 2 - Expected: 2]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure data_diff_on_20_rows_only is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for + select rownum + * case when mod(rownum,2) = 0 then -1 else 1 end bad_col, + rownum good_col + from dual connect by level <=100; + open l_expected for select rownum bad_col, rownum good_col from dual connect by level <=110; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + + l_expected_message := q'[Actual: refcursor [ count = 100 ] was expected to equal: refcursor [ count = 110 ] +Diff: +Rows: [ 60 differences, showing first 20 ] + Row No. 2 - Actual: -2 + Row No. 2 - Expected: 2 + Row No. 4 - Actual: -4 + Row No. 4 - Expected: 4 + Row No. 6 - Actual: -6 + Row No. 6 - Expected: 6 + Row No. 8 - Actual: -8 + Row No. 8 - Expected: 8 + % + Row No. 38 - Actual: -38 + Row No. 38 - Expected: 38 + Row No. 40 - Actual: -40 + Row No. 40 - Expected: 40]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure column_and_data_diff is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_expected for + select 1 as ID, 'JACK' as FIRST_NAME, 'SPARROW' AS LAST_NAME, 10000 AS SALARY from dual union all + select 2 as ID, 'LUKE' as FIRST_NAME, 'SKYWALKER' AS LAST_NAME, 1000 AS SALARY from dual union all + select 3 as ID, 'TONY' as FIRST_NAME, 'STARK' AS LAST_NAME, 100000 AS SALARY from dual; + open l_actual for + select 'M' AS GENDER, 'JACK' as FIRST_NAME, 'SPARROW' AS LAST_NAME, 1 as ID, '25000' AS SALARY from dual union all + select 'M' AS GENDER, 'TONY' as FIRST_NAME, 'STARK' AS LAST_NAME, 3 as ID, '100000' AS SALARY from dual union all + select 'F' AS GENDER, 'JESSICA' as FIRST_NAME, 'JONES' AS LAST_NAME, 4 as ID, '2345' AS SALARY from dual union all + select 'M' AS GENDER, 'LUKE' as FIRST_NAME, 'SKYWALKER' AS LAST_NAME, 2 as ID, '1000' AS SALARY from dual; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + l_expected_message := q'[Actual: refcursor [ count = 4 ] was expected to equal: refcursor [ count = 3 ] +Diff: +Columns: + Column is misplaced. Expected position: 1, actual position: 4. + Column data-type is invalid. Expected: NUMBER, actual: VARCHAR2. + Column [position: 1, data-type: CHAR] is not expected in results. +Rows: [ 4 differences ] + Row No. 1 - Actual: 25000 + Row No. 1 - Expected: 10000 + Row No. 2 - Actual: TONYSTARK3100000 + Row No. 2 - Expected: 2LUKESKYWALKER1000 + Row No. 3 - Actual: JESSICAJONES42345 + Row No. 3 - Expected: 3TONYSTARK100000 + Row No. 4 - Extra: MLUKESKYWALKER21000]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure prepare_table + as + pragma autonomous_transaction; + begin + execute immediate + 'create table test_table_for_cursors ( + some_blob blob, + some_clob clob, + some_date date, + some_ds_interval interval day(9) to second(9), + some_nummber number, + some_timestamp timestamp(9), + some_timestamp_tz timestamp(9) with time zone, + some_timestamp_ltz timestamp(9) with local time zone, + some_varchar2 varchar2(4000), + some_ym_interval interval year(9) to month + )'; + execute immediate q'[ + insert into test_table_for_cursors + values( :gc_blob, :gc_clob, :gc_date, :gc_ds_int, :gc_num, :gc_ts, :gc_ts_tz, :gc_ts_ltz, :gc_varchar, :gc_ym_int + ) +]' using gc_blob, gc_clob, gc_date, gc_ds_int, gc_num, gc_ts, gc_ts_tz, gc_ts_ltz, gc_varchar, gc_ym_int; + commit; + end; + + procedure cleanup_table + as + pragma autonomous_transaction; + begin + execute immediate 'drop table test_table_for_cursors'; + end; + + procedure compares_sql_and_plsql_types is + l_expected sys_refcursor; + l_actual sys_refcursor; + begin + --Arrange + open l_expected for + select gc_blob some_blob, + gc_clob some_clob, + gc_date some_date, + gc_ds_int some_ds_interval, + gc_num some_nummber, + gc_ts some_timestamp, + gc_ts_tz some_timestamp_tz, + gc_ts_ltz some_timestamp_ltz , + gc_varchar some_varchar2, + gc_ym_int some_ym_interval + from dual; + open l_actual for q'[select * from test_table_for_cursors]'; + --Act + ut3.ut.expect(l_expected).to_equal(l_actual); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure closes_cursor_after_use + as + l_actual sys_refcursor; + begin + --Arrange + open l_actual for select 1 as value from dual; + --Act + ut3.ut.expect(l_actual).to_be_empty(); + --Assert + ut.expect(l_actual%isopen).to_be_false(); + end; + + procedure closes_cursor_after_use_on_err + as + l_actual sys_refcursor; + begin + --Arrange + open l_actual for select 1/0 as value from dual; + --Act + begin + ut3.ut.expect(l_actual).to_be_empty(); + exception + when others then + null; + end; + --Assert + ut.expect(l_actual%isopen).to_be_false(); + end; + + procedure reports_on_exception_in_cursor + as + l_actual sys_refcursor; + l_error_code integer := -19202; --Error occurred in XML processing + begin + --Act + open l_actual for select 1/0 as error_column from dual connect by level < 10; + begin + ut3.ut.expect(l_actual).to_be_empty(); + --Assert + ut.fail('Expected '||l_error_code||' but nothing was raised'); + exception + when others then + ut.expect(sqlcode).to_equal(l_error_code); + end; + end; + + procedure exception_when_closed_cursor + is + l_actual sys_refcursor; + l_error_code constant integer := -20155; + begin + --Arrange + open l_actual for select * from dual; + close l_actual; + --Act + ut3.ut.expect( l_actual ).not_to_be_null; + exception + when others then + --Assert + ut.expect(sqlcode).to_equal(l_error_code); + end; + + procedure compares_over_1000_rows + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select object_name from all_objects where rownum <=1100; + open l_expected for select object_name from all_objects where rownum <=1100; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + function get_cursor return sys_refcursor is + l_cursor sys_refcursor; + begin + open l_cursor for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + return l_cursor; + end; + + procedure deprec_to_equal_excl_varch is + begin + --Act + ut3.ut.expect(get_cursor()).to_equal(get_cursor(), a_exclude => 'A_COLUMN,Some_Col'); + --Assert + ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); + ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); + end; + + procedure deprec_to_equal_excl_list is + begin + --Act + ut3.ut.expect(get_cursor()).to_equal(get_cursor(), a_exclude => ut3.ut_varchar2_list('A_COLUMN','Some_Col')); + --Assert + ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); + ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); + end; + + procedure deprec_not_to_equal_excl_varch is + begin + --Act + ut3.ut.expect(get_cursor()).not_to_equal(get_cursor(), a_exclude => 'A_COLUMN,Some_Col'); + --Assert + ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); + ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); + end; + + procedure deprec_not_to_equal_excl_list is + begin + --Act + ut3.ut.expect(get_cursor()).not_to_equal(get_cursor(), a_exclude => ut3.ut_varchar2_list('A_COLUMN','Some_Col')); + --Assert + ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); + ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); + end; + + procedure deprec_equal_excl_varch is + begin + --Act + ut3.ut.expect(get_cursor()).to_(ut3.equal(get_cursor(), a_exclude => 'A_COLUMN,Some_Col')); + --Assert + ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); + ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); + end; + + procedure deprec_equal_excl_list is + begin + --Act + ut3.ut.expect(get_cursor()).to_(ut3.equal(get_cursor(), a_exclude => ut3.ut_varchar2_list('A_COLUMN','Some_Col'))); + --Assert + ut.expect(cardinality(ut3.ut_expectation_processor.get_warnings())).to_equal(1); + ut.expect(ut3.ut_expectation_processor.get_warnings()(1)).to_be_like('The syntax: "%" is deprecated.%'); + end; + + procedure col_diff_on_col_name_implicit is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select '1' , '2' from dual connect by level <=2; + open l_expected for select rownum , rownum expected_column_name from dual connect by level <=2; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + + l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]% +Diff:% +Columns:% + Column [data-type: NUMBER] is missing. Expected column position: 1.% + Column [data-type: NUMBER] is missing. Expected column position: 2.% + Column <%1%> [position: 1, data-type: CHAR] is not expected in results.% + Column <%2%> [position: 2, data-type: CHAR] is not expected in results.% +Rows: [ 2 differences ]% + All rows are different as the columns are not matching.%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure col_mtch_on_col_name_implicit is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select '1' , rownum from dual connect by level <=2; + open l_expected for select '1' , rownum from dual connect by level <=2; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + + procedure include_col_name_implicit is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + begin + --Arrange + open l_actual for select rownum as rn, 'a', 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a', 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + begin + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).include(q'!/ROW/RN,'a',//SOME_COL!'); + --Assert + ut.fail('Expected exception but nothing was raised'); + exception + when others then + ut.expect(sqlcode).to_be_between(-31013,-31011); + end; + end; + + procedure exclude_col_name_implicit is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + begin + --Arrange + open l_actual for select rownum as rn, 'a', 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a', 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + begin + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).exclude(q'!/ROW/RN,'a',//SOME_COL!'); + --Assert + ut.fail('Expected exception but nothing was raised'); + exception + when others then + ut.expect(sqlcode).to_be_between(-31013,-31011); + end; + end; + + procedure cursor_unorderd_compr_success is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + begin + --Arrange + open l_actual for select username , user_id from all_users order by username asc; + open l_expected for select username , user_id from all_users order by username desc; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).unordered; + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure cursor_unordered_compare_fail is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select 'test1' username,-100 user_id from dual + union all + select 'test' username,-666 user_id from dual + order by 1 asc; + + open l_expected for select 'test1' username,-100 user_id from dual + union all + select 'test' username,-667 user_id from dual + order by 1 desc; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).unordered; + l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]% +%Diff:% +%Rows: [ 2 differences ]% +%Extra: test-666% +%Missing: test-667%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure cursor_joinby_compare is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + begin + --Arrange + open l_actual for select owner, object_name,object_type from all_objects where owner = user + order by 1,2,3 asc; + open l_expected for select owner, object_name,object_type from all_objects where owner = user + order by 1,2,3 desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('OWNER'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure cursor_joinby_compare_twocols is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + begin + --Arrange + open l_actual for select owner, object_name,object_type from all_objects where owner = user + order by 1,2,3 asc; + open l_expected for select owner, object_name,object_type from all_objects where owner = user + order by 1,2,3 desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by(ut3.ut_varchar2_list('OWNER,OBJECT_NAME')); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure cursor_joinby_compare_nokey is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select rownum as rn, 'x' SOME_COL from dual a connect by level < 4; + open l_expected for select rownum as rn, 'x' SOME_COL from dual a connect by level < 4; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('OWNER'); + --Assert + l_expected_message := q'[%Actual: refcursor [ count = 3 ] was expected to equal: refcursor [ count = 3 ]% +Diff:% +%Unable to join sets:% +%Join key OWNER does not exists in expected% +%Join key OWNER does not exists in actual%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure cur_joinby_comp_twocols_nokey is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select rownum as rn, 'x' SOME_COL from dual a connect by level < 4; + open l_expected for select rownum as rn, 'x' SOME_COL from dual a connect by level < 4; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by(ut3.ut_varchar2_list('OWNER,USER_ID')); + --Assert + l_expected_message := q'[%Actual: refcursor [ count = 3 ] was expected to equal: refcursor [ count = 3 ]% +Diff:% +%Unable to join sets:% +%Join key OWNER does not exists in expected% +%Join key USER_ID does not exists in expected% +%Join key OWNER does not exists in actual% +%Join key USER_ID does not exists in actual%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure cursor_joinby_compare_exkey is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select rownum as rn, 'x' SOME_COL from dual a connect by level < 4; + open l_expected for select rownum as rn, 'x' SOME_COL from dual a connect by level < 4; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('SOME_COL').exclude('SOME_COL'); + --Assert + l_expected_message := q'[%Actual: refcursor [ count = 3 ] was expected to equal: refcursor [ count = 3 ]% +Diff:% +%Unable to join sets:% +%Join key SOME_COL does not exists in expected% +%Join key SOME_COL does not exists in actual%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure cur_joinby_comp_twocols_exkey is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select rownum as rn, 'x' SOME_COL from dual a connect by level < 4; + open l_expected for select rownum as rn, 'x' SOME_COL from dual a connect by level < 4; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by(ut3.ut_varchar2_list('RN,SOME_COL')).exclude('RN'); + --Assert + l_expected_message := q'[%Actual: refcursor [ count = 3 ] was expected to equal: refcursor [ count = 3 ]% +Diff:% +%Unable to join sets:% +%Join key RN does not exists in expected% +%Join key RN does not exists in actual%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure cursor_joinby_comp_nokey_ex is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select rownum as rni, 'x' SOME_COL from dual a connect by level < 4; + open l_expected for select rownum as rn, 'x' SOME_COL from dual a connect by level < 4; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('RNI'); + --Assert + l_expected_message := q'[%Actual: refcursor [ count = 3 ] was expected to equal: refcursor [ count = 3 ]% +Diff:% +%Unable to join sets:% +%Join key RNI does not exists in expected%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure cursor_joinby_comp_nokey_ac is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_actual for select rownum as rn, 'x' SOME_COL from dual a connect by level < 4; + open l_expected for select rownum as rni, 'x' SOME_COL from dual a connect by level < 4; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('RNI'); + --Assert + l_expected_message := q'[%Actual: refcursor [ count = 3 ] was expected to equal: refcursor [ count = 3 ]% +Diff:% +%Unable to join sets:% +%Join key RNI does not exists in actual%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure cursor_joinby_compare_1000 is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + begin + --Arrange + open l_actual for select object_name from all_objects where rownum <=1100; + open l_expected for select object_name from all_objects where rownum <=1100; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('OBJECT_NAME'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure cursor_joinby_compare_fail is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_expected for select username, user_id from all_users union all + select 'TEST' username, -600 user_id from dual order by 1 desc; + + open l_actual for select username, user_id from all_users union all + select 'TEST' username, -610 user_id from dual order by 1 asc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('USERNAME'); + --Assert + l_expected_message := q'[%Actual: refcursor [ count = % ] was expected to equal: refcursor [ count = % ] +%Diff:% +%Rows: [ 1 differences ]% +%PK TEST - Actual:%-610% +%PK TEST - Expected:%-600%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure cursor_joinby_cmp_twocol_fail is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_expected for select username, user_id from all_users union all + select 'TEST' username, -600 user_id from dual order by 1 desc; + + open l_actual for select username, user_id from all_users union all + select 'TEST' username, -610 user_id from dual order by 1 asc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by(ut3.ut_varchar2_list('USERNAME,USER_ID')); + --Assert + l_expected_message := q'[%Actual: refcursor [ count = % ] was expected to equal: refcursor [ count = % ] +%Diff:% +%Rows: [ 2 differences ]% +%PK TEST-610 - Extra% +%PK TEST-600 - Missing%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure cur_joinby_cmp_threcol_fail is + l_actual SYS_REFCURSOR; + l_expected SYS_REFCURSOR; + l_actual_message varchar2(32767); + l_expected_message varchar2(32767); + begin + --Arrange + open l_expected for select username, user_id,'Y' is_valid from all_users union all + select 'TEST' username, -600 user_id,'Y' is_valid from dual order by 1 desc; + + open l_actual for select username, user_id,'Y' is_valid from all_users union all + select 'TEST' username, -610 user_id,'Y' is_valid from dual order by 1 asc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by(ut3.ut_varchar2_list('USERNAME,IS_VALID')); + --Assert + l_expected_message := q'[%Actual: refcursor [ count = % ] was expected to equal: refcursor [ count = % ] +%Diff:% +%Rows: [ 1 differences ]% +%PK TESTY - Actual:%-610% +%PK TESTY - Expected:%-600%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure unord_incl_cols_as_list + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).include(ut3.ut_varchar2_list('RN','//A_Column','SOME_COL')).unordered; + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure joinby_incl_cols_as_list + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).include(ut3.ut_varchar2_list('RN','//A_Column','SOME_COL')).join_by('SOME_COL'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure joinby_excl_cols_as_list + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).exclude(ut3.ut_varchar2_list('//Some_Col','A_COLUMN')).join_by('SOME_COL'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure unord_excl_cols_as_list + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 4; + open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).exclude(ut3.ut_varchar2_list('A_COLUMN|//Some_Col')).unordered; + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure excl_dif_cols_as_list + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'TEST' as A_COLUMN from dual a connect by level < 4; + open l_expected for select rownum as rn, 1 as A_COLUMN from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).exclude(ut3.ut_varchar2_list('A_COLUMN')); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure inlc_dif_cols_as_list + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'TEST' as A_COLUMN from dual a connect by level < 4; + open l_expected for select rownum as rn, 1 as A_COLUMN from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).include(ut3.ut_varchar2_list('RN')); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure inlc_exc_dif_cols_as_list + as + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn, 'TEST' as A_COLUMN from dual a connect by level < 4; + open l_expected for select rownum as rn, 1 as A_COLUMN from dual a connect by level < 4; + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).include(ut3.ut_varchar2_list('RN')).exclude(ut3.ut_varchar2_list('A_COLUMN')); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure compare_obj_typ_col_un is + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select test_dummy_object( rownum, 'Something '||rownum, rownum) as colval + from dual connect by level <=2 order by rownum asc; + + open l_expected for select test_dummy_object( rownum, 'Something '||rownum, rownum) as colval + from dual connect by level <=2 order by rownum desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).unordered; + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure compare_obj_typ_col_jb is + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select test_dummy_object( rownum, 'Something '||rownum, rownum) as colval + from dual connect by level <=2 order by rownum asc; + + open l_expected for select test_dummy_object( rownum, 'Something '||rownum, rownum) as colval + from dual connect by level <=2 order by rownum desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('COLVAL/ID'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure comp_obj_typ_col_un_fail is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + --Arrange + open l_actual for select test_dummy_object( rownum, 'Something '||rownum, rownum) as colval + from dual connect by level <=2 order by rownum asc; + + open l_expected for select test_dummy_object( rownum, 'Somethings '||rownum, rownum) as colval + from dual connect by level <=3 order by rownum desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).unordered; + l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 3 ]% +Diff:% +Rows: [ 5 differences ] +%Extra: 2Something 22% +%Extra: 1Something 11% +%Missing: 1Somethings 11% +%Missing: 2Somethings 22% +%Missing: 3Somethings 33%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure comp_obj_typ_col_jb_fail is + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select test_dummy_object( rownum, 'Something '||rownum, rownum) as colval + from dual connect by level <=2 order by rownum asc; + + open l_expected for select test_dummy_object( rownum, 'Somethings '||rownum, rownum) as colval + from dual connect by level <=2 order by rownum desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('COLVAL/ID'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_not_null(); + end; + + procedure comp_obj_typ_col_jb_multi is + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + --Arrange + open l_actual for select rownum as rn,test_dummy_object( rownum, 'Something '||rownum, rownum) as colval + from dual connect by level <=2 order by rownum asc; + + open l_expected for select rownum as rn,test_dummy_object( rownum, 'Something '||rownum, rownum) as colval + from dual connect by level <=2 order by rownum desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by(ut3.ut_varchar2_list('RN,COLVAL/ID')); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure comp_obj_typ_col_jb_nokey is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + --Arrange + open l_actual for select test_dummy_object( rownum, 'Something '||rownum, rownum) as colval + from dual connect by level <=2 order by rownum asc; + + open l_expected for select test_dummy_object( rownum, 'Something '||rownum, rownum) as colval + from dual connect by level <=2 order by rownum desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('COLVAL/IDS'); + + l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]% +Diff:% +%Unable to join sets:% +%Join key COLVAL/IDS does not exists in expected% +%Join key COLVAL/IDS does not exists in actual%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure compare_nest_tab_col_jb is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_key_value_pair(rownum,'Something '||rownum) + bulk collect into l_actual_tab + from dual connect by level <=2; + + select ut3.ut_key_value_pair(rownum,'Something '||rownum) + bulk collect into l_expected_tab + from dual connect by level <=2; + + --Arrange + open l_actual for select key,value + from table(l_actual_tab) order by 1 asc; + + open l_expected for select key,value + from table(l_expected_tab) order by 1 desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('KEY'); + + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure compare_nest_tab_col_jb_fail is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_key_value_pair(rownum,'Something '||rownum) + bulk collect into l_actual_tab + from dual connect by level <=2; + + select ut3.ut_key_value_pair(rownum,'Somethings '||rownum) + bulk collect into l_expected_tab + from dual connect by level <=2; + + --Arrange + open l_actual for select key,value + from table(l_actual_tab) order by 1 asc; + + open l_expected for select key,value + from table(l_expected_tab) order by 1 desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('KEY'); + l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]% +%Diff:% +%Rows: [ 2 differences ]% +%PK % - Actual: %% +%PK % - Expected: %% +%PK % - Actual: %% +%PK % - Expected: %%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure compare_nest_tab_cols_jb is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_key_value_pair(rownum,'Something '||rownum) + bulk collect into l_actual_tab + from dual connect by level <=2; + + select ut3.ut_key_value_pair(rownum,'Something '||rownum) + bulk collect into l_expected_tab + from dual connect by level <=2; + + --Arrange + open l_actual for select key,value + from table(l_actual_tab) order by 1 asc; + + open l_expected for select key,value + from table(l_expected_tab) order by 1 desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by(ut3.ut_varchar2_list('KEY,VALUE')); + + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure compare_nest_tab_cols_jb_fail is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_key_value_pair(rownum,'Something '||rownum) + bulk collect into l_actual_tab + from dual connect by level <=2; + + select ut3.ut_key_value_pair(rownum,'Somethings '||rownum) + bulk collect into l_expected_tab + from dual connect by level <=2; + + --Arrange + open l_actual for select key,value + from table(l_actual_tab) order by 1 asc; + + open l_expected for select key,value + from table(l_expected_tab) order by 1 desc; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by(ut3.ut_varchar2_list('KEY,VALUE')); + l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]% +%Diff:% +%Rows: [ 4 differences ]% +%PK %% - Extra% +%PK %% - Extra% +%PK %% - Missing% +%PK %% - Missing%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + end; + + procedure compare_tabtype_as_cols_jb is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_key_value_pair(rownum,'Something '||rownum) + bulk collect into l_actual_tab + from dual connect by level <=2; + + select ut3.ut_key_value_pair(rownum,'Somethings '||rownum) + bulk collect into l_expected_tab + from dual connect by level <=2; + + --Arrange + open l_actual for select rownum rn, l_actual_tab as nested_table + from dual connect by level <=2; + + open l_expected for select rownum rn, l_expected_tab as nested_table + from dual connect by level <=2; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('NESTED_TABLE'); + + --Assert + l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]% +%Diff:% +%Rows: [ 2 differences ]% +%PK %%%%%%%%%%%%%Extra%%% +%PK %%%%%%%%%%%%%Extra%%% +%PK %%%%%%%%%%%%%Missing%%% +%PK %%%%%%%%%%%%%Missing%%%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + + end; + + procedure compare_tabtype_as_cols is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_key_value_pair(rownum,'Something '||rownum) + bulk collect into l_actual_tab + from dual connect by level <=2 order by rownum asc; + + select ut3.ut_key_value_pair(rownum,'Something '||rownum) + bulk collect into l_expected_tab + from dual connect by level <=2 order by rownum asc; + + --Arrange + open l_actual for select rownum rn, l_actual_tab as nested_table + from dual connect by level <=2; + + open l_expected for select rownum rn, l_expected_tab as nested_table + from dual connect by level <=2; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + + end; + + procedure compare_tabtype_as_cols_coll is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_tab ut3.ut_key_value_pairs := ut3.ut_key_value_pairs(); + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_key_value_pair(rownum,'Something '||rownum) + bulk collect into l_actual_tab + from dual connect by level <=2; + + select ut3.ut_key_value_pair(rownum,'Somethings '||rownum) + bulk collect into l_expected_tab + from dual connect by level <=2; + + --Arrange + open l_actual for select rownum rn, l_actual_tab as nested_table + from dual connect by level <=2; + + open l_expected for select rownum rn, l_expected_tab as nested_table + from dual connect by level <=2; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('NESTED_TABLE/UT_KEY_VALUE_PAIR'); + + --Assert + l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ] +%Diff: +%Unable to join sets: +%Join key NESTED_TABLE/UT_KEY_VALUE_PAIR does not exists in expected% +%Join key NESTED_TABLE/UT_KEY_VALUE_PAIR does not exists in actual% +%Please make sure that your join clause is not refferring to collection element%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + + end; + + procedure compare_rec_colltype_as_cols is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_annotated_object; + l_expected_tab ut3.ut_annotated_object; + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_actual_tab from dual; + + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_expected_tab from dual; + + --Arrange + open l_actual for select l_actual_tab as nested_table from dual; + + open l_expected for select l_expected_tab as nested_table from dual; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('NESTED_TABLE'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + + end; + + procedure compare_rec_colltype_as_attr is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_annotated_object; + l_expected_tab ut3.ut_annotated_object; + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_actual_tab from dual; + + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_expected_tab from dual; + + --Arrange + open l_actual for select l_actual_tab as nested_table from dual; + + open l_expected for select l_expected_tab as nested_table from dual; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('NESTED_TABLE/OBJECT_OWNER'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + + end; + + procedure compare_collection_in_rec is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_annotated_object; + l_expected_tab ut3.ut_annotated_object; + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_actual_tab from dual; + + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_expected_tab from dual; + + --Arrange + open l_actual for select l_actual_tab as nested_table from dual; + + open l_expected for select l_expected_tab as nested_table from dual; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('NESTED_TABLE/ANNOTATIONS'); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + + end; + + procedure compare_rec_coll_as_cols_fl is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_annotated_object; + l_expected_tab ut3.ut_annotated_object; + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_actual_tab + from dual; + + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'1test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_expected_tab + from dual; + + --Arrange + open l_actual for select rownum rn, l_actual_tab as nested_table + from dual; + + open l_expected for select rownum rn, l_expected_tab as nested_table + from dual; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('NESTED_TABLE/OBJECT_OWNER'); + + --Assert + l_expected_message := q'[%Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = 1 ] +%Diff: +%Rows: [ 1 differences ] +%PK TEST - Actual: TESTTESTTEST1testtesttest2testtesttest% +%PK TEST - Expected: TESTTESTTEST11testtesttest2testtesttest%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + --ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure compare_rec_coll_as_join is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_actual_tab ut3.ut_annotated_object; + l_expected_tab ut3.ut_annotated_object; + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'1test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_actual_tab from dual; + + select ut3.ut_annotated_object('TEST','TEST','TEST', + ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'), + ut3.ut_annotation(2,'test','test','test')) + ) + into l_expected_tab from dual; + + --Arrange + open l_actual for select l_actual_tab as nested_table from dual; + + open l_expected for select l_expected_tab as nested_table from dual; + + --Act + ut3.ut.expect(l_actual).to_equal(l_expected).join_by('NESTED_TABLE/ANNOTATIONS/TEXT'); + + --Assert + l_expected_message := q'[%Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = 1 ]% +%Diff:% +%Unable to join sets:% +%Join key NESTED_TABLE/ANNOTATIONS/TEXT does not exists in expected% +%Join key NESTED_TABLE/ANNOTATIONS/TEXT does not exists in actual% +%Please make sure that your join clause is not refferring to collection element%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + + end; + +end; +/ diff --git a/test/core/expectations/compound_data/test_expectations_cursor.pks b/test/core/expectations/test_expectations_cursor.pks similarity index 61% rename from test/core/expectations/compound_data/test_expectations_cursor.pks rename to test/core/expectations/test_expectations_cursor.pks index 4868b72ce..a1cff85d9 100644 --- a/test/core/expectations/compound_data/test_expectations_cursor.pks +++ b/test/core/expectations/test_expectations_cursor.pks @@ -1,7 +1,7 @@ create or replace package test_expectations_cursor is - --%suite(cursor) - --%suitepath(utplsql.core.expectations.compound_data) + --%suite(cursor expectations) + --%suitepath(utplsql.core.expectations) --%aftereach procedure cleanup_expectations; @@ -26,7 +26,7 @@ create or replace package test_expectations_cursor is --%test(Gives success on to_be_null if cursor is null) procedure success_to_be_null; - --%test(Gives succes on not_to_be_not_null if cursor is null) + --%test(Gives success on not_to_be_not_null if cursor is null) procedure success_not_to_be_not_null; --%test(Gives success on not_to_be_null if cursor is not null) @@ -199,5 +199,122 @@ create or replace package test_expectations_cursor is --%test( Fail on passing implicit column name as exclude filter ) procedure exclude_col_name_implicit; + --%test( Compare cursors using unordered method success) + procedure cursor_unorderd_compr_success; + + --%test( Compare cursors using unordered method failure) + procedure cursor_unordered_compare_fail; + + --%test( Compare cursors join by single key ) + procedure cursor_joinby_compare; + + --%test( Compare cursors join by composite key) + procedure cursor_joinby_compare_twocols; + + --%test( Compare cursors join by single key - key doesnt exists ) + procedure cursor_joinby_compare_nokey; + + --%test( Compare cursors join by composite key - one part of key doesnt exists ) + procedure cur_joinby_comp_twocols_nokey; + + --%test( Compare cursors join by single key - key doesnt is excluded ) + procedure cursor_joinby_compare_exkey; + + --%test( Compare cursors join by composite key - one part of key is excluded exists ) + procedure cur_joinby_comp_twocols_exkey; + + --%test( Compare cursors join by single key - key doesnt exists in expected) + procedure cursor_joinby_comp_nokey_ex; + + --%test( Compare cursors join by single key - key doesnt exists in actual) + procedure cursor_joinby_comp_nokey_ac; + + --%test( Compare cursors join by single key more than 1000 rows) + procedure cursor_joinby_compare_1000; + + --%test( Compare two column cursors join by and fail to match ) + procedure cursor_joinby_compare_fail; + + --%test( Compare two column cursors join by two columns and fail to match ) + procedure cursor_joinby_cmp_twocol_fail; + + --%test( Compare three column cursors join by two columns and fail to match ) + procedure cur_joinby_cmp_threcol_fail; + + --%test(Unordered List of columns to include) + procedure unord_incl_cols_as_list; + + --%test(Join By List of columns to include) + procedure joinby_incl_cols_as_list; + + --%test(Unordered List of columns to exclude) + procedure unord_excl_cols_as_list; + + --%test(Join By List of columns to exclude) + procedure joinby_excl_cols_as_list; + + --%test(Exclude columns of different type) + procedure excl_dif_cols_as_list; + + --%test(Include column of same type leaving different type out) + procedure inlc_dif_cols_as_list; + + --%test(Include column of same type leaving different type out and exclude different type) + procedure inlc_exc_dif_cols_as_list; + + --%test(Compare object type unordered) + procedure compare_obj_typ_col_un; + + --%test(Compare object type join by) + procedure compare_obj_typ_col_jb; + + --%test(Compare nested table type unordered fail) + procedure comp_obj_typ_col_un_fail; + + --%test(Compare object type join by fail) + procedure comp_obj_typ_col_jb_fail; + + --%test(Compare object type join by multi key) + procedure comp_obj_typ_col_jb_multi; + + --%test(Compare object type join by missing nested key) + procedure comp_obj_typ_col_jb_nokey; + + --%test(Compare table type join by) + procedure compare_nest_tab_col_jb; + + --%test(Compare table type join by - Failure) + procedure compare_nest_tab_col_jb_fail; + + --%test(Compare table type join by mulitple columns) + procedure compare_nest_tab_cols_jb; + + --%test(Compare table type join by multiple columns- Failure) + procedure compare_nest_tab_cols_jb_fail; + + --%test(Compare table type as column join by multiple columns - Cannot find match) + procedure compare_tabtype_as_cols_jb; + + --%test(Compare table type as column normal compare ) + procedure compare_tabtype_as_cols; + + --%test(Compare table type as column join on collection element ) + procedure compare_tabtype_as_cols_coll; + + --%test(Compare same content on record with collections join on record) + procedure compare_rec_colltype_as_cols; + + --%test(Compare same content record with collection join on record attribute) + procedure compare_rec_colltype_as_attr; + + --%test(Compare same content record with collection join on whole collection) + procedure compare_collection_in_rec; + + --%test(Compare diffrent content record with collection join on record attribute) + procedure compare_rec_coll_as_cols_fl; + + --%test(Trying to join on collection element inside record ) + procedure compare_rec_coll_as_join; + end; / diff --git a/test/core/expectations/test_matchers.pkb b/test/core/expectations/test_matchers.pkb index cbc265319..e66f7c750 100644 --- a/test/core/expectations/test_matchers.pkb +++ b/test/core/expectations/test_matchers.pkb @@ -64,7 +64,7 @@ create or replace package body test_matchers is cleanup_expectations(); end exec_be_between2; - procedure exec_be_like(a_type varchar2, a_value varchar2, a_pattern varchar2, a_escape varchar2, a_result integer, a_prefix varchar2) is + procedure exec_be_like(a_type varchar2, a_value varchar2, a_pattern varchar2, a_escape varchar2, a_result integer, a_prefix varchar2 default null) is begin execute immediate 'declare @@ -156,6 +156,7 @@ create or replace package body test_matchers is exec_be_between2('timestamp with time zone', 'null', 'systimestamp-1', 'systimestamp+1', ut3.ut_utils.gc_failure, ''); exec_be_between2('interval year to month', 'null', '''2-0''', '''2-2''', ut3.ut_utils.gc_failure, ''); exec_be_between2('interval day to second', 'null', '''2 00:59:58''', '''2 01:00:01''', ut3.ut_utils.gc_failure, ''); + exec_be_between2('date', 'null', 'sysdate-2', 'sysdate-1', ut3.ut_utils.gc_failure, 'not_'); exec_be_between2('number', 'null', '1.99', '1.999', ut3.ut_utils.gc_failure, 'not_'); exec_be_between2('varchar2(1)', 'null', '''a''', '''b''', ut3.ut_utils.gc_failure, 'not_'); @@ -174,6 +175,7 @@ create or replace package body test_matchers is exec_be_between2('timestamp with time zone', 'systimestamp', 'null', 'systimestamp+1', ut3.ut_utils.gc_failure, ''); exec_be_between2('interval year to month', '''2-1''', 'null', '''2-2''', ut3.ut_utils.gc_failure, ''); exec_be_between2('interval day to second', '''2 01:00:00''', 'null', '''2 01:00:01''', ut3.ut_utils.gc_failure, ''); + exec_be_between2('date', 'sysdate', 'null', 'sysdate-1', ut3.ut_utils.gc_failure, 'not_'); exec_be_between2('number', '2.0', 'null', '1.999', ut3.ut_utils.gc_failure, 'not_'); exec_be_between2('varchar2(1)', '''b''', 'null', '''b''', ut3.ut_utils.gc_failure, 'not_'); @@ -182,19 +184,21 @@ create or replace package body test_matchers is exec_be_between2('timestamp with time zone', 'systimestamp+1', 'null', 'systimestamp', ut3.ut_utils.gc_failure, 'not_'); exec_be_between2('interval year to month', '''2-2''', 'null', '''2-1''', ut3.ut_utils.gc_failure, 'not_'); exec_be_between2('interval day to second', '''2 01:00:00''', 'null', '''2 00:59:59''', ut3.ut_utils.gc_failure, 'not_'); + --Fails for unsupported data-type + exec_be_between2('clob', '''b''', '''a''', '''c''', ut3.ut_utils.gc_failure, ''); end; procedure test_match is begin - exec_match('varchar2(100)', '''Stephen''', '^Ste(v|ph)en$', '', ut3.ut_utils.gc_success, ''); - exec_match('varchar2(100)', '''sTEPHEN''', '^Ste(v|ph)en$', 'i', ut3.ut_utils.gc_success, ''); - exec_match('clob', 'rpad('', '',32767)||''Stephen''', 'Ste(v|ph)en$', '', ut3.ut_utils.gc_success, ''); - exec_match('clob', 'rpad('', '',32767)||''sTEPHEN''', 'Ste(v|ph)en$', 'i', ut3.ut_utils.gc_success, ''); + exec_match('varchar2(100)', '''Stephen''', '^Ste(v|ph)en$', '', ut3.ut_utils.gc_success); + exec_match('varchar2(100)', '''sTEPHEN''', '^Ste(v|ph)en$', 'i', ut3.ut_utils.gc_success); + exec_match('clob', 'rpad('', '',32767)||''Stephen''', 'Ste(v|ph)en$', '', ut3.ut_utils.gc_success); + exec_match('clob', 'rpad('', '',32767)||''sTEPHEN''', 'Ste(v|ph)en$', 'i', ut3.ut_utils.gc_success); - exec_match('varchar2(100)', '''Stephen''', '^Steven$', '', ut3.ut_utils.gc_failure, ''); - exec_match('varchar2(100)', '''sTEPHEN''', '^Steven$', 'i', ut3.ut_utils.gc_failure, ''); - exec_match('clob', 'to_clob(rpad('', '',32767)||''Stephen'')', '^Stephen', '', ut3.ut_utils.gc_failure, ''); - exec_match('clob', 'to_clob(rpad('', '',32767)||''sTEPHEN'')', '^Stephen', 'i', ut3.ut_utils.gc_failure, ''); + exec_match('varchar2(100)', '''Stephen''', '^Steven$', '', ut3.ut_utils.gc_failure); + exec_match('varchar2(100)', '''sTEPHEN''', '^Steven$', 'i', ut3.ut_utils.gc_failure); + exec_match('clob', 'to_clob(rpad('', '',32767)||''Stephen'')', '^Stephen', '', ut3.ut_utils.gc_failure); + exec_match('clob', 'to_clob(rpad('', '',32767)||''sTEPHEN'')', '^Stephen', 'i', ut3.ut_utils.gc_failure); exec_match('varchar2(100)', '''Stephen''', '^Ste(v|ph)en$', '', ut3.ut_utils.gc_failure, 'not_'); exec_match('varchar2(100)', '''sTEPHEN''', '^Ste(v|ph)en$', 'i', ut3.ut_utils.gc_failure, 'not_'); @@ -205,19 +209,21 @@ create or replace package body test_matchers is exec_match('varchar2(100)', '''sTEPHEN''', '^Steven$', 'i', ut3.ut_utils.gc_success, 'not_'); exec_match('clob', 'to_clob(rpad('', '',32767)||''Stephen'')', '^Stephen', '', ut3.ut_utils.gc_success, 'not_'); exec_match('clob', 'to_clob(rpad('', '',32767)||''sTEPHEN'')', '^Stephen', 'i', ut3.ut_utils.gc_success, 'not_'); + --Fails for unsupported data-type + exec_match('number', '12345', '^123.*', 'i', ut3.ut_utils.gc_failure); end; procedure test_be_like is begin - exec_be_like('varchar2(100)', '''Stephen_King''', 'Ste__en%', '', ut3.ut_utils.gc_success, ''); - exec_be_like('varchar2(100)', '''Stephen_King''', 'Ste__en\_K%', '\', ut3.ut_utils.gc_success, ''); - exec_be_like('clob', 'rpad(''a'',32767,''a'')||''Stephen_King''', 'a%Ste__en%', '', ut3.ut_utils.gc_success, ''); - exec_be_like('clob', 'rpad(''a'',32767,''a'')||''Stephen_King''', 'a%Ste__en\_K%', '\', ut3.ut_utils.gc_success, ''); + exec_be_like('varchar2(100)', '''Stephen_King''', 'Ste__en%', '', ut3.ut_utils.gc_success); + exec_be_like('varchar2(100)', '''Stephen_King''', 'Ste__en\_K%', '\', ut3.ut_utils.gc_success); + exec_be_like('clob', 'rpad(''a'',32767,''a'')||''Stephen_King''', 'a%Ste__en%', '', ut3.ut_utils.gc_success); + exec_be_like('clob', 'rpad(''a'',32767,''a'')||''Stephen_King''', 'a%Ste__en\_K%', '\', ut3.ut_utils.gc_success); - exec_be_like('varchar2(100)', '''Stephen_King''', 'Ste_en%', '', ut3.ut_utils.gc_failure, ''); - exec_be_like('varchar2(100)', '''Stephen_King''', 'Stephe\__%', '\', ut3.ut_utils.gc_failure, ''); - exec_be_like('clob', 'rpad(''a'',32767,''a'')||''Stephen_King''', 'a%Ste_en%', '', ut3.ut_utils.gc_failure, ''); - exec_be_like('clob', 'rpad(''a'',32767,''a'')||''Stephen_King''', 'a%Stephe\__%', '\', ut3.ut_utils.gc_failure, ''); + exec_be_like('varchar2(100)', '''Stephen_King''', 'Ste_en%', '', ut3.ut_utils.gc_failure); + exec_be_like('varchar2(100)', '''Stephen_King''', 'Stephe\__%', '\', ut3.ut_utils.gc_failure); + exec_be_like('clob', 'rpad(''a'',32767,''a'')||''Stephen_King''', 'a%Ste_en%', '', ut3.ut_utils.gc_failure); + exec_be_like('clob', 'rpad(''a'',32767,''a'')||''Stephen_King''', 'a%Stephe\__%', '\', ut3.ut_utils.gc_failure); exec_be_like('varchar2(100)', '''Stephen_King''', 'Ste__en%', '', ut3.ut_utils.gc_failure, 'not_'); exec_be_like('varchar2(100)', '''Stephen_King''', 'Ste__en\_K%', '\', ut3.ut_utils.gc_failure, 'not_'); @@ -228,6 +234,9 @@ create or replace package body test_matchers is exec_be_like('varchar2(100)', '''Stephen_King''', 'Stephe\__%', '\', ut3.ut_utils.gc_success, 'not_'); exec_be_like('clob', 'rpad(''a'',32767,''a'')||''Stephen_King''', 'a%Ste_en%', '', ut3.ut_utils.gc_success, 'not_'); exec_be_like('clob', 'rpad(''a'',32767,''a'')||''Stephen_King''', 'a%Stephe\__%', '\', ut3.ut_utils.gc_success, 'not_'); + + --Fails for unsupported data-type + exec_be_like('number', '12345', '123%', '', ut3.ut_utils.gc_failure); end; procedure test_timestamp_between is diff --git a/test/core/expectations/scalar_data/unary/test_expect_not_to_be_null.pkb b/test/core/expectations/unary/test_expect_not_to_be_null.pkb similarity index 100% rename from test/core/expectations/scalar_data/unary/test_expect_not_to_be_null.pkb rename to test/core/expectations/unary/test_expect_not_to_be_null.pkb diff --git a/test/core/expectations/scalar_data/unary/test_expect_not_to_be_null.pks b/test/core/expectations/unary/test_expect_not_to_be_null.pks similarity index 97% rename from test/core/expectations/scalar_data/unary/test_expect_not_to_be_null.pks rename to test/core/expectations/unary/test_expect_not_to_be_null.pks index 867f9274b..fa2d6193f 100644 --- a/test/core/expectations/scalar_data/unary/test_expect_not_to_be_null.pks +++ b/test/core/expectations/unary/test_expect_not_to_be_null.pks @@ -1,7 +1,7 @@ create or replace package test_expect_not_to_be_null is --%suite(not_to_be_null) - --%suitepath(utplsql.core.expectations.scalar_data.unary) + --%suitepath(utplsql.core.expectations.unary) --%aftereach procedure cleanup_expectations; diff --git a/test/core/expectations/compound_data/test_expect_to_be_empty.pkb b/test/core/expectations/unary/test_expect_to_be_empty.pkb similarity index 75% rename from test/core/expectations/compound_data/test_expect_to_be_empty.pkb rename to test/core/expectations/unary/test_expect_to_be_empty.pkb index 05e05a706..ef4c34c12 100644 --- a/test/core/expectations/compound_data/test_expect_to_be_empty.pkb +++ b/test/core/expectations/unary/test_expect_to_be_empty.pkb @@ -198,5 +198,70 @@ was expected to be empty%%]'; ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); end; + procedure success_be_empty_clob is + begin + -- Act + ut3.ut.expect( empty_clob() ).to_( ut3.be_empty() ); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure fail_be_empty_clob is + begin + -- Act + ut3.ut.expect( to_clob(' ') ).to_( ut3.be_empty() ); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure success_be_empty_blob is + begin + -- Act + ut3.ut.expect( empty_blob() ).to_( ut3.be_empty() ); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure fail_be_empty_blob is + begin + -- Act + ut3.ut.expect( to_blob('AA') ).to_( ut3.be_empty() ); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + + procedure fail_not_be_empty_clob is + begin + -- Act + ut3.ut.expect( empty_clob() ).not_to( ut3.be_empty() ); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure success_not_be_empty_clob is + begin + -- Act + ut3.ut.expect( to_clob(' ') ).not_to( ut3.be_empty() ); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + + procedure fail_not_be_empty_blob is + begin + -- Act + ut3.ut.expect( empty_blob() ).not_to( ut3.be_empty() ); + --Assert + ut.expect(expectations.failed_expectations_data()).not_to_be_empty(); + end; + + procedure success_not_be_empty_blob is + begin + -- Act + ut3.ut.expect( to_blob('AA') ).not_to( ut3.be_empty() ); + --Assert + ut.expect(expectations.failed_expectations_data()).to_be_empty(); + end; + end; / \ No newline at end of file diff --git a/test/core/expectations/compound_data/test_expect_to_be_empty.pks b/test/core/expectations/unary/test_expect_to_be_empty.pks similarity index 51% rename from test/core/expectations/compound_data/test_expect_to_be_empty.pks rename to test/core/expectations/unary/test_expect_to_be_empty.pks index f81a78670..f48db600f 100644 --- a/test/core/expectations/compound_data/test_expect_to_be_empty.pks +++ b/test/core/expectations/unary/test_expect_to_be_empty.pks @@ -1,11 +1,13 @@ create or replace package test_expect_to_be_empty is - --%suite((not)to_be_empty) - --%suitepath(utplsql.core.expectations.compound_data) + --%suite + --%suitepath(utplsql.core.expectations.unary) --%aftereach procedure cleanup_expectations; + --%context(to_be_empty) + --%test(Gives success for an empty cursor) procedure success_be_empty_cursor; @@ -15,30 +17,15 @@ create or replace package test_expect_to_be_empty is --%test(Reports the content of cursor when cursor is not empty) procedure fail_be_empty_cursor_report; - --%test(Negated - Gives success for a non empty cursor) - procedure success_not_be_empty_cursor; - - --%test(Negated - Gives failure for an empty cursor) - procedure fail_not_be_empty_cursor; - --%test(Gives success for an empty collection) procedure success_be_empty_collection; --%test(Gives failure for a non empty collection) procedure fail_be_empty_collection; - --%test(Negated - Gives success for a non empty collection) - procedure success_not_be_empty_coll; - - --%test(Negated - Gives failure for an empty collection) - procedure fail_not_be_empty_collection; - --%test(Gives failure for a NULL collection) procedure fail_be_empty_null_collection; - --%test(Negated - Gives failure for an empty collection) - procedure fail_not_be_empty_null_coll; - --%test(Gives failure for an object) procedure fail_be_empty_object; @@ -48,14 +35,59 @@ create or replace package test_expect_to_be_empty is --%test(Gives failure for number) procedure fail_be_empty_number; - --%test(Negated - Gives failure for an object) + --%test(Gives success for an empty CLOB) + procedure success_be_empty_clob; + + --%test(Gives failure for a non empty CLOB) + procedure fail_be_empty_clob; + + --%test(Gives success for an empty BLOB) + procedure success_be_empty_blob; + + --%test(Gives failure for a non empty BLOB) + procedure fail_be_empty_blob; + + --%endcontext + + --%context(not_to_be_empty) + + --%test(Gives failure for an empty cursor) + procedure fail_not_be_empty_cursor; + + --%test(Gives success for a non empty cursor) + procedure success_not_be_empty_cursor; + + --%test(Gives success for a non empty collection) + procedure success_not_be_empty_coll; + + --%test(Gives failure for an empty collection) + procedure fail_not_be_empty_collection; + + --%test(Gives failure for an empty collection) + procedure fail_not_be_empty_null_coll; + + --%test(Gives failure for an object) procedure fail_not_be_empty_object; - --%test(Negated - Gives failure for a null object) + --%test(Gives failure for a null object) procedure fail_not_be_empty_null_object; - --%test(Negated - Gives failure for number) + --%test(Gives failure for number) procedure fail_not_be_empty_number; + --%test(Gives failure for an empty CLOB) + procedure fail_not_be_empty_clob; + + --%test(Gives success for a non empty CLOB) + procedure success_not_be_empty_clob; + + --%test(Gives failure for an empty BLOB) + procedure fail_not_be_empty_blob; + + --%test(Gives success for a non empty BLOB) + procedure success_not_be_empty_blob; + + --%endcontext + end; / diff --git a/test/core/expectations/scalar_data/unary/test_expect_to_be_not_null.pkb b/test/core/expectations/unary/test_expect_to_be_not_null.pkb similarity index 99% rename from test/core/expectations/scalar_data/unary/test_expect_to_be_not_null.pkb rename to test/core/expectations/unary/test_expect_to_be_not_null.pkb index 5926a7d87..be6b3f2f8 100644 --- a/test/core/expectations/scalar_data/unary/test_expect_to_be_not_null.pkb +++ b/test/core/expectations/unary/test_expect_to_be_not_null.pkb @@ -33,7 +33,7 @@ is ut.expect(expectations.failed_expectations_data()).to_be_empty(); end; - procedure blob_0_length is + procedure empty_blob is begin --Act execute immediate expectations.unary_expectation_block('to_be_not_null', 'blob', 'empty_blob()'); @@ -57,7 +57,7 @@ is ut.expect(expectations.failed_expectations_data()).to_be_empty(); end; - procedure clob_0_length is + procedure empty_clob is begin --Act execute immediate expectations.unary_expectation_block('to_be_not_null', 'clob', 'empty_clob()'); diff --git a/test/core/expectations/scalar_data/unary/test_expect_to_be_not_null.pks b/test/core/expectations/unary/test_expect_to_be_not_null.pks similarity index 91% rename from test/core/expectations/scalar_data/unary/test_expect_to_be_not_null.pks rename to test/core/expectations/unary/test_expect_to_be_not_null.pks index f28a88af2..351482fee 100644 --- a/test/core/expectations/scalar_data/unary/test_expect_to_be_not_null.pks +++ b/test/core/expectations/unary/test_expect_to_be_not_null.pks @@ -1,7 +1,7 @@ create or replace package test_expect_to_be_not_null is --%suite(to_be_not_null) - --%suitepath(utplsql.core.expectations.scalar_data.unary) + --%suitepath(utplsql.core.expectations.unary) --%aftereach procedure cleanup_expectations; @@ -15,8 +15,8 @@ is --%test(Gives success for not null blob) procedure blob_not_null; - --%test(Gives success for blob with length 0) - procedure blob_0_length; + --%test(Gives success for empty blob) + procedure empty_blob; --%test(Gives success for not null boolean) procedure boolean_not_null; @@ -24,8 +24,8 @@ is --%test(Gives success for not null clob) procedure clob_not_null; - --%test(Gives success for clob with length 0) - procedure clob_0_length; + --%test(Gives success for empty clob) + procedure empty_clob; --%test(Gives success for not null date) procedure date_not_null; diff --git a/test/core/expectations/scalar_data/unary/test_expect_to_be_null.pkb b/test/core/expectations/unary/test_expect_to_be_null.pkb similarity index 99% rename from test/core/expectations/scalar_data/unary/test_expect_to_be_null.pkb rename to test/core/expectations/unary/test_expect_to_be_null.pkb index 09c461597..4179bfbe6 100644 --- a/test/core/expectations/scalar_data/unary/test_expect_to_be_null.pkb +++ b/test/core/expectations/unary/test_expect_to_be_null.pkb @@ -142,7 +142,7 @@ is ut.expect( expectations.failed_expectations_data( ) ).not_to_be_empty( ); end; - procedure blob_0_length is + procedure empty_blob is begin --Act execute immediate expectations.unary_expectation_block( 'to_be_null', 'blob', 'empty_blob()' ); @@ -166,7 +166,7 @@ is ut.expect( expectations.failed_expectations_data( ) ).not_to_be_empty( ); end; - procedure clob_0_length is + procedure empty_clob is begin --Act execute immediate expectations.unary_expectation_block( 'to_be_null', 'clob', 'empty_clob()' ); diff --git a/test/core/expectations/unary/test_expect_to_be_null.pks b/test/core/expectations/unary/test_expect_to_be_null.pks new file mode 100644 index 000000000..8b34e1279 --- /dev/null +++ b/test/core/expectations/unary/test_expect_to_be_null.pks @@ -0,0 +1,97 @@ +create or replace package test_expect_to_be_null +is + --%suite(to_be_null) + --%suitepath(utplsql.core.expectations.unary) + + --%aftereach + procedure cleanup_expectations; + + --%beforeall + procedure create_types; + + --%afterall + procedure drop_types; + + --%test(Gives success with null blob) + procedure null_blob; + + --%test(Gives success with null boolean) + procedure null_boolean; + + --%test(Gives success with null clob) + procedure null_clob; + + --%test(Gives success with null date) + procedure null_date; + + --%test(Gives success with null number) + procedure null_number; + + --%test(Gives success null timestamp) + procedure null_timestamp; + + --%test(Gives success with null timestamp with local time zone) + procedure null_timestamp_with_ltz; + + --%test(Gives success with null timestamp with time zone) + procedure null_timestamp_with_tz; + + --%test(Gives success with null varchar2) + procedure null_varchar2; + + --%test(Gives success with null anydata) + procedure null_anydata; + + --%test(Gives success with uninitialized object within anydata) + procedure uninit_object_in_anydata; + + --%test(Gives success with uninitialized nested table within anydata) + procedure uninit_nested_table_in_anydata; + + --%test(Gives success with uninitialized varray within anydata) + procedure uninit_varray_in_anydata; + + --%test(Gives failure for not null blob) + procedure blob_not_null; + + --%test(Gives failure with empty blob) + procedure empty_blob; + + --%test(Gives failure for not null boolean) + procedure boolean_not_null; + + --%test(Gives failure for not null clob) + procedure clob_not_null; + + --%test(Gives failure with empty clob) + procedure empty_clob; + + --%test(Gives failure for not null date) + procedure date_not_null; + + --%test(Gives failure for not null number) + procedure number_not_null; + + --%test(Gives failure for not null timestamp) + procedure timestamp_not_null; + + --%test(Gives failure for not null timestamp with local time zone) + procedure timestamp_with_ltz_not_null; + + --%test(Gives failure for not null timestamp with time zone) + procedure timestamp_with_tz_not_null; + + --%test(Gives failure for not null varchar2) + procedure varchar2_not_null; + + --%test(Gives failure for initialized object within anydata) + procedure initialized_object; + + --%test(Gives failure for initialized nested table within anydata) + procedure initialized_nested_table; + + --%test(Gives failure for initialized varray within anydata) + procedure initialized_varray; + +end test_expect_to_be_null; +/ diff --git a/test/core/expectations/scalar_data/unary/test_expect_to_be_true_false.pkb b/test/core/expectations/unary/test_expect_to_be_true_false.pkb similarity index 100% rename from test/core/expectations/scalar_data/unary/test_expect_to_be_true_false.pkb rename to test/core/expectations/unary/test_expect_to_be_true_false.pkb diff --git a/test/core/expectations/scalar_data/unary/test_expect_to_be_true_false.pks b/test/core/expectations/unary/test_expect_to_be_true_false.pks similarity index 96% rename from test/core/expectations/scalar_data/unary/test_expect_to_be_true_false.pks rename to test/core/expectations/unary/test_expect_to_be_true_false.pks index e30338b83..abdbf44b6 100644 --- a/test/core/expectations/scalar_data/unary/test_expect_to_be_true_false.pks +++ b/test/core/expectations/unary/test_expect_to_be_true_false.pks @@ -1,7 +1,7 @@ create or replace package test_expect_to_be_true_false is --%suite(to_be_true/false) - --%suitepath(utplsql.core.expectations.scalar_data.unary) + --%suitepath(utplsql.core.expectations.unary) --%aftereach procedure cleanup_expectations; diff --git a/test/core/expectations/compound_data/test_expect_to_have_count.pkb b/test/core/expectations/unary/test_expect_to_have_count.pkb similarity index 100% rename from test/core/expectations/compound_data/test_expect_to_have_count.pkb rename to test/core/expectations/unary/test_expect_to_have_count.pkb diff --git a/test/core/expectations/compound_data/test_expect_to_have_count.pks b/test/core/expectations/unary/test_expect_to_have_count.pks similarity index 96% rename from test/core/expectations/compound_data/test_expect_to_have_count.pks rename to test/core/expectations/unary/test_expect_to_have_count.pks index e89ca2fc5..636f98ba4 100644 --- a/test/core/expectations/compound_data/test_expect_to_have_count.pks +++ b/test/core/expectations/unary/test_expect_to_have_count.pks @@ -1,7 +1,7 @@ create or replace package test_expect_to_have_count is --%suite((not)to_have_count) - --%suitepath(utplsql.core.expectations.compound_data) + --%suitepath(utplsql.core.expectations.unary) --%aftereach procedure cleanup_expectations; diff --git a/test/core/reporters.pkb b/test/core/reporters.pkb index 29299ca08..8eb2a4992 100644 --- a/test/core/reporters.pkb +++ b/test/core/reporters.pkb @@ -1,6 +1,7 @@ create or replace package body reporters is procedure create_test_helper_package is + pragma autonomous_transaction; begin execute immediate q'[create or replace package test_reporters as @@ -119,9 +120,26 @@ end;]'; end; procedure reporters_cleanup is + pragma autonomous_transaction; begin drop_test_helper_package; end; + procedure check_xml_encoding_included( + a_reporter ut3.ut_output_reporter_base, + a_client_character_set varchar2 + ) is + l_results ut3.ut_varchar2_list; + l_actual clob; + begin + --Act + select * + bulk collect into l_results + from table(ut3.ut.run('test_reporters', a_reporter, a_client_character_set => a_client_character_set)); + l_actual := ut3.ut_utils.table_to_clob(l_results); + --Assert + ut.expect(l_actual).to_be_like('%'); + end; + end reporters; / diff --git a/test/core/reporters.pks b/test/core/reporters.pks index 998427203..229e4e9b1 100644 --- a/test/core/reporters.pks +++ b/test/core/reporters.pks @@ -1,8 +1,18 @@ create or replace package reporters is + --%suite + --%suitepath(utplsql.core) + + --%beforeall procedure reporters_setup; + --%afterall procedure reporters_cleanup; + procedure check_xml_encoding_included( + a_reporter ut3.ut_output_reporter_base, + a_client_character_set varchar2 + ); + end reporters; / diff --git a/test/core/reporters/test_coverage.pkb b/test/core/reporters/test_coverage.pkb index 347f4f463..4e3846af8 100644 --- a/test/core/reporters/test_coverage.pkb +++ b/test/core/reporters/test_coverage.pkb @@ -1,7 +1,5 @@ create or replace package body test_coverage is - g_run_id integer; - function get_mock_run_id return integer is v_result integer; begin @@ -100,22 +98,32 @@ create or replace package body test_coverage is select a_run_id, c_unit_id, 7, 1, 1 from dual; end; - procedure setup_dummy_coverage is + procedure create_dummy_coverage_pkg is pragma autonomous_transaction; begin create_dummy_coverage_package(); create_dummy_coverage_test(); + end; + + procedure setup_dummy_coverage is + pragma autonomous_transaction; + begin g_run_id := get_mock_run_id(); ut3.ut_coverage.mock_coverage_id(g_run_id, ut3.ut_coverage.gc_proftab_coverage); mock_coverage_data(g_run_id); commit; end; - procedure cleanup_dummy_coverage is + procedure drop_dummy_coverage_pkg is pragma autonomous_transaction; begin begin execute immediate q'[drop package ut3.test_dummy_coverage]'; exception when others then null; end; begin execute immediate q'[drop package ut3.dummy_coverage]'; exception when others then null; end; + end; + + procedure cleanup_dummy_coverage is + pragma autonomous_transaction; + begin delete from ut3.plsql_profiler_data where runid = g_run_id; delete from ut3.plsql_profiler_units where runid = g_run_id; delete from ut3.plsql_profiler_runs where runid = g_run_id; @@ -229,6 +237,7 @@ create or replace package body test_coverage is ) ); cleanup_dummy_coverage(); + drop_dummy_coverage_pkg(); create_dummy_coverage_test_1; --Act @@ -244,7 +253,8 @@ create or replace package body test_coverage is --Assert l_actual := ut3.ut_utils.table_to_clob(l_results); - ut.expect(l_actual).to_equal(to_clob(' + ut.expect(l_actual).to_equal(to_clob(' + ')); drop_dummy_coverage_test_1; end; diff --git a/test/core/reporters/test_coverage.pks b/test/core/reporters/test_coverage.pks index d507fa0ee..65e99666b 100644 --- a/test/core/reporters/test_coverage.pks +++ b/test/core/reporters/test_coverage.pks @@ -3,9 +3,16 @@ create or replace package test_coverage is --%suite --%suitepath(utplsql.core.reporters) + g_run_id integer; + + --%beforeall + procedure create_dummy_coverage_pkg; --%beforeall procedure setup_dummy_coverage; + + --%afterall + procedure drop_dummy_coverage_pkg; --%afterall procedure cleanup_dummy_coverage; @@ -23,6 +30,7 @@ create or replace package test_coverage is procedure coverage_for_file; --%test(Coverage data is not cached between runs - issue #562 ) + --%aftertest(create_dummy_coverage_pkg) --%aftertest(setup_dummy_coverage) procedure coverage_tmp_data_refresh; diff --git a/test/core/reporters/test_coverage/test_coverage_sonar_reporter.pkb b/test/core/reporters/test_coverage/test_coverage_sonar_reporter.pkb index 7aa2b3cd4..81b2c12f8 100644 --- a/test/core/reporters/test_coverage/test_coverage_sonar_reporter.pkb +++ b/test/core/reporters/test_coverage/test_coverage_sonar_reporter.pkb @@ -6,7 +6,8 @@ create or replace package body test_coverage_sonar_reporter is l_actual clob; begin --Arrange - l_expected := ' + l_expected := ' + @@ -29,5 +30,10 @@ create or replace package body test_coverage_sonar_reporter is ut.expect(l_actual).to_equal(l_expected); end; + procedure check_encoding_included is + begin + reporters.check_xml_encoding_included(ut3.ut_coverage_sonar_reporter(), 'UTF-8'); + end; + end; / diff --git a/test/core/reporters/test_coverage/test_coverage_sonar_reporter.pks b/test/core/reporters/test_coverage/test_coverage_sonar_reporter.pks index 26aad7cb5..31cb358dd 100644 --- a/test/core/reporters/test_coverage/test_coverage_sonar_reporter.pks +++ b/test/core/reporters/test_coverage/test_coverage_sonar_reporter.pks @@ -6,5 +6,8 @@ create or replace package test_coverage_sonar_reporter is --%test(reports on a project file mapped to database object) procedure report_on_file; + --%test(Includes XML header with encoding when encoding provided) + procedure check_encoding_included; + end; / diff --git a/test/core/reporters/test_coverage/test_coveralls_reporter.pkb b/test/core/reporters/test_coverage/test_coveralls_reporter.pkb index 2efa8f0ca..3b6b88346 100644 --- a/test/core/reporters/test_coverage/test_coveralls_reporter.pkb +++ b/test/core/reporters/test_coverage/test_coveralls_reporter.pkb @@ -6,10 +6,17 @@ create or replace package body test_coveralls_reporter is l_actual clob; begin --Arrange - l_expected := '{"source_files":[ + l_expected := q'[{"source_files":[ { "name": "test/ut3.dummy_coverage.pkb", -"coverage": [null,null,null,1,0,null,1]}]} - '; +"coverage": [null, +null, +null, +1, +0, +null, +1 +]}]} + ]'; --Act select * bulk collect into l_results @@ -26,5 +33,46 @@ create or replace package body test_coveralls_reporter is ut.expect(l_actual).to_equal(l_expected); end; + procedure report_zero_coverage is + l_results ut3.ut_varchar2_list; + l_expected clob; + l_actual clob; + pragma autonomous_transaction; + begin + --Arrange + l_expected := q'[{"source_files":[ +{ "name": "ut3.dummy_coverage", +"coverage": [0, +0, +0, +0, +0, +0, +0, +0, +0, +0]}]} + ]'; + + test_coverage.cleanup_dummy_coverage; + + --Act + select * + bulk collect into l_results + from table( + ut3.ut.run( + 'ut3.test_dummy_coverage', + ut3.ut_coveralls_reporter(), + a_include_objects => ut3.ut_varchar2_list('UT3.DUMMY_COVERAGE') + ) + ); + l_actual := ut3.ut_utils.table_to_clob(l_results); + --Assert + ut.expect(l_actual).to_equal(l_expected); + + test_coverage.setup_dummy_coverage; + + end; + end; / diff --git a/test/core/reporters/test_coverage/test_coveralls_reporter.pks b/test/core/reporters/test_coverage/test_coveralls_reporter.pks index a479e69a2..bf2b861f7 100644 --- a/test/core/reporters/test_coverage/test_coveralls_reporter.pks +++ b/test/core/reporters/test_coverage/test_coveralls_reporter.pks @@ -6,5 +6,8 @@ create or replace package test_coveralls_reporter is --%test(reports on a project file mapped to database object) procedure report_on_file; + --%test(reports zero coverage on each line of non-executed database object) + procedure report_zero_coverage; + end; / diff --git a/test/core/reporters/test_coverage/test_html_extended_reporter.pkb b/test/core/reporters/test_coverage/test_html_extended_reporter.pkb index cd71a6c8c..b1f6fa4bd 100644 --- a/test/core/reporters/test_coverage/test_html_extended_reporter.pkb +++ b/test/core/reporters/test_coverage/test_html_extended_reporter.pkb @@ -4,9 +4,10 @@ create or replace package body test_html_extended_reporter is l_results ut3.ut_varchar2_list; l_expected varchar2(32767); l_actual clob; + l_charset varchar2(100) := 'ISO-8859-1'; begin --Arrange - l_expected := '%

UT3.DUMMY_COVERAGE

%4 relevant lines. 3 lines covered (including 1 lines partially covered ) and 1 lines missed%'; + l_expected := '%%

UT3.DUMMY_COVERAGE

%4 relevant lines. 3 lines covered (including 1 lines partially covered ) and 1 lines missed%'; select * bulk collect into l_results @@ -15,7 +16,8 @@ create or replace package body test_html_extended_reporter is a_path => 'ut3.test_dummy_coverage', a_reporter=> ut3.ut_coverage_html_reporter(), a_source_files => ut3.ut_varchar2_list( 'test/ut3.dummy_coverage.pkb' ), - a_test_files => ut3.ut_varchar2_list( ) + a_test_files => ut3.ut_varchar2_list( ), + a_client_character_set => l_charset ) ); l_actual := ut3.ut_utils.table_to_clob(l_results); diff --git a/test/core/reporters/test_coverage/test_html_proftab_reporter.pkb b/test/core/reporters/test_coverage/test_html_proftab_reporter.pkb index 7167dc6f6..c10af2869 100644 --- a/test/core/reporters/test_coverage/test_html_proftab_reporter.pkb +++ b/test/core/reporters/test_coverage/test_html_proftab_reporter.pkb @@ -4,11 +4,10 @@ create or replace package body test_html_proftab_reporter is l_results ut3.ut_varchar2_list; l_expected varchar2(32767); l_actual clob; + l_charset varchar2(100) := 'ISO-8859-1'; begin --Arrange - l_expected := '%

UT3.DUMMY_COVERAGE

%3 relevant lines. 2 lines covered and 1 lines missed%'; - - --l_expected := '%

UT3.DUMMY_COVERAGE

66% lines covered

3 relevant lines. 2 lines covered ) and 1 lines missed
%'; + l_expected := '%%

UT3.DUMMY_COVERAGE

%3 relevant lines. 2 lines covered and 1 lines missed%'; --Act select * bulk collect into l_results @@ -17,7 +16,8 @@ create or replace package body test_html_proftab_reporter is a_path => 'ut3.test_dummy_coverage', a_reporter=> ut3.ut_coverage_html_reporter(), a_source_files => ut3.ut_varchar2_list( 'test/ut3.dummy_coverage.pkb' ), - a_test_files => ut3.ut_varchar2_list( ) + a_test_files => ut3.ut_varchar2_list( ), + a_client_character_set => l_charset ) ); l_actual := ut3.ut_utils.table_to_clob(l_results); diff --git a/test/core/reporters/test_junit_reporter.pkb b/test/core/reporters/test_junit_reporter.pkb index 280431aa3..29beaaa55 100644 --- a/test/core/reporters/test_junit_reporter.pkb +++ b/test/core/reporters/test_junit_reporter.pkb @@ -61,9 +61,35 @@ create or replace package body test_junit_reporter as execute immediate q'[create or replace package body tst_package_junit_nosuite as procedure test1 is begin ut.expect(1).to_equal(1); end; end;]'; + + execute immediate q'[create or replace package Tst_Fix_Case_Sensitive as + --%suite + + --%test(bugfix) + procedure bUgFiX; + end;]'; - reporters.reporters_setup; + execute immediate q'[create or replace package body Tst_Fix_Case_Sensitive as + procedure bUgFiX is begin ut.expect(1).to_equal(1); end; + end;]'; + execute immediate q'[create or replace package check_fail_escape is + --%suitepath(core) + --%suite(checkfailedescape) + --%displayname(Check JUNIT XML failure is escaped) + + --%test(Fail Miserably) + procedure fail_miserably; + + end;]'; + + execute immediate q'[create or replace package body check_fail_escape is + procedure fail_miserably is + begin + ut3.ut.expect('test').to_equal(''); + end; + end;]'; + end; procedure escapes_special_chars is @@ -118,7 +144,7 @@ create or replace package body test_junit_reporter as from table(ut3.ut.run('check_junit_reporting',ut3.ut_junit_reporter())); l_actual := ut3.ut_utils.table_to_clob(l_results); --Assert - ut.expect(l_actual).to_be_like('%at "%.CHECK_JUNIT_REPORTING%", line %'); + ut.expect(l_actual).to_be_like('%at "%.CHECK_JUNIT_REPORTING%", line %'); end; procedure check_classname_suite is @@ -171,7 +197,8 @@ create or replace package body test_junit_reporter as procedure report_test_without_desc is l_results ut3.ut_varchar2_list; l_actual clob; - l_expected varchar2(32767):= q'[ + l_expected varchar2(32767):= q'[ + @@ -196,7 +223,8 @@ create or replace package body test_junit_reporter as procedure report_suite_without_desc is l_results ut3.ut_varchar2_list; l_actual clob; - l_expected varchar2(32767):= q'[ + l_expected varchar2(32767):= q'[ + @@ -217,7 +245,8 @@ create or replace package body test_junit_reporter as procedure reporort_produces_expected_out is l_results ut3.ut_varchar2_list; l_actual clob; - l_expected varchar2(32767):=q'[ + l_expected varchar2(32767):=q'[ + @@ -267,6 +296,46 @@ create or replace package body test_junit_reporter as ut.expect(l_actual).to_be_like(l_expected); end; + procedure check_failure_escaped is + l_results ut3.ut_varchar2_list; + l_actual clob; + begin + --Act + select * + bulk collect into l_results + from table(ut3.ut.run('check_fail_escape',ut3.ut_junit_reporter())); + l_actual := ut3.ut_utils.table_to_clob(l_results); + --Assert + ut.expect(l_actual).to_be_like('%Actual: 'test' (varchar2) was expected to equal: '<![CDATA[some stuff]]>' (varchar2)%'); + end; + + procedure check_classname_is_populated is + l_results ut3.ut_varchar2_list; + l_actual clob; + l_expected varchar2(32767):= q'[ + + + + + + + + + +]'; + begin + select * + bulk collect into l_results + from table(ut3.ut.run('Tst_Fix_Case_Sensitive',ut3.ut_junit_reporter())); + l_actual := ut3.ut_utils.table_to_clob(l_results); + ut.expect(l_actual).to_be_like(l_expected); + end; + + procedure check_encoding_included is + begin + reporters.check_xml_encoding_included(ut3.ut_junit_reporter(), 'UTF-8'); + end; + procedure remove_test_package is pragma autonomous_transaction; begin @@ -274,7 +343,9 @@ create or replace package body test_junit_reporter as execute immediate 'drop package check_junit_rep_suitepath'; execute immediate 'drop package tst_package_junit_nodesc'; execute immediate 'drop package tst_package_junit_nosuite'; - reporters.reporters_cleanup; + execute immediate 'drop package check_fail_escape'; + execute immediate 'drop package Tst_Fix_Case_Sensitive'; end; + end; / diff --git a/test/core/reporters/test_junit_reporter.pks b/test/core/reporters/test_junit_reporter.pks index 91bc03f31..b39c5ff03 100644 --- a/test/core/reporters/test_junit_reporter.pks +++ b/test/core/reporters/test_junit_reporter.pks @@ -27,14 +27,23 @@ create or replace package test_junit_reporter as --%test(Reports duration according to XML specification for numbers) procedure check_nls_number_formatting; - --%test(Report on test without description) + --%test(Report on test without description) procedure report_test_without_desc; - --%test(Report on suite without description) + --%test(Report on suite without description) procedure report_suite_without_desc; - --%test(Report produces expected output) + --%test(Report produces expected output) procedure reporort_produces_expected_out; + + --%test( Check classname is populated when procedure is mixed cased - bug #659) + procedure check_classname_is_populated; + + --%test( Validate that fail with special char are escaped ) + procedure check_failure_escaped; + + --%test(Includes XML header with encoding when encoding provided) + procedure check_encoding_included; --%afterall procedure remove_test_package; diff --git a/test/core/reporters/test_sonar_test_reporter.pkb b/test/core/reporters/test_sonar_test_reporter.pkb new file mode 100644 index 000000000..9cf38ea91 --- /dev/null +++ b/test/core/reporters/test_sonar_test_reporter.pkb @@ -0,0 +1,36 @@ +create or replace package body test_sonar_test_reporter as + + procedure report_produces_expected_out is + l_results ut3.ut_varchar2_list; + l_actual clob; + l_expected varchar2(32767):=q'[ + + +% +%%% +%%% +%% + +]'; + + begin + select * + bulk collect into l_results + from table( + ut3.ut.run( + 'test_reporters', + ut3.ut_sonar_test_reporter(), + a_test_file_mappings => ut3.ut_file_mapper.build_file_mappings( user, ut3.ut_varchar2_list('tests/helpers/test_reporters.pkb')) + ) + ); + l_actual := ut3.ut_utils.table_to_clob(l_results); + ut.expect(l_actual).to_be_like(l_expected); + end; + + procedure check_encoding_included is + begin + reporters.check_xml_encoding_included(ut3.ut_sonar_test_reporter(), 'UTF-8'); + end; + +end; +/ diff --git a/test/core/reporters/test_sonar_test_reporter.pks b/test/core/reporters/test_sonar_test_reporter.pks new file mode 100644 index 000000000..ab4776c38 --- /dev/null +++ b/test/core/reporters/test_sonar_test_reporter.pks @@ -0,0 +1,13 @@ +create or replace package test_sonar_test_reporter as + + --%suite(ut_sonar_test_reporter) + --%suitepath(utplsql.core.reporters) + + --%test(Report produces expected output) + procedure report_produces_expected_out; + + --%test(Includes XML header with encoding when encoding provided) + procedure check_encoding_included; + +end; +/ diff --git a/test/core/reporters/test_teamcity_reporter.pkb b/test/core/reporters/test_teamcity_reporter.pkb new file mode 100644 index 000000000..e3c05003f --- /dev/null +++ b/test/core/reporters/test_teamcity_reporter.pkb @@ -0,0 +1,52 @@ +create or replace package body test_teamcity_reporter as + + procedure report_produces_expected_out is + l_output_data ut3.ut_varchar2_list; + l_output clob; + l_expected varchar2(32767); + begin + l_expected := q'{%##teamcity[testSuiteStarted timestamp='%' name='utplsqlorg'] +%##teamcity[testSuiteStarted timestamp='%' name='utplsqlorg.helpers'] +%##teamcity[testSuiteStarted timestamp='%' name='utplsqlorg.helpers.tests'] +%##teamcity[testSuiteStarted timestamp='%' name='utplsqlorg.helpers.tests.test'] +%##teamcity[testSuiteStarted timestamp='%' name='utplsqlorg.helpers.tests.test.test_reporters'] +%##teamcity[testSuiteStarted timestamp='%' name='A suite for testing different outcomes from reporters'] +%##teamcity[testStarted timestamp='%' captureStandardOutput='true' name='ut3_tester.test_reporters.passing_test'] + + + + + +%##teamcity[testFinished timestamp='%' duration='%' name='ut3_tester.test_reporters.passing_test'] +%##teamcity[testStarted timestamp='%' captureStandardOutput='true' name='ut3_tester.test_reporters.failing_test'] + + + +%##teamcity[testFailed timestamp='%' message='Fails as values are different' name='ut3_tester.test_reporters.failing_test'] +%##teamcity[testFinished timestamp='%' duration='%' name='ut3_tester.test_reporters.failing_test'] +%##teamcity[testStarted timestamp='%' captureStandardOutput='true' name='ut3_tester.test_reporters.erroring_test'] + + + +%##teamcity[testStdErr timestamp='%' name='ut3_tester.test_reporters.erroring_test' out='Test exception:|rORA-06512: at |"UT3_TESTER.TEST_REPORTERS|", line %|rORA-06512: at %|r|r'] +%##teamcity[testFailed timestamp='%' details='Test exception:|rORA-06512: at |"UT3_TESTER.TEST_REPORTERS|", line %|rORA-06512: at %|r|r' message='Error occured' name='ut3_tester.test_reporters.erroring_test'] +%##teamcity[testFinished timestamp='%' duration='%' name='ut3_tester.test_reporters.erroring_test'] +%##teamcity[testStarted timestamp='%' captureStandardOutput='true' name='ut3_tester.test_reporters.disabled_test'] +%##teamcity[testIgnored timestamp='%' name='ut3_tester.test_reporters.disabled_test'] +%##teamcity[testSuiteFinished timestamp='%' name='A suite for testing different outcomes from reporters'] +%##teamcity[testSuiteFinished timestamp='%' name='utplsqlorg.helpers.tests.test.test_reporters'] +%##teamcity[testSuiteFinished timestamp='%' name='utplsqlorg.helpers.tests.test'] +%##teamcity[testSuiteFinished timestamp='%' name='utplsqlorg.helpers.tests'] +%##teamcity[testSuiteFinished timestamp='%' name='utplsqlorg.helpers'] +%##teamcity[testSuiteFinished timestamp='%' name='utplsqlorg']}'; + --act + select * + bulk collect into l_output_data + from table(ut3.ut.run('test_reporters',ut3.ut_teamcity_reporter())); + + --assert + ut.expect(ut3.ut_utils.table_to_clob(l_output_data)).to_be_like(l_expected); + end; + +end; +/ diff --git a/test/core/reporters/test_teamcity_reporter.pks b/test/core/reporters/test_teamcity_reporter.pks new file mode 100644 index 000000000..277044417 --- /dev/null +++ b/test/core/reporters/test_teamcity_reporter.pks @@ -0,0 +1,10 @@ +create or replace package test_teamcity_reporter as + + --%suite(ut_teamcity_reporter) + --%suitepath(utplsql.core.reporters) + + --%test(Report produces expected output) + procedure report_produces_expected_out; + +end; +/ diff --git a/test/core/reporters/test_tfs_junit_reporter.pkb b/test/core/reporters/test_tfs_junit_reporter.pkb index cf2ec95b8..bd09b8682 100644 --- a/test/core/reporters/test_tfs_junit_reporter.pkb +++ b/test/core/reporters/test_tfs_junit_reporter.pkb @@ -48,8 +48,28 @@ create or replace package body test_tfs_junit_reporter as null; end; end;]'; + + + execute immediate q'[create or replace package check_fail_escape is + --%suitepath(core) + --%suite(checkfailedescape) + --%displayname(Check JUNIT XML failure is escaped) + + --%test(Fail Miserably) + procedure fail_miserably; + + end;]'; + + execute immediate q'[create or replace package body check_fail_escape is + procedure fail_miserably is + begin + ut3.ut.expect('test').to_equal(''); + end; + end;]'; + end; + procedure escapes_special_chars is l_results ut3.ut_varchar2_list; l_actual clob; @@ -88,7 +108,7 @@ create or replace package body test_tfs_junit_reporter as from table(ut3.ut.run('check_junit_reporting',ut3.ut_tfs_junit_reporter())); l_actual := ut3.ut_utils.table_to_clob(l_results); --Assert - ut.expect(l_actual).to_be_like('%at "%.CHECK_JUNIT_REPORTING%", line %'); + ut.expect(l_actual).to_be_like('%at "%.CHECK_JUNIT_REPORTING%", line %'); end; procedure check_classname_suite is @@ -114,7 +134,8 @@ create or replace package body test_tfs_junit_reporter as from table(ut3.ut.run('check_junit_flat_suitepath',ut3.ut_tfs_junit_reporter())); l_actual := ut3.ut_utils.table_to_clob(l_results); --Assert - ut.expect(l_actual).to_be_like(' + ut.expect(l_actual).to_be_like(' + @@ -143,6 +164,19 @@ create or replace package body test_tfs_junit_reporter as execute immediate 'alter session set NLS_NUMERIC_CHARACTERS='''||l_nls_numeric_characters||''''; end; + procedure check_failure_escaped is + l_results ut3.ut_varchar2_list; + l_actual clob; + begin + --Act + select * + bulk collect into l_results + from table(ut3.ut.run('check_fail_escape',ut3.ut_tfs_junit_reporter())); + l_actual := ut3.ut_utils.table_to_clob(l_results); + --Assert + ut.expect(l_actual).to_be_like('%Actual: 'test' (varchar2) was expected to equal: '<![CDATA[some stuff]]>' (varchar2)%'); + end; + procedure check_classname_suitepath is l_results ut3.ut_varchar2_list; l_actual clob; @@ -161,6 +195,13 @@ create or replace package body test_tfs_junit_reporter as execute immediate 'drop package check_junit_reporting'; execute immediate 'drop package check_junit_rep_suitepath'; execute immediate 'drop package check_junit_flat_suitepath'; + execute immediate 'drop package check_fail_escape'; + end; + + procedure check_encoding_included is + begin + reporters.check_xml_encoding_included(ut3.ut_tfs_junit_reporter(), 'UTF-8'); end; + end; / diff --git a/test/core/reporters/test_tfs_junit_reporter.pks b/test/core/reporters/test_tfs_junit_reporter.pks index c01feb36a..cc589be1b 100644 --- a/test/core/reporters/test_tfs_junit_reporter.pks +++ b/test/core/reporters/test_tfs_junit_reporter.pks @@ -27,6 +27,12 @@ create or replace package test_tfs_junit_reporter as --%test(Reports duration according to XML specification for numbers) procedure check_nls_number_formatting; + --%test( Validate that failures with special char are escaped ) + procedure check_failure_escaped; + + --%test(Includes XML header with encoding when encoding provided) + procedure check_encoding_included; + --%afterall procedure remove_test_package; end; diff --git a/test/core/reporters/test_xunit_reporter.pkb b/test/core/reporters/test_xunit_reporter.pkb deleted file mode 100644 index f75c53ce4..000000000 --- a/test/core/reporters/test_xunit_reporter.pkb +++ /dev/null @@ -1,133 +0,0 @@ -create or replace package body test_xunit_reporter as - - procedure crate_a_test_package is - pragma autonomous_transaction; - begin - execute immediate q'[create or replace package check_xunit_reporting is - --%suite(A suite with ) - - --%test(A test with ) - procedure test_do_stuff; - - end;]'; - execute immediate q'[create or replace package body check_xunit_reporting is - procedure test_do_stuff is - begin - ut3.ut.expect(1).to_equal(1); - ut3.ut.expect(1).to_equal(2); - end; - - end;]'; - - execute immediate q'[create or replace package check_xunit_rep_suitepath is - --%suitepath(core) - --%suite(check_xunit_rep_suitepath) - --%displayname(Check XUNIT Get path for suitepath) - - --%test(check_xunit_rep_suitepath) - --%displayname(Check XUNIT Get path for suitepath) - procedure check_xunit_rep_suitepath; - end;]'; - execute immediate q'[create or replace package body check_xunit_rep_suitepath is - procedure check_xunit_rep_suitepath is - begin - ut3.ut.expect(1).to_equal(1); - end; - end;]'; - end; - - procedure escapes_special_chars is - l_results ut3.ut_varchar2_list; - l_actual clob; - begin - --Act - select * - bulk collect into l_results - from table(ut3.ut.run('check_xunit_reporting',ut3.ut_xunit_reporter())); - l_actual := ut3.ut_utils.table_to_clob(l_results); - --Assert - ut.expect(l_actual).not_to_be_like('%%'); - ut.expect(l_actual).to_be_like('%<tag>%'); - end; - - procedure reports_only_failed_or_errored is - l_results ut3.ut_varchar2_list; - l_actual clob; - begin - --Act - select * - bulk collect into l_results - from table(ut3.ut.run('check_xunit_reporting',ut3.ut_xunit_reporter())); - l_actual := ut3.ut_utils.table_to_clob(l_results); - --Assert - ut.expect(l_actual).not_to_be_like('%Actual: 1 (number) was expected to equal: 1 (number)%'); - ut.expect(l_actual).to_be_like('%Actual: 1 (number) was expected to equal: 2 (number)%'); - end; - - procedure reports_failed_line is - l_results ut3.ut_varchar2_list; - l_actual clob; - begin - --Act - select * - bulk collect into l_results - from table(ut3.ut.run('check_xunit_reporting',ut3.ut_xunit_reporter())); - l_actual := ut3.ut_utils.table_to_clob(l_results); - --Assert - ut.expect(l_actual).to_be_like('%at "%.CHECK_XUNIT_REPORTING%", line %'); - end; - - procedure check_classname_suite is - l_results ut3.ut_varchar2_list; - l_actual clob; - begin - --Act - select * - bulk collect into l_results - from table(ut3.ut.run('check_xunit_reporting',ut3.ut_xunit_reporter())); - l_actual := ut3.ut_utils.table_to_clob(l_results); - --Assert - ut.expect(l_actual).to_be_like('%testcase classname="check_xunit_reporting"%'); - end; - - procedure check_nls_number_formatting is - l_results ut3.ut_varchar2_list; - l_actual clob; - l_nls_numeric_characters varchar2(30); - begin - --Arrange - select nsp.value into l_nls_numeric_characters - from nls_session_parameters nsp - where parameter = 'NLS_NUMERIC_CHARACTERS'; - execute immediate q'[alter session set NLS_NUMERIC_CHARACTERS=', ']'; - --Act - select * - bulk collect into l_results - from table(ut3.ut.run('check_xunit_reporting', ut3.ut_xunit_reporter())); - l_actual := ut3.ut_utils.table_to_clob(l_results); - --Assert - ut.expect(l_actual).to_match('time="[0-9]*\.[0-9]{3,6}"'); - --Cleanup - execute immediate 'alter session set NLS_NUMERIC_CHARACTERS='''||l_nls_numeric_characters||''''; - end; - - procedure check_classname_suitepath is - l_results ut3.ut_varchar2_list; - l_actual clob; - begin - --Act - select * - bulk collect into l_results - from table(ut3.ut.run('check_xunit_rep_suitepath',ut3.ut_xunit_reporter())); - l_actual := ut3.ut_utils.table_to_clob(l_results); - --Assert - ut.expect(l_actual).to_be_like('%testcase classname="core.check_xunit_rep_suitepath"%'); - end; - procedure remove_test_package is - pragma autonomous_transaction; - begin - execute immediate 'drop package check_xunit_reporting'; - execute immediate 'drop package check_xunit_rep_suitepath'; - end; -end; -/ diff --git a/test/core/test_output_buffer.pkb b/test/core/test_output_buffer.pkb index 7d60c5213..a22f3772d 100644 --- a/test/core/test_output_buffer.pkb +++ b/test/core/test_output_buffer.pkb @@ -55,12 +55,12 @@ create or replace package body test_output_buffer is --Act l_expected := lpad('a text',4000,',a text'); l_buffer.send_line(l_expected); - l_start := systimestamp; + l_start := localtimestamp; select * into l_result from table(l_buffer.get_lines(1,1)); - l_duration := systimestamp - l_start; + l_duration := localtimestamp - l_start; ut.expect(l_result).to_equal(l_expected); - ut.expect(l_duration).to_be_greater_than(interval '1' second); + ut.expect(l_duration).to_be_greater_than(interval '0.99' second); select count(1) into l_remaining from ut3.ut_output_buffer_tmp where output_id = l_buffer.output_id; ut.expect(l_remaining).to_equal(0); diff --git a/test/core/test_output_buffer.pks b/test/core/test_output_buffer.pks index 6311d2275..1392b39ad 100644 --- a/test/core/test_output_buffer.pks +++ b/test/core/test_output_buffer.pks @@ -3,7 +3,7 @@ create or replace package test_output_buffer is --%suite(output_buffer) --%suitepath(utplsql.core) - --%test(Recieves a line from buffer table and deletes) + --%test(Receives a line from buffer table and deletes) procedure test_recieve; --%test(Does not send line if null text given) diff --git a/test/core/test_suite_builder.pkb b/test/core/test_suite_builder.pkb index 654143349..19ea81aa0 100644 --- a/test/core/test_suite_builder.pkb +++ b/test/core/test_suite_builder.pkb @@ -150,6 +150,25 @@ create or replace package body test_suite_builder is ); end; + procedure test_annotation is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(2, 'suite','Cool', null), + ut3.ut_annotation(8, 'test','Some test', 'test_procedure') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like( + '%' || + '%test_procedureSome testsome_package.test_procedure' || + '%%' + ); + end; + procedure test_annot_duplicated is l_actual clob; l_annotations ut3.ut_annotations; @@ -415,6 +434,61 @@ create or replace package body test_suite_builder is ); end; + procedure multiple_standalone_bef_aft is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(1, 'suite','Cool', null), + ut3.ut_annotation(2, 'beforeall', 'some_package.first_before_all',null), + ut3.ut_annotation(3, 'beforeall', 'different_package.another_before_all',null), + ut3.ut_annotation(4, 'beforeeach', 'first_before_each',null), + ut3.ut_annotation(5, 'beforeeach', 'different_owner.different_package.another_before_each',null), + ut3.ut_annotation(6, 'aftereach', 'first_after_each',null), + ut3.ut_annotation(7, 'aftereach', 'another_after_each,different_owner.different_package.one_more_after_each',null), + ut3.ut_annotation(8, 'afterall', 'first_after_all',null), + ut3.ut_annotation(9, 'afterall', 'another_after_all',null), + ut3.ut_annotation(14, 'test','A test', 'some_test'), + ut3.ut_annotation(15, 'beforetest','before_test_proc', 'some_test'), + ut3.ut_annotation(16, 'beforetest','before_test_proc2', 'some_test'), + ut3.ut_annotation(18, 'aftertest','after_test_proc', 'some_test'), + ut3.ut_annotation(20, 'aftertest','after_test_proc2', 'some_test') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like( + '%%some_package%some_test' || + '%' || + '%some_packagefirst_before_each' || + '%different_ownerdifferent_packageanother_before_each' || + '%' || + '%' || + '%some_packagebefore_test_proc' || + '%some_packagebefore_test_proc2' || + '%' || + '%' || + '%some_packageafter_test_proc' || + '%some_packageafter_test_proc2' || + '%' || + '%' || + '%some_packagefirst_after_each' || + '%some_packageanother_after_each' || + '%different_ownerdifferent_packageone_more_after_each' || + '%' || + '%' || + '%' || + '%some_packagefirst_before_all' || + '%different_packageanother_before_all' || + '%' || + '%' || + '%some_packagefirst_after_all' || + '%some_packageanother_after_all' || + '%%' + ); + end; + procedure before_after_on_single_proc is l_actual clob; l_annotations ut3.ut_annotations; @@ -449,6 +523,68 @@ create or replace package body test_suite_builder is ); end; + procedure multiple_mixed_bef_aft is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(1, 'suite','Cool', null), + ut3.ut_annotation(2, 'beforeall', null,'first_before_all'), + ut3.ut_annotation(3, 'beforeall', 'different_package.another_before_all',null), + ut3.ut_annotation(4, 'beforeeach', 'first_before_each',null), + ut3.ut_annotation(5, 'beforeeach', 'different_owner.different_package.another_before_each',null), + ut3.ut_annotation(6, 'aftereach', null, 'first_after_each'), + ut3.ut_annotation(7, 'aftereach', 'another_after_each,different_owner.different_package.one_more_after_each',null), + ut3.ut_annotation(8, 'afterall', 'first_after_all',null), + ut3.ut_annotation(9, 'afterall', 'another_after_all',null), + ut3.ut_annotation(14, 'test','A test', 'some_test'), + ut3.ut_annotation(15, 'beforetest','before_test_proc', 'some_test'), + ut3.ut_annotation(16, 'beforetest','before_test_proc2', 'some_test'), + ut3.ut_annotation(18, 'aftertest','after_test_proc', 'some_test'), + ut3.ut_annotation(20, 'aftertest','after_test_proc2', 'some_test'), + ut3.ut_annotation(21, 'beforeall', null,'last_before_all'), + ut3.ut_annotation(22, 'aftereach', null, 'last_after_each'), + ut3.ut_annotation(23, 'afterall', null, 'last_after_all') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like( + '%%some_package%some_test' || + '%' || + '%some_packagefirst_before_each' || + '%different_ownerdifferent_packageanother_before_each' || + '%' || + '%' || + '%some_packagebefore_test_proc' || + '%some_packagebefore_test_proc2' || + '%' || + '%' || + '%some_packageafter_test_proc' || + '%some_packageafter_test_proc2' || + '%' || + '%' || + '%some_packagefirst_after_each' || + '%some_packageanother_after_each' || + '%different_ownerdifferent_packageone_more_after_each' || + '%some_packagelast_after_each' || + '%' || + '%' || + '%' || + '%some_packagefirst_before_all' || + '%different_packageanother_before_all' || + '%some_packagelast_before_all' || + '%' || + '%' || + '%some_packagefirst_after_all' || + '%some_packageanother_after_all' || + '%some_packagelast_after_all' || + '%%' + ); + end; + + procedure before_after_mixed_with_test is l_actual clob; l_annotations ut3.ut_annotations; @@ -485,8 +621,9 @@ create or replace package body test_suite_builder is ut3.ut_annotation(1, 'suite','Cool', null), ut3.ut_annotation(2, 'beforeall',null, 'suite_level_beforeall'), ut3.ut_annotation(3, 'test','In suite', 'suite_level_test'), - ut3.ut_annotation(4, 'context','A context', null), - ut3.ut_annotation(5, 'beforeall',null, 'context_setup'), + ut3.ut_annotation(4, 'context','a_context', null), + ut3.ut_annotation(5, 'displayname','A context', null), + ut3.ut_annotation(6, 'beforeall',null, 'context_setup'), ut3.ut_annotation(7, 'test', 'In context', 'test_in_a_context'), ut3.ut_annotation(8, 'endcontext',null, null) ); @@ -498,10 +635,10 @@ create or replace package body test_suite_builder is '%' || '%' || '' || - '%context_1A contextsome_package.context_1' || + '%a_contextA contextsome_package.a_context' || '%' || '' || - '%test_in_a_contextIn contextsome_package.context_1.test_in_a_context' || + '%test_in_a_contextIn contextsome_package.a_context.test_in_a_context' || '%' || '' || '' || @@ -527,15 +664,15 @@ create or replace package body test_suite_builder is begin --Arrange l_annotations := ut3.ut_annotations( - ut3.ut_annotation(1, 'suite','Cool', null), - ut3.ut_annotation(2, 'test','In suite', 'suite_level_test'), - ut3.ut_annotation(3, 'context','A context', null), - ut3.ut_annotation(4, 'beforeall',null, 'context_beforeall'), - ut3.ut_annotation(5, 'beforeeach',null, 'context_beforeeach'), + ut3.ut_annotation(1, 'suite', 'Cool', null), + ut3.ut_annotation(2, 'test', 'In suite', 'suite_level_test'), + ut3.ut_annotation(3, 'context', 'a_context', null), + ut3.ut_annotation(4, 'beforeall', 'context_beforeall', null), + ut3.ut_annotation(5, 'beforeeach', null, 'context_beforeeach'), ut3.ut_annotation(6, 'test', 'In context', 'test_in_a_context'), - ut3.ut_annotation(7, 'aftereach',null, 'context_aftereach'), - ut3.ut_annotation(8, 'afterall',null, 'context_afterall'), - ut3.ut_annotation(9, 'endcontext',null, null) + ut3.ut_annotation(7, 'aftereach', 'context_aftereach' ,null), + ut3.ut_annotation(8, 'afterall', null, 'context_afterall'), + ut3.ut_annotation(9, 'endcontext', null, null) ); --Act l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); @@ -544,7 +681,7 @@ create or replace package body test_suite_builder is '' || '%' || '%' || - '%context_1' || + '%a_context' || '%' || '%' || '%test_in_a_context' || @@ -579,7 +716,7 @@ create or replace package body test_suite_builder is ut3.ut_annotation(2, 'beforeall',null, 'suite_level_beforeall'), ut3.ut_annotation(3, 'beforeeach',null, 'suite_level_beforeeach'), ut3.ut_annotation(4, 'test','In suite', 'suite_level_test'), - ut3.ut_annotation(5, 'context','A context', null), + ut3.ut_annotation(5, 'context','a_context', null), ut3.ut_annotation(6, 'test', 'In context', 'test_in_a_context'), ut3.ut_annotation(7, 'endcontext',null, null), ut3.ut_annotation(8, 'aftereach',null, 'suite_level_aftereach'), @@ -592,7 +729,7 @@ create or replace package body test_suite_builder is '' || '%' || '%' || - '%context_1' || + '%a_context' || '%' || '%' || '%test_in_a_context' || @@ -665,8 +802,9 @@ create or replace package body test_suite_builder is ut3.ut_annotation(1, 'suite','Cool', null), ut3.ut_annotation(2, 'beforeall',null, 'suite_level_beforeall'), ut3.ut_annotation(3, 'test','In suite', 'suite_level_test'), - ut3.ut_annotation(4, 'context','A context', null), - ut3.ut_annotation(5, 'beforeall',null, 'context_setup'), + ut3.ut_annotation(4, 'context','a_context', null), + ut3.ut_annotation(5, 'displayname','A context', null), + ut3.ut_annotation(6, 'beforeall',null, 'context_setup'), ut3.ut_annotation(7, 'test', 'In context', 'test_in_a_context'), ut3.ut_annotation(8, 'endcontext',null, null), ut3.ut_annotation(9, 'endcontext',null, null) @@ -682,10 +820,10 @@ create or replace package body test_suite_builder is '' || '%' || '' || - '%context_1A contextsome_package.context_1' || + '%a_contextA contextsome_package.a_context' || '%' || '' || - '%test_in_a_contextIn contextsome_package.context_1.test_in_a_context' || + '%test_in_a_contextIn contextsome_package.a_context.test_in_a_context' || '%' || '' || '' || @@ -705,5 +843,214 @@ create or replace package body test_suite_builder is ); end; -end; + procedure throws_value_empty is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(1, 'suite','Cool', null), + ut3.ut_annotation(3, 'test','A test with empty throws annotation', 'A_TEST_PROCEDURE'), + ut3.ut_annotation(3, 'throws',null, 'A_TEST_PROCEDURE') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like( + '%%"--%throws" annotation requires a parameter. Annotation ignored.%%' + ); + end; + + procedure throws_value_invalid is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(1, 'suite','Cool', null), + ut3.ut_annotation(3, 'test','A test with invalid throws annotation', 'A_TEST_PROCEDURE'), + ut3.ut_annotation(3, 'throws',' -20145 , bad_variable_name ', 'A_TEST_PROCEDURE') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like( + '%%Invalid parameter value "bad_variable_name" for "--%throws" annotation. Parameter ignored.%%' + ); + end; + + + procedure before_aftertest_multi is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(1, 'suite','Cool', null), + ut3.ut_annotation(14, 'test','A test', 'some_test'), + ut3.ut_annotation(15, 'beforetest','before_test_proc', 'some_test'), + ut3.ut_annotation(16, 'beforetest','before_test_proc2', 'some_test'), + ut3.ut_annotation(18, 'aftertest','after_test_proc', 'some_test'), + ut3.ut_annotation(20, 'aftertest','after_test_proc2', 'some_test') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like( + '%%some_package%some_test' || + '%' || + '%some_packagebefore_test_proc' || + '%some_packagebefore_test_proc2' || + '%' || + '%' || + '%some_packageafter_test_proc' || + '%some_packageafter_test_proc2' || + '%' || + '%%' + ); + end; + + procedure before_aftertest_twice is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(1, 'suite','Cool', null), + ut3.ut_annotation(14, 'test','A test', 'some_test'), + ut3.ut_annotation(15, 'beforetest','before_test_proc, before_test_proc2', 'some_test'), + ut3.ut_annotation(16, 'beforetest','before_test_proc3', 'some_test'), + ut3.ut_annotation(18, 'aftertest','after_test_proc,after_test_proc2', 'some_test'), + ut3.ut_annotation(20, 'aftertest','after_test_proc3', 'some_test') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like( + '%%some_package%some_test' || + '%' || + '%some_packagebefore_test_proc' || + '%some_packagebefore_test_proc2' || + '%some_packagebefore_test_proc3' || + '%' || + '%' || + '%some_packageafter_test_proc' || + '%some_packageafter_test_proc2' || + '%some_packageafter_test_proc3' || + '%' || + '%%' + ); + end; + + procedure before_aftertest_pkg_proc is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(1, 'suite','Cool', null), + ut3.ut_annotation(14, 'test','A test', 'some_test'), + ut3.ut_annotation(15, 'beforetest','external_package.before_test_proc', 'some_test'), + ut3.ut_annotation(18, 'aftertest','external_package.after_test_proc', 'some_test') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like( + '%%some_package%some_test' || + '%' || + '%external_packagebefore_test_proc' || + '%' || + '%' || + '%external_packageafter_test_proc' || + '%' || + '%%' + ); + end; + + procedure before_aftertest_mixed_syntax is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(1, 'suite','Cool', null), + ut3.ut_annotation(14, 'test','A test', 'some_test'), + ut3.ut_annotation(15, 'beforetest','external_package.before_test_proc, before_test_proc2', 'some_test'), + ut3.ut_annotation(18, 'aftertest','external_package.after_test_proc, after_test_proc2', 'some_test') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like( + '%%some_package%some_test' || + '%' || + '%external_packagebefore_test_proc' || + '%some_packagebefore_test_proc2' || + '%' || + '%' || + '%external_packageafter_test_proc' || + '%some_packageafter_test_proc2' || + '%' || + '%%' + ); + end; + + procedure test_annotation_ordering is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(1, 'suite','Cool', null), + ut3.ut_annotation(4, 'test','B test', 'b_test'), + ut3.ut_annotation(10, 'test','Z test', 'z_test'), + ut3.ut_annotation(14, 'test','A test', 'a_test') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like( + '%%some_package%b_test' || + '%%'|| + '%%some_package%z_test' || + '%%'|| + '%%some_package%a_test' || + '%%' + ); + end; + + procedure test_bad_procedure_annotation is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(1, 'suite','Cool', null), + ut3.ut_annotation(2, 'bad_procedure_annotation',null, 'some_procedure'), + ut3.ut_annotation(6, 'test','A test', 'do_stuff') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like('%Unsupported annotation "--\%bad_procedure_annotation". Annotation ignored.% line 2%', '\'); + end; + + procedure test_bad_package_annotation is + l_actual clob; + l_annotations ut3.ut_annotations; + begin + --Arrange + l_annotations := ut3.ut_annotations( + ut3.ut_annotation(1, 'suite','Cool', null), + ut3.ut_annotation(17, 'bad_package_annotation',null, null), + ut3.ut_annotation(24, 'test','A test', 'do_stuff') + ); + --Act + l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE'); + --Assert + ut.expect(l_actual).to_be_like('%Unsupported annotation "--\%bad_package_annotation". Annotation ignored.% line 17%', '\'); + end; + +end test_suite_builder; / diff --git a/test/core/test_suite_builder.pks b/test/core/test_suite_builder.pks index d8bf40164..36517432b 100644 --- a/test/core/test_suite_builder.pks +++ b/test/core/test_suite_builder.pks @@ -2,56 +2,70 @@ create or replace package test_suite_builder is --%suite(suite_builder) --%suitepath(utplsql.core) + --%context(suite) + --%displayname(--%suite annotation) + --%test(Sets suite name from package name and leaves description empty) procedure no_suite_description; --%test(Sets suite description using first --%suite annotation) procedure suite_description_from_suite; - --%test(Sets suite path using first --%suitepath annotation) - procedure suitepath_from_non_empty_path; + --%test(Gives warning if more than one --%suite annotation used) + procedure suite_annot_duplicated; + + --%endcontext + + --%context(displayname) + --%displayname(--%displayname annotation) --%test(Overrides suite description using first --%displayname annotation) procedure suite_descr_from_displayname; - --%test(Sets rollback type using first --%rollback annotation) - procedure rollback_type_valid; + --%test(Gives warning if more than one --%displayname annotation used) + procedure displayname_annot_duplicated; - --%test(Gives warning if more than one --%rollback annotation used) - procedure rollback_type_duplicated; + --%test(Gives warning if --%displayname annotation has no value) + procedure displayname_annot_empty; - --%test(Gives warning if more than one --%suite annotation used) - procedure suite_annot_duplicated; + --%endcontext + + --%context(test) + --%displayname(--%test annotation) + + --%test(Creates a test item for procedure annotated with --%test annotation) + procedure test_annotation; --%test(Gives warning if more than one --%test annotation used) procedure test_annot_duplicated; - --%test(Gives warning if more than one --%beforeall annotation used) - procedure beforeall_annot_duplicated; + --%endcontext - --%test(Gives warning if more than one --%beforeeach annotation used) - procedure beforeeach_annot_duplicated; - - --%test(Gives warning if more than one --%afterall annotation used) - procedure afterall_annot_duplicated; + --%context(suitepath) + --%displayname(--%suitepath annotation) - --%test(Gives warning if more than one --%aftereach annotation used) - procedure aftereach_annot_duplicated; + --%test(Sets suite path using first --%suitepath annotation) + procedure suitepath_from_non_empty_path; --%test(Gives warning if more than one --%suitepath annotation used) procedure suitepath_annot_duplicated; - --%test(Gives warning if more than one --%displayname annotation used) - procedure displayname_annot_duplicated; - --%test(Gives warning if --%suitepath annotation has no value) procedure suitepath_annot_empty; --%test(Gives warning if --%suitepath annotation has invalid value) procedure suitepath_annot_invalid_path; - --%test(Gives warning if --%displayname annotation has no value) - procedure displayname_annot_empty; + --%endcontext + + --%context(rollback) + --%displayname(--%rollback annotation) + + --%test(Sets rollback type using first --%rollback annotation) + procedure rollback_type_valid; + + --%test(Gives warning if more than one --%rollback annotation used) + procedure rollback_type_duplicated; --%test(Gives warning if --%rollback annotation has no value) procedure rollback_type_empty; @@ -59,15 +73,43 @@ create or replace package test_suite_builder is --%test(Gives warning if --%rollback annotation has invalid value) procedure rollback_type_invalid; - --%test(Supports multiple before/after definitions) + --%endcontext + + --%context(before_after_all_each) + --%displayname(--%before/after all/each annotations) + + --%test(Supports multiple before/after all/each procedure level definitions) procedure multiple_before_after; - --%test(Supports before/after all/each annotations on single procedure) + --%test(Supports multiple before/after all/each standalone level definitions) + procedure multiple_standalone_bef_aft; + + --%test(Supports mixing before/after all/each annotations on single procedure) procedure before_after_on_single_proc; + --%test(Supports mixed before/after all/each as standalone and procedure level definitions) + procedure multiple_mixed_bef_aft; + + --%test(Gives warning if more than one --%beforeall annotation used on procedure) + procedure beforeall_annot_duplicated; + + --%test(Gives warning if more than one --%beforeeach annotation used on procedure) + procedure beforeeach_annot_duplicated; + + --%test(Gives warning if more than one --%afterall annotation used on procedure) + procedure afterall_annot_duplicated; + + --%test(Gives warning if more than one --%aftereach annotation used on procedure) + procedure aftereach_annot_duplicated; + --%test(Gives warning on before/after all/each annotations mixed with test) procedure before_after_mixed_with_test; + --%endcontext + + --%context(context) + --%displayname(--%context annotation) + --%test(Creates nested suite for content between context/endcontext annotations) procedure suite_from_context; @@ -83,5 +125,54 @@ create or replace package test_suite_builder is --%test(Gives warning if --%endcontext is missing a preceding --%context) procedure endcontext_without_context; -end; + --%endcontext + + --%context(throws) + --%displayname(--%throws annotation) + + --%test(Gives warning if --%throws annotation has no value) + procedure throws_value_empty; + + --%test(Gives warning if --%throws annotation has invalid value) + procedure throws_value_invalid; + + --%endcontext + + --%context(beforetest_aftertest) + --%displayname(--%beforetest/aftertest annotation) + + --%test(Supports multiple occurrences of beforetest/aftertest for a test) + procedure before_aftertest_multi; + + --%test(Supports same procedure defined twice) + procedure before_aftertest_twice; + + --%test(Supports beforetest from external package) + procedure before_aftertest_pkg_proc; + + --%test(Supports mix of procedure and package.procedure) + procedure before_aftertest_mixed_syntax; + + --%endcontext + + --%context(test) + --%displayname(--%test annontation) + + --%test(Is added to suite according to annotation order in package spec) + procedure test_annotation_ordering; + + --%endcontext + + --%context(unknown_annotation) + --%displayname(--%bad_annotation) + + --%test(Gives warning when unknown procedure level annotation passed) + procedure test_bad_procedure_annotation; + + --%test(Gives warning when unknown package level annotation passed) + procedure test_bad_package_annotation; + + --%endcontext + +end test_suite_builder; / diff --git a/test/core/test_suite_manager.pkb b/test/core/test_suite_manager.pkb index 827812f98..59f1f42ea 100644 --- a/test/core/test_suite_manager.pkb +++ b/test/core/test_suite_manager.pkb @@ -242,6 +242,32 @@ end test_package_3;]'; end; end test_package_3;]'; + + execute immediate q'[create or replace package test_package_with_ctx is + + --%suite(test_package_with_ctx) + + gv_glob_val number; + + --%context(some_context) + --%displayname(Some context description) + + --%test + --%displayname(Test1 from test package 1) + procedure test1; + + --%endcontext + +end test_package_with_ctx;]'; + + execute immediate q'[create or replace package body test_package_with_ctx is + + procedure test1 is + begin + null; + end; + +end test_package_with_ctx;]'; end; @@ -251,6 +277,7 @@ end test_package_3;]'; execute immediate 'drop package test_package_1'; execute immediate 'drop package test_package_2'; execute immediate 'drop package test_package_3'; + execute immediate 'drop package test_package_with_ctx'; end; procedure test_schema_run is @@ -872,10 +899,9 @@ end test_package_3;]'; l_objects_to_run ut3.ut_suite_items; begin l_objects_to_run := ut3.ut_suite_manager.configure_execution_by_path(ut3.ut_varchar2_list('failing_invalid_spec')); - ut.fail('Invalid package didnt raised exception'); - exception - when others then - ut.expect(sqlerrm).to_be_like('%failing_invalid_spec%'); + + ut3.ut.expect(l_objects_to_run.count).to_be_greater_than(0); + ut3.ut.expect(l_objects_to_run(l_objects_to_run.first).object_name).to_equal('failing_invalid_spec'); end; procedure compile_invalid_package is @@ -912,6 +938,26 @@ end;]'; execute immediate 'drop package failing_invalid_spec'; end; + procedure test_search_nonexisting_pck is + l_objects_to_run ut3.ut_suite_items; + begin + l_objects_to_run := ut3.ut_suite_manager.configure_execution_by_path(ut3.ut_varchar2_list('ut3.failing_non_existing')); + ut.fail('Non existing package didnt raised exception'); + exception + when others then + ut.expect(sqlerrm).to_be_like('%failing_non_existing%'); + end; + + procedure test_search_nonexist_sch_pck is + l_objects_to_run ut3.ut_suite_items; + begin + l_objects_to_run := ut3.ut_suite_manager.configure_execution_by_path(ut3.ut_varchar2_list('failing_non_existing')); + ut.fail('Non existing package without schema didnt raised exception'); + exception + when others then + ut.expect(sqlerrm).to_be_like('%ORA-44001: invalid schema%'); + end; + procedure test_desc_with_comma is l_objects_to_run ut3.ut_suite_items; l_suite ut3.ut_suite; @@ -1333,5 +1379,59 @@ end;]'; clean_disabled_pck; end; + procedure pck_proc_in_ctx_by_name is + c_path varchar2(100) := USER||'.test_package_with_ctx.test1'; + l_objects_to_run ut3.ut_suite_items; + + l_test_suite ut3.ut_logical_suite; + l_ctx_suite ut3.ut_logical_suite; + l_test_proc ut3.ut_test; + begin + --Act + l_objects_to_run := ut3.ut_suite_manager.configure_execution_by_path(ut3.ut_varchar2_list(c_path)); + + --Assert + ut.expect(l_objects_to_run.count).to_equal(1); + + l_test_suite := treat(l_objects_to_run(1) as ut3.ut_logical_suite); + ut.expect(l_test_suite.name).to_equal('test_package_with_ctx'); + ut.expect(l_test_suite.items.count).to_equal(1); + + l_ctx_suite := treat(l_test_suite.items(1) as ut3.ut_logical_suite); + ut.expect(l_ctx_suite.name).to_equal('some_context'); + ut.expect(l_ctx_suite.description).to_equal('Some context description'); + ut.expect(l_ctx_suite.items.count).to_equal(1); + + l_test_proc := treat(l_ctx_suite.items(1) as ut3.ut_test); + ut.expect(l_test_proc.name).to_equal('test1'); + end; + + procedure pck_proc_in_ctx_by_path is + c_path varchar2(100) := USER||':test_package_with_ctx.some_context.test1'; + l_objects_to_run ut3.ut_suite_items; + + l_test_suite ut3.ut_logical_suite; + l_ctx_suite ut3.ut_logical_suite; + l_test_proc ut3.ut_test; + begin + --Act + l_objects_to_run := ut3.ut_suite_manager.configure_execution_by_path(ut3.ut_varchar2_list(c_path)); + + --Assert + ut.expect(l_objects_to_run.count).to_equal(1); + + l_test_suite := treat(l_objects_to_run(1) as ut3.ut_logical_suite); + ut.expect(l_test_suite.name).to_equal('test_package_with_ctx'); + ut.expect(l_test_suite.items.count).to_equal(1); + + l_ctx_suite := treat(l_test_suite.items(1) as ut3.ut_logical_suite); + ut.expect(l_ctx_suite.name).to_equal('some_context'); + ut.expect(l_ctx_suite.description).to_equal('Some context description'); + ut.expect(l_ctx_suite.items.count).to_equal(1); + + l_test_proc := treat(l_ctx_suite.items(1) as ut3.ut_test); + ut.expect(l_test_proc.name).to_equal('test1'); + end; + end test_suite_manager; / diff --git a/test/core/test_suite_manager.pks b/test/core/test_suite_manager.pks index 8585a86aa..45466b9d2 100644 --- a/test/core/test_suite_manager.pks +++ b/test/core/test_suite_manager.pks @@ -65,12 +65,18 @@ create or replace package test_suite_manager is --%test(Prepare runner for the suites package by path for current user) procedure test_top_subpck_by_path_cu; - --%test(Prepare runner for invalid package) + --%test(Prepare runner for invalid package - it will add to suite but fail on exec ) --%beforetest(compile_invalid_package) --%aftertest(drop_invalid_package) procedure test_search_invalid_pck; procedure compile_invalid_package; procedure drop_invalid_package; + + --%test(Prepare runner for nonexisting package with schema) + procedure test_search_nonexisting_pck; + + --%test(Prepare runner for nonexisting package without schema) + procedure test_search_nonexist_sch_pck; --%test(Test description with comma) --%beforetest(setup_desc_with_comma) @@ -139,5 +145,11 @@ create or replace package test_suite_manager is --%test(Whole suite gets disabled with floating annotation) procedure disable_suite_floating_annot; + --%test(Prepare runner for a package procedure inside context) + procedure pck_proc_in_ctx_by_name; + + --%test(Prepare runner for a package procedure inside context by path) + procedure pck_proc_in_ctx_by_path; + end test_suite_manager; / diff --git a/test/core/test_ut_executable.pkb b/test/core/test_ut_executable.pkb new file mode 100644 index 000000000..b5f372c32 --- /dev/null +++ b/test/core/test_ut_executable.pkb @@ -0,0 +1,163 @@ +create or replace package body test_ut_executable is + + g_dbms_output_text varchar2(30) := 'Some output from procedure'; + + procedure exec_schema_package_proc is + l_executable ut3.ut_executable; + l_test ut3.ut_test; + l_result boolean; + begin + --Arrange + l_test := ut3.ut_test(a_object_name => 'test_ut_executable',a_name => 'test_ut_executable'); + l_executable := ut3.ut_executable_test( null, 'test_ut_executable', 'passing_proc', ut3.ut_utils.gc_test_execute ); + --Act + l_result := l_executable.do_execute(l_test); + --Assert + ut.expect(l_result).to_be_true; + ut.expect(l_executable.serveroutput).to_be_null; + ut.expect(l_executable.get_error_stack_trace()).to_be_null; + end; + + procedure exec_package_proc_output is + l_executable ut3.ut_executable; + l_test ut3.ut_test; + l_result boolean; + begin + --Arrange + l_test := ut3.ut_test(a_object_name => 'test_ut_executable',a_name => 'test_ut_executable'); + l_executable := ut3.ut_executable_test( user, 'test_ut_executable', 'output_proc', ut3.ut_utils.gc_test_execute ); + --Act + l_result := l_executable.do_execute(l_test); + --Assert + ut.expect(l_result).to_be_true; + ut.expect(l_executable.serveroutput).to_equal(to_clob(g_dbms_output_text||chr(10))); + ut.expect(l_executable.get_error_stack_trace()).to_be_null; + end; + + procedure exec_failing_proc is + l_executable ut3.ut_executable; + l_test ut3.ut_test; + l_result boolean; + begin + --Arrange + l_test := ut3.ut_test(a_object_name => 'test_ut_executable',a_name => 'test_ut_executable'); + l_executable := ut3.ut_executable_test( user, 'test_ut_executable', 'throwing_proc', ut3.ut_utils.gc_test_execute ); + --Act + l_result := l_executable.do_execute(l_test); + --Assert + ut.expect(l_result).to_be_false; + ut.expect(l_executable.serveroutput).to_be_null; + ut.expect(l_executable.get_error_stack_trace()).to_be_like('ORA-06501: PL/SQL: program error%'); + end; + + procedure create_state_dependant_pkg is + pragma autonomous_transaction; + begin + execute immediate q'[ + create or replace package stateful_package as + g_state varchar2(1) := 'A'; + end; + ]'; + execute immediate q'[ + create or replace package state_dependant_pkg as + procedure run; + end; + ]'; + execute immediate q'[ + create or replace package body state_dependant_pkg as + procedure run is + x varchar2(30); + begin + if stateful_package.g_state = 'A' then + dbms_output.put_line('stateful_package.g_state = "A"'); + end if; + end; + end; + ]'; + end; + + procedure modify_stateful_package is + l_job_name varchar2(30) := 'recreate_stateful_package'; + l_cnt integer := 1; + pragma autonomous_transaction; + begin + dbms_scheduler.create_job( + job_name => l_job_name, + job_type => 'PLSQL_BLOCK', + job_action => q'/ + begin + execute immediate q'[ + create or replace package stateful_package as + g_state varchar2(3) := 'abc'; + end;]'; + end;/', + start_date => localtimestamp, + enabled => TRUE, + auto_drop => TRUE, + comments => 'one-time job' + ); + dbms_lock.sleep(0.4); + while l_cnt > 0 loop + select count(1) into l_cnt + from dba_scheduler_running_jobs srj + where srj.job_name = l_job_name; + end loop; + end; + + procedure drop_state_dependant_pkg is + pragma autonomous_transaction; + begin + execute immediate 'drop package state_dependant_pkg'; + execute immediate 'drop package stateful_package'; + end; + + + procedure exec_invalid_state_proc is + l_executable ut3.ut_executable; + l_test ut3.ut_test; + l_result boolean; + begin + --Arrange + l_test := ut3.ut_test(a_object_name => 'state_dependant_pkg',a_name => 'state_dependant_pkg'); + l_executable := ut3.ut_executable_test( user, 'state_dependant_pkg', 'run', ut3.ut_utils.gc_test_execute ); + l_result := l_executable.do_execute(l_test); + ut.expect(l_result).to_be_true; + + modify_stateful_package; + + l_test := ut3.ut_test(a_object_name => 'state_dependant_pkg',a_name => 'state_dependant_pkg'); + l_executable := ut3.ut_executable_test( user, 'state_dependant_pkg', 'run', ut3.ut_utils.gc_test_execute ); + --Act + l_result := l_executable.do_execute(l_test); + --Assert + ut.expect(l_result).to_be_false; + ut.expect(l_executable.serveroutput).to_be_null; + ut.expect(l_executable.get_error_stack_trace()).to_be_like('ORA-04061: existing state of package "UT3_TESTER.STATEFUL_PACKAGE" has been invalidated%'); + ut.expect(ut3.ut_expectation_processor.invalidation_exception_found()).to_be_true; + end; + + procedure form_name is + begin + ut.expect(ut3.ut_executable_test( user, 'package', 'proc', null ).form_name()).to_equal(user||'.package.proc'); + ut.expect(ut3.ut_executable_test( null, 'package', 'proc', null ).form_name()).to_equal('package.proc'); + ut.expect(ut3.ut_executable_test( null, 'proc', null, null ).form_name()).to_equal('proc'); + ut.expect(ut3.ut_executable_test( user, 'proc', null, null ).form_name()).to_equal(user||'.proc'); + end; + + procedure passing_proc is + begin + null; + end; + + procedure output_proc is + begin + dbms_output.put_line(g_dbms_output_text); + end; + + procedure throwing_proc is + begin + raise program_error; + end; + +end; +/ diff --git a/test/core/test_ut_executable.pks b/test/core/test_ut_executable.pks new file mode 100644 index 000000000..51641ecbf --- /dev/null +++ b/test/core/test_ut_executable.pks @@ -0,0 +1,41 @@ +create or replace package test_ut_executable is + + --%suite(ut_executable) + --%suitepath(utplsql.core) + + --%context(do_execute) + + --%test(Executes procedure in current schema when user was not provided) + procedure exec_schema_package_proc; + + --%test(Executes procedure and saves dbms_output) + procedure exec_package_proc_output; + + --%test(Executes a procedure raising exception, saves dbms_output and exception stack trace) + procedure exec_failing_proc; + + --%test(Sets state invalid flag when package-state invalidated and saves exception stack trace) + --%beforetest(create_state_dependant_pkg) + --%aftertest(drop_state_dependant_pkg) + procedure exec_invalid_state_proc; + + procedure create_state_dependant_pkg; + procedure drop_state_dependant_pkg; + + --%endcontext + + --%context(form_name) + + --%test(Builds a name for the executable test) + procedure form_name; + + --%endcontext + + procedure passing_proc; + + procedure output_proc; + + procedure throwing_proc; + +end; +/ diff --git a/test/core/test_ut_utils.pkb b/test/core/test_ut_utils.pkb index 36f849aae..326f5a49b 100644 --- a/test/core/test_ut_utils.pkb +++ b/test/core/test_ut_utils.pkb @@ -2,6 +2,37 @@ create or replace package body test_ut_utils is gv_nls_value nls_session_parameters.value%type; + gc_delimiter varchar2(1) := get_numeric_delimiter(); + + function get_numeric_delimiter return varchar2 is + l_result varchar2(1); + begin + select substr(value, 1, 1) into l_result from nls_session_parameters t where t.parameter = 'NLS_NUMERIC_CHARACTERS'; + return l_result; + end; + + function clob_to_blob(p_clob clob) return blob is + l_blob blob; + l_dest_offset integer := 1; + l_source_offset integer := 1; + l_lang_context integer := dbms_lob.default_lang_ctx; + l_warning integer := dbms_lob.warn_inconvertible_char; + begin + dbms_lob.createtemporary(l_blob, true); + dbms_lob.converttoblob( + dest_lob =>l_blob, + src_clob =>p_clob, + amount =>DBMS_LOB.LOBMAXSIZE, + dest_offset =>l_dest_offset, + src_offset =>l_source_offset, + blob_csid =>DBMS_LOB.DEFAULT_CSID, + lang_context=>l_lang_context, + warning =>l_warning + ); + return l_blob; + end; + + procedure common_clob_to_table_exec(p_clob varchar2, p_delimiter varchar2, p_expected_list ut3.ut_varchar2_list, p_limit number) is begin execute immediate 'declare @@ -54,163 +85,149 @@ end;]' using p_expected_list; common_clob_to_table_exec( ',a,,c,d,', ',', ut3.ut_varchar2_list('','a','','c','d',''), 1000); end; - procedure test_to_char is + procedure test_test_result_to_char is begin ut.expect(ut3.ut_utils.test_result_to_char(-1),'test unknown').to_equal('Unknown(-1)'); ut.expect(ut3.ut_utils.test_result_to_char(null),'test unknown').to_equal('Unknown(NULL)'); ut.expect(ut3.ut_utils.test_result_to_char(ut3.ut_utils.gc_success),'test unknown').to_equal(ut3.ut_utils.gc_success_char); end; - procedure test_to_string_blob is - l_text varchar2(32767) := 'A test char'; - l_value blob := utl_raw.cast_to_raw(l_text); - l_expected varchar2(32767) := ''''||rawtohex(l_value)||''''; - l_result varchar2(32767); + procedure to_string_emptyblob is begin - l_result := ut3.ut_utils.to_String(l_value); - ut.expect(l_result).to_equal(l_expected); + ut.expect(ut3.ut_data_value_blob(empty_blob()).to_string()).to_equal('EMPTY'); end; - procedure test_to_string_clob is - l_value clob := 'A test char'; - l_expected varchar2(32767) := ''''||l_value||''''; - l_result varchar2(32767); + procedure to_string_emptyclob is begin - l_result := ut3.ut_utils.to_String(l_value); - ut.expect(l_result).to_equal(l_expected); + ut.expect(ut3.ut_data_value_clob(empty_clob()).to_string()).to_equal('EMPTY'); end; - procedure test_to_string_date is - l_value date := to_date('2016-12-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss'); - l_expected varchar2(100) := '2016-12-31T23:59:59'; - l_result varchar2(32767); + procedure to_string_nullblob is begin - l_result := ut3.ut_utils.to_String(l_value); - ut.expect(l_result).to_equal(l_expected); + ut.expect(ut3.ut_data_value_blob(null).to_string()).to_equal('NULL'); end; - procedure to_string_null is + procedure to_string_nullclob is begin - ut.expect(ut3.ut_utils.to_String(to_blob(NULL))).to_equal('NULL'); - ut.expect(ut3.ut_utils.to_String(to_clob(NULL))).to_equal('NULL'); - ut.expect(ut3.ut_utils.to_String(to_date(NULL))).to_equal('NULL'); - ut.expect(ut3.ut_utils.to_String(to_number(NULL))).to_equal('NULL'); - ut.expect(ut3.ut_utils.to_String(to_timestamp(NULL))).to_equal('NULL'); + ut.expect(ut3.ut_data_value_clob(null).to_string()).to_equal('NULL'); end; - procedure to_string is - l_value timestamp(9) := to_timestamp('2016-12-31 23:59:59.123456789', 'yyyy-mm-dd hh24:mi:ss.ff'); - l_value2 timestamp(9) with local time zone:= to_timestamp('2016-12-31 23:59:59.123456789', 'yyyy-mm-dd hh24:mi:ss.ff'); - l_value3 timestamp(9) with time zone := to_timestamp_tz('2016-12-31 23:59:59.123456789 -8:00', 'yyyy-mm-dd hh24:mi:ss.ff tzh:tzm'); - l_value4 varchar2(20) := 'A test char'; - l_expected varchar2(100); - l_result varchar2(100); - l_delimiter varchar2(10); + procedure to_string_nulldate is + begin + ut.expect(ut3.ut_data_value_date(null).to_string()).to_equal('NULL'); + end; + + procedure to_string_nullnumber is + begin + ut.expect(ut3.ut_data_value_number(null).to_string()).to_equal('NULL'); + end; + + procedure to_string_nulltimestamp is + begin + ut.expect(ut3.ut_data_value_timestamp(null).to_string()).to_equal('NULL'); + end; + + procedure to_string_nulltimestamp_ltz is + begin + ut.expect(ut3.ut_data_value_timestamp_ltz(null).to_string()).to_equal('NULL'); + end; + + procedure to_string_nulltimestamp_tz is + begin + ut.expect(ut3.ut_data_value_timestamp_tz(null).to_string()).to_equal('NULL'); + end; + + procedure to_string_nullvarchar2 is + begin + ut.expect(ut3.ut_data_value_varchar2(null).to_string()).to_equal('NULL'); + end; + + procedure to_string_blob is + l_text varchar2(32767) := 'A test char'; + l_value blob := utl_raw.cast_to_raw(l_text); + l_expected varchar2(32767) := ''''||rawtohex(l_value)||''''; begin - select substr(value, 1, 1) into l_delimiter from nls_session_parameters t where t.parameter = 'NLS_NUMERIC_CHARACTERS'; - l_expected := '2016-12-31T23:59:59'||l_delimiter||'123456789'; + ut.expect(ut3.ut_data_value_blob(l_value).to_string()).to_equal(l_expected); + end; - l_result := ut3.ut_utils.to_String(l_value); - ut.expect(l_result,'Returns a full string representation of a timestamp with maximum precission').to_equal(l_expected); + procedure to_string_clob is + l_value clob := 'A test char'; + l_expected varchar2(32767) := ''''||l_value||''''; + begin + ut.expect(ut3.ut_data_value_clob(l_value).to_string()).to_equal(l_expected); + end; - l_expected := '2016-12-31T23:59:59'||l_delimiter||'123456789'; - l_result := ut3.ut_utils.to_String(l_value2); - ut.expect(l_result,'Returns a full string representation of a timestamp with maximum precission').to_equal(l_expected); + procedure to_string_date is + l_value date := to_date('2016-12-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss'); + l_expected varchar2(100) := '2016-12-31T23:59:59'; + begin + ut.expect(ut3.ut_data_value_date(l_value).to_string()).to_equal(l_expected); + end; - l_expected := '2016-12-31T23:59:59'||l_delimiter||'123456789 -08:00'; + procedure to_string_timestamp is + l_value timestamp(9) := to_timestamp('2016-12-31 23:59:59.123456789', 'yyyy-mm-dd hh24:mi:ss.ff'); + l_expected varchar2(100) := '2016-12-31T23:59:59'||gc_delimiter||'123456789'; + begin + ut.expect(ut3.ut_data_value_timestamp(l_value).to_string()).to_equal(l_expected); + end; - l_result := ut3.ut_utils.to_String(l_value3); - ut.expect(l_result,'Returns a full string representation of a timestamp with maximum precission').to_equal(l_expected); + procedure to_string_timestamp_ltz is + l_value timestamp(9) with local time zone := to_timestamp('2016-12-31 23:59:59.123456789', 'yyyy-mm-dd hh24:mi:ss.ff'); + l_expected varchar2(100) := '2016-12-31T23:59:59'||gc_delimiter||'123456789'; + begin + ut.expect(ut3.ut_data_value_timestamp_ltz(l_value).to_string()).to_equal(l_expected); + end; - l_expected := ''''||l_value4||''''; - l_result := ut3.ut_utils.to_String(l_value4); - ut.expect(l_result,'Returns a varchar2 eclosed in quotes').to_equal(l_expected); + procedure to_string_timestamp_tz is + l_value timestamp(9) with time zone := to_timestamp_tz('2016-12-31 23:59:59.123456789 -8:00', 'yyyy-mm-dd hh24:mi:ss.ff tzh:tzm'); + l_expected varchar2(100) := '2016-12-31T23:59:59'||gc_delimiter||'123456789 -08:00'; + begin + ut.expect(ut3.ut_data_value_timestamp_tz(l_value).to_string()).to_equal(l_expected); + end; + procedure to_string_varchar2 is + l_value varchar2(20) := 'A test char'; + l_expected varchar2(100) := ''''||l_value||''''; + begin + ut.expect(ut3.ut_data_value_varchar2(l_value).to_string()).to_equal(l_expected); end; - procedure to_string_big_blob is + procedure to_string_verybigblob is l_text clob := lpad('A test char',32767,'1')||lpad('1',32767,'1'); l_value blob; - l_result varchar2(32767); - function clob_to_blob(p_clob clob) return blob - as - l_blob blob; - l_dest_offset integer := 1; - l_source_offset integer := 1; - l_lang_context integer := dbms_lob.default_lang_ctx; - l_warning integer := dbms_lob.warn_inconvertible_char; - begin - dbms_lob.createtemporary(l_blob, true); - dbms_lob.converttoblob( - dest_lob =>l_blob, - src_clob =>p_clob, - amount =>DBMS_LOB.LOBMAXSIZE, - dest_offset =>l_dest_offset, - src_offset =>l_source_offset, - blob_csid =>DBMS_LOB.DEFAULT_CSID, - lang_context=>l_lang_context, - warning =>l_warning - ); - return l_blob; - end; begin l_value := clob_to_blob(l_text); - --Act - l_result := ut3.ut_utils.to_String(l_value); - --Assert - ut.EXPECT(length(l_result)).to_equal(ut3.ut_utils.gc_max_output_string_length); - ut.EXPECT(l_result).to_be_like('%'||ut3.ut_utils.gc_more_data_string); - + ut.expect(length(ut3.ut_data_value_blob(l_value).to_string())).to_equal(ut3.ut_utils.gc_max_output_string_length); + ut.expect(ut3.ut_data_value_blob(l_value).to_string()).to_be_like('%'||ut3.ut_utils.gc_more_data_string); end; - procedure to_string_big_clob is + procedure to_string_verybigclob is l_value clob := lpad('A test char',32767,'1')||lpad('1',32767,'1'); - l_result varchar2(32767); begin - --Act - l_result := ut3.ut_utils.to_String(l_value); - --Assert - ut.EXPECT(length(l_result)).to_equal(ut3.ut_utils.gc_max_output_string_length); - ut.EXPECT(l_result).to_be_like('%'||ut3.ut_utils.gc_more_data_string); + ut.expect(length(ut3.ut_data_value_clob(l_value).to_string())).to_equal(ut3.ut_utils.gc_max_output_string_length); + ut.expect(ut3.ut_data_value_clob(l_value).to_string()).to_be_like('%'||ut3.ut_utils.gc_more_data_string); end; - procedure to_string_big_number is + procedure to_string_verybignumber is l_value number := 1234567890123456789012345678901234567890; l_expected varchar2(100) := '1234567890123456789012345678901234567890'; - l_result varchar2(100); begin - --Act - l_result := ut3.ut_utils.to_String(l_value); - --Assert - ut.expect(l_result).TO_equal(l_expected); + ut.expect(ut3.ut_data_value_number(l_value).to_string()).to_equal(l_expected); end; - procedure to_string_big_varchar2 is + procedure to_string_verybigvarchar2 is l_value varchar2(32767) := lpad('A test char',32767,'1'); l_result varchar2(32767); begin - --Act - l_result := ut3.ut_utils.to_String(l_value); - --Assert - ut.EXPECT(length(l_result)).to_equal(ut3.ut_utils.gc_max_output_string_length); - ut.EXPECT(l_result).to_be_like('%'||ut3.ut_utils.gc_more_data_string); + ut.expect(length(ut3.ut_data_value_varchar2(l_value).to_string())).to_equal(ut3.ut_utils.gc_max_output_string_length); + ut.expect(ut3.ut_data_value_varchar2(l_value).to_string()).to_be_like('%'||ut3.ut_utils.gc_more_data_string); end; - procedure to_string_big_tiny_number is + procedure to_string_verysmallnumber is l_value number := 0.123456789012345678901234567890123456789; - l_expected varchar2(100); - l_result varchar2(100); - l_delimiter varchar2(1); + l_expected varchar2(100) := gc_delimiter||'123456789012345678901234567890123456789'; begin - --Act - select substr(value, 1, 1) into l_delimiter from nls_session_parameters t where t.parameter = 'NLS_NUMERIC_CHARACTERS'; - l_expected := l_delimiter||'123456789012345678901234567890123456789'; - - l_result := ut3.ut_utils.to_String(l_value); - - --Assert - ut.expect(l_result).TO_equal(l_expected); - + ut.expect(ut3.ut_data_value_number(l_value).to_string()).to_equal(l_expected); end; procedure test_table_to_clob is diff --git a/test/core/test_ut_utils.pks b/test/core/test_ut_utils.pks index 4d5ce56af..8452f84c3 100644 --- a/test/core/test_ut_utils.pks +++ b/test/core/test_ut_utils.pks @@ -1,61 +1,106 @@ create or replace package test_ut_utils is - --%suite + --%suite(ut_utils) --%suitepath(utplsql.core) - --%test + function get_numeric_delimiter return varchar2; + + --%test(clob_to_table - Converts a clob into ut_varchar2_list using specified delimiter) procedure test_clob_to_table; - --%test - procedure test_to_char; + --%test(test_result_to_char - Converts numeric test result to character representation) + procedure test_test_result_to_char; + + + --%context(to_string) + + --%test(Returns 'EMPTY' string for NULL BLOB) + procedure to_string_emptyblob; + + --%test(Returns 'EMPTY' string for NULL CLOB) + procedure to_string_emptyclob; + + --%test(Returns 'NULL' string for NULL BLOB) + procedure to_string_nullblob; + + --%test(Returns 'NULL' string for NULL CLOB) + procedure to_string_nullclob; + + --%test(Returns 'NULL' string for NULL date) + procedure to_string_nulldate; + + --%test(Returns 'NULL' string for NULL number) + procedure to_string_nullnumber; + + --%test(Returns 'NULL' string for NULL timestamp) + procedure to_string_nulltimestamp; - --%test - procedure test_to_string_blob; + --%test(Returns 'NULL' string for NULL timestamp with local timezone) + procedure to_string_nulltimestamp_ltz; - --%test - procedure test_to_string_clob; + --%test(Returns 'NULL' string for NULL timestamp with timezone) + procedure to_string_nulltimestamp_tz; - --%test - procedure test_to_string_date; + --%test(Returns 'NULL' string for NULL varchar) + procedure to_string_nullvarchar2; - --%test - procedure to_string_null; + --%test(Returns string representation of BLOB) + procedure to_string_blob; - --%test - procedure to_string; + --%test(Returns string representation of CLOB) + procedure to_string_clob; - --%test(Trims long Blob to max lenght and appends '[...]' at the end of string) - procedure to_string_big_blob; + --%test(Returns string representation of date) + procedure to_string_date; - --%test(Trims long Clob to max lenght and appends '[...]' at the end of string) - procedure to_string_big_clob; + --%test(Returns string representation of timestamp) + procedure to_string_timestamp; - --%test(Returns a full string representation of a very big number) - procedure to_string_big_number; + --%test(Returns string representation of timestamp with local timezone) + procedure to_string_timestamp_ltz; - --%test(Trims long varchars to max lenght and appends '[...]' at the end of string) - procedure to_string_big_varchar2; + --%test(Returns string representation of timestamp with timezone) + procedure to_string_timestamp_tz; - --%test(Returns a full string representation of a very small number) - procedure to_string_big_tiny_number; + --%test(Returns varchar value) + procedure to_string_varchar2; - --%test(Table to clob function test) + --%test(Returns BLOB trimmed to 4000 chars with trailing [...]) + procedure to_string_verybigblob; + +--%test(Returns CLOB trimmed to 4000 chars with trailing [...]) + procedure to_string_verybigclob; + + --%test(Returns string representation of large number) + procedure to_string_verybignumber; + + --%test(Returns varchar2 trimmed to 4000 chars with trailing [...]) + procedure to_string_verybigvarchar2; + + --%test(Returns string representation of small number) + procedure to_string_verysmallnumber; + + --%endcontext + + --%test(table_to_clob - converts ut_varchar2_list into a CLOB value) procedure test_table_to_clob; - --%test(append_to_clob works With Multi Byte Chars) + --%test(append_to_clob - adds multibyte varchar to CLOB) --%beforetest(setup_append_with_multibyte) --%aftertest(clean_append_with_multibyte) procedure test_append_with_multibyte; procedure setup_append_with_multibyte; procedure clean_append_with_multibyte; - --%test(clob_to_table multibyte) + --%test(clob_to_table - converts multibyte CLOB to ut_varchar2_list) --%disabled(We cannot run this test successfully on 12.1 until we change NLSCHARACTERSET from US7ASCII to AL32UTF8) procedure test_clob_to_table_multibyte; - --%test(to_version splits version string into individual version components) + --%test(to_version - splits version string into individual version components) procedure test_to_version_split; + --%context(trim_list_elements) + --%test(Trims the elements of a collection) procedure test_trim_list_elements; @@ -65,6 +110,10 @@ create or replace package test_ut_utils is --%test(Trim list elements with empty collection) procedure trim_list_elemts_empty_collect; + --%endcontext + + --%context(filter_list) + --%test(Filters the collection's elements) procedure test_filter_list; @@ -74,7 +123,9 @@ create or replace package test_ut_utils is --%test(Filter list elements with empty collection) procedure filter_list_empty_collection; - --%test(Replace multi-line comments with empty lines) + --%endcontext + + --%test(replace_multiline_comments - replaces multi-line comments with empty lines) procedure replace_multiline_comments; end test_ut_utils; diff --git a/test/install_and_run_tests.sh b/test/install_and_run_tests.sh index 444346bb2..2c6f78ae1 100644 --- a/test/install_and_run_tests.sh +++ b/test/install_and_run_tests.sh @@ -20,7 +20,8 @@ utPLSQL-cli/bin/utplsql run ${UT3_TESTER}/${UT3_TESTER_PASSWORD}@${CONNECTION_ST -f=ut_coverage_html_reporter -o=coverage.html \ -f=ut_coveralls_reporter -o=coverage.json \ -f=ut_sonar_test_reporter -o=test_results.xml \ --f=ut_xunit_reporter -o=xunit_test_results.xml \ +-f=ut_junit_reporter -o=junit_test_results.xml \ +-f=ut_tfs_junit_reporter -o=tfs_test_results.xml \ -scc status_line_regex="^[0-9]+ tests, ([0-9]+) failed, ([0-9]+) errored.*" diff --git a/test/install_tests.sql b/test/install_tests.sql index 282e8b440..e0a5d6d9f 100644 --- a/test/install_tests.sql +++ b/test/install_tests.sql @@ -22,10 +22,13 @@ whenever oserror exit failure rollback @@core/test_ut_test.pks @@core/annotations/test_annotation_parser.pks @@core/annotations/test_annotation_manager.pks +@@core/annotations/test_before_after_test_annotation.pks +@@core/expectations/test_expectation_processor.pks @@core/expectations/test_matchers.pks @@core/test_output_buffer.pks @@core/test_file_mapper.pks @@core/test_suite_manager.pks +@@core/test_ut_executable.pks @@core/test_suite_builder.pks @@core/reporters.pks @@core/reporters/test_coverage.pks @@ -41,20 +44,22 @@ set define on @@install_below_12_2.sql 'core/reporters/test_coverage/test_html_proftab_reporter.pks' set define off @@core/reporters/test_tfs_junit_reporter.pks +@@core/reporters/test_sonar_test_reporter.pks +@@core/reporters/test_teamcity_reporter.pks @@core/expectations.pks -@@core/expectations/scalar_data/binary/test_be_greater_or_equal.pks -@@core/expectations/scalar_data/binary/test_be_greater_than.pks -@@core/expectations/scalar_data/binary/test_be_less_or_equal.pks -@@core/expectations/scalar_data/binary/test_equal.pks -@@core/expectations/scalar_data/binary/test_expect_to_be_less_than.pks -@@core/expectations/compound_data/test_expect_to_be_empty.pks -@@core/expectations/compound_data/test_expect_to_have_count.pks -@@core/expectations/compound_data/test_expectations_cursor.pks -@@core/expectations/compound_data/test_expectation_anydata.pks -@@core/expectations/scalar_data/unary/test_expect_not_to_be_null.pks -@@core/expectations/scalar_data/unary/test_expect_to_be_not_null.pks -@@core/expectations/scalar_data/unary/test_expect_to_be_null.pks -@@core/expectations/scalar_data/unary/test_expect_to_be_true_false.pks +@@core/expectations/binary/test_be_greater_or_equal.pks +@@core/expectations/binary/test_be_greater_than.pks +@@core/expectations/binary/test_be_less_or_equal.pks +@@core/expectations/binary/test_equal.pks +@@core/expectations/binary/test_expect_to_be_less_than.pks +@@core/expectations/unary/test_expect_to_be_empty.pks +@@core/expectations/unary/test_expect_to_have_count.pks +@@core/expectations/unary/test_expect_not_to_be_null.pks +@@core/expectations/unary/test_expect_to_be_not_null.pks +@@core/expectations/unary/test_expect_to_be_null.pks +@@core/expectations/unary/test_expect_to_be_true_false.pks +@@core/expectations/test_expectations_cursor.pks +@@core/expectations/test_expectation_anydata.pks @@core/annotations/test_annot_throws_exception.pks @@core.pkb @@ -65,10 +70,13 @@ set define off @@core/test_ut_test.pkb @@core/annotations/test_annotation_parser.pkb @@core/annotations/test_annotation_manager.pkb +@@core/expectations/test_expectation_processor.pkb @@core/expectations/test_matchers.pkb +@@core/annotations/test_before_after_test_annotation.pkb @@core/test_output_buffer.pkb @@core/test_file_mapper.pkb @@core/test_suite_manager.pkb +@@core/test_ut_executable.pkb @@core/test_suite_builder.pkb @@core/reporters.pkb @@core/reporters/test_coverage.pkb @@ -84,20 +92,22 @@ set define on @@install_below_12_2.sql 'core/reporters/test_coverage/test_html_proftab_reporter.pkb' set define off @@core/reporters/test_tfs_junit_reporter.pkb +@@core/reporters/test_sonar_test_reporter.pkb +@@core/reporters/test_teamcity_reporter.pkb @@core/expectations.pkb -@@core/expectations/scalar_data/binary/test_be_greater_or_equal.pkb -@@core/expectations/scalar_data/binary/test_be_greater_than.pkb -@@core/expectations/scalar_data/binary/test_be_less_or_equal.pkb -@@core/expectations/scalar_data/binary/test_equal.pkb -@@core/expectations/scalar_data/binary/test_expect_to_be_less_than.pkb -@@core/expectations/compound_data/test_expect_to_be_empty.pkb -@@core/expectations/compound_data/test_expect_to_have_count.pkb -@@core/expectations/compound_data/test_expectations_cursor.pkb -@@core/expectations/compound_data/test_expectation_anydata.pkb -@@core/expectations/scalar_data/unary/test_expect_not_to_be_null.pkb -@@core/expectations/scalar_data/unary/test_expect_to_be_not_null.pkb -@@core/expectations/scalar_data/unary/test_expect_to_be_null.pkb -@@core/expectations/scalar_data/unary/test_expect_to_be_true_false.pkb +@@core/expectations/binary/test_be_greater_or_equal.pkb +@@core/expectations/binary/test_be_greater_than.pkb +@@core/expectations/binary/test_be_less_or_equal.pkb +@@core/expectations/binary/test_equal.pkb +@@core/expectations/binary/test_expect_to_be_less_than.pkb +@@core/expectations/unary/test_expect_to_be_empty.pkb +@@core/expectations/unary/test_expect_to_have_count.pkb +@@core/expectations/unary/test_expect_not_to_be_null.pkb +@@core/expectations/unary/test_expect_to_be_not_null.pkb +@@core/expectations/unary/test_expect_to_be_null.pkb +@@core/expectations/unary/test_expect_to_be_true_false.pkb +@@core/expectations/test_expectations_cursor.pkb +@@core/expectations/test_expectation_anydata.pkb @@core/annotations/test_annot_throws_exception.pkb set linesize 200