Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
b1e3b0de
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,发现更多精彩内容 >>
提交
b1e3b0de
编写于
4月 02, 2013
作者:
W
wwccss
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
+ add the support for windows.
+ add the support for bat file. + add the suuport for skip.
上级
f5db2938
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
180 addition
and
20 deletion
+180
-20
langs/test08.bat
langs/test08.bat
+7
-0
zt
zt
+173
-20
未找到文件。
langs/test08.bat
0 → 100644
浏览文件 @
b1e3b0de
@echo
off
goto
TC
title
:
bat
hello
world
.
expect
:
hello
world
.
:TC
echo
hello
world
.
zt
浏览文件 @
b1e3b0de
...
...
@@ -11,20 +11,23 @@
* @link http://www.zentao.net
*
* Todo:
* 1. 操作系统的支持。
* 2. 帮助支持。
* 3. 指定用例或者目录运行。
* 4. windows下面的各个脚本解释程序的支持。
* 5. 多语言的支持。
* 6. 和禅道的绑定集成。
* 1. 帮助支持。
* 2. 指定用例或者目录运行。
* 3. 多语言的支持。
* 4. 和禅道的绑定集成。
*/
/* Turn off error reporting. */
error_reporting
(
E_ALL
^
E_NOTICE
);
/* Define constants. */
define
(
'TC_BEGIN'
,
'<<TC'
);
define
(
'TC_END'
,
'TC'
);
/* Short DIRECTORY_SEPARATOR . */
define
(
'DS'
,
DIRECTORY_SEPARATOR
);
/* 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'
);
...
...
@@ -62,6 +65,22 @@ class zentaotest
*/
public
$home
;
/**
* The profile.
*
* @var string
* @access public
*/
public
$profile
;
/**
* The custom config params.
*
* @var object
* @access public
*/
public
$config
;
/**
* Current working directory.
*
...
...
@@ -78,6 +97,14 @@ class zentaotest
*/
public
$scripts
=
array
();
/**
* Script langs.
*
* @var array
* @access public
*/
public
$langs
=
array
();
/**
* The begin time.
*
...
...
@@ -153,6 +180,8 @@ class zentaotest
$this
->
setOS
();
$this
->
setTemp
();
$this
->
setHome
();
$this
->
setProfile
();
$this
->
loadConfig
();
$this
->
setCWD
();
$this
->
setReportFile
();
}
...
...
@@ -184,7 +213,7 @@ class zentaotest
{
if
(
!
empty
(
$_SERVER
[
'TMP'
]))
$this
->
temp
=
realpath
(
$_SERVER
[
'TMP'
]);
if
(
!
empty
(
$_SERVER
[
'TEMP'
]))
$this
->
temp
=
realpath
(
$_SERVER
[
'TEMP'
]);
if
(
empty
(
$this
->
temp
))
$this
->
temp
=
dirname
(
__FILE__
)
.
D
IRECTORY_SEPERATOR
;
if
(
empty
(
$this
->
temp
))
$this
->
temp
=
dirname
(
__FILE__
)
.
D
S
;
}
else
{
...
...
@@ -206,7 +235,7 @@ class zentaotest
{
if
(
isset
(
$_SERVER
[
'HOMEDRIVE'
])
and
isset
(
$_SERVER
[
'HOMEPATH'
]))
{
$this
->
home
=
$_SERVER
[
'HOMEDRIVE'
]
.
$_SERVER
[
'HOMEPATH'
]
.
D
IRECTORY_SEPERATOR
;
$this
->
home
=
$_SERVER
[
'HOMEDRIVE'
]
.
$_SERVER
[
'HOMEPATH'
]
.
D
S
;
}
else
{
...
...
@@ -215,11 +244,50 @@ class zentaotest
}
else
{
$this
->
home
=
getenv
(
'HOME'
)
.
D
IRECTORY_SEPARATOR
;
$this
->
home
=
getenv
(
'HOME'
)
.
D
S
;
}
}
/**
* Set the profile.
*
* @access public
* @return void
*/
public
function
setProfile
()
{
$this
->
profile
=
$this
->
home
.
'.ztconfig'
;
if
(
!
is_file
(
$this
->
profile
))
touch
(
$this
->
profile
);
}
/**
* Load config from the profile.
*
* @access public
* @return void
*/
public
function
loadConfig
()
{
$this
->
config
=
json_decode
(
file_get_contents
(
$this
->
profile
));
if
(
!
$this
->
config
)
{
$this
->
config
=
new
stdclass
();
$this
->
config
->
langs
=
new
stdclass
();
}
}
/**
* Save config to profile.
*
* @access public
* @return void
*/
public
function
saveConfig
()
{
file_put_contents
(
$this
->
profile
,
json_encode
(
$this
->
config
));
}
/**
* Set current working directory.
*
...
...
@@ -228,7 +296,7 @@ class zentaotest
*/
public
function
setCWD
()
{
$this
->
cwd
=
getcwd
()
.
D
IRECTORY_SEPARATOR
;
$this
->
cwd
=
getcwd
()
.
D
S
;
}
/**
...
...
@@ -239,7 +307,7 @@ class zentaotest
*/
public
function
setReportFile
()
{
$this
->
reportFile
=
$this
->
temp
.
date
(
'Ymd.Hi'
)
.
'.log'
;
$this
->
reportFile
=
$this
->
temp
.
DS
.
date
(
'Ymd.Hi'
)
.
'.log'
;
}
/**
...
...
@@ -254,6 +322,7 @@ class zentaotest
$zt
=
new
zentaotest
();
$zt
->
logBegin
();
$zt
->
findScripts
(
$dir
);
$zt
->
setInterpreters
();
$zt
->
setMaxLength
(
$zt
->
scripts
);
$zt
->
runScripts
();
$zt
->
logEnd
();
...
...
@@ -295,9 +364,48 @@ class zentaotest
}
else
{
if
(
strpos
(
file_get_contents
(
$script
),
TC_BEGIN
)
!==
false
)
$this
->
scripts
[]
=
realpath
(
$script
);
if
(
strpos
(
file_get_contents
(
$script
),
TC_BEGIN
)
!==
false
)
{
$this
->
scripts
[]
=
realpath
(
$script
);
/* Get the script language. */
$lang
=
strtolower
(
pathinfo
(
$script
,
PATHINFO_EXTENSION
));
if
(
$lang
)
$this
->
langs
[
$lang
]
=
$lang
;
}
}
}
}
/**
* Set interpreters for scripts languages.
*
* @access public
* @return void
*/
public
function
setInterpreters
()
{
foreach
(
$this
->
langs
as
$lang
)
{
if
(
isset
(
$this
->
config
->
langs
->
$lang
))
continue
;
if
(
$lang
==
'bat'
)
continue
;
while
(
true
)
{
echo
"Please set the interpreter for
$lang
scripts, type 'skip' to skip:"
;
$input
=
trim
(
fgets
(
STDIN
));
if
(
!
is_file
(
$input
))
{
if
(
$input
==
'skip'
)
break
;
echo
"The interpreter you input not exists, please try again.
\n
"
;
continue
;
}
$this
->
config
->
langs
->
$lang
=
$input
;
break
;
}
}
$this
->
saveConfig
();
}
/**
...
...
@@ -408,18 +516,19 @@ class zentaotest
/* Set the default value of expect. */
if
(
!
isset
(
$this
->
current
->
expect
))
$this
->
current
->
expect
=
''
;
/* Append the script file name. */
/* Append the script file name
and lang
. */
$this
->
current
->
script
=
$script
;
$this
->
current
->
lang
=
pathinfo
(
$script
,
PATHINFO_EXTENSION
);
/* Check whether the expect file exists. */
$path
=
pathinfo
(
$script
);
$expectFile
=
str_replace
(
$path
[
'basename'
],
'.'
.
$path
[
'basename'
],
$script
);
$expectFile
=
str_replace
(
'.'
.
$path
[
'extension'
],
'.et'
,
$expectFile
);
if
(
is_file
(
$expectFile
))
return
$this
->
current
->
expect
=
trim
(
file_get_contents
(
$expectFile
));
if
(
is_file
(
$expectFile
))
return
$this
->
current
->
expect
=
trim
(
$this
->
dos2unix
(
file_get_contents
(
$expectFile
)
));
/* Check whether the expectx file exists. */
$expectxFile
=
str_replace
(
'.et'
,
'.ex'
,
$expectFile
);
if
(
is_file
(
$expectxFile
))
return
$this
->
current
->
expectx
=
trim
(
file_get_contents
(
$expectxFile
));
if
(
is_file
(
$expectxFile
))
return
$this
->
current
->
expectx
=
trim
(
$this
->
dos2unix
(
file_get_contents
(
$expectxFile
)
));
}
/**
...
...
@@ -431,7 +540,29 @@ class zentaotest
public
function
getScriptOutput
()
{
chdir
(
dirname
(
$this
->
current
->
script
));
$this
->
current
->
output
=
trim
(
`{$this->current->script}`
);
if
(
$this
->
os
==
'win'
)
{
$lang
=
$this
->
current
->
lang
;
if
(
$lang
==
'bat'
)
{
$this
->
current
->
output
=
trim
(
`{$this->current->script}`
);
}
elseif
(
isset
(
$this
->
config
->
langs
->
$lang
))
{
$this
->
current
->
output
=
trim
(
`{$this->config->langs->$lang} {$this->current->script}`
);
}
else
{
$this
->
current
->
output
=
"skip"
;
}
}
else
{
$this
->
current
->
output
=
trim
(
`{$this->current->script}`
);
}
chdir
(
$this
->
cwd
);
}
...
...
@@ -443,6 +574,14 @@ class zentaotest
*/
public
function
computeResult
()
{
/* If the output is skip, skip this script. */
if
(
$this
->
current
->
output
==
'skip'
)
{
$this
->
current
->
result
=
'skip'
;
$this
->
results
[
'skip'
]
++
;
return
true
;
}
/* First try to compare the expect and output. */
if
(
strcmp
(
$this
->
current
->
expect
,
$this
->
current
->
output
)
===
0
)
{
...
...
@@ -516,7 +655,7 @@ class zentaotest
$string
=
preg_replace
(
'/\r\n/'
,
"
\n
"
,
$string
);
$string
=
preg_quote
(
$string
,
'/'
);
$string
=
str_replace
(
'%e'
,
'\\'
.
D
IRECTORY_SEPARATOR
,
$string
);
$string
=
str_replace
(
'%e'
,
'\\'
.
D
S
,
$string
);
$string
=
str_replace
(
'%s'
,
'[^\r\n]+'
,
$string
);
$string
=
str_replace
(
'%S'
,
'[^\r\n]*'
,
$string
);
$string
=
str_replace
(
'%a'
,
'.+'
,
$string
);
...
...
@@ -541,6 +680,8 @@ class zentaotest
*/
public
function
diff
(
$expect
,
$out
)
{
$expect
=
str_replace
(
"
\r
"
,
''
,
$expect
);
$out
=
str_replace
(
"
\r
"
,
''
,
$out
);
$w
=
explode
(
"
\n
"
,
$expect
);
$o
=
explode
(
"
\n
"
,
$out
);
$w1
=
array_diff_assoc
(
$w
,
$o
);
...
...
@@ -724,6 +865,18 @@ class zentaotest
return
$string
;
}
/**
* Convert a string fro dos format to unix.
*
* @param string $string
* @access public
* @return string
*/
public
function
dos2unix
(
$string
)
{
return
str_replace
(
"
\r
"
,
''
,
$string
);
}
/**
* Print error message.
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录