private_please 0.0.5 → 0.1.0

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 (89) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +3 -5
  4. data/CHANGELOG +4 -0
  5. data/Gemfile +2 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +58 -98
  8. data/Rakefile +6 -2
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/private_please/config.rb +15 -0
  12. data/lib/private_please/methods_calls_tracker.rb +44 -0
  13. data/lib/private_please/reporting/simple_text.rb +43 -0
  14. data/lib/private_please/reporting/templates/simple.txt.erb +11 -0
  15. data/lib/private_please/storage/called_methods_memory_store.rb +20 -0
  16. data/lib/private_please/tracking/debug/trace_point_data_logger.rb +81 -0
  17. data/lib/private_please/tracking/method_details.rb +27 -0
  18. data/lib/private_please/tracking/result.rb +25 -0
  19. data/lib/private_please/tracking/trace_point_details.rb +41 -0
  20. data/lib/private_please/tracking/trace_point_processor.rb +71 -0
  21. data/lib/private_please/utils/ruby_utils.rb +44 -0
  22. data/lib/private_please/utils/source_file_utils.rb +20 -0
  23. data/lib/private_please/utils/two_level_stack.rb +13 -0
  24. data/lib/private_please/version.rb +2 -1
  25. data/lib/private_please.rb +27 -34
  26. data/private_please.gemspec +32 -25
  27. metadata +106 -185
  28. data/Guardfile +0 -8
  29. data/LICENSE +0 -22
  30. data/TODO +0 -20
  31. data/bin/pp_ruby +0 -62
  32. data/bin/ruby_pp +0 -62
  33. data/doc/dev_notes.txt +0 -32
  34. data/doc/fixtures/complex.rb +0 -103
  35. data/doc/fixtures/empty_class.rb +0 -7
  36. data/doc/fixtures/fixture_helper.rb +0 -8
  37. data/doc/fixtures/sample.rb +0 -57
  38. data/lib/private_please/candidate.rb +0 -49
  39. data/lib/private_please/report/table.rb +0 -44
  40. data/lib/private_please/report.rb +0 -6
  41. data/lib/private_please/reporter/base.rb +0 -14
  42. data/lib/private_please/reporter/data_compiler.rb +0 -82
  43. data/lib/private_please/reporter/helpers/options_helpers.rb +0 -37
  44. data/lib/private_please/reporter/helpers/text_table_helpers.rb +0 -9
  45. data/lib/private_please/reporter/simple_text.rb +0 -18
  46. data/lib/private_please/reporter/templates/simple.txt.erb +0 -80
  47. data/lib/private_please/reporter.rb +0 -8
  48. data/lib/private_please/ruby_backports.rb +0 -22
  49. data/lib/private_please/storage/calls_store.rb +0 -41
  50. data/lib/private_please/storage/candidates_store.rb +0 -52
  51. data/lib/private_please/storage/methods_names.rb +0 -10
  52. data/lib/private_please/storage/methods_names_bucket.rb +0 -69
  53. data/lib/private_please/storage.rb +0 -8
  54. data/lib/private_please/tracking/extension.rb +0 -12
  55. data/lib/private_please/tracking/instrumentor.rb +0 -49
  56. data/lib/private_please/tracking/instruments_all_methods_below.rb +0 -28
  57. data/lib/private_please/tracking/instruments_automatically_all_methods_in_all_classes.rb +0 -68
  58. data/lib/private_please/tracking/line_change_tracker.rb +0 -26
  59. data/lib/private_please/tracking/load_utils/gem_utils.rb +0 -49
  60. data/lib/private_please/tracking/load_utils/standard_lib_utils.rb +0 -38
  61. data/lib/private_please/tracking/load_utils.rb +0 -32
  62. data/lib/private_please/tracking/utils.rb +0 -34
  63. data/lib/private_please/tracking.rb +0 -49
  64. data/sample.rb +0 -68
  65. data/spec/01_tracking_candidate_methods/excluding_gems_and_standard_libraries_spec.rb +0 -31
  66. data/spec/01_tracking_candidate_methods/explicitely_with_the_private_please_command_spec.rb +0 -118
  67. data/spec/01_tracking_candidate_methods/load_utils_spec.rb +0 -40
  68. data/spec/01_tracking_candidate_methods/systematically_in_auto_mode_spec.rb +0 -185
  69. data/spec/03_logging_calls_on_candidate_methods_spec.rb +0 -37
  70. data/spec/04_instrumented_program_activity_observation_result_spec.rb +0 -86
  71. data/spec/05_reporting/report_table_spec.rb +0 -51
  72. data/spec/06_at_exit_spec.rb +0 -18
  73. data/spec/_helpers/assert_helpers.rb +0 -76
  74. data/spec/fixtures/bug_22.rb +0 -17
  75. data/spec/fixtures/bug_30.rb +0 -6
  76. data/spec/fixtures/issue_25.rb +0 -12
  77. data/spec/fixtures/sample_class_for_report.rb +0 -56
  78. data/spec/fixtures/sample_class_with_all_calls_combinations.rb +0 -69
  79. data/spec/sandbox/Gemfile +0 -4
  80. data/spec/sandbox/Gemfile.lock +0 -14
  81. data/spec/sandbox/README.txt +0 -26
  82. data/spec/sandbox/normal.rb +0 -7
  83. data/spec/sandbox/normal_prepended_with_require.rb +0 -8
  84. data/spec/spec_helper.rb +0 -38
  85. data/spec/units/calls_store_spec.rb +0 -15
  86. data/spec/units/candidates_store_spec.rb +0 -55
  87. data/spec/units/reporter/data_compiler_spec.rb +0 -12
  88. data/spec/units/reporter/fixtures/simple_case_1.rb +0 -30
  89. data/spec/units/reporter/fixtures/simple_case_2.rb +0 -55
@@ -1,86 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'PrivatePlease.reporter', 'observing an instrumented program activity' do
4
-
5
- def run_the_instrumented_program
6
- ActivityTest::Simple.new.tap do |o|
7
- o.not_a_candidate_1
8
- o.not_a_candidate_2
9
- o.class.not_a_candidate_c1
10
- o.bad_candidate_3
11
- o.bad_candidate_6
12
- o.class.bad_candidate_c3
13
- end
14
- ActivityTest::Simple2.new.bad_candidate_too
15
- ActivityTest::Simple2 .bad_candidate_c_too
16
- end
17
-
18
- before do
19
-
20
- module ActivityTest
21
- class Simple
22
- def not_a_candidate_1; bad_candidate_3 end
23
- def not_a_candidate_2; good_candidate_7 end
24
- def self.not_a_candidate_c1;
25
- good_candidate_c2
26
- end
27
- private_please
28
- def bad_candidate_3; good_candidate_4 end
29
- def good_candidate_4; good_candidate_5 end
30
- def good_candidate_5; bad_candidate_6 end
31
- def bad_candidate_6; good_candidate_7 end
32
- def good_candidate_7; end
33
- def ignored_8 ; 'never called' end
34
- def self.ignored_c9 ; 'never called' end
35
- def self.good_candidate_c2; end
36
- def self.bad_candidate_c3; end
37
- end
38
-
39
- class Simple2
40
- private_please
41
- def bad_candidate_too; end
42
- def ignored_2; 'never called' end
43
- def self.ignored_c3; 'never called' end
44
- def self.bad_candidate_c_too; end
45
- end
46
- end unless defined?(ActivityTest::Simple)
47
- end
48
-
49
- # Note: test all in 1 go because testing in bits would fail, and it differs from real usage.
50
- it 'obtains the right info by observing the program activity' do
51
- run_the_instrumented_program
52
- the_report_data = PrivatePlease::Reporter::SimpleText.new(PrivatePlease.candidates_store, PrivatePlease.calls_store).data
53
- {
54
- :good_candidates => the_report_data.good_candidates,
55
- :good_candidates_c => the_report_data.good_candidates_c,
56
- :bad_candidates => the_report_data.bad_candidates,
57
- :bad_candidates_c => the_report_data.bad_candidates_c,
58
- :ignored => the_report_data.never_called_candidates,
59
- :ignored_c => the_report_data.never_called_candidates_c
60
- }.should == {
61
- :good_candidates => {
62
- 'ActivityTest::Simple' => mnames_for([:good_candidate_4, :good_candidate_5, :good_candidate_7])
63
- },
64
- :good_candidates_c => {
65
- 'ActivityTest::Simple' => mnames_for([:good_candidate_c2])
66
- },
67
- :bad_candidates => {
68
- 'ActivityTest::Simple' => mnames_for([:bad_candidate_3, :bad_candidate_6]),
69
- 'ActivityTest::Simple2' => mnames_for([:bad_candidate_too])
70
- },
71
- :bad_candidates_c => {
72
- 'ActivityTest::Simple' => mnames_for([:bad_candidate_c3]),
73
- 'ActivityTest::Simple2' => mnames_for([:bad_candidate_c_too])
74
- },
75
- :ignored => {
76
- 'ActivityTest::Simple' => mnames_for([:ignored_8]),
77
- 'ActivityTest::Simple2' => mnames_for([:ignored_2])
78
- },
79
- :ignored_c => {
80
- 'ActivityTest::Simple' => mnames_for([:ignored_c9]),
81
- 'ActivityTest::Simple2' => mnames_for([:ignored_c3])
82
- }
83
- }
84
- end
85
-
86
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PrivatePlease::Report::Table do
4
- let(:col_1) { %w(a b c) }
5
- let(:col_2) { %w(X Y Z) }
6
-
7
- def table(col_1, col_2)
8
- PrivatePlease::Report::Table.new(col_1, col_2)
9
- end
10
- #------------------------------------------------------------------------------
11
-
12
- it 'wraps 2 columns of data' do
13
- t = table(col_1, col_2)
14
- t.col_1.should == col_1
15
- t.col_2.should == col_2
16
- end
17
-
18
- it 'pads with nil whichever column is shorter' do
19
- table(['1'], %w(a b c)).tap do |t|
20
- t.col_1.should == ['1', nil, nil]
21
- t.col_2.should == %w(a b c)
22
- end
23
- table(%w(a b c), ['1']).tap do |t|
24
- t.col_1.should == %w(a b c)
25
- t.col_2.should == ['1', nil, nil]
26
- end
27
-
28
- end
29
-
30
- example '#rows returns an array of [String, String]' do
31
- t = table(['1', '2'], col_2)
32
- t.rows.should == [
33
- ['1', 'X'],
34
- ['2', 'Y'],
35
- [nil, 'Z'],
36
- ]
37
- end
38
-
39
- example '#empty?' do
40
- table(['1', '2'], []).should_not be_empty
41
- table([], ['1', '2']).should_not be_empty
42
- table([], [] ).should be_empty
43
- end
44
-
45
- example '#longest_value_length' do
46
- table(['a', '12345'], ['b', 'c']).longest_value_length.should == '12345'.length
47
- table(['b'], ['a', '12345'] ).longest_value_length.should == '12345'.length
48
- table([], [] ).longest_value_length.should == 0
49
- end
50
-
51
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'at_exit() behaviour' do
4
-
5
- it 'prints the PP simpletext report to $stdout (when not in test mode)' do
6
- $private_please_tests_are_running = false
7
- PrivatePlease::Reporter::SimpleText.stub(:new => stub(:text => '<the-report-text>'))
8
- $stdout.
9
- should_receive(:puts).
10
- with('<the-report-text>')
11
- begin
12
- PrivatePlease.at_exit
13
- ensure
14
- $private_please_tests_are_running = true
15
- end
16
- end
17
-
18
- end
@@ -1,76 +0,0 @@
1
- #----------
2
-
3
- def mnames_for(args)
4
- PrivatePlease::Storage::MethodsNames.new(Array(args))
5
- end
6
-
7
- #----------
8
-
9
- class Hash
10
- def to_methods_names_bucket
11
- PrivatePlease::Storage::MethodsNamesBucket.new.tap do |bucket|
12
- each_pair do |class_name, method_names_as_a|
13
- method_names_as_a.each do |method_name|
14
- bucket.add_method_name(class_name, method_name)
15
- end
16
- end
17
- end
18
- end
19
- end
20
-
21
-
22
- def assert_classes_names(expected)
23
- PrivatePlease.candidates_store.classes_names.should == expected
24
- end
25
-
26
- def assert_instance_methods_candidates(raw_expected)
27
- expected = raw_expected.to_methods_names_bucket if raw_expected.is_a?(Hash)
28
- PrivatePlease.candidates_store.instance_methods.should == expected
29
- end
30
-
31
- def assert_class_methods_candidates(raw_expected)
32
- expected = raw_expected.to_methods_names_bucket if raw_expected.is_a?(Hash)
33
- PrivatePlease.candidates_store.class_methods.should == expected
34
- end
35
- alias :assert_singleton_methods_candidates :assert_class_methods_candidates
36
-
37
- #----------
38
-
39
- def assert_calls_detected(expected)
40
- calls_db = PrivatePlease.calls_store
41
- { :inside => calls_db.internal_calls,
42
- :inside_c => calls_db.class_internal_calls,
43
- :outside => calls_db.external_calls,
44
- :outside_c => calls_db.class_external_calls
45
- }.should == expected
46
- end
47
-
48
- NO_CALLS_OBSERVED = {}
49
-
50
- def assert_no_calls_detected
51
- assert_calls_detected :inside => NO_CALLS_OBSERVED, :outside => NO_CALLS_OBSERVED,
52
- :inside_c => NO_CALLS_OBSERVED, :outside_c => NO_CALLS_OBSERVED
53
- end
54
-
55
- #----------
56
- # Reporter::DataCompiler :
57
- #----------
58
-
59
- def run_and_inspect(fixture_file, __file__)
60
- PrivatePlease.pp_automatic_mode_enable
61
- load File.expand_path(File.dirname(__file__) + "/fixtures/#{fixture_file}")
62
- c = PrivatePlease::Reporter::DataCompiler.new(PrivatePlease.candidates_store, PrivatePlease.calls_store)
63
- data = c.compile_data
64
- end
65
-
66
- def assert_report_data_matches(data, expected_results = $expected_results)
67
- ['candidates_classes_names', data.candidates_classes_names ].should == ['candidates_classes_names', expected_results[:candidates_classes_names ]]
68
- ['good_candidates', data.good_candidates ].should == ['good_candidates', expected_results[:good_candidates ]]
69
- ['bad_candidates', data.bad_candidates ].should == ['bad_candidates', expected_results[:bad_candidates ]]
70
- ['never_called_candidates', data.never_called_candidates ].should == ['never_called_candidates', expected_results[:never_called_candidates ]]
71
- ['good_candidates_c', data.good_candidates_c ].should == ['good_candidates_c', expected_results[:good_candidates_c ]]
72
- ['bad_candidates_c', data.bad_candidates_c ].should == ['bad_candidates_c', expected_results[:bad_candidates_c ]]
73
- ['never_called_candidates_c', data.never_called_candidates_c].should == ['never_called_candidates_c', expected_results[:never_called_candidates_c]]
74
- end
75
-
76
- #----------
@@ -1,17 +0,0 @@
1
- load File.expand_path File.dirname(__FILE__) + '/../../doc/fixtures/fixture_helper.rb'
2
-
3
- module Extra
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- end
7
- module ClassMethods
8
- def a_class_method_via_module_Extra ; end
9
- end
10
- end
11
-
12
-
13
- class Simple
14
- include Extra
15
- end
16
- Simple.a_class_method_via_module_Extra
17
-
@@ -1,6 +0,0 @@
1
- # Fails with 1.8.7, works with 1.9.3, 2.0.0
2
- require 'private_please'
3
- require 'rubygems'
4
- require 'coderay'
5
- print CodeRay.scan('puts "Hello, world!"', :ruby).inspect # OK
6
- print CodeRay.scan('puts "Hello, world!"', :ruby).html # FAIL
@@ -1,12 +0,0 @@
1
- require 'private_please'
2
-
3
- require 'csv' ## <<==
4
- CSV.generate("/tmp/#{Time.now}") { |_| } ## <<==
5
-
6
- class Foo
7
- def initialize; foo end
8
- def foo ;end
9
- end
10
- Foo.new
11
-
12
- puts PrivatePlease.candidates_store.classes_names
@@ -1,56 +0,0 @@
1
- require 'private_please'
2
-
3
- module ReportSample
4
- ###########################################
5
- class Simple # Internal calls : #
6
- # -> called methods are _GOOD CANDIDATES_ #
7
- def make_internal_calls ###########################################
8
- instance_m_1 # i -> i
9
- self.class.class_m_1 # i -> C
10
- self.class.c_make_internal_method_calls # i -> C --> C
11
- end # +-> i
12
-
13
- def self.c_make_internal_method_calls #
14
- class_m_1 # C -> C
15
- new.instance_m_2 # C -> i
16
- end #
17
- end
18
-
19
- #######################################################
20
- class AnotherClass # External calls (would fail if methods were private) #
21
- # -> called methods are _BAD CANDIDATES_ #
22
- def make_external_calls #######################################################
23
- Simple.new.instance_m_1 # i -> i
24
- Simple .class_m_1 # i -> C
25
- self.class.c_make_external_calls # i -> C -> i
26
- end # -> C
27
- def self.c_make_external_calls #
28
- Simple.new.instance_m_1 # C -> i
29
- Simple .class_m_1 # C -> C
30
- end #
31
- def call_the_candidate_from_inside_and_outside
32
- make_external_calls
33
- Simple.new.make_internal_calls
34
- end
35
- end
36
-
37
- #-----------------------------------------------------------------------------------------------------------------------
38
- class Simple
39
- def self.not_a_candidate_c1;
40
- class_m_2
41
- end
42
-
43
- private_please
44
- def instance_m_1; end
45
- def instance_m_2; end
46
-
47
- def self.class_m_1;
48
- class_m_2
49
- end
50
- def self.class_m_2; end
51
-
52
- def never_called_1; end
53
- def self.class_never_called_1; end
54
- end
55
- end unless defined?(ReportSample::Simple)
56
- #-----------------------------------------------------------------------------------------------------------------------
@@ -1,69 +0,0 @@
1
- module CallsSample
2
- ###########################################
3
- class Simple # Internal calls : #
4
- # -> called methods are _GOOD CANDIDATES_ #
5
- def make_internal_calls ###########################################
6
- instance_m_1 # i -> i
7
- self.class.class_m_1 # i -> C
8
- self.class.c_make_internal_method_calls # i -> C --> C
9
- end # +-> i
10
-
11
- def self.c_make_internal_method_calls #
12
- class_m_1 # C -> C
13
- new.instance_m_2 # C -> i
14
- end #
15
- end
16
-
17
- #######################################################
18
- class AnotherClass # External calls (would fail if methods were private) #
19
- # -> called methods are _BAD CANDIDATES_ #
20
- def make_external_calls #######################################################
21
- Simple.new.instance_m_1 # i -> i
22
- Simple .class_m_1 # i -> C
23
- self.class.c_make_external_calls # i -> C -> i
24
- end # -> C
25
- def self.c_make_external_calls #
26
- Simple.new.instance_m_1 # C -> i
27
- Simple .class_m_1 # C -> C
28
- end #
29
- def call_the_candidate_from_inside_and_outside
30
- make_external_calls
31
- CallsSample::Simple.new.make_internal_calls
32
- end
33
- end
34
-
35
- #-----------------------------------------------------------------------------------------------------------------------
36
- module Extra ; private_please end # <<=== Pre-instrument.
37
- module Extra::ClassMethods ; private_please end # <<=== Pre-instrument.
38
-
39
- module Extra
40
- def self.included(base)
41
- base.extend(ClassMethods)
42
- end
43
- def an_instance_method ; end
44
- module ClassMethods
45
- def a_class_method_via_module_Extra ; end
46
- end
47
- end
48
-
49
-
50
- class Simple
51
- def self.not_a_candidate_c1;
52
- class_m_2
53
- end
54
-
55
- private_please
56
- include Extra
57
- def instance_m_1; end
58
- def instance_m_2; end
59
-
60
- def self.class_m_1;
61
- class_m_2
62
- end
63
- def self.class_m_2; end
64
-
65
- def never_called_1; end
66
- def self.class_never_called_1; end
67
- end
68
- #-----------------------------------------------------------------------------------------------------------------------
69
- end unless defined?(CallsSample::Simple)
data/spec/sandbox/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- # A sample Gemfile
2
- source "https://rubygems.org"
3
-
4
- gem 'private_please', :path => '../..'
@@ -1,14 +0,0 @@
1
- PATH
2
- remote: ../..
3
- specs:
4
- private_please (0.0.4rc)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
-
10
- PLATFORMS
11
- ruby
12
-
13
- DEPENDENCIES
14
- private_please!
@@ -1,26 +0,0 @@
1
- To inspect the program
2
- normal.rb
3
- with PrivatePlease, launch it one of these ways :
4
-
5
- $ ruby -rubygems -e "require 'private_please' ; load 'normal.rb'"
6
- or
7
- $ bundle exec ruby -e "require 'private_please' ; load 'normal.rb'"
8
-
9
- You can also insert the
10
- require 'private_please'
11
- code in the program itself. (see normal_prepended_with_require.rb, line 3)
12
-
13
-
14
- ruby normal.rb
15
- ->
16
- ruby -rubygems -e "require 'private_please' ; load 'normal.rb'"
17
- ruby -rubygems simple_with_require.rb
18
-
19
-
20
- be ruby normal.rb
21
- ->
22
- be ruby -e "require 'private_please' ; load 'normal.rb'"
23
- be ruby simple_with_require.rb
24
-
25
-
26
-