Skip to content

Commit b040e3a

Browse files
committed
[GR-13087] Test for "no properties"
PullRequest: truffleruby/716
2 parents 618ce28 + f14f331 commit b040e3a

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ AllCops:
88
- 'lib/truffle/date/delta/parser.rb' # generated code
99
- 'lib/truffle/socket/mri.rb' # taken from MRI
1010
- 'lib/truffle/ffi/library.rb' # taken from FFI gem
11+
- 'src/test/ruby/types.rb' # deliberately strange code for debugging purposes
1112

1213
# Type 'Layout' (166):
1314
# Supports --auto-correct

src/test/java/org/truffleruby/RubyDebugTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.InputStream;
3636
import java.io.InputStreamReader;
3737
import java.io.Reader;
38+
import java.util.Collection;
3839
import java.util.LinkedList;
3940
import java.util.concurrent.atomic.AtomicInteger;
4041

@@ -216,6 +217,56 @@ public void testEvalThrow() throws Throwable {
216217
assertExecutedOK("OK");
217218
}
218219

220+
@Ignore
221+
@Test
222+
public void testProperties() throws Throwable {
223+
Source source = getSource("src/test/ruby/types.rb");
224+
run.addLast(() -> {
225+
assertNull(suspendedEvent);
226+
assertNotNull(debuggerSession);
227+
breakpoint = Breakpoint.newBuilder(DebuggerTester.getSourceImpl(source)).lineIs(27).build();
228+
debuggerSession.install(breakpoint);
229+
});
230+
assertLocation(27, "nme + nm1",
231+
"name", "\"Panama\"", // Possible bug: should really the quotes be included?
232+
"cityArray", "[80, 97, 110, 97, 109, 97]",
233+
"citySum", "590",
234+
"weatherTemperature", "14",
235+
"blt", "true",
236+
"blf", "false",
237+
"null", "nil",
238+
"nm1", "1",
239+
"nm11", "1.111",
240+
"nme", "3.5e+46",
241+
"nc", "(2+3i)",
242+
"nr", "(5404319552844595/18014398509481984)",
243+
"str", "\"A String\"",
244+
"symbol", ":symbolic",
245+
"arr", "[1, \"2\", 3.56, true, nil, \"A String\"]",
246+
"hash", "{:a=>1, \"b\"=>2}");
247+
run.addLast(() -> {
248+
final DebugStackFrame frame = suspendedEvent.getTopStackFrame();
249+
DebugValue value = frame.getScope().getDeclaredValue("name");
250+
Collection<DebugValue> properties = value.getProperties();
251+
assertTrue("String has " + properties.size() + " properties.", properties.size() > 0); // BUG: String have no properties
252+
value = frame.getScope().getDeclaredValue("hash");
253+
properties = value.getProperties();
254+
assertEquals(2, properties.size()); // 'hash' has two properties
255+
try {
256+
properties.iterator().next().as(String.class);
257+
} catch (IllegalStateException ex) {
258+
"Value is not readable".equals(ex.getMessage()); // BUG
259+
Assert.fail(ex.getMessage());
260+
}
261+
assertNotNull(value.getProperty("a")); // == null, BUG
262+
assertEquals(0, frame.getScope().getDeclaredValue("symbol").getProperties().size());
263+
assertEquals(6, frame.getScope().getDeclaredValue("arr").getArray().size());
264+
});
265+
performWork();
266+
context.eval(source);
267+
assertExecutedOK("OK");
268+
}
269+
219270
private void performWork() {
220271
try {
221272
if (ex == null && !run.isEmpty()) {

src/test/ruby/types.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 1.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
# Beware, RubyDebugTest use hard-coded line numbers from this file!
10+
11+
def temperature_in_city(name)
12+
cityArray = name.bytes
13+
citySum = cityArray.reduce(0, :+)
14+
weatherTemperature = citySum.modulo(36)
15+
blt = true
16+
blf = false
17+
null = nil
18+
nm1 = 1
19+
nm11 = 1.111
20+
nme = 35e45
21+
nc = 2 + 3i
22+
nr = Rational(0.3)
23+
str = 'A String'
24+
symbol = :symbolic
25+
arr = [1, '2', 3.56, blt, nil, str]
26+
hash = {:a => 1, 'b' => 2}
27+
nme + nm1
28+
end
29+
30+
temperature_in_city('Panama')

0 commit comments

Comments
 (0)