Skip to content

Commit 4b62410

Browse files
committed
Add cucumber tests for stack and watch window
1 parent 88d37e6 commit 4b62410

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

features/correct_window_setup.feature

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Feature: Correct window setup
2+
In order to use Vdebug with all window panels
3+
As a user
4+
I want to see correct watch, stack and status information
5+
6+
Scenario: The watch window
7+
Given I have a file example.php containing
8+
"""
9+
<?php
10+
$var1 = 1;
11+
$var2 = array("hello", "world");
12+
?>
13+
"""
14+
And I start the debugger with the PHP script example.php
15+
When I step over
16+
Then the watch window should show the variable $var1
17+
And the watch window should show the variable $var2
18+
And the watch window variable $var1 should be (int) 1
19+
And the watch window variable $var2 should be (uninitialized)
20+
21+
Scenario: The stack window
22+
Given I have a file example.php containing
23+
"""
24+
<?php
25+
$var1 = 1;
26+
$var2 = array("hello", "world");
27+
?>
28+
"""
29+
And I start the debugger with the PHP script example.php
30+
When I step over
31+
Then the first item on the stack should show the file example.php
32+
And the first item on the stack should show line 3
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Then "the first item on the stack should show the file $file" do |file|
2+
vdebug.stack.first[:file].should include file
3+
end
4+
5+
Then "the first item on the stack should show line $line" do |line|
6+
vdebug.stack.first[:line].should == line
7+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
Then "the watch window should show the variable $var" do |var|
22
vdebug.watch_window_content.should include var
33
end
4+
5+
Then "the watch window variable $var should be $value" do |var, value|
6+
vdebug.watch_vars[var].should == value
7+
end

rubylib/vdebug.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@ def watch_window_content
5050
fetch_buffer_content 'DebuggerWatch'
5151
end
5252

53+
def watch_vars
54+
watch_lines = watch_window_content.split("\n")[4..-1]
55+
Hash[watch_lines.join("").split('|').map { |v|
56+
v[3..-1].split("=", 2).map(&:strip)
57+
}]
58+
end
59+
60+
def stack_window_content
61+
fetch_buffer_content 'DebuggerStack'
62+
end
63+
64+
def stack
65+
stack_window_content.split("\n").map { |l|
66+
s = {}
67+
matches = /^\[(\d+)\] {([^}]+)} @ ([^:]+):(\d+)/.match(l)
68+
if matches
69+
s[:level] = matches[1]
70+
s[:name] = matches[2]
71+
s[:file] = matches[3]
72+
s[:line] = matches[4]
73+
s
74+
else
75+
raise "Invalid stack line: #{l}"
76+
end
77+
}
78+
end
79+
5380
def status_window_content
5481
fetch_buffer_content 'DebuggerStatus'
5582
end

0 commit comments

Comments
 (0)