Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
社会瑞弟呀
brakeman
提交
9cddb184
B
brakeman
项目概览
社会瑞弟呀
/
brakeman
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
brakeman
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9cddb184
编写于
9月 25, 2012
作者:
J
Justin Collins
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add rescan test helpers
上级
5004d3ad
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
165 addition
and
2 deletion
+165
-2
test/test.rb
test/test.rb
+165
-2
未找到文件。
test/test.rb
浏览文件 @
9cddb184
...
@@ -42,7 +42,7 @@ module BrakemanTester::FindWarning
...
@@ -42,7 +42,7 @@ module BrakemanTester::FindWarning
warnings
=
find
opts
warnings
=
find
opts
assert_not_equal
0
,
warnings
.
length
,
"No warning found"
assert_not_equal
0
,
warnings
.
length
,
"No warning found"
assert_equal
1
,
warnings
.
length
,
"Matched more than one warning"
assert_equal
1
,
warnings
.
length
,
"Matched more than one warning"
end
end
def
assert_no_warning
opts
def
assert_no_warning
opts
warnings
=
find
opts
warnings
=
find
opts
...
@@ -94,7 +94,170 @@ module BrakemanTester::CheckExpected
...
@@ -94,7 +94,170 @@ module BrakemanTester::CheckExpected
end
end
def
test_zero_errors
def
test_zero_errors
assert_equal
0
,
report
[
:errors
].
length
assert_equal
0
,
report
[
:errors
].
length
end
end
module
BrakemanTester::RescanTestHelper
attr_reader
:original
,
:rescan
,
:rescanner
#Takes care of copying files to a temporary directory, scanning the files,
#performing operations in the block (if provided), then rescanning the files
#given in `changed`.
#
#Provide an array of changed files for rescanning.
def
before_rescan_of
changed
changed
=
[
changed
]
unless
changed
.
is_a?
Array
Dir
.
mktmpdir
do
|
dir
|
@dir
=
dir
FileUtils
.
cp_r
"
#{
TEST_PATH
}
/apps/rails3.2/."
,
dir
@original
=
Brakeman
.
run
:app_path
=>
dir
,
:debug
=>
false
yield
dir
if
block_given?
@rescanner
=
Brakeman
::
Rescanner
.
new
(
@original
.
options
,
@original
.
processor
,
changed
)
@rescan
=
@rescanner
.
recheck
assert_existing
end
end
def
fixed
rescan
.
fixed_warnings
end
def
new
rescan
.
new_warnings
end
def
existing
rescan
.
existing_warnings
end
#Check how many fixed warnings were reported
def
assert_fixed
expected
assert_equal
expected
,
fixed
.
length
,
"Expected
#{
expected
}
fixed warnings, but found
#{
fixed
.
length
}
"
end
#Check how many new warnings were reported
def
assert_new
expected
assert_equal
expected
,
new
.
length
,
"Expected
#{
expected
}
new warnings, but found
#{
new
.
length
}
"
end
#Check how many existing warnings were reported
def
assert_existing
expected
=
(
@rescan
.
old_results
.
all_warnings
.
length
-
fixed
.
length
)
assert_equal
expected
,
existing
.
length
,
"Expected
#{
expected
}
existing warnings, but found
#{
existing
.
length
}
"
end
def
assert_changes
expected
=
true
assert_equal
expected
,
rescanner
.
changes
end
def
assert_reindex
*
types
if
types
==
[
:none
]
assert
rescanner
.
reindex
.
empty?
else
assert_equal
Set
.
new
(
types
),
rescanner
.
reindex
end
end
def
full_path
file
File
.
expand_path
file
,
@dir
end
def
remove
file
path
=
full_path
file
assert
File
.
exist?
path
File
.
delete
path
assert_equal
false
,
File
.
exist?
(
path
)
end
def
append
file
,
code
File
.
open
full_path
(
file
),
"a"
do
|
f
|
f
.
puts
code
end
end
def
replace_with_sexp
file
path
=
full_path
file
parsed
=
parse
File
.
read
path
output
=
yield
parsed
File
.
open
path
,
"w"
do
|
f
|
f
.
puts
Ruby2Ruby
.
new
.
process
output
end
end
def
replace
file
,
pattern
,
replacement
path
=
full_path
file
input
=
File
.
read
path
input
.
sub!
pattern
,
replacement
File
.
open
path
,
"w"
do
|
f
|
f
.
puts
input
end
end
def
write_file
file
,
content
File
.
open
full_path
(
file
),
"w+"
do
|
f
|
f
.
puts
content
end
end
def
remove_method
file
,
method_name
replace_with_sexp
file
do
|
parsed
|
class_body
=
parsed
.
body
if
class_body
[
1
].
node_type
==
:block
class_body
[
1
].
reject!
do
|
node
|
node
.
is_a?
Sexp
and
node
.
node_type
==
:defn
and
node
.
method_name
==
method_name
end
elsif
class_body
[
1
].
node_type
==
:defn
and
class_body
[
1
].
method_name
==
method_name
class_body
[
1
]
=
nil
end
parsed
end
end
def
add_method
file
,
code
parsed_method
=
parse
code
replace_with_sexp
file
do
|
parsed
|
class_body
=
parsed
.
body
if
class_body
[
1
].
node_type
==
:block
class_body
[
1
]
<<
parsed_method
elsif
class_body
[
1
]
class_body
[
1
]
=
s
(
:block
,
class_body
[
1
],
parsed_method
)
else
class_body
[
1
]
=
parsed_method
end
parsed
end
end
def
parse
code
if
RUBY_VERSION
=~
/^1\.9/
Ruby19Parser
.
new
.
parse
code
else
RubyParser
.
new
.
parse
code
end
end
end
end
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录