nasl-pedant 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/Rakefile +8 -0
- data/bin/pedant +33 -0
- data/lib/pedant/check.rb +135 -0
- data/lib/pedant/checks/conditional_or_loop_is_empty.rb +70 -0
- data/lib/pedant/checks/contains_ip_address_literals.rb +49 -0
- data/lib/pedant/checks/contains_no_carriage_returns.rb +48 -0
- data/lib/pedant/checks/contains_no_tabs.rb +48 -0
- data/lib/pedant/checks/contains_registration_section.rb +107 -0
- data/lib/pedant/checks/contains_unreachable_code.rb +68 -0
- data/lib/pedant/checks/ends_with_newline.rb +49 -0
- data/lib/pedant/checks/files_parse_without_error.rb +101 -0
- data/lib/pedant/checks/parse_test_code.rb +63 -0
- data/lib/pedant/checks/plugin_type_not_specified.rb +79 -0
- data/lib/pedant/cli.rb +82 -0
- data/lib/pedant/command.rb +96 -0
- data/lib/pedant/commands/check.rb +76 -0
- data/lib/pedant/commands/test.rb +37 -0
- data/lib/pedant/knowledge_base.rb +42 -0
- data/lib/pedant/test.rb +59 -0
- data/lib/pedant/version.rb +3 -0
- data/lib/pedant.rb +51 -0
- data/pedant.gemspec +25 -0
- data/test/test_helper.rb +5 -0
- data/test/unit/checks/conditional_or_loop_is_empty.rb +125 -0
- data/test/unit/checks/contains_ip_address_literals.rb +45 -0
- data/test/unit/checks/contains_no_carriage_returns.rb +43 -0
- data/test/unit/checks/contains_no_tabs.rb +45 -0
- data/test/unit/checks/contains_registration_section.rb +101 -0
- data/test/unit/checks/contains_unreachable_code.rb +93 -0
- data/test/unit/checks/ends_with_newline.rb +45 -0
- data/test/unit/checks/plugin_type_not_specified.rb +72 -0
- metadata +123 -0
data/lib/pedant.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011, Mak Kolybabi
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
27
|
+
require 'nasl'
|
28
|
+
require 'pathname'
|
29
|
+
require 'rainbow'
|
30
|
+
|
31
|
+
module Pedant
|
32
|
+
def self.root
|
33
|
+
@root ||= Pathname.new('').expand_path
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.lib
|
37
|
+
root + 'lib'
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.test
|
41
|
+
root + 'test'
|
42
|
+
end
|
43
|
+
|
44
|
+
autoload :Check, 'pedant/check'
|
45
|
+
autoload :Cli, 'pedant/cli'
|
46
|
+
autoload :Command, 'pedant/command'
|
47
|
+
autoload :KnowledgeBase, 'pedant/knowledge_base'
|
48
|
+
autoload :Test, 'pedant/test'
|
49
|
+
end
|
50
|
+
|
51
|
+
$LOAD_PATH.unshift(Pedant.lib.to_s)
|
data/pedant.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'pedant/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'nasl-pedant'
|
7
|
+
s.version = Pedant::VERSION
|
8
|
+
s.authors = ['Mak Kolybabi']
|
9
|
+
s.email = ['mak@kolybabi.com']
|
10
|
+
s.homepage = 'http://github.com/mogigoma/pedant'
|
11
|
+
s.summary = %q{A static analysis framework for the Nessus Attack Scripting Language.}
|
12
|
+
|
13
|
+
s.rubyforge_project = 'nasl-pedant'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.add_development_dependency 'rake'
|
21
|
+
s.add_development_dependency 'minitest'
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'rainbow'
|
24
|
+
s.add_runtime_dependency 'nasl', '>= 0.0.4'
|
25
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011, Mak Kolybabi
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
27
|
+
class TestConditionalOrLoopIsEmpty < Test::Unit::TestCase
|
28
|
+
include Pedant::Test
|
29
|
+
|
30
|
+
def test_none
|
31
|
+
check(
|
32
|
+
:pass,
|
33
|
+
:CheckConditionalOrLoopIsEmpty,
|
34
|
+
%q||
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_for
|
39
|
+
check(
|
40
|
+
:fail,
|
41
|
+
:CheckConditionalOrLoopIsEmpty,
|
42
|
+
%q|for (;1;) ;|
|
43
|
+
)
|
44
|
+
|
45
|
+
check(
|
46
|
+
:pass,
|
47
|
+
:CheckConditionalOrLoopIsEmpty,
|
48
|
+
%q|for (;1;) {}|
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_foreach
|
53
|
+
check(
|
54
|
+
:fail,
|
55
|
+
:CheckConditionalOrLoopIsEmpty,
|
56
|
+
%q|foreach foo (bar) ;|
|
57
|
+
)
|
58
|
+
|
59
|
+
check(
|
60
|
+
:pass,
|
61
|
+
:CheckConditionalOrLoopIsEmpty,
|
62
|
+
%q|foreach foo (bar) {}|
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_if
|
67
|
+
check(
|
68
|
+
:fail,
|
69
|
+
:CheckConditionalOrLoopIsEmpty,
|
70
|
+
%q|if (1) ;|
|
71
|
+
)
|
72
|
+
|
73
|
+
check(
|
74
|
+
:fail,
|
75
|
+
:CheckConditionalOrLoopIsEmpty,
|
76
|
+
%q|if (1) ; else {}|
|
77
|
+
)
|
78
|
+
|
79
|
+
check(
|
80
|
+
:fail,
|
81
|
+
:CheckConditionalOrLoopIsEmpty,
|
82
|
+
%q|if (1) {} else ;|
|
83
|
+
)
|
84
|
+
|
85
|
+
check(
|
86
|
+
:pass,
|
87
|
+
:CheckConditionalOrLoopIsEmpty,
|
88
|
+
%q|if (1) {}|
|
89
|
+
)
|
90
|
+
|
91
|
+
check(
|
92
|
+
:pass,
|
93
|
+
:CheckConditionalOrLoopIsEmpty,
|
94
|
+
%q|if (1) {} else {}|
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_repeat
|
99
|
+
check(
|
100
|
+
:fail,
|
101
|
+
:CheckConditionalOrLoopIsEmpty,
|
102
|
+
%q|repeat ; until 1;|
|
103
|
+
)
|
104
|
+
|
105
|
+
check(
|
106
|
+
:pass,
|
107
|
+
:CheckConditionalOrLoopIsEmpty,
|
108
|
+
%q|repeat {} until 1;|
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_while
|
113
|
+
check(
|
114
|
+
:fail,
|
115
|
+
:CheckConditionalOrLoopIsEmpty,
|
116
|
+
%q|while (1) ;|
|
117
|
+
)
|
118
|
+
|
119
|
+
check(
|
120
|
+
:pass,
|
121
|
+
:CheckConditionalOrLoopIsEmpty,
|
122
|
+
%q|while (1) {}|
|
123
|
+
)
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011, Mak Kolybabi
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
27
|
+
class TestContainsIpAddressLiterals < Test::Unit::TestCase
|
28
|
+
include Pedant::Test
|
29
|
+
|
30
|
+
def test_none
|
31
|
+
check(
|
32
|
+
:pass,
|
33
|
+
:CheckContainsIpAddressLiterals,
|
34
|
+
%q||
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_one
|
39
|
+
check(
|
40
|
+
:warn,
|
41
|
+
:CheckContainsIpAddressLiterals,
|
42
|
+
%q|z = 1.2.3.4;|
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011, Mak Kolybabi
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
27
|
+
class TestContainsNoCarriageReturns < Test::Unit::TestCase
|
28
|
+
include Pedant::Test
|
29
|
+
|
30
|
+
def test_none
|
31
|
+
check(
|
32
|
+
:pass,
|
33
|
+
:CheckContainsNoCarriageReturns,
|
34
|
+
%q||
|
35
|
+
)
|
36
|
+
|
37
|
+
check(
|
38
|
+
:warn,
|
39
|
+
:CheckContainsNoCarriageReturns,
|
40
|
+
%Q|\r\n|
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011, Mak Kolybabi
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
27
|
+
class TestContainsNoTabs < Test::Unit::TestCase
|
28
|
+
include Pedant::Test
|
29
|
+
|
30
|
+
def test_none
|
31
|
+
check(
|
32
|
+
:pass,
|
33
|
+
:CheckContainsNoTabs,
|
34
|
+
%q||
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_one
|
39
|
+
check(
|
40
|
+
:warn,
|
41
|
+
:CheckContainsNoTabs,
|
42
|
+
%Q|\t|
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011, Mak Kolybabi
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
27
|
+
class TestContainsRegistrationSection < Test::Unit::TestCase
|
28
|
+
include Pedant::Test
|
29
|
+
|
30
|
+
def test_does
|
31
|
+
check(
|
32
|
+
:pass,
|
33
|
+
:CheckContainsRegistrationSection,
|
34
|
+
%q|if (description) { exit(0); }|
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_does_not
|
39
|
+
check(
|
40
|
+
:fail,
|
41
|
+
:CheckContainsRegistrationSection,
|
42
|
+
%q||
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_unexpected
|
47
|
+
check(
|
48
|
+
:fail,
|
49
|
+
:CheckContainsRegistrationSection,
|
50
|
+
%q|if (description) ;|
|
51
|
+
)
|
52
|
+
|
53
|
+
check(
|
54
|
+
:fail,
|
55
|
+
:CheckContainsRegistrationSection,
|
56
|
+
%q|if (description) {}|
|
57
|
+
)
|
58
|
+
|
59
|
+
check(
|
60
|
+
:fail,
|
61
|
+
:CheckContainsRegistrationSection,
|
62
|
+
%q|if (description) { ; }|
|
63
|
+
)
|
64
|
+
|
65
|
+
check(
|
66
|
+
:fail,
|
67
|
+
:CheckContainsRegistrationSection,
|
68
|
+
%q|if (description) { foo(); }|
|
69
|
+
)
|
70
|
+
|
71
|
+
check(
|
72
|
+
:fail,
|
73
|
+
:CheckContainsRegistrationSection,
|
74
|
+
%q|if (description) { exit(); }|
|
75
|
+
)
|
76
|
+
|
77
|
+
check(
|
78
|
+
:fail,
|
79
|
+
:CheckContainsRegistrationSection,
|
80
|
+
%q|if (description) { exit(foo:1); }|
|
81
|
+
)
|
82
|
+
|
83
|
+
check(
|
84
|
+
:fail,
|
85
|
+
:CheckContainsRegistrationSection,
|
86
|
+
%q|if (description) { exit(foo, bar); }|
|
87
|
+
)
|
88
|
+
|
89
|
+
check(
|
90
|
+
:fail,
|
91
|
+
:CheckContainsRegistrationSection,
|
92
|
+
%q|if (description) { exit(1); }|
|
93
|
+
)
|
94
|
+
|
95
|
+
check(
|
96
|
+
:fail,
|
97
|
+
:CheckContainsRegistrationSection,
|
98
|
+
%q|if (description) { exit(0, foo); }|
|
99
|
+
)
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011, Mak Kolybabi
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
27
|
+
class TestContainsUnreachableCode < Test::Unit::TestCase
|
28
|
+
include Pedant::Test
|
29
|
+
|
30
|
+
def test_top
|
31
|
+
check(
|
32
|
+
:pass,
|
33
|
+
:CheckContainsUnreachableCode,
|
34
|
+
%q||
|
35
|
+
)
|
36
|
+
|
37
|
+
check(
|
38
|
+
:fail,
|
39
|
+
:CheckContainsUnreachableCode,
|
40
|
+
%q|exit(); foo();|
|
41
|
+
)
|
42
|
+
|
43
|
+
check(
|
44
|
+
:fail,
|
45
|
+
:CheckContainsUnreachableCode,
|
46
|
+
%q|return; foo();|
|
47
|
+
)
|
48
|
+
|
49
|
+
check(
|
50
|
+
:fail,
|
51
|
+
:CheckContainsUnreachableCode,
|
52
|
+
%q|break; foo();|
|
53
|
+
)
|
54
|
+
|
55
|
+
check(
|
56
|
+
:fail,
|
57
|
+
:CheckContainsUnreachableCode,
|
58
|
+
%q|continue; foo();|
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_block
|
63
|
+
check(
|
64
|
+
:pass,
|
65
|
+
:CheckContainsUnreachableCode,
|
66
|
+
%q|{}|
|
67
|
+
)
|
68
|
+
|
69
|
+
check(
|
70
|
+
:fail,
|
71
|
+
:CheckContainsUnreachableCode,
|
72
|
+
%q|{ exit(); foo(); }|
|
73
|
+
)
|
74
|
+
|
75
|
+
check(
|
76
|
+
:fail,
|
77
|
+
:CheckContainsUnreachableCode,
|
78
|
+
%q|{ return; foo(); }|
|
79
|
+
)
|
80
|
+
|
81
|
+
check(
|
82
|
+
:fail,
|
83
|
+
:CheckContainsUnreachableCode,
|
84
|
+
%q|{ break; foo(); }|
|
85
|
+
)
|
86
|
+
|
87
|
+
check(
|
88
|
+
:fail,
|
89
|
+
:CheckContainsUnreachableCode,
|
90
|
+
%q|{ continue; foo(); }|
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011, Mak Kolybabi
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
27
|
+
class TestEndsWithNewline < Test::Unit::TestCase
|
28
|
+
include Pedant::Test
|
29
|
+
|
30
|
+
def test_does
|
31
|
+
check(
|
32
|
+
:pass,
|
33
|
+
:CheckEndsWithNewline,
|
34
|
+
%Q|\n|
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_does_not
|
39
|
+
check(
|
40
|
+
:warn,
|
41
|
+
:CheckEndsWithNewline,
|
42
|
+
%q||
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011, Mak Kolybabi
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
27
|
+
class TestPluginTypeNotSpecified < Test::Unit::TestCase
|
28
|
+
include Pedant::Test
|
29
|
+
|
30
|
+
def test_none
|
31
|
+
check(
|
32
|
+
:fail,
|
33
|
+
:CheckPluginTypeNotSpecified,
|
34
|
+
%q||
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_one
|
39
|
+
check(
|
40
|
+
:pass,
|
41
|
+
:CheckPluginTypeNotSpecified,
|
42
|
+
%q|script_set_attribute(attribute:"plugin_type", value:"local");|
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_many
|
47
|
+
check(
|
48
|
+
:fail,
|
49
|
+
:CheckPluginTypeNotSpecified,
|
50
|
+
%q|script_set_attribute(attribute:"plugin_type", value:"local");| +
|
51
|
+
%q|script_set_attribute(attribute:"plugin_type", value:"remote");|
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_valid
|
56
|
+
['combined', 'local', 'remote'].each do |type|
|
57
|
+
check(
|
58
|
+
:pass,
|
59
|
+
:CheckPluginTypeNotSpecified,
|
60
|
+
%Q|script_set_attribute(attribute:"plugin_type", value:"#{type}");|
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_invalid
|
66
|
+
check(
|
67
|
+
:fail,
|
68
|
+
:CheckPluginTypeNotSpecified,
|
69
|
+
%q|script_set_attribute(attribute:"plugin_type", value:"foo");|
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|