r109773 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109772‎ | r109773 | r109774 >
Date:22:10, 22 January 2012
Author:jpostlethwaite
Status:ok
Tags:
Comment:
Adding unittest.sh. See r109762.
Modified paths:
  • /trunk/extensions/UnitTest/tests/unittest.sh (added) (history)

Diff [purge]

Index: trunk/extensions/UnitTest/tests/unittest.sh
@@ -0,0 +1,386 @@
 2+#!/bin/sh
 3+################################################################################
 4+#
 5+# Wikimedia Foundation
 6+#
 7+# LICENSE
 8+#
 9+# This program is free software; you can redistribute it and/or modify
 10+# it under the terms of the GNU General Public License as published by
 11+# the Free Software Foundation; either version 2 of the License, or
 12+# (at your option) any later version.
 13+#
 14+# This program is distributed in the hope that it will be useful,
 15+# but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 17+# GNU General Public License for more details.
 18+#
 19+#
 20+# @license http://www.gnu.org/copyleft/gpl.html GNU GENERAL PUBLIC LICENSE
 21+# @author Jeremy Postlethwaite <jpostlethwaite@wikimedia.org>
 22+#
 23+################################################################################
 24+#
 25+# The script:
 26+#
 27+# unittest.sh - Launch PHPUnit for specific test group(s).
 28+#
 29+################################################################################
 30+#
 31+# Debugging the script
 32+#
 33+# The set -x option causes sh to print each command to standard error before
 34+# executing it. Since this can generate a lot of output, you may want to turn
 35+# tracing on just before the section that you want to trace, and turn it off
 36+# immediately afterward:
 37+#set -x
 38+#
 39+################################################################################
 40+#
 41+# help()
 42+#
 43+################################################################################
 44+help()
 45+{
 46+ cat <<HELP
 47+
 48+NAME
 49+ unittest.sh -- Run phpunit
 50+
 51+SYNOPSIS
 52+ $0
 53+ [-h | --help] [help]
 54+ [-g | --list-groups] ["relative/path/to/file"]
 55+
 56+ [-d | --debug ]
 57+ [-nc | --no-configuration ]
 58+
 59+ [-cc | --coverage-clover ["/full/path/to/index.xml"] ]
 60+ [-ch | --coverage-html ["/full/path/to/folder"] ]
 61+ [-tdh | --testdox-html ["/full/path/to/testdox.html"] ]
 62+ [-tdt | --testdox-text ["/full/path/to/testdox.txt"] ]
 63+
 64+ [-ljs | --log-json ["/full/path/to/log.json"] ]
 65+ [-lju | --log-junit ["/full/path/to/log.xml"] ]
 66+
 67+ [-a | --all ]
 68+
 69+DESCRIPTION
 70+ The unittest.sh script is designed to facilitate running phpunit.
 71+
 72+EXAMPLES
 73+
 74+ # List all groups available for testing
 75+
 76+ $0 -g
 77+
 78+ # List all groups available for testing in the file PostTestCase
 79+
 80+ $0 -g GlobalCollect/AllTests.php
 81+
 82+ # List all groups available for testing in the file PostTestCase
 83+
 84+ $0 -g GlobalCollect/PostTestCase.php
 85+
 86+ # Run unit testing with html code coverage report to default path
 87+
 88+ $0 -ch
 89+
 90+ # Run unit testing with html code coverage report
 91+
 92+ $0 -ch GlobalCollect/AllTests
 93+
 94+ # Run unit testing with clover code coverage report to default path
 95+
 96+ $0 -cc
 97+
 98+ # Run unit testing with clover code coverage report
 99+
 100+ $0 -cc GlobalCollect/AllTests
 101+
 102+ # Generate testdox report
 103+
 104+ $0 -tdh
 105+ $0 --testdox-html
 106+
 107+ # Turn on PHPUnit debugging
 108+
 109+ $0 -d
 110+ $0 --debug
 111+
 112+ # Ignore the local phpunit.xml file
 113+
 114+ $0 -nc
 115+ $0 --no-configuration
 116+
 117+ # Run all testing options: -cc -ch -tdh -d -ljs -lju
 118+
 119+ $0 -a
 120+ $0 --all
 121+
 122+HELP
 123+ exit 0
 124+}
 125+################################################################################
 126+#
 127+# load_configuration()
 128+#
 129+# Load the configuration file
 130+#
 131+################################################################################
 132+load_configuration()
 133+{
 134+ CONFIGURATION_FILE="unittest.conf"
 135+
 136+ # Load the custom configuration file if it exists
 137+ if [ -f "${CONFIGURATION_FILE}" ]; then
 138+ echo "Loading the configuration file (${CONFIGURATION_FILE}) in: `pwd`"
 139+ . ${CONFIGURATION_FILE};
 140+ else
 141+
 142+ # Load the default configuration file
 143+ CONFIGURATION_FILE="${CONFIGURATION_FILE}.dist"
 144+
 145+ if [ -f "${CONFIGURATION_FILE}" ]; then
 146+ echo "Loading the default configuration file (${CONFIGURATION_FILE}.dist) in: `pwd`"
 147+ . ${CONFIGURATION_FILE};
 148+ else
 149+ echo "The default configuration file (${CONFIGURATION_FILE}) is missing from: `pwd`"
 150+ exit 1;
 151+ fi
 152+ fi
 153+}
 154+################################################################################
 155+#
 156+# Begin execution of script
 157+#
 158+################################################################################
 159+# Run help if needed.
 160+[ -z "${1}" ] && help
 161+[ "${1}" = "-h" ] && help
 162+[ "${1}" = "help" ] && help
 163+
 164+#
 165+# @var string $UNITTEST_DIRECTORY This is the relative path to the
 166+# configuration file.
 167+UNITTEST_DIRECTORY="`dirname $0`/"
 168+
 169+# Change to script directory to keep path variables consistent.
 170+cd ${UNITTEST_DIRECTORY}
 171+
 172+load_configuration
 173+################################################################################
 174+#
 175+# @var string $PHPUNIT_COVERAGE_HTML_LINK The link to html code coverage
 176+#
 177+PHPUNIT_COVERAGE_HTML_LINK=${UNITTEST_URL}
 178+#
 179+# @var string $PHPUNIT_COVERAGE_CLOVER_LINK The link to clover code coverage
 180+#
 181+PHPUNIT_COVERAGE_CLOVER_LINK=${UNITTEST_URL}
 182+#
 183+# @var string $PHPUNIT_COVERAGE_TESTDOX_LINK The link to testdox code coverage
 184+#
 185+PHPUNIT_COVERAGE_TESTDOX_LINK=${UNITTEST_URL}
 186+#
 187+# @var string $PHPUNIT_LOG_JSON_LINK The link to json log results
 188+#
 189+PHPUNIT_LOG_JSON_LINK=${UNITTEST_URL}
 190+#
 191+# @var string $PHPUNIT_LOG_JUNIT_LINK The link to junit log results
 192+#
 193+PHPUNIT_LOG_JUNIT_LINK=${UNITTEST_URL}
 194+#
 195+# @var string $PHPUNIT_LOG_TAP_LINK The link to tap log results
 196+#
 197+PHPUNIT_LOG_TAP_LINK=${UNITTEST_URL}
 198+
 199+# The flags that will be passed to phpunit.
 200+#
 201+# @var string $PHPUNIT_UNITTEST_FLAGS
 202+#
 203+PHPUNIT_UNITTEST_FLAGS=${1};
 204+
 205+# Run unit tests without the configuration
 206+#
 207+# @var integer $PHPUNIT_UNITTEST_WITHOUT_CONFIGURATION This will be equal to one if
 208+# phpunit.xml is not used. See the flag: -nc
 209+#
 210+PHPUNIT_UNITTEST_WITHOUT_CONFIGURATION=0;
 211+
 212+# These are the flags that will be run if -a | --all is specified
 213+#
 214+# @var integer $PHPUNIT_UNITTEST_ALL_FLAGS
 215+#
 216+PHPUNIT_UNITTEST_ALL_FLAGS="-cc -ch -tdh -d -ljs -lju";
 217+################################################################################
 218+
 219+################################################################################
 220+#
 221+# Loop through options to pass to phpunit.php
 222+#
 223+################################################################################
 224+
 225+#echo "Pre: ${PHPUNIT_UNITTEST_FLAGS}"
 226+
 227+# Check to see if all options will be ran.
 228+if [[ "${PHPUNIT_UNITTEST_FLAGS}" == "-a" ]]; then
 229+ echo "Running all options for testing: ${PHPUNIT_UNITTEST_ALL_FLAGS}"
 230+ PHPUNIT_UNITTEST_FLAGS=${PHPUNIT_UNITTEST_ALL_FLAGS};
 231+fi
 232+
 233+#echo "Post: ${PHPUNIT_UNITTEST_FLAGS}"
 234+
 235+PHPUNIT_SKIP_FLAG=0;
 236+
 237+for PHPUNIT_UNITTEST_FLAG in ${PHPUNIT_UNITTEST_FLAGS}
 238+do
 239+ if [[ "${PHPUNIT_SKIP_FLAG}" > 0 ]]; then
 240+ #echo "PHPUNIT_SKIP_FLAG: ${PHPUNIT_SKIP_FLAG}";
 241+ PHPUNIT_SKIP_FLAG=(${PHPUNIT_SKIP_FLAG} - 1);
 242+ continue;
 243+ fi
 244+
 245+ #echo "Loop: ${PHPUNIT_UNITTEST_FLAGS}"
 246+
 247+ case "${PHPUNIT_UNITTEST_FLAG}" in
 248+
 249+ # list-groups
 250+ -g|--list-groups)
 251+ PHPUNIT_LIST_GROUPS="--list-groups"
 252+ break ;;
 253+
 254+ # coverage-html
 255+ -ch)
 256+ PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --coverage-html ${PHPUNIT_COVERAGE_HTML}";
 257+ PHPUNIT_COVERAGE_HTML_LINK="${PHPUNIT_COVERAGE_HTML_LINK}${PHPUNIT_COVERAGE_HTML}";
 258+ PHPUNIT_UNITTEST_WITHOUT_CONFIGURATION=1;
 259+ continue ;;
 260+
 261+ --coverage-html)
 262+ PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --coverage-html $2";
 263+ PHPUNIT_COVERAGE_HTML_LINK="${PHPUNIT_COVERAGE_HTML_LINK}$2";
 264+ PHPUNIT_SKIP_FLAG=1;
 265+ continue ;;
 266+
 267+ # coverage-clover
 268+ -cc)
 269+ PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --coverage-clover ${PHPUNIT_COVERAGE_CLOVER}";
 270+ PHPUNIT_COVERAGE_CLOVER_LINK="${PHPUNIT_COVERAGE_CLOVER_LINK}${PHPUNIT_COVERAGE_CLOVER}";
 271+ continue ;;
 272+
 273+ --coverage-clover)
 274+ PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --coverage-clover $2";
 275+ PHPUNIT_COVERAGE_CLOVER_LINK="${PHPUNIT_COVERAGE_CLOVER_LINK}$2";
 276+ PHPUNIT_SKIP_FLAG=1;
 277+ continue ;;
 278+
 279+ # no-configuration
 280+ -nc|--no-configuration)
 281+ PHPUNIT_OPTS="${PHPUNIT_OPTS} --no-configuration";
 282+ continue ;;
 283+
 284+ # testdox-html
 285+ -tdh)
 286+ PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --testdox-html ${PHPUNIT_TESTDOX_HTML}";
 287+ PHPUNIT_COVERAGE_TESTDOX_LINK="${PHPUNIT_COVERAGE_TESTDOX_LINK}${PHPUNIT_TESTDOX_HTML}";
 288+ continue ;;
 289+
 290+ --testdox-html)
 291+ PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --testdox-html $2";
 292+ PHPUNIT_COVERAGE_TESTDOX_LINK="${PHPUNIT_COVERAGE_TESTDOX_LINK}$2";
 293+ PHPUNIT_SKIP_FLAG=1;
 294+ continue ;;
 295+
 296+ # log-json
 297+ -ljs)
 298+ PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --log-json ${PHPUNIT_LOG_JSON}";
 299+ PHPUNIT_LOG_JSON_LINK="${PHPUNIT_LOG_JSON_LINK}${PHPUNIT_LOG_JSON}";
 300+ PHPUNIT_UNITTEST_WITHOUT_CONFIGURATION=1;
 301+ continue ;;
 302+
 303+ --log-json)
 304+ PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --log-json $2";
 305+ PHPUNIT_LOG_JSON_LINK="${PHPUNIT_LOG_JSON_LINK}$2";
 306+ PHPUNIT_SKIP_FLAG=1;
 307+ continue ;;
 308+
 309+ # log-junit
 310+ -lju)
 311+ PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --log-junit ${PHPUNIT_LOG_JUNIT}";
 312+ PHPUNIT_LOG_JUNIT_LINK="${PHPUNIT_LOG_JUNIT_LINK}${PHPUNIT_LOG_JUNIT}";
 313+ PHPUNIT_UNITTEST_WITHOUT_CONFIGURATION=1;
 314+ continue ;;
 315+
 316+ --log-junit)
 317+ PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --log-junit $2";
 318+ PHPUNIT_LOG_JUNIT_LINK="${PHPUNIT_LOG_JUNIT_LINK}$2";
 319+ PHPUNIT_SKIP_FLAG=1;
 320+ continue ;;
 321+
 322+ # debug
 323+ -d|--debug)
 324+ PHPUNIT_OPTS="${PHPUNIT_OPTS} --debug";
 325+ continue ;;
 326+
 327+ # file
 328+ -f|--file)
 329+ PHPUNIT_FILE="$2"
 330+ PHPUNIT_SKIP_FLAG=1;
 331+ continue ;;
 332+
 333+ *)
 334+ PHPUNIT_GROUPS="${PHPUNIT_GROUPS:+"$PHPUNIT_GROUPS,"}${PHPUNIT_UNITTEST_FLAGS}";
 335+ echo "-----------"
 336+ continue ;;
 337+ esac
 338+done
 339+################################################################################
 340+#
 341+# Information statements
 342+#
 343+################################################################################
 344+echo ""
 345+
 346+echo "SCRIPT PATH: ${PATH}"
 347+
 348+echo ""
 349+
 350+echo "PWD: `pwd`"
 351+
 352+echo ""
 353+
 354+COMMAND_OPTIONS="${PHPUNIT_OPTS} ${PHPUNIT_LIST_GROUPS} ${PHPUNIT_COVERAGE} ${PHPUNIT_GROUPS:+--group $PHPUNIT_GROUPS} ${PHPUNIT_FILE}"
 355+echo "COMMAND: ${PHPUNIT} ${COMMAND_OPTIONS}"
 356+
 357+echo ""
 358+
 359+echo "HTML code coverage link: ${PHPUNIT_COVERAGE_HTML_LINK}"
 360+
 361+echo ""
 362+
 363+echo "Clover code coverage link: ${PHPUNIT_COVERAGE_CLOVER_LINK}"
 364+
 365+echo ""
 366+
 367+echo "Testdox code coverage link: ${PHPUNIT_COVERAGE_TESTDOX_LINK}"
 368+
 369+echo ""
 370+
 371+echo "Log results json: ${PHPUNIT_LOG_JSON_LINK}"
 372+
 373+echo ""
 374+
 375+echo "Log results junit: ${PHPUNIT_LOG_JUNIT_LINK}"
 376+
 377+echo ""
 378+
 379+################################################################################
 380+# Debugging
 381+#
 382+# The set -n option causes sh to read the script but not execute any commands.
 383+# This is useful for checking syntax.
 384+#set -n
 385+################################################################################
 386+
 387+${PHPUNIT} ${PHPUNIT_OPTS} ${COMMAND_OPTIONS}
Property changes on: trunk/extensions/UnitTest/tests/unittest.sh
___________________________________________________________________
Added: svn:eol-style
1388 + native
Added: svn:executable
2389 + *
Added: svn:keywords
3390 + Author Date HeadURL Header Id Revision

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109762Adding UnitTest Extensionjpostlethwaite21:45, 22 January 2012

Status & tagging log