提交 31bc99a4 编写于 作者: W wwccss

* rewrite the atf.

上级 cdff2b39
#!/usr/bin/env php
<?php
<<<TC
title: php hello world.
expect: hello world.
TC;
echo 'hello world.';
include 'init.php';
title('the hello word case for php scripts');
run(sprintf('helloworld')) && expect('helloworld');
#!/usr/bin/env php
<?php
<<<TC
title: with format chars.
expect: hello world %i.
TC;
echo 'hello world ' . time() . '.' ;
include 'init.php';
title('with format chars(http://qa.php.net/phpt_details.php#expectf_section)');
run('hello world ' . time()) && expect('hello world %i');
run('hello world zentao') && expect('hello world %s');
#!/usr/bin/env php
<?php
<<<TC
title: with regular rules.
expectx: hello world [0-9]*.
TC;
echo 'hello world ' . time() . '.' ;
include 'init.php';
title('with regular rules');
run(sprintf('hello world ' . time())) && expectx('hello world [0-9]*');
#!/usr/bin/env php
<?php
<<<TC
title: with multi lines.
expect:|
2
3
TC;
include 'init.php';
title('with multi lines.');
run(multiline()) && expect("2\n3\n");
echo 1 + 1 . "\n";
echo 1 + 2 . "\n";
function multiline()
{
$lines = (1 + 1 . "\n");
$lines .= (1 + 2 . "\n");
return $lines;
}
#!/usr/bin/env php
<?php
<<<TC
title: expect saved in .05_expect_file.et
TC;
echo 'hello world.' . "\n";
echo 'I am zentao testing framework';
#!/usr/bin/env php
<?php
include 'init.php';
title('a failed case example.');
run(printHello(chr(rand(ord('a'), ord('z'))))) && expect('hello world %i');
run(printHello(chr(rand(ord('a'), ord('z'))))) && expect('hello world [a-z]{2}');
run(printHello(time())) && expect('hello world [0-9]{11}');
function printHello($dynamic)
{
return 'hello world ' . $dynamic;
}
#!/usr/bin/env php
<?php
<<<TC
title: expect with regular saved in .06_expect_file.ex
TC;
echo 'hello world ' . time() . "\n";
echo 'hello world ' . chr(rand(ord('a'), ord('z'))) . "\n";
#!/usr/bin/env php
<?php
<<<TC
title: a failed case with expect tag.
expect:|
2
3
3
TC;
echo 1 + 1 . "\n";
echo 1 + 2 . "\n";
echo 1 + 3 . "\n";
......@@ -37,6 +37,8 @@ function run($output)
echo space(4) . "output: |\n";
foreach($lines as $line) echo space(6) . trim($line) . "\n";
return true;
}
/**
......
#!/usr/bin/env python
'''
<<TC
title: python hello world.
expect: hello world.
TC
'''
print 'hello world.';
def s(step):
return step
execfile("init.py");
title('hello world.');
run(s('hello world.')) and expect('test');
......@@ -679,8 +679,8 @@ class zentaotest
public function parseOutput()
{
$output = (object)spyc::yamlLoadString($this->current->output);
$this->current->title = $output->title;
$this->current->steps = $output->steps;
$this->current->title = isset($output->title) ? $output->title : '';
$this->current->steps = isset($output->steps) ? $output->steps : '';
}
/**
......@@ -692,7 +692,7 @@ class zentaotest
public function computeCaseResult()
{
/* First to check the case skip or not. */
if(strpos($this->current->output, 'skip') !== false)
if(strpos($this->current->output, 'skip') !== false or empty($this->current->steps))
{
$this->current->result = 'skip';
$this->results['skip'] ++;
......@@ -703,15 +703,14 @@ class zentaotest
$result = 'pass';
/* Compute result of every step. */
foreach($this->current->steps as $step)
foreach($this->current->steps as $key => $step)
{
$step = (object)$step;
$this->computeStepResult($step);
if($step->result == 'fail')
{
$result = 'fail';
break;
}
if($step->result == 'fail') $result = 'fail';
/* Save the compute result step to $this->current->steps. */
$this->current->steps[$key] = $step;
}
if($result == 'fail')
......@@ -978,21 +977,23 @@ class zentaotest
$this->reportInfo .= "\n";
foreach($this->failedScripts as $script)
{
$script->expect = '';
$script->output = '';
foreach($script->steps as $step)
$this->reportInfo .= str_repeat('-', 80) . "\n";
$this->reportInfo .= "FAIL [$script->script] $script->title\n";
foreach($script->steps as $key => $step)
{
$step = (object)$step;
$script->expect .= (isset($step->expectx) ? $step->expectx : $step->expect) . "\n";
$script->output .= $step->output . "\n";
}
$script->diff = $this->diff($script->expect, $script->output);
if($step->result != 'fail') continue;
$stepNO = $key + 1;
$step->expect = trim($step->expect);
$step->output = trim($step->output);
$step->diff = trim($step->diff);
$this->reportInfo .= "\n{{===\nfailed $script->script <$script->title>}}\n";
$this->reportInfo .= "[expect]\n$script->expect\n";
$this->reportInfo .= "[output]\n$script->output\n";
$this->reportInfo .= "[diff]\n$script->diff";
$this->reportInfo .= "\n===}}\n";
$this->reportInfo .= "===STEP $stepNO ===\n";
$this->reportInfo .= "[expect]\n$step->expect\n\n";
$this->reportInfo .= "[output]\n$step->output\n\n";
$this->reportInfo .= "[diff]\n$step->diff\n\n";
}
$this->reportInfo .= str_repeat('-', 80) . "\n";
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册