Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
4857ef39
Z
zentaoatf
项目概览
易企天创
/
zentaoatf
大约 1 年 前同步成功
通知
11
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zentaoatf
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4857ef39
编写于
4月 05, 2013
作者:
W
wwccss
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of git@github.com:easysoft/zentaoatf
上级
1af2cf8b
d15c49f6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
94 addition
and
74 deletion
+94
-74
zt
zt
+94
-74
未找到文件。
zt
浏览文件 @
4857ef39
...
...
@@ -13,38 +13,32 @@
* Todo:
* 1. 帮助支持。
* 2. 指定用例或者目录运行。
* 3. 多语言的支持。
* 4. 和禅道的绑定集成。
* 5. 保存日志文件考虑换个目录。windows下面,或者单独创建一个目录。每次执行删除若干分钟之前的?
* 6. 输出日志的时候根据操作系统判断换行符。
* 7. 每种语言可以设置支持的编码,然后输出的时候根据编码输出。
* 8. 首次运行的时候,提示用户选择语言,编码。
* 9. 不同的操作系统有不同的skipfile。
*/
/* Turn off error reporting. */
error_reporting
(
E_ALL
^
E_NOTICE
);
error_reporting
(
E_ALL
);
/* Short DIRECTORY_SEPARATOR . */
define
(
'DS'
,
DIRECTORY_SEPARATOR
);
/* The time zone. */
define
(
'TIME_ZONE'
,
'Asia/Shanghai'
);
/* Skip files. */
define
(
'SKIP_FILES'
,
'exe,dll,gif,jpg,png,bmp'
);
/* The begin and end mark of testing scripts. */
define
(
'TC_BEGIN'
,
'TC'
);
define
(
'TC_END'
,
'TC'
);
/* Colors. */
define
(
'COLOR_PREFIX'
,
"
\033
["
);
define
(
'COLOR_POSTFIX'
,
"
\033
[0m"
);
define
(
'COLOR_RED'
,
'31m'
);
define
(
'COLOR_GREEN'
,
'32m'
);
define
(
'COLOR_YELLOW'
,
'33m'
);
define
(
'COLOR_PURPLE'
,
'35m'
);
/* Config. */
$config
=
new
stdclass
();
$config
->
timezone
=
'Asia/Shanghai'
;
$config
->
skipfiles
=
'exe,dll,gif,jpg,png,bmp'
;
$config
->
casePrefix
=
'TC'
;
$config
->
casePostfix
=
'TC'
;
/* Ansi control codes. */
$config
->
ansi
=
new
stdclass
();
$config
->
ansi
->
off
=
"
\033
[0m"
;
$config
->
ansi
->
red
=
"
\033
[31m"
;
$config
->
ansi
->
green
=
"
\033
[32m"
;
$config
->
ansi
->
yellow
=
"
\033
[33m"
;
$config
->
ansi
->
purple
=
"
\033
[35m"
;
/* Run testing. */
zentaotest
::
run
(
isset
(
$argv
[
1
])
?
$argv
[
1
]
:
'./'
);
...
...
@@ -52,6 +46,14 @@ zentaotest::run(isset($argv[1]) ? $argv[1] : './');
/* The class defination of zentao auto testing framework. */
class
zentaotest
{
/**
* The config object.
*
* @var object
* @access public
*/
public
$config
;
/**
* The os type.
*
...
...
@@ -77,7 +79,7 @@ class zentaotest
public
$home
;
/**
* The profile.
* The profile
for user personal settings
.
*
* @var string
* @access public
...
...
@@ -85,12 +87,12 @@ class zentaotest
public
$profile
;
/**
* The custom
config param
s.
* The custom
setting
s.
*
* @var object
* @access public
*/
public
$
config
;
public
$
settings
;
/**
* Current working directory.
...
...
@@ -109,12 +111,12 @@ class zentaotest
public
$scripts
=
array
();
/**
* Script
lang
s.
* Script
interpreter
s.
*
* @var array
* @access public
*/
public
$
lang
s
=
array
();
public
$
interpreter
s
=
array
();
/**
* The begin time.
...
...
@@ -188,16 +190,29 @@ class zentaotest
*/
public
function
__construct
()
{
$this
->
setConfig
();
$this
->
setOS
();
$this
->
setTemp
();
$this
->
setHome
();
$this
->
setProfile
();
$this
->
load
Config
();
$this
->
load
Settings
();
$this
->
setCWD
();
$this
->
setTimeZone
();
$this
->
setReportFile
();
}
/**
* Set config.
*
* @access public
* @return void
*/
public
function
setConfig
()
{
global
$config
;
$this
->
config
=
$config
;
}
/**
* Set current os, please see:http://en.wikipedia.org/wiki/Uname#Table_of_standard_uname_output.
*
...
...
@@ -274,30 +289,30 @@ class zentaotest
}
/**
* Load
config
from the profile.
* Load
settings
from the profile.
*
* @access public
* @return void
*/
public
function
load
Config
()
public
function
load
Settings
()
{
$this
->
config
=
json_decode
(
file_get_contents
(
$this
->
profile
));
if
(
!
$this
->
config
)
$this
->
settings
=
json_decode
(
file_get_contents
(
$this
->
profile
));
if
(
!
$this
->
settings
)
{
$this
->
config
=
new
stdclass
();
$this
->
config
->
lang
s
=
new
stdclass
();
$this
->
settings
=
new
stdclass
();
$this
->
settings
->
interpreter
s
=
new
stdclass
();
}
}
/**
* Save
config
to profile.
* Save
settings
to profile.
*
* @access public
* @return void
*/
public
function
save
Config
()
public
function
save
Settings
()
{
file_put_contents
(
$this
->
profile
,
json_encode
(
$this
->
config
));
file_put_contents
(
$this
->
profile
,
json_encode
(
$this
->
settings
));
}
/**
...
...
@@ -319,7 +334,7 @@ class zentaotest
*/
public
function
setTimeZone
()
{
date_default_timezone_set
(
TIME_ZONE
);
date_default_timezone_set
(
$this
->
config
->
timezone
);
}
/**
...
...
@@ -387,22 +402,22 @@ class zentaotest
}
else
{
/* Get the script
language
. */
$
lang
=
strtolower
(
pathinfo
(
$script
,
PATHINFO_EXTENSION
));
if
(
$
lang
and
strpos
(
SKIP_FILES
,
$lang
)
!==
false
)
continue
;
/* Get the script
interpreter
. */
$
interpreter
=
strtolower
(
pathinfo
(
$script
,
PATHINFO_EXTENSION
));
if
(
$
interpreter
and
strpos
(
$this
->
config
->
skipfiles
,
$interpreter
)
!==
false
)
continue
;
/* Has TC_BEGIN in the script, save it. */
if
(
strpos
(
file_get_contents
(
$script
),
TC_BEGIN
)
!==
false
)
if
(
strpos
(
file_get_contents
(
$script
),
$this
->
config
->
casePrefix
)
!==
false
)
{
$this
->
scripts
[]
=
realpath
(
$script
);
if
(
$
lang
)
$this
->
langs
[
$lang
]
=
$lang
;
if
(
$
interpreter
)
$this
->
interpreters
[
$interpreter
]
=
$interpreter
;
}
}
}
}
/**
* Set interpreters for scripts
languages
.
* Set interpreters for scripts.
*
* @access public
* @return void
...
...
@@ -411,14 +426,14 @@ class zentaotest
{
if
(
$this
->
os
!=
'win'
)
return
;
foreach
(
$this
->
langs
as
$lang
)
foreach
(
$this
->
interpreters
as
$interpreter
)
{
if
(
isset
(
$this
->
config
->
langs
->
$lang
))
continue
;
if
(
$
lang
==
'bat'
)
continue
;
if
(
isset
(
$this
->
settings
->
interpreters
->
$interpreter
))
continue
;
if
(
$
interpreter
==
'bat'
)
continue
;
while
(
true
)
{
echo
"Please set
the interpreter for
$lang
scripts, enter to skip:"
;
echo
"Please set
interpreter for
$interpreter
scripts, enter to skip:"
;
$input
=
trim
(
fgets
(
STDIN
));
if
(
!
is_file
(
$input
))
{
...
...
@@ -428,11 +443,11 @@ class zentaotest
continue
;
}
$this
->
config
->
langs
->
$lang
=
$input
;
$this
->
settings
->
interpreters
->
$interpreter
=
$input
;
break
;
}
}
$this
->
save
Config
();
$this
->
save
Settings
();
}
/**
...
...
@@ -483,7 +498,7 @@ class zentaotest
*/
public
function
printTotal
()
{
$totalInfo
=
date
(
'n/j G:i:s'
)
.
" found "
.
$this
->
colorString
(
count
(
$this
->
scripts
),
COLOR_YELLOW
)
.
" scripts.
\n\n
"
;
$totalInfo
=
date
(
'n/j G:i:s'
)
.
" found "
.
$this
->
colorString
(
count
(
$this
->
scripts
),
$this
->
config
->
ansi
->
yellow
)
.
" scripts.
\n\n
"
;
(
print
(
$totalInfo
))
&&
$this
->
reportInfo
.
=
$totalInfo
;
}
...
...
@@ -533,8 +548,8 @@ class zentaotest
{
/* Extract the yaml defination. */
$contents
=
trim
(
file_get_contents
(
$script
));
$begin
=
strpos
(
$contents
,
TC_BEGIN
)
+
strlen
(
TC_BEGIN
);
$end
=
strpos
(
$contents
,
TC_END
,
$begin
);
$begin
=
strpos
(
$contents
,
$this
->
config
->
casePrefix
)
+
strlen
(
$this
->
config
->
casePrefix
);
$end
=
strpos
(
$contents
,
$this
->
config
->
casePostfix
);
$yaml
=
substr
(
$contents
,
$begin
,
$end
-
$begin
);
/* Parse the yaml. */
...
...
@@ -543,9 +558,9 @@ class zentaotest
/* Set the default value of expect. */
if
(
!
isset
(
$this
->
current
->
expect
))
$this
->
current
->
expect
=
''
;
/* Append the script file name and
lang
. */
/* Append the script file name and
interpreter
. */
$this
->
current
->
script
=
$script
;
$this
->
current
->
lang
=
pathinfo
(
$script
,
PATHINFO_EXTENSION
);
$this
->
current
->
interpreter
=
pathinfo
(
$script
,
PATHINFO_EXTENSION
);
/* Check whether the expect file exists. */
$path
=
pathinfo
(
$script
);
...
...
@@ -570,15 +585,15 @@ class zentaotest
if
(
$this
->
os
==
'win'
)
{
$
lang
=
$this
->
current
->
lang
;
$
interpreter
=
$this
->
current
->
interpreter
;
if
(
$
lang
==
'bat'
)
if
(
$
interpreter
==
'bat'
)
{
$this
->
current
->
output
=
trim
(
`{$this->current->script}`
);
}
elseif
(
isset
(
$this
->
config
->
langs
->
$lang
))
elseif
(
isset
(
$this
->
settings
->
interpreters
->
$interpreter
))
{
$this
->
current
->
output
=
trim
(
`{$this->
config->langs->$lang
} {$this->current->script}`
);
$this
->
current
->
output
=
trim
(
`{$this->
settings->interpreters->$interpreter
} {$this->current->script}`
);
}
else
{
...
...
@@ -651,7 +666,7 @@ class zentaotest
if
(
$regulars
==
$output
)
{
$this
->
current
->
result
=
'pass'
;
$this
->
result
[
'pass'
]
++
;
$this
->
result
s
[
'pass'
]
++
;
return
true
;
}
else
...
...
@@ -730,9 +745,9 @@ class zentaotest
*/
public
function
printResult
()
{
if
(
$this
->
current
->
result
==
'pass'
)
$resultInfo
=
$this
->
colorString
(
'PASS '
,
COLOR_GREEN
);
if
(
$this
->
current
->
result
==
'fail'
)
$resultInfo
=
$this
->
colorString
(
'FAIL '
,
COLOR_RED
);
if
(
$this
->
current
->
result
==
'skip'
)
$resultInfo
=
$this
->
colorString
(
'SKIP '
,
COLOR_PURPLE
);
if
(
$this
->
current
->
result
==
'pass'
)
$resultInfo
=
$this
->
colorString
(
'PASS '
,
$this
->
config
->
ansi
->
green
);
if
(
$this
->
current
->
result
==
'fail'
)
$resultInfo
=
$this
->
colorString
(
'FAIL '
,
$this
->
config
->
ansi
->
red
);
if
(
$this
->
current
->
result
==
'skip'
)
$resultInfo
=
$this
->
colorString
(
'SKIP '
,
$this
->
config
->
ansi
->
purple
);
(
print
(
$resultInfo
))
&&
$this
->
reportInfo
.
=
$resultInfo
;
}
...
...
@@ -819,16 +834,16 @@ class zentaotest
*/
public
function
printSummary
()
{
$summary
=
"
\n
"
.
date
(
"n/j G:i:s"
)
.
' run '
.
$this
->
colorString
(
count
(
$this
->
scripts
),
COLOR_YELLOW
)
.
' scripts '
;
$summary
=
"
\n
"
.
date
(
"n/j G:i:s"
)
.
' run '
.
$this
->
colorString
(
count
(
$this
->
scripts
),
$this
->
config
->
ansi
->
yellow
)
.
' scripts '
;
$summary
.
=
"in "
.
round
(
$this
->
end
-
$this
->
begin
,
2
)
.
's. '
;
$passRate
=
'('
.
round
(
$this
->
results
[
'pass'
]
/
count
(
$this
->
scripts
),
3
)
*
100
.
'%'
.
')'
;
$failRate
=
'('
.
round
(
$this
->
results
[
'fail'
]
/
count
(
$this
->
scripts
),
3
)
*
100
.
'%'
.
')'
;
$skipRate
=
'('
.
round
(
$this
->
results
[
'skip'
]
/
count
(
$this
->
scripts
),
3
)
*
100
.
'%'
.
')'
;
$summary
.
=
$this
->
colorString
(
$this
->
results
[
'pass'
]
.
$passRate
.
' pass, '
,
COLOR_GREEN
);
$summary
.
=
$this
->
color
String
(
$this
->
results
[
'fail'
]
.
$failRate
.
' fail, '
,
COLOR_RED
);
$summary
.
=
$this
->
color
String
(
$this
->
results
[
'skip'
]
.
$skipRate
.
' skip. '
,
COLOR_PURPLE
);
$summary
.
=
$this
->
colorString
(
$this
->
results
[
'pass'
]
.
$passRate
.
' pass, '
,
$this
->
config
->
ansi
->
green
);
$summary
.
=
$this
->
color
string
(
$this
->
results
[
'fail'
]
.
$failRate
.
' fail, '
,
$this
->
config
->
ansi
->
red
);
$summary
.
=
$this
->
color
string
(
$this
->
results
[
'skip'
]
.
$skipRate
.
' skip. '
,
$this
->
config
->
ansi
->
purple
);
(
print
(
$summary
))
&&
$this
->
reportInfo
.
=
$summary
;
}
...
...
@@ -857,7 +872,7 @@ class zentaotest
}
file_put_contents
(
$this
->
reportFile
,
$this
->
removeColor
(
$this
->
reportInfo
));
echo
'Report: '
.
$this
->
colorString
(
$this
->
reportFile
,
COLOR_YELLOW
)
.
" .
\n
"
;
echo
'Report: '
.
$this
->
colorString
(
$this
->
reportFile
,
$this
->
config
->
ansi
->
yellow
)
.
" .
\n
"
;
}
/**
...
...
@@ -870,13 +885,13 @@ class zentaotest
*/
public
function
colorString
(
$string
,
$color
)
{
if
(
$this
->
os
==
'win'
)
if
(
$this
->
os
==
'win
2
'
)
{
$console
=
getenv
(
'console'
);
if
(
$console
!==
'ansicon'
)
return
$string
;
}
return
COLOR_PREFIX
.
$color
.
$string
.
COLOR_POSTFIX
;
return
$color
.
$string
.
$this
->
config
->
ansi
->
off
;
}
/**
...
...
@@ -888,11 +903,11 @@ class zentaotest
*/
public
function
removeColor
(
$string
)
{
$string
=
str_replace
(
COLOR_PREFIX
.
COLOR_GREEN
,
''
,
$string
);
$string
=
str_replace
(
COLOR_PREFIX
.
COLOR_RED
,
''
,
$string
);
$string
=
str_replace
(
COLOR_PREFIX
.
COLOR_YELLOW
,
''
,
$string
);
$string
=
str_replace
(
COLOR_PREFIX
.
COLOR_PURPLE
,
''
,
$string
);
$string
=
str_replace
(
COLOR_POSTFIX
,
''
,
$string
);
$string
=
str_replace
(
$this
->
config
->
ansi
->
green
,
''
,
$string
);
$string
=
str_replace
(
$this
->
config
->
ansi
->
red
,
''
,
$string
);
$string
=
str_replace
(
$this
->
config
->
ansi
->
yellow
,
''
,
$string
);
$string
=
str_replace
(
$this
->
config
->
ansi
->
purple
,
''
,
$string
);
$string
=
str_replace
(
$this
->
config
->
ansi
->
off
,
''
,
$string
);
return
$string
;
}
...
...
@@ -909,6 +924,11 @@ class zentaotest
return
str_replace
(
"
\r
"
,
''
,
$string
);
}
public
function
printIconv
(
$string
)
{
echo
iconv
(
'utf-8'
,
'gbk'
,
$string
);
}
/**
* Print error message.
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录