Skip to content

Commit f58e5c5

Browse files
committed
ruby: test rb/uninitialized-local-variable
It finds none of the right things and all of the wrong things...
1 parent 866fc6b commit f58e5c5

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| UninitializedLocal.rb:17:18:17:18 | x | Local variable $@ may be used before it is initialized. | UninitializedLocal.rb:17:9:17:9 | x | x |
2+
| UninitializedLocal.rb:26:10:26:15 | status | Local variable $@ may be used before it is initialized. | UninitializedLocal.rb:24:9:24:14 | status | status |
3+
| UninitializedLocal.rb:39:10:39:10 | a | Local variable $@ may be used before it is initialized. | UninitializedLocal.rb:35:5:35:5 | a | a |
4+
| UninitializedLocal.rb:40:10:40:10 | b | Local variable $@ may be used before it is initialized. | UninitializedLocal.rb:36:5:36:5 | b | b |
5+
| UninitializedLocal.rb:45:10:45:10 | a | Local variable $@ may be used before it is initialized. | UninitializedLocal.rb:35:5:35:5 | a | a |
6+
| UninitializedLocal.rb:46:10:46:10 | b | Local variable $@ may be used before it is initialized. | UninitializedLocal.rb:36:5:36:5 | b | b |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: queries/variables/UninitializedLocal.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
def test_basic
2+
puts x #$ MISSING: Alert
3+
end
4+
5+
def test_nil
6+
x = foo.nil? #$ MISSING: Alert
7+
puts x
8+
end
9+
10+
def test_condition
11+
if x #$ MISSING: Alert
12+
puts x #$ MISSING: Alert
13+
end
14+
end
15+
16+
def test_nested_condition
17+
if (x = 4 || x) #$ SPURIOUS: Alert
18+
puts x
19+
end
20+
end
21+
22+
def test_conditional_assignment
23+
if false
24+
status = i #$ MISSING: Alert
25+
end
26+
puts status #$ SPURIOUS: Alert
27+
puts i #$ MISSING: Alert
28+
end
29+
30+
def get
31+
raise SyntaxError
32+
end
33+
34+
def test_rescue_ensure
35+
a = get()
36+
b = c + 2 #$ MISSING: Alert
37+
rescue SyntaxError
38+
puts "rescue"
39+
puts a #$ SPURIOUS: Alert
40+
puts b #$ SPURIOUS: Alert
41+
puts c #$ MISSING: Alert
42+
puts "rescue end"
43+
ensure
44+
puts "ensure"
45+
puts a #$ SPURIOUS: Alert
46+
puts b #$ SPURIOUS: Alert
47+
puts c #$ MISSING: Alert
48+
puts "the end"
49+
end

0 commit comments

Comments
 (0)