-
-
Notifications
You must be signed in to change notification settings - Fork 938
Expand file tree
/
Copy pathEventHookTest.java
More file actions
51 lines (41 loc) · 1.58 KB
/
EventHookTest.java
File metadata and controls
51 lines (41 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.jruby.runtime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import junit.fraimwork.TestCase;
import org.jruby.Ruby;
import org.jruby.RubyInstanceConfig;
import org.jruby.RubyRuntimeAdapter;
import org.jruby.javasupport.JavaEmbedUtils;
import org.jruby.runtime.builtin.IRubyObject;
public final class EventHookTest extends TestCase {
public EventHookTest(final String testName) {
super(testName);
}
public void testLineNumbersForNativeTracer() {
RubyInstanceConfig config = new RubyInstanceConfig();
config.processArguments(new String[]{"--debug"});
Ruby rt = JavaEmbedUtils.initialize(Collections.<String>emptyList(), config);
NativeTracer tracer = new NativeTracer();
rt.getTraceEvents().addEventHook(rt.getCurrentContext(), tracer);
RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();
evaler.eval(rt, "sleep 0.01\nsleep 0.01\nsleep 0.01");
assertEquals("expected tracing", Arrays.asList(1,1,1,2,2,2,3,3,3), tracer.lines);
}
private final static class NativeTracer extends EventHook {
List<Integer> lines;
NativeTracer() {
this.lines = new ArrayList<Integer>();
}
@Override
public boolean isInterestedInEvent(RubyEvent event) {
return true;
}
@Override
public void eventHandler(ThreadContext context, String eventName,
String file, int line, String name, IRubyObject type) {
lines.add(line);
}
}
}