Author: Derick Rethans
Date: 2006-10-04 14:42:42 +0200 (Wed, 04 Oct 2006)
New Revision: 3634
Log:
- Infrastructure for running tests in the "stable" tree.
- Infrastructure for testing releases in the "stable" tree.
- This patch also updates the test runner to support single named options
for logging and xml files, and removes the superfluous options for specifying
database settings.
Modified:
scripts/check-differences.sh
scripts/release1.sh
scripts/setup-env.sh
trunk/Base/src/base.php
trunk/UnitTest/src/runtests.php
trunk/UnitTest/src/test/printer.php
trunk/UnitTest/src/test/runner.php
Modified: scripts/check-differences.sh
===================================================================
--- scripts/check-differences.sh 2006-10-04 12:37:28 UTC (rev 3633)
+++ scripts/check-differences.sh 2006-10-04 12:42:42 UTC (rev 3634)
@@ -8,4 +8,4 @@
comp=`echo $1 | cut -d / -f 2`
version=`echo $1 | cut -d / -f 3`
-diff -N -I @version -x .svn -ru8p releases/$comp/$version trunk/$comp | less
+diff -N -I @version -x .svn -ru6p releases/$comp/$version trunk/$comp | less
Modified: scripts/release1.sh
===================================================================
--- scripts/release1.sh 2006-10-04 12:37:28 UTC (rev 3633)
+++ scripts/release1.sh 2006-10-04 12:42:42 UTC (rev 3634)
@@ -7,18 +7,33 @@
component=$1
echo
-cd trunk
+# figure out if we need to release from a branch or not
+parts=`echo $component | cut -d / -s -f 2`;
+if test "$parts" == ""; then
+ branch='trunk';
+ prefix='../..';
+ unittestcmd='UnitTest/src/runtests.php';
+ logfilename=$component
+else
+ branch='stable';
+ prefix='../../..';
+ unittestcmd='../trunk/UnitTest/src/runtests.php -r stable';
+ logfilename=`echo $component | tr / -`;
+fi
+
+cd $branch
+
echo "* Checking line endings"
cd $component
-status=`../../scripts/check-end-of-file-marker.sh`
+status=`$prefix/scripts/check-end-of-file-marker.sh`
if test "$status" != ""; then
echo
echo "Aborted: Line ending problems in:"
echo $status
exit
fi
-cd ..
+cd - >/dev/null
echo "* Checking for local modifications"
status=`svn st $component`
@@ -38,8 +53,8 @@
fi
echo "* Running tests"
-php UnitTest/src/runtests.php -D "mysql://root:[EMAIL PROTECTED]/ezc"
$component |tee /tmp/test-$component.log
-testresult=`cat /tmp/test-$component.log | grep FAILURES`;
+php $unittestcmd -D "mysql://root:[EMAIL PROTECTED]/ezc" $component |tee
/tmp/test-$logfilename.log
+testresult=`cat /tmp/test-$logfilename.log | grep FAILURES`;
if test "$testresult" == "FAILURES!"; then
echo
echo "Aborted: TESTS FAILED";
Modified: scripts/setup-env.sh
===================================================================
--- scripts/setup-env.sh 2006-10-04 12:37:28 UTC (rev 3633)
+++ scripts/setup-env.sh 2006-10-04 12:42:42 UTC (rev 3634)
@@ -2,6 +2,7 @@
cd trunk
+echo "Creating autoload environment for 'trunk':";
if test -d autoload; then
echo "Autoload directory exists."
else
@@ -9,13 +10,13 @@
mkdir autoload
fi
-for i in `find . -name \*_autoload.php | grep -v tutorial_autoload.php`; do
- p=`echo $i | cut -d / -f 2`;
- r=`echo $i | cut -d / -f 3`;
+for i in */src/*autoload.php; do
+ p=`echo $i | cut -d / -f 1`;
+ r=`echo $i | cut -d / -f 2`;
+ b=`echo $i | cut -d / -f 3`;
if test ! $p == "autoload"; then
if test ! $r == "releases"; then
- b=`echo $i | cut -d / -f 4`
if test -L autoload/$b; then
echo "Symlink for $b to $i exists."
else
@@ -25,3 +26,33 @@
fi
fi
done
+
+cd -
+
+echo "Setting up environment for 'stable'"
+
+if ! test -L stable/autoload/base_autoload.php; then
+ ln -s ../../trunk/Base/src/base_autoload.php
stable/autoload/base_autoload.php
+fi
+
+if ! test -L stable/autoload/test_autoload.php; then
+ ln -s ../../trunk/UnitTest/src/test_autoload.php
stable/autoload/test_autoload.php
+fi
+
+for i in Base UnitTest; do
+ if ! test -L stable/$i; then
+ ln -s ../trunk/$i stable/$i
+ fi
+done
+
+echo "- Creating autoload files:"
+
+for i in `cat stable/branch-info`; do
+ componentName=`echo $i | cut -d / -f 1`;
+ componentVersion=`echo $i | cut -d / -f 2`;
+ echo ' - ' $componentName
+ for j in stable/$i/src/*_autoload.php; do
+ targetFile='stable/autoload/'`echo $j | cut -d / -f 5`;
+ cat $j | sed
"s/$componentName\//$componentName\/$componentVersion\//g" > $targetFile
+ done
+done
Modified: trunk/Base/src/base.php
===================================================================
--- trunk/Base/src/base.php 2006-10-04 12:37:28 UTC (rev 3633)
+++ trunk/Base/src/base.php 2006-10-04 12:42:42 UTC (rev 3634)
@@ -28,9 +28,15 @@
/**
* Indirectly it determines the path where the autoloads are stored.
*/
- const libraryMode = "devel";
+ private static $libraryMode = "devel";
/**
+ * Contains the current working directory, which is used when the
+ * $libraryMode is set to "custom".
+ */
+ private static $currentWorkingDirectory = null;
+
+ /**
* @var string The full path to the autoload directory.
*/
protected static $packageDir;
@@ -140,7 +146,7 @@
trigger_error( "Couldn't find autoload directory '$path'",
E_USER_ERROR );
}
/* FIXME: this should go away - only for development */
- if ( self::libraryMode == 'devel' )
+ if ( self::$libraryMode == 'devel' || self::$libraryMode == 'custom' )
{
$dirs = self::getRepositoryDirectories();
$message = "Could not find a '{$className}' class to file mapping.
Searched for " . implode( ' and ', $fileNames ) . " in: ";
@@ -155,6 +161,12 @@
return false;
}
+ public static function setWorkingDirectory( $directory )
+ {
+ self::$libraryMode = 'custom';
+ self::$currentWorkingDirectory = $directory;
+ }
+
/**
* Returns the path to the autoload directory. The path depends on
* the installation of the ezComponents. The SVN version has different
@@ -167,8 +179,11 @@
// Get the path to the components.
$baseDir = dirname( __FILE__ );
- switch ( ezcBase::libraryMode )
+ switch ( ezcBase::$libraryMode )
{
+ case "custom":
+ ezcBase::$packageDir = self::$currentWorkingDirectory . '/';
+ break;
case "devel":
case "tarball":
ezcBase::$packageDir = $baseDir. "/../../";
@@ -249,17 +264,31 @@
protected static function loadFile( $file )
{
$originalFile = $file;
- list( $first, $second ) = explode( '/', $file, 2 );
- switch ( ezcBase::libraryMode )
+ switch ( ezcBase::$libraryMode )
{
case "devel":
case "tarball":
- // Add the "src/" after the package name.
+ list( $first, $second ) = explode( '/', $file, 2 );
$file = $first . "/src/" . $second;
break;
+ case "custom":
+ list( $first, $second ) = explode( '/', $file, 2 );
+ // Add the "src/" after the package name.
+ if ( $first == 'Base' || $first == 'UnitTest' )
+ {
+ list( $first, $second ) = explode( '/', $file, 2 );
+ $file = $first . "/src/" . $second;
+ }
+ else
+ {
+ list( $first, $second, $third ) = explode( '/', $file, 3 );
+ $file = $first . '/' . $second . "/src/" . $third;
+ }
+ break;
+
case "pear":
- $file = $first . '/'. $second;
+ /* do nothing, it's already correct */
break;
}
@@ -346,7 +375,7 @@
{
$autoloadDirs = array();
ezcBase::setPackageDir();
- $repositoryDir = realpath( dirname( __FILE__ ) . '/../../' );
+ $repositoryDir = self::$currentWorkingDirectory ?
self::$currentWorkingDirectory : ( realpath( dirname( __FILE__ ) . '/../../' )
);
$autoloadDirs[$repositoryDir] = array( 'ezc', $repositoryDir .
"/autoload" );
foreach ( ezcBase::$repositoryDirs as $extraDirKey => $extraDirArray )
Modified: trunk/UnitTest/src/runtests.php
===================================================================
--- trunk/UnitTest/src/runtests.php 2006-10-04 12:37:28 UTC (rev 3633)
+++ trunk/UnitTest/src/runtests.php 2006-10-04 12:42:42 UTC (rev 3634)
@@ -1,6 +1,7 @@
<?php
// All errors must be reported
error_reporting( E_ALL | E_STRICT );
+ini_set( 'include_path', getcwd(). ':' . dirname( __FILE__ ) . '/../..:' .
ini_get( 'include_path' ) );
require_once("Base/src/base.php");
function __autoload( $className )
Modified: trunk/UnitTest/src/test/printer.php
===================================================================
--- trunk/UnitTest/src/test/printer.php 2006-10-04 12:37:28 UTC (rev 3633)
+++ trunk/UnitTest/src/test/printer.php 2006-10-04 12:42:42 UTC (rev 3634)
@@ -5,6 +5,11 @@
class ezcTestPrinter extends PHPUnit_TextUI_ResultPrinter
{
+ public function __construct( $verbose = false )
+ {
+ parent::__construct( null, $verbose );
+ }
+
/**
* Overrides ResultPrinter::nextColumn method to get rid of to automatic
* newline inserts.
Modified: trunk/UnitTest/src/test/runner.php
===================================================================
--- trunk/UnitTest/src/test/runner.php 2006-10-04 12:37:28 UTC (rev 3633)
+++ trunk/UnitTest/src/test/runner.php 2006-10-04 12:42:42 UTC (rev 3634)
@@ -6,13 +6,6 @@
{
const SUITE_FILENAME = "tests/suite.php";
- public function __construct()
- {
- // Call this method only once?
- $printer = new ezcTestPrinter();
- $this->setPrinter( $printer );
- }
-
/**
* For now, until the Console Tools is finished, we use the following
* parameters:
@@ -46,7 +39,8 @@
$consoleInput->registerOption( $help );
$help = new ezcConsoleOption( 'r', 'release',
ezcConsoleInput::TYPE_STRING );
- $help->shorthelp = "The release from the svn. e.g: trunk, 1.0, 1.0rc1,
etc. Default release is trunk.";
+ $help->shorthelp = "The release from the svn. Use either 'trunk' or
'stable'.";
+ $help->default = 'trunk';
$consoleInput->registerOption( $help );
// DSN option
@@ -56,61 +50,18 @@
$dsn->longhelp .= "mysql://[EMAIL PROTECTED]@localhost/unittests";
$consoleInput->registerOption( $dsn );
- // host
- $host = new ezcConsoleOption( 'h', 'host',
ezcConsoleInput::TYPE_STRING );
- $host->shorthelp = "Hostname of the database";
- $consoleInput->registerOption( $host );
-
- // type
- $type = new ezcConsoleOption( 't', 'type',
ezcConsoleInput::TYPE_STRING );
- $type->shorthelp = "Type of the database: (mysql, postsql, oracle,
etc).";
- $consoleInput->registerOption( $type );
-
- // user
- $user = new ezcConsoleOption( 'u', 'user',
ezcConsoleInput::TYPE_STRING );
- $user->shorthelp = "User to connect with the database.";
- $consoleInput->registerOption( $user );
-
- // password
- $password = new ezcConsoleOption( 'p', 'password',
ezcConsoleInput::TYPE_STRING );
- $password->shorthelp = "Password that belongs to the user that connect
with the database.";
- $consoleInput->registerOption( $password );
-
- // database
- $database = new ezcConsoleOption( 'd', 'database',
ezcConsoleInput::TYPE_STRING );
- $database->shorthelp = "Database name.";
- $consoleInput->registerOption( $database );
-
- // Add relations, one for all.
- $type->addDependency( new ezcConsoleOptionRule( $host ) );
- $user->addDependency( new ezcConsoleOptionRule( $host ) );
- $database->addDependency( new ezcConsoleOptionRule( $host ) );
-
- // Add relations, all for one.
- $host->addDependency( new ezcConsoleOptionRule( $type ) );
- $host->addDependency( new ezcConsoleOptionRule( $user ) );
- $host->addDependency( new ezcConsoleOptionRule( $database ) );
-
- // And the password belongs to the user.
- $password->addDependency( new ezcConsoleOptionRule( $user ) );
-
- // Exclude DSN from the host parameters.
- $host->addExclusion( new ezcConsoleOptionRule( $dsn ) );
-
// coverage report dir
$report = new ezcConsoleOption( 'c', 'report-dir',
ezcConsoleInput::TYPE_STRING );
$report->shorthelp = "Directory to store test reports and code
coverage reports in.";
- $report->default = "";
$consoleInput->registerOption( $report );
// xml logfile
- $xml = new ezcConsoleOption( '', 'log-xml',
ezcConsoleInput::TYPE_STRING );
+ $xml = new ezcConsoleOption( 'x', 'log-xml',
ezcConsoleInput::TYPE_STRING );
$xml->shorthelp = "Log test execution in XML format to file.";
- $xml->default = "";
$consoleInput->registerOption( $xml );
// Verbose option
- $verbose = new ezcConsoleOption( '', 'verbose',
ezcConsoleInput::TYPE_NONE );
+ $verbose = new ezcConsoleOption( 'v', 'verbose',
ezcConsoleInput::TYPE_NONE );
$verbose->shorthelp = "Output more verbose information.";
$consoleInput->registerOption( $verbose );
}
@@ -129,19 +80,17 @@
protected static function displayHelp( $consoleInput )
{
- echo ("runtests [OPTION...] [PACKAGE | FILE] [PACKAGE | FILE] ...
\n\n" );
- $options = $consoleInput->getOptions();
-
- foreach ( $options as $option )
- {
- echo "-{$option->short}, --{$option->long}\t
{$option->shorthelp}\n";
- }
-
- echo "\n";
+ echo $consoleInput->getHelpText( 'eZ components test runner' );
}
public function runFromArguments()
{
+ /* The following hack is needed so that we can also test the console
tools in the stable branch */
+ if ( in_array( 'stable', $_SERVER['argv'] ) )
+ {
+ ezcBase::setWorkingDirectory( getcwd() );
+ }
+
$consoleInput = new ezcConsoleInput();
self::registerConsoleArguments( $consoleInput );
self::processConsoleArguments( $consoleInput );
@@ -152,18 +101,13 @@
exit();
}
- if ( $consoleInput->getOption( 'dsn' )->value ||
$consoleInput->getOption( 'host' )->value )
+ if ( $consoleInput->getOption( 'dsn' )->value )
{
$dsn = $consoleInput->getOption( 'dsn' )->value;
- $type = $consoleInput->getOption( 'type' )->value;
- $user = $consoleInput->getOption( 'user' )->value;
- $password = $consoleInput->getOption( 'password' )->value;
- $host = $consoleInput->getOption( 'host' )->value;
- $database = $consoleInput->getOption( 'database' )->value;
try
{
- $this->initializeDatabase( $dsn, $type, $user, $password,
$host, $database );
+ $this->initializeDatabase( $dsn );
}
catch ( Exception $e )
{
@@ -178,7 +122,6 @@
// Set the release. Default is trunk.
$release = $consoleInput->getOption( 'release' )->value;
- $release = ( $release == false || $release == "trunk" ? "trunk" :
"releases/$release" );
$allSuites = $this->prepareTests( $consoleInput->getArguments(),
$release );
$logfile = $consoleInput->getOption( 'log-xml' )->value;
@@ -194,11 +137,18 @@
$params['reportDirectory'] = $reportDir;
}
- if ( $consoleInput->getOption( "help" )->value )
+ if ( $consoleInput->getOption( "verbose" )->value )
{
$params['verbose'] = true;
}
+ else
+ {
+ $params['verbose'] = false;
+ }
+ $printer = new ezcTestPrinter( $params['verbose'] );
+ $this->setPrinter( $printer );
+
$this->doRun( $allSuites, $params );
}
@@ -209,19 +159,20 @@
protected function prepareTests( $packages, $release )
{
- $directory = dirname( __FILE__ ) . "/../../..";
-
+ $directory = getcwd();
+
$allSuites = new ezcTestSuite();
$allSuites->setName( "eZ components" );
if ( sizeof( $packages ) == 0 )
{
- $packages = $this->getPackages( $directory );
+ $packages = $this->getPackages( $release, $directory );
}
foreach ( $packages as $package )
{
- if ( strpos( $package, "/" ) !== false )
+ $slashCount = substr_count( $package, '/' );
+ if ( ( $release == 'trunk' && $slashCount !== 0 ) || ( $release ==
'stable' && $slashCount > 1 ) )
{
if ( file_exists( $package ) )
{
@@ -277,46 +228,37 @@
}
/**
+ * @param string $release Release branch (stable or trunk)
* @param string $dir Absolute or relative path to directory to look in.
*
* @return array Package names.
*/
- protected function getPackages( $dir )
+ protected function getPackages( $release, $dir )
{
$packages = array();
if ( is_dir( $dir ) )
{
- if ( $dh = opendir( $dir ) )
+ $entries = glob( $release == 'trunk' ? "$dir/*" : "$dir/*/*" );
+ foreach ( $entries as $entry )
{
- while ( ( $entry = readdir( $dh ) ) !== false )
+ if ( $this->isPackageDir( $entry ) )
{
- if ( $this->isPackage( $dir, $entry ) )
- {
- $packages[] = $entry;
- }
+ $packages[] = str_replace( $dir . '/', '', $entry );
}
- closedir( $dh );
}
- }
+ }
return $packages;
}
- protected function isPackage( $dir, $entry )
+ protected function isPackageDir( $dir )
{
- // Prepend directory if needed.
- $fullPath = $dir == "" ? $entry : $dir ."/". $entry;
-
// Check if it is a package.
- if ( !is_dir( $fullPath ) )
+ if ( !is_dir( $dir ) || !file_exists( $dir . '/tests/suite.php' ) )
{
return false;
}
- if ( $entry[0] == "." )
- {
- return false; // .svn, ., ..
- }
return true;
}
@@ -368,6 +310,10 @@
{
require_once( $suitePath );
+ if ( $release == 'stable' )
+ {
+ $package = substr( $package, 0, strpos( $package, '/' ) );
+ }
$className = "ezc". $package . "Suite";
$s = call_user_func( array( $className, 'suite' ) );
@@ -378,25 +324,13 @@
return null;
}
- protected function initializeDatabase( $dsn, $type, $user, $password,
$host, $database )
+ protected function initializeDatabase( $dsn )
{
$ts = ezcTestSettings::getInstance();
+ $settings = ezcDbFactory::parseDSN( $dsn );
- if ( $dsn )
- {
- $settings = ezcDbFactory::parseDSN( $dsn );
-
- // Store the settings
- $ts->db->dsn = $dsn;
- }
- else
- {
- $settings = array( "type" => $type,
- "user" => $user,
- "password" => $password,
- "host" => $host,
- "database" => $database );
- }
+ // Store the settings
+ $ts->db->dsn = $dsn;
try
{
@@ -408,20 +342,8 @@
{
die( $e->getMessage() );
}
-
- // TODO Check if the database exists, and whether it is empty.
-
}
- protected function printError( $errorString )
- {
- print( $errorString . "\n\n" );
-
- print( "The DSN should look like:
<Driver>://<User>[:Password]@<Host>/<Database> \n" );
- print( "For example: mysql://root:[EMAIL PROTECTED]/unittests\n\n" );
- exit();
- }
-
public static function addFileToFilter( $filename, $group = 'DEFAULT' )
{
PHPUnit_Util_Filter::addFileToFilter( $filename, $group );
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components