Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions bamboo/bamboo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

CUR_DIR=$(cd $(dirname $0) && pwd);
#PROJECT_PATH=`readlink -f "$CUR_DIR/../.."`

LIMB_DIR=$1

if [ ! -d $LIMB_DIR ]; then
echo 'Please pass a full path to limb repo as argument to this script'
exit 1;
fi

PROJECT_PATH=`readlink -f "$LIMB_DIR"/../`

#LIMB_DIR=`readlink -f "$CUR_DIR/.."`
#LIMB_DIR=$PROJECT_PATH

LIMB_DIR_NAME=`basename "$LIMB_DIR"`

echo $LIMB_DIR_NAME

rm -rf $CUR_DIR/var/*

if [ "$LIMB_DIR_NAME" != "limb" ]; then
mv $PROJECT_PATH/$LIMB_DIR_NAME $PROJECT_PATH/limb
fi

rm -rf $PROJECT_PATH/limb/bamboo

mkdir -p $PROJECT_PATH/limb/bamboo
cp -r $CUR_DIR/* $PROJECT_PATH/limb/bamboo

php $PROJECT_PATH/limb/bamboo/runner.php

if [ "$LIMB_DIR_NAME" != "limb" ]; then
mv $PROJECT_PATH/limb $PROJECT_PATH/$LIMB_DIR_NAME
fi
9 changes: 9 additions & 0 deletions bamboo/common.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

require_once('limb/bootstrap.php');

lmb_require('limb/bamboo/tests_runner/BambooTestReporter.class.php');
lmb_require('limb/bamboo/tests_runner/BambooTestRunner.class.php');
lmb_require('limb/bamboo/tests_runner/BambooTestXmlGenerator.class.php');

lmb_require('limb/fs/src/lmbFs.class.php');
181 changes: 181 additions & 0 deletions bamboo/runner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#!/usr/bin/env php
<?php
set_include_path(dirname(__FILE__) . '/../../' . PATH_SEPARATOR . get_include_path());
ini_set('memory_limit', '256M');

define('LIMB_PATH', dirname(__FILE__) . '/../');

require_once(LIMB_PATH . '/tests_runner/common.inc.php');
/* require_once(LIMB_PATH . '/tests_runner/src/lmbTestRunner.class.php'); */
/* require_once(LIMB_PATH . '/tests_runner/src/lmbTestTreeFilePathNode.class.php'); */
/* require_once(LIMB_PATH . '/tests_runner/src/lmbTestTreeGlobNode.class.php'); */
require_once(LIMB_PATH . '/bamboo/common.inc.php');

chdir(LIMB_PATH);

$fork = true;
$quiet = false;
$tests = array();
$skipped = array();

function out($msg)
{
global $quiet;

if(!$quiet)
echo $msg;
}

function process_argv(&$argv, &$defines = array())
{
global $quiet;
global $fork;
global $skipped;

$new_argv = array();
$selected_option = '';
$next_is_def = false;
foreach($argv as $arg)
{
// control arguments
switch($arg)
{
case '-D':
$next_is_def = true;
break;
case '-q':
$quiet = true;
break;
case '--no-fork':
$fork = false;
break;
case '--include-path':
case '--skip':
$selected_option = $arg;
break;
case '--':
$selected_option = '';
break;
default:
if($next_is_def)
{
list($dn,$dv) = explode('=', $arg);
$defines[] = "-D \"$dn=$dv\"";
echo "Defining $dn=$dv\n";
define("$dn", $dv);
$next_is_def = false;
break;
}
// value arguments
switch($selected_option)
{
case '--skip':
$skipped[] = $arg;
break;
case '--include-path':
set_include_path(dirname(__FILE__) . '/' . $arg . PATH_SEPARATOR . get_include_path());
$selected_option = '';
break;
default:
$new_argv[] = $arg;
break;
}
}
}
$argv = $new_argv;
}

function get_php_bin()
{
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_contents();
ob_end_clean();

if(isset($_ENV["_"]) && basename($_ENV["_"]) != basename(__FILE__))
$php_bin = $_ENV["_"];
else
$php_bin = "php";//any better way to guess it otherwise?

$php_ini = "";

$lines = explode("\n", $info);
foreach($lines as $line)
{
if(preg_match('~^Loaded Configuration File\s*=>\s*(.*)$~', $line, $m))
{
if(file_exists($m[1]))
$php_ini = "-c " . $m[1];
}
}
return $php_bin . " " . $php_ini;
}

$defines = array();

process_argv($argv, $defines);

if(sizeof($argv) > 1)
$tests = array_splice($argv, 1);

if(!$tests)
$tests = glob("*", GLOB_ONLYDIR);


$tests = array_diff($tests, $skipped);

if($fork)
{
$php_bin = get_php_bin();
out("=========== Forking processes for each test path(PHP cmdline '$php_bin') ===========\n");
}

$res = true;
foreach($tests as $test)
{
if(file_exists($test) || is_dir($test))
{
$result_xml_path = LIMB_PATH . '/bamboo/var/' . $test . '_result.xml';
if($fork)
{
$response = system($php_bin . " " . __FILE__ . " -q --no-fork " . implode(" ", $defines) . " $test", $ret);
if($ret != 0)
$res = false;

if(!file_exists($result_xml_path))
{
$error_result_string = "<?xml version='1.0' encoding='UTF-8' ?>
<testsuite errors='0' tests='1' failures='1' name='" . $test . "'>
<testcase name='" . $test . "'>
<failure message='Fatal error'><![CDATA[" . $response . "]]></failure>
</testcase>
</testsuite>
";

lmbFs :: safeWrite($result_xml_path, $error_result_string);
}
}
else
{
$runner = new BambooTestRunner();
$runner->setReporter($reporter = new BambooTestReporter());

if($runner->run(new lmbTestTreeFilePathNode($test)))
{
$generator = new BambooTestXmlGenerator($reporter);
lmbFs :: safeWrite($result_xml_path, $generator->generate());
}
else
$res = false;
}
}
else
out("=========== Test path '$test' is not valid, skipping ==========\n");
}

if(!$res)
out("=========== TESTS HAD ERRORS(see above) ===========\n");
else
out("=========== ALL TESTS PASSED ===========\n");

exit($res ? 0 : 1);
65 changes: 65 additions & 0 deletions bamboo/tests_runner/BambooTestReporter.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
lmb_require('limb/tests_runner/src/lmbTestShellReporter.class.php');

class BambooTestReporter extends lmbTestShellReporter
{
protected $_results;
protected $_skipped = 0;

function paintSkip($message)
{
$this->_skipped++;
parent :: paintSkip($message);
$this->_generateElement($message, 'Skipped');
}

function getSkippedCount()
{
return $this->_skipped;
}

function _generateElement($message, $status)
{
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);

$result = array(
'test_class' => $breadcrumb[count($breadcrumb) - 2],
'test_method' => $breadcrumb[count($breadcrumb) - 1],
'time' => time(),
'message' => $message,
'status' => $status,
);

$this->_results[] = $result;
}

function paintPass($message)
{
parent::paintPass($message);
$this->_generateElement($message, 'Passed');
}

function paintFail($message)
{
parent::paintFail($message);
$this->_generateElement($message, 'Failed');
}

function paintError($message)
{
parent::paintError($message);
$this->_generateElement($message, 'Error');
}

function paintException($message)
{
parent::paintException($message);
$this->_generateElement($message, 'Exception');
}

function getResults()
{
return $this->_results;
}
}
24 changes: 24 additions & 0 deletions bamboo/tests_runner/BambooTestRunner.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
lmb_require('limb/tests_runner/src/lmbTestRunner.class.php');
lmb_require('limb/tests_runner/src/lmbTestTreeFilePathNode.class.php');

class BambooTestRunner extends lmbTestRunner
{
/* function run($cases) */
/* { */
/* return parent :: run(new lmbTestTreeFilePathNode($cases)); */
/* } */

protected function _getReporter()
{
if(!$this->reporter)
{
require_once('limb/test_runner/src/lmbTestShellReporter.class.php');
SimpleTest :: prefer(new lmbTestShellReporter());

$this->reporter = clone(SimpleTest :: preferred(array('SimpleReporter', 'SimpleReporterDecorator')));
}

return $this->reporter;
}
}
Loading