redcar 0.3.4.3 → 0.3.5

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.
Files changed (196) hide show
  1. data/CHANGES +45 -0
  2. data/README.md +2 -1
  3. data/ROADMAP.md +0 -1
  4. data/Rakefile +10 -4
  5. data/bin/redcar +2 -2
  6. data/lib/openssl/build.properties +7 -0
  7. data/lib/plugin_manager/lib/plugin_manager.rb +10 -0
  8. data/lib/plugin_manager/lib/plugin_manager/plugin_definition.rb +1 -13
  9. data/lib/redcar.rb +12 -8
  10. data/lib/redcar/installer.rb +16 -15
  11. data/lib/redcar/ruby_extensions.rb +146 -1
  12. data/lib/redcar/runner.rb +16 -7
  13. data/lib/redcar/usage.rb +4 -7
  14. data/lib/redcar_quick_start.rb +5 -5
  15. data/lib/regex_replace.rb +0 -7
  16. data/plugins/application/features/step_definitions/command_steps.rb +5 -0
  17. data/plugins/application/features/step_definitions/dialog_steps.rb +5 -0
  18. data/plugins/application/features/step_definitions/filter_list_dialog_steps.rb +38 -0
  19. data/plugins/application/features/step_definitions/window_steps.rb +1 -1
  20. data/plugins/application/features/support/env.rb +44 -8
  21. data/plugins/application/lib/application.rb +32 -33
  22. data/plugins/application/lib/application/command.rb +32 -2
  23. data/plugins/application/lib/application/command/executor.rb +2 -12
  24. data/plugins/application/lib/application/dialog.rb +14 -14
  25. data/plugins/application/lib/application/event_spewer.rb +32 -0
  26. data/plugins/application/lib/application/menu.rb +5 -5
  27. data/plugins/application/lib/application/menu/builder.rb +5 -0
  28. data/plugins/application/lib/application/menu/lazy_menu.rb +24 -0
  29. data/plugins/application/lib/application/notebook.rb +4 -3
  30. data/plugins/application/lib/application/tab.rb +6 -2
  31. data/plugins/application/lib/application/window.rb +8 -4
  32. data/plugins/application/spec/application/menu/builder_spec.rb +17 -1
  33. data/plugins/application/spec/application/notebook_spec.rb +1 -1
  34. data/plugins/application_swt/build.xml +74 -0
  35. data/plugins/application_swt/lib/application_swt.rb +79 -0
  36. data/plugins/application_swt/lib/application_swt/cucumber_patches.rb +6 -1
  37. data/plugins/application_swt/lib/application_swt/dialog_adapter.rb +25 -17
  38. data/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb +50 -12
  39. data/plugins/application_swt/lib/application_swt/html_tab.rb +20 -0
  40. data/plugins/application_swt/lib/application_swt/menu.rb +26 -2
  41. data/plugins/application_swt/lib/application_swt/notebook.rb +10 -12
  42. data/plugins/application_swt/lib/application_swt/window.rb +11 -11
  43. data/plugins/application_swt/src/com/redcareditor/application_swt/CocoaUIEnhancer.java +313 -0
  44. data/plugins/auto_completer/lib/auto_completer.rb +74 -67
  45. data/plugins/auto_completer/lib/auto_completer/current_document_completion_source.rb +19 -0
  46. data/plugins/auto_completer/lib/auto_completer/document_controller.rb +2 -2
  47. data/plugins/auto_completer/lib/auto_completer/word_list.rb +8 -1
  48. data/plugins/auto_indenter/features/ruby_style_indentation.feature +24 -0
  49. data/plugins/auto_indenter/features/step_definitions/indentation_steps.rb +6 -0
  50. data/plugins/auto_indenter/features/support/env.rb +2 -0
  51. data/plugins/auto_indenter/lib/auto_indenter.rb +86 -0
  52. data/plugins/auto_indenter/lib/auto_indenter/analyzer.rb +91 -0
  53. data/plugins/auto_indenter/lib/auto_indenter/commands.rb +34 -0
  54. data/plugins/auto_indenter/lib/auto_indenter/document_controller.rb +67 -12
  55. data/plugins/auto_indenter/lib/auto_indenter/rules.rb +41 -0
  56. data/plugins/auto_indenter/spec/auto_indenter/analyzer_spec.rb +151 -0
  57. data/plugins/auto_indenter/spec/spec_helper.rb +5 -0
  58. data/plugins/auto_pairer/lib/auto_pairer.rb +1 -0
  59. data/plugins/auto_pairer/lib/auto_pairer/document_controller.rb +43 -42
  60. data/plugins/auto_pairer/lib/auto_pairer/pairs_for_scope.rb +1 -5
  61. data/plugins/core/lib/core.rb +12 -1
  62. data/plugins/core/lib/core/observable.rb +7 -7
  63. data/plugins/core/lib/core/persistent_cache.rb +14 -2
  64. data/plugins/core/lib/core/plugin.rb +7 -0
  65. data/plugins/core/lib/core/resource.rb +78 -0
  66. data/plugins/core/lib/core/task.rb +62 -0
  67. data/plugins/core/lib/core/task_queue.rb +72 -0
  68. data/plugins/core/spec/core/resource_spec.rb +124 -0
  69. data/plugins/core/spec/core/task_queue_spec.rb +202 -0
  70. data/plugins/core/spec/spec_helper.rb +23 -1
  71. data/plugins/declarations/TODO +3 -0
  72. data/plugins/declarations/lib/declarations.rb +144 -0
  73. data/plugins/declarations/lib/declarations/completion_source.rb +22 -0
  74. data/plugins/declarations/lib/declarations/file.rb +68 -0
  75. data/plugins/declarations/lib/declarations/parser.rb +94 -0
  76. data/plugins/declarations/lib/declarations/select_tag_dialog.rb +44 -0
  77. data/plugins/declarations/plugin.rb +7 -0
  78. data/plugins/declarations/spec/declarations/file_spec.rb +62 -0
  79. data/plugins/declarations/spec/fixtures/federalist.rb +15 -0
  80. data/plugins/declarations/spec/spec_helper.rb +4 -0
  81. data/plugins/edit_view/features/indentation_commands.feature +40 -0
  82. data/plugins/edit_view/features/line_delimiter.feature +40 -0
  83. data/plugins/edit_view/features/step_definitions/editing_steps.rb +16 -4
  84. data/plugins/edit_view/features/step_definitions/notebook_steps.rb +1 -1
  85. data/plugins/edit_view/features/step_definitions/tab_steps.rb +1 -1
  86. data/plugins/edit_view/features/step_definitions/window_steps.rb +5 -1
  87. data/plugins/edit_view/features/support/env.rb +3 -5
  88. data/plugins/edit_view/features/undo_and_redo.feature +21 -0
  89. data/plugins/edit_view/lib/edit_view.rb +57 -4
  90. data/plugins/edit_view/lib/edit_view/actions/arrow_keys.rb +19 -3
  91. data/plugins/edit_view/lib/edit_view/document.rb +46 -11
  92. data/plugins/edit_view/lib/edit_view/document/indentation.rb +35 -0
  93. data/plugins/edit_view/lib/edit_view/modified_tabs_checker.rb +35 -0
  94. data/plugins/edit_view/lib/edit_view/tab_settings.rb +13 -3
  95. data/plugins/edit_view/spec/edit_view/document/indentation_spec.rb +112 -0
  96. data/plugins/edit_view/spec/edit_view/document_spec.rb +22 -0
  97. data/plugins/edit_view/spec/spec_helper.rb +1 -0
  98. data/plugins/edit_view_swt/lib/edit_view_swt.rb +59 -7
  99. data/plugins/edit_view_swt/lib/edit_view_swt/document.rb +3 -3
  100. data/plugins/edit_view_swt/lib/edit_view_swt/word_movement.rb +2 -2
  101. data/plugins/edit_view_swt/vendor/java-mateview.rb +3 -2
  102. data/plugins/encryption/encryption.rb +13 -6
  103. data/plugins/execute_current_tab/lib/execute_current_tab.rb +25 -15
  104. data/plugins/html_view/assets/redcar.css +32 -1
  105. data/plugins/html_view/lib/html_view.rb +23 -3
  106. data/plugins/html_view/lib/html_view/html_tab.rb +4 -0
  107. data/plugins/my_plugin/lib/my_plugin.rb +4 -12
  108. data/plugins/plugin_manager_ui/lib/plugin_manager_ui.rb +1 -0
  109. data/plugins/plugin_manager_ui/views/index.html.erb +30 -37
  110. data/plugins/project/features/find_file.feature +75 -0
  111. data/plugins/project/features/open_and_save_files.feature +7 -7
  112. data/plugins/project/features/open_directory_tree.feature +11 -3
  113. data/plugins/project/features/refresh_directory_tree.feature +7 -1
  114. data/plugins/project/features/step_definitions/directory_steps.rb +11 -1
  115. data/plugins/project/features/step_definitions/file_steps.rb +10 -0
  116. data/plugins/project/features/support/env.rb +6 -1
  117. data/plugins/project/features/watch_for_modified_files.feature +79 -0
  118. data/plugins/project/lib/project.rb +72 -306
  119. data/plugins/project/lib/project/commands.rb +128 -0
  120. data/plugins/project/lib/project/dir_mirror.rb +5 -1
  121. data/plugins/project/lib/project/drb_service.rb +21 -31
  122. data/plugins/project/lib/project/file_list.rb +76 -0
  123. data/plugins/project/lib/project/file_mirror.rb +13 -1
  124. data/plugins/project/lib/project/find_file_dialog.rb +22 -52
  125. data/plugins/project/lib/project/manager.rb +210 -0
  126. data/plugins/project/lib/project/recent_directories.rb +16 -3
  127. data/plugins/project/plugin.rb +1 -1
  128. data/plugins/project/spec/fixtures/myproject/README +2 -0
  129. data/plugins/project/spec/fixtures/myproject/lib/foo_lib.rb +1 -0
  130. data/plugins/project/spec/fixtures/myproject/spec/foo_spec.rb +1 -0
  131. data/plugins/project/{features → spec}/fixtures/winter.txt +0 -0
  132. data/plugins/project/spec/project/dir_mirror_spec.rb +1 -12
  133. data/plugins/project/spec/project/file_list_spec.rb +140 -0
  134. data/plugins/project/spec/spec_helper.rb +20 -0
  135. data/plugins/redcar/plugin.rb +1 -0
  136. data/plugins/redcar/redcar.rb +254 -84
  137. data/plugins/redcar_debug/lib/redcar_debug.rb +58 -11
  138. data/plugins/redcar_debug/vendor/jruby-prof/README +46 -0
  139. data/plugins/redcar_debug/vendor/jruby-prof/Rakefile +36 -0
  140. data/plugins/redcar_debug/vendor/jruby-prof/build.xml +31 -0
  141. data/plugins/redcar_debug/vendor/jruby-prof/example/call_tree.html +22677 -0
  142. data/plugins/redcar_debug/vendor/jruby-prof/example/call_tree.txt +589 -0
  143. data/plugins/redcar_debug/vendor/jruby-prof/example/flat.txt +28 -0
  144. data/plugins/redcar_debug/vendor/jruby-prof/example/graph.html +1670 -0
  145. data/plugins/redcar_debug/vendor/jruby-prof/example/graph.txt +125 -0
  146. data/plugins/redcar_debug/vendor/jruby-prof/example/pidigits.rb +92 -0
  147. data/plugins/redcar_debug/vendor/jruby-prof/example/test.rb +28 -0
  148. data/plugins/redcar_debug/vendor/jruby-prof/example/test2.rb +29 -0
  149. data/plugins/redcar_debug/vendor/jruby-prof/example/test_exception.rb +28 -0
  150. data/plugins/redcar_debug/vendor/jruby-prof/example/test_overhead.rb +43 -0
  151. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof.rb +66 -0
  152. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/abstract_printer.rb +21 -0
  153. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/flat_text_printer.rb +35 -0
  154. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/graph_html_printer.rb +123 -0
  155. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/graph_text_printer.rb +45 -0
  156. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/invocation_set.rb +34 -0
  157. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/method.rb +107 -0
  158. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/profile_invocation.rb +43 -0
  159. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/simple_tree_printer.rb +27 -0
  160. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/tree_html_printer.rb +144 -0
  161. data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/Invocation.java +14 -0
  162. data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/JRubyProf.java +94 -0
  163. data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/ProfEventHook.java +49 -0
  164. data/plugins/redcar_debug/vendor/jruby-prof/templates/graph_row.html.erb +18 -0
  165. data/plugins/redcar_debug/vendor/jruby-prof/test/basic_test.rb +291 -0
  166. data/plugins/redcar_debug/views/history.html.erb +33 -0
  167. data/plugins/redcar_debug/views/index.html.erb +33 -0
  168. data/plugins/repl/lib/repl/internal_mirror.rb +3 -15
  169. data/plugins/repl/spec/repl/internal_mirror_spec.rb +2 -2
  170. data/plugins/snippets/lib/snippets.rb +0 -1
  171. data/plugins/snippets/lib/snippets/document_controller.rb +7 -1
  172. data/plugins/task_manager/lib/task_manager.rb +28 -0
  173. data/plugins/task_manager/plugin.rb +11 -0
  174. data/plugins/task_manager/views/index.html.erb +67 -0
  175. data/plugins/textmate/lib/textmate.rb +17 -21
  176. data/plugins/textmate/lib/textmate/plist.rb +1 -2
  177. data/plugins/textmate/lib/textmate/preference.rb +5 -1
  178. data/plugins/textmate/lib/textmate/snippet.rb +6 -1
  179. data/plugins/tree_view_swt/lib/tree_view_swt.rb +0 -6
  180. data/textmate/Bundles/Cucumber.tmbundle/Preferences/Comments.tmPreferences +1 -1
  181. data/textmate/Bundles/Cucumber.tmbundle/Preferences/next_Cucumber_Plain_Text_Feature_Completions.tmPreferences +30 -0
  182. data/textmate/Bundles/Cucumber.tmbundle/Preferences/next_Symbol_list___Scenario.tmPreferences +19 -0
  183. data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/next_Cucumber_Plain_Text_Feature.tmLanguage +221 -0
  184. data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/next_Cucumber_Steps.tmLanguage +424 -0
  185. data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/plaintext_template.erb +19 -77
  186. data/textmate/Bundles/Cucumber.tmbundle/info.plist +1 -20
  187. data/textmate/Bundles/Perl.tmbundle/Syntaxes/Perl.plist +1 -1
  188. data/textmate/Themes/Emacs Strict.tmTheme +241 -0
  189. data/textmate/Themes/IR_White.tmTheme +792 -0
  190. data/textmate/Themes/Monokai.tmTheme +291 -0
  191. data/textmate/Themes/WhysPoignant.tmTheme +191 -0
  192. metadata +92 -7
  193. data/plugins/application/features/main_window.feature +0 -8
  194. data/plugins/project/lib/project/project_command.rb +0 -5
  195. data/textmate/Bundles/Cucumber.tmbundle/Snippets/Scenario.tmSnippet +0 -22
  196. data/textmate/Bundles/Cucumber.tmbundle/Snippets/Story.tmSnippet +0 -25
@@ -0,0 +1,14 @@
1
+
2
+ package org.jruby.prof;
3
+
4
+ import java.util.*;
5
+ public class Invocation {
6
+ public String className;
7
+ public String methodName;
8
+ public Invocation parent;
9
+ public boolean returned = false;
10
+ public long duration = 0;
11
+ public long count = 0;
12
+ public long startTimeCurrent;
13
+ public ArrayList<Invocation> children = new ArrayList<Invocation>();
14
+ }
@@ -0,0 +1,94 @@
1
+
2
+ package org.jruby.prof;
3
+
4
+ import java.util.*;
5
+ import org.jruby.Ruby;
6
+ import org.jruby.runtime.ThreadContext;
7
+
8
+ public class JRubyProf {
9
+
10
+ private static Map<ThreadContext, Invocation> currentInvocations;
11
+
12
+ public static ProfEventHook hook = null;
13
+ public static long startedTracingTime;
14
+ public static long lastTracingDuration;
15
+
16
+ public static void startTracing() {
17
+ hook = new ProfEventHook();
18
+ Ruby.getGlobalRuntime().addEventHook(hook);
19
+ currentInvocations = Collections.synchronizedMap(new HashMap<ThreadContext, Invocation>());
20
+ shouldProfile = true;
21
+ startedTracingTime = System.currentTimeMillis();
22
+ }
23
+
24
+ public static Map<ThreadContext, Invocation> stopTracing() {
25
+ shouldProfile = false;
26
+ Ruby.getGlobalRuntime().removeEventHook(hook);
27
+ hook = null;
28
+ lastTracingDuration = System.currentTimeMillis() - startedTracingTime;
29
+ for (ThreadContext context : currentInvocations.keySet()) {
30
+ Invocation inv = currentInvocations.get(context);
31
+ while (inv.parent != null)
32
+ inv = inv.parent;
33
+ currentInvocations.put(context, inv);
34
+ }
35
+ return currentInvocations;
36
+ }
37
+
38
+ public static boolean isRunning() {
39
+ return shouldProfile;
40
+ }
41
+
42
+ private static boolean shouldProfile = false;
43
+ private boolean initProfileMethod = false;
44
+
45
+ public static synchronized void before(ThreadContext context, String className, String methodName) {
46
+ if (!shouldProfile) return;
47
+ Invocation inv = null;
48
+ if (currentInvocations.containsKey(context)) {
49
+ Invocation parent = currentInvocations.get(context);
50
+ for (Invocation subinv : parent.children) {
51
+ if (subinv.className.equals(className) && subinv.methodName.equals(methodName)) {
52
+ inv = subinv;
53
+ }
54
+ }
55
+ if (inv == null) {
56
+ inv = new Invocation();
57
+ inv.parent = parent;
58
+ inv.className = className;
59
+ inv.methodName = methodName;
60
+ parent.children.add(inv);
61
+ }
62
+ currentInvocations.put(context, inv);
63
+ //System.out.printf("pushing %s %s to %s %s in %s\n", inv.className, inv.methodName, parent.className, parent.methodName, context.toString());
64
+ //System.out.printf("current for %s is %s %s\n", context.toString(), inv.className, inv.methodName);
65
+ }
66
+ else {
67
+ inv = new Invocation();
68
+ currentInvocations.put(context, inv);
69
+ //System.out.printf("current for %s is %s %s\n", context.toString(), inv.className, inv.methodName);
70
+ before(context, className, methodName);
71
+ }
72
+ inv.startTimeCurrent = System.currentTimeMillis();
73
+ }
74
+
75
+ public static synchronized void after(ThreadContext context, String className, String methodName) {
76
+ if (!shouldProfile) return;
77
+ Invocation current = currentInvocations.get(context);
78
+ long time;
79
+ if (current == null) return;
80
+ time = System.currentTimeMillis() - current.startTimeCurrent;
81
+ if (current.startTimeCurrent == 0)
82
+ System.out.printf("warning, startTimeCurrent is 0 in after\n");
83
+ current.startTimeCurrent = 0;
84
+ current.duration += time;
85
+ current.returned = true;
86
+ current.count += 1;
87
+ if (current.parent != null) {
88
+ currentInvocations.put(context, current.parent);
89
+ //System.out.printf("popping: %s %s took %dms, now at %s %s\n", current.className, current.methodName, time, current.parent.className, current.parent.methodName);
90
+ }
91
+ //System.out.printf("current for %s is %s %s\n", context.toString(), current.parent.className, current.parent.methodName);
92
+ }
93
+
94
+ }
@@ -0,0 +1,49 @@
1
+
2
+ package org.jruby.prof;
3
+
4
+ import org.jruby.prof.JRubyProf;
5
+
6
+ import org.jruby.RubyObject;
7
+ import org.jruby.RubyModule;
8
+ import org.jruby.MetaClass;
9
+ import org.jruby.runtime.EventHook;
10
+ import org.jruby.runtime.RubyEvent;
11
+ import org.jruby.runtime.ThreadContext;
12
+ import org.jruby.runtime.builtin.IRubyObject;
13
+
14
+ public class ProfEventHook extends EventHook {
15
+ public void eventHandler(ThreadContext context, String eventName, String file, int line, String methodName, IRubyObject type) {
16
+ RubyModule module = (RubyModule) type;
17
+ String className;
18
+ if (module == null) {
19
+ className = "null";
20
+ }
21
+ else {
22
+ if (module instanceof MetaClass) {
23
+ IRubyObject obj = ((MetaClass) module).getAttached();
24
+ if (obj instanceof RubyModule) {
25
+ module = (RubyModule) obj;
26
+ className = "<Class::" + module.getName() + ">";
27
+ }
28
+ else if (obj instanceof RubyObject) {
29
+ className = "<Instance::" + ((RubyObject) obj).getType().getName() + ">";
30
+ }
31
+ else {
32
+ className = "unknown";
33
+ }
34
+ }
35
+ else {
36
+ className = module.getName();
37
+ }
38
+ }
39
+ //System.out.printf("eventHandler(_, %s, %s, %d, %s, %s)\n", eventName, file, line, methodName, className);
40
+ if (className.equals("<Class::Java::OrgJrubyProf::JRubyProf>")) return;
41
+ if (eventName.equals("call") || eventName.equals("c-call")) {
42
+ JRubyProf.before(context, className, methodName);
43
+ }
44
+ else if (eventName.equals("return") || eventName.equals("c-return")) {
45
+ JRubyProf.after(context, className, methodName);
46
+ }
47
+ }
48
+ public boolean isInterestedInEvent(RubyEvent event) { return true; }
49
+ }
@@ -0,0 +1,18 @@
1
+
2
+
3
+ <tr class="<%= major_row ? "method" : "" %>">
4
+ <td><%= ("%2.2f%" % total_pc) if major_row %></td>
5
+ <td><%= ("%2.2f%" % self_pc) if major_row %></td>
6
+ <td><%= total/1000.0 %></td>
7
+ <td><%= self_/1000.0 %></td>
8
+ <td><%= children/1000.0 %></td>
9
+ <td><%= calls %></td>
10
+ <td>
11
+ <% if major_row %>
12
+ <a name="<%= safe_name(name) + (inv_id ? "_#{inv_id}" : "") %>"><%= name %></a>
13
+ <% else %>
14
+ <a href="#<%= safe_name(name) + (inv_id ? "_#{inv_id}" : "") %>"><%= name %></a>
15
+ <% end %>
16
+ </td>
17
+ </tr>
18
+
@@ -0,0 +1,291 @@
1
+ require 'test/unit'
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
4
+ require 'jruby-prof'
5
+
6
+ class C1
7
+ def C1.hello
8
+ sleep(0.1)
9
+ end
10
+
11
+ def hello
12
+ sleep(0.2)
13
+ end
14
+ end
15
+
16
+ module M1
17
+ def hello
18
+ sleep(0.3)
19
+ end
20
+ end
21
+
22
+ class C2
23
+ include M1
24
+ extend M1
25
+ end
26
+
27
+ class C3
28
+ def hello
29
+ sleep(0.4)
30
+ end
31
+ end
32
+
33
+ module M4
34
+ def hello
35
+ sleep(0.5)
36
+ end
37
+ end
38
+
39
+ module M5
40
+ include M4
41
+ def goodbye
42
+ hello
43
+ end
44
+ end
45
+
46
+ class C6
47
+ include M5
48
+ def test
49
+ goodbye
50
+ end
51
+ end
52
+
53
+ class BasicTest < Test::Unit::TestCase
54
+ def setup
55
+ # Need to use wall time for this test due to the sleep calls
56
+ #RubyProf::measure_mode = RubyProf::WALL_TIME
57
+ end
58
+
59
+ def test_running
60
+ assert(!JRubyProf.running?)
61
+ JRubyProf.start
62
+ assert(JRubyProf.running?)
63
+ JRubyProf.stop
64
+ assert(!JRubyProf.running?)
65
+ end
66
+
67
+ def test_double_profile
68
+ JRubyProf.start
69
+ assert_raise(RuntimeError) do
70
+ JRubyProf.start
71
+ end
72
+
73
+ assert_raise(RuntimeError) do
74
+ JRubyProf.profile do
75
+ puts 1
76
+ end
77
+ end
78
+ JRubyProf.stop
79
+ end
80
+
81
+ def test_no_block
82
+ assert_raise(ArgumentError) do
83
+ JRubyProf.profile
84
+ end
85
+ end
86
+
87
+ def test_class_methods
88
+ result = JRubyProf.profile do
89
+ C1.hello
90
+ end
91
+
92
+ # Length should be 3:
93
+ # BasicTest#test_class_methods
94
+ # <Class::C1>#hello
95
+ # Kernel#sleep
96
+
97
+ methods = result.values.to_a.first.get_methods.values.sort_by {|m| m.name}
98
+ p methods
99
+ assert_equal(3, methods.length)
100
+
101
+ # Check the names
102
+ assert_equal('BasicTest#test_class_methods', methods[0].name)
103
+ assert_equal('<Class::C1>#hello', methods[1].name)
104
+ assert_equal('Kernel#sleep', methods[2].name)
105
+
106
+ # Check times
107
+ assert_in_delta(0.1, methods[0].total_time, 0.01)
108
+ assert_in_delta(0, methods[0].wait_time, 0.01)
109
+ assert_in_delta(0, methods[0].self_time, 0.01)
110
+
111
+ assert_in_delta(0.1, methods[1].total_time, 0.01)
112
+ assert_in_delta(0, methods[1].wait_time, 0.01)
113
+ assert_in_delta(0, methods[1].self_time, 0.01)
114
+
115
+ assert_in_delta(0.1, methods[2].total_time, 0.01)
116
+ assert_in_delta(0, methods[2].wait_time, 0.01)
117
+ assert_in_delta(0.1, methods[2].self_time, 0.01)
118
+ end
119
+ #
120
+ #if RUBY_VERSION < '1.9'
121
+ # PARENT = Object
122
+ #else
123
+ # PARENT = BasicObject
124
+ #end
125
+ #
126
+ #def test_instance_methods
127
+ # result = RubyProf.profile do
128
+ # C1.new.hello
129
+ # end
130
+ #
131
+ # # Methods called
132
+ # # BasicTest#test_instance_methods
133
+ # # Class.new
134
+ # # Class:Object#allocate
135
+ # # for Object#initialize
136
+ # # C1#hello
137
+ # # Kernel#sleep
138
+ #
139
+ # methods = result.threads.values.first.sort.reverse
140
+ # assert_equal(6, methods.length)
141
+ # names = methods.map(&:full_name)
142
+ # assert_equal('BasicTest#test_instance_methods', names[0])
143
+ # assert_equal('C1#hello', names[1])
144
+ # assert_equal('Kernel#sleep', names[2])
145
+ # assert_equal('Class#new', names[3])
146
+ # # order can differ
147
+ # assert(names.include?("<Class::#{PARENT}>#allocate"))
148
+ # assert(names.include?("#{PARENT}#initialize"))
149
+ #
150
+ # # Check times
151
+ # assert_in_delta(0.2, methods[0].total_time, 0.02)
152
+ # assert_in_delta(0, methods[0].wait_time, 0.02)
153
+ # assert_in_delta(0, methods[0].self_time, 0.02)
154
+ #
155
+ # assert_in_delta(0.2, methods[1].total_time, 0.02)
156
+ # assert_in_delta(0, methods[1].wait_time, 0.02)
157
+ # assert_in_delta(0, methods[1].self_time, 0.02)
158
+ #
159
+ # assert_in_delta(0.2, methods[2].total_time, 0.02)
160
+ # assert_in_delta(0, methods[2].wait_time, 0.02)
161
+ # assert_in_delta(0.2, methods[2].self_time, 0.02)
162
+ #
163
+ # assert_in_delta(0, methods[3].total_time, 0.01)
164
+ # assert_in_delta(0, methods[3].wait_time, 0.01)
165
+ # assert_in_delta(0, methods[3].self_time, 0.01)
166
+ #
167
+ # assert_in_delta(0, methods[4].total_time, 0.01)
168
+ # assert_in_delta(0, methods[4].wait_time, 0.01)
169
+ # assert_in_delta(0, methods[4].self_time, 0.01)
170
+ #
171
+ # assert_in_delta(0, methods[5].total_time, 0.01)
172
+ # assert_in_delta(0, methods[5].wait_time, 0.01)
173
+ # assert_in_delta(0, methods[5].self_time, 0.01)
174
+ #end
175
+ #
176
+ #def test_module_methods
177
+ # result = RubyProf.profile do
178
+ # C2.hello
179
+ # end
180
+ #
181
+ # # Methods:
182
+ # # BasicTest#test_module_methods
183
+ # # M1#hello
184
+ # # Kernel#sleep
185
+ #
186
+ # methods = result.threads.values.first.sort.reverse
187
+ # assert_equal(3, methods.length)
188
+ #
189
+ # assert_equal('BasicTest#test_module_methods', methods[0].full_name)
190
+ # assert_equal('M1#hello', methods[1].full_name)
191
+ # assert_equal('Kernel#sleep', methods[2].full_name)
192
+ #
193
+ # # Check times
194
+ # assert_in_delta(0.3, methods[0].total_time, 0.1)
195
+ # assert_in_delta(0, methods[0].wait_time, 0.02)
196
+ # assert_in_delta(0, methods[0].self_time, 0.02)
197
+ #
198
+ # assert_in_delta(0.3, methods[1].total_time, 0.1)
199
+ # assert_in_delta(0, methods[1].wait_time, 0.02)
200
+ # assert_in_delta(0, methods[1].self_time, 0.02)
201
+ #
202
+ # assert_in_delta(0.3, methods[2].total_time, 0.1)
203
+ # assert_in_delta(0, methods[2].wait_time, 0.02)
204
+ # assert_in_delta(0.3, methods[2].self_time, 0.1)
205
+ #end
206
+ #
207
+ #def test_module_instance_methods
208
+ # result = RubyProf.profile do
209
+ # C2.new.hello
210
+ # end
211
+ #
212
+ # # Methods:
213
+ # # BasicTest#test_module_instance_methods
214
+ # # Class#new
215
+ # # <Class::Object>#allocate
216
+ # # Object#initialize
217
+ # # M1#hello
218
+ # # Kernel#sleep
219
+ #
220
+ # methods = result.threads.values.first.sort.reverse
221
+ # assert_equal(6, methods.length)
222
+ # names = methods.map(&:full_name)
223
+ # assert_equal('BasicTest#test_module_instance_methods', names[0])
224
+ # assert_equal('M1#hello', names[1])
225
+ # assert_equal('Kernel#sleep', names[2])
226
+ # assert_equal('Class#new', names[3])
227
+ # assert(names.include?("<Class::#{PARENT}>#allocate"))
228
+ # assert(names.include?("#{PARENT}#initialize"))
229
+ #
230
+ # # Check times
231
+ # assert_in_delta(0.3, methods[0].total_time, 0.1)
232
+ # assert_in_delta(0, methods[0].wait_time, 0.1)
233
+ # assert_in_delta(0, methods[0].self_time, 0.1)
234
+ #
235
+ # assert_in_delta(0.3, methods[1].total_time, 0.02)
236
+ # assert_in_delta(0, methods[1].wait_time, 0.01)
237
+ # assert_in_delta(0, methods[1].self_time, 0.01)
238
+ #
239
+ # assert_in_delta(0.3, methods[2].total_time, 0.02)
240
+ # assert_in_delta(0, methods[2].wait_time, 0.01)
241
+ # assert_in_delta(0.3, methods[2].self_time, 0.02)
242
+ #
243
+ # assert_in_delta(0, methods[3].total_time, 0.01)
244
+ # assert_in_delta(0, methods[3].wait_time, 0.01)
245
+ # assert_in_delta(0, methods[3].self_time, 0.01)
246
+ #
247
+ # assert_in_delta(0, methods[4].total_time, 0.01)
248
+ # assert_in_delta(0, methods[4].wait_time, 0.01)
249
+ # assert_in_delta(0, methods[4].self_time, 0.01)
250
+ #
251
+ # assert_in_delta(0, methods[5].total_time, 0.01)
252
+ # assert_in_delta(0, methods[5].wait_time, 0.01)
253
+ # assert_in_delta(0, methods[5].self_time, 0.01)
254
+ #end
255
+ #
256
+ #def test_singleton
257
+ # c3 = C3.new
258
+ #
259
+ # class << c3
260
+ # def hello
261
+ # end
262
+ # end
263
+ #
264
+ # result = RubyProf.profile do
265
+ # c3.hello
266
+ # end
267
+ #
268
+ # methods = result.threads.values.first.sort.reverse
269
+ # assert_equal(2, methods.length)
270
+ #
271
+ # assert_equal('BasicTest#test_singleton', methods[0].full_name)
272
+ # assert_equal('<Object::C3>#hello', methods[1].full_name)
273
+ #
274
+ # assert_in_delta(0, methods[0].total_time, 0.01)
275
+ # assert_in_delta(0, methods[0].wait_time, 0.01)
276
+ # assert_in_delta(0, methods[0].self_time, 0.01)
277
+ #
278
+ # assert_in_delta(0, methods[1].total_time, 0.01)
279
+ # assert_in_delta(0, methods[1].wait_time, 0.01)
280
+ # assert_in_delta(0, methods[1].self_time, 0.01)
281
+ #end
282
+ #
283
+ #def test_traceback
284
+ # RubyProf.start
285
+ # assert_raise(NoMethodError) do
286
+ # RubyProf.xxx
287
+ # end
288
+ #
289
+ # RubyProf.stop
290
+ #end
291
+ end