Skip to content

Commit f39dce0

Browse files
committed
fix: remove duplicate kernel patch files
1 parent 791e926 commit f39dce0

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
alias t := test
22

33
test:
4-
ruby -Itest test/test_tracer.rb
4+
ruby -Itest test/test_kernel_patches.rb test/test_tracer.rb
55

66
bench pattern="*" write_report="console":
77
ruby test/benchmarks/run_benchmarks.rb '{{pattern}}' --write-report={{write_report}}

codetracer/kernel_patches.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def self.install(tracer)
1414
@@original_methods[:print] = Kernel.instance_method(:print)
1515

1616
Kernel.module_eval do
17+
alias_method :old_p, :p unless method_defined?(:old_p)
18+
alias_method :old_puts, :puts unless method_defined?(:old_puts)
19+
alias_method :old_print, :print unless method_defined?(:old_print)
20+
1721
define_method(:p) do |*args|
1822
loc = caller_locations(1,1).first
1923
@@tracers.each do |t|
@@ -33,7 +37,7 @@ def self.install(tracer)
3337
define_method(:print) do |*args|
3438
loc = caller_locations(1,1).first
3539
@@tracers.each do |t|
36-
t.record_event(loc.path, loc.lineno, args.join("\n"))
40+
t.record_event(loc.path, loc.lineno, args.join)
3741
end
3842
@@original_methods[:print].bind(self).call(*args)
3943
end

test/test_kernel_patches.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def teardown
4646
def test_patching_and_basic_event_recording
4747
Codetracer::KernelPatches.install(@tracer1)
4848

49-
expected_line_p = __LINE__ + 1; p 'hello'
50-
expected_line_puts = __LINE__ + 1; puts 'world'
51-
expected_line_print = __LINE__ + 1; print 'test'
49+
expected_line_p = __LINE__; p 'hello'
50+
expected_line_puts = __LINE__; puts 'world'
51+
expected_line_print = __LINE__; print 'test'
5252

5353
assert_equal 3, @tracer1.events.size
5454

@@ -74,7 +74,7 @@ def test_multiple_tracers
7474
Codetracer::KernelPatches.install(@tracer1)
7575
Codetracer::KernelPatches.install(@tracer2)
7676

77-
expected_line_multi = __LINE__ + 1; p 'multitest'
77+
expected_line_multi = __LINE__; p 'multitest'
7878

7979
assert_equal 1, @tracer1.events.size
8080
assert_equal 1, @tracer2.events.size
@@ -93,7 +93,7 @@ def test_multiple_tracers
9393
@tracer1.clear_events
9494
@tracer2.clear_events
9595

96-
expected_line_one_left = __LINE__ + 1; p 'one left'
96+
expected_line_one_left = __LINE__; p 'one left'
9797

9898
assert_empty @tracer1.events, "Tracer1 should have no events after being uninstalled"
9999
assert_equal 1, @tracer2.events.size
@@ -122,17 +122,17 @@ def test_correct_event_arguments
122122

123123
arg_obj = { key: "value", number: 123 }
124124

125-
expected_line_p_detailed = __LINE__ + 1; p "detailed_p", arg_obj
126-
expected_line_puts_detailed = __LINE__ + 1; puts "detailed_puts", arg_obj.to_s
127-
expected_line_print_detailed = __LINE__ + 1; print "detailed_print", arg_obj.to_s
125+
expected_line_p_detailed = __LINE__; p "detailed_p", arg_obj
126+
expected_line_puts_detailed = __LINE__; puts "detailed_puts", arg_obj.to_s
127+
expected_line_print_detailed = __LINE__; print "detailed_print", arg_obj.to_s
128128

129129
assert_equal 3, @tracer1.events.size
130130

131131
event_p = @tracer1.events[0]
132132
assert_equal __FILE__, event_p[:path], "Path for p mismatch"
133133
assert_equal expected_line_p_detailed, event_p[:lineno], "Line number for p mismatch"
134134
# p calls inspect on each argument and joins with newline if multiple, but here it's one string then obj
135-
assert_equal "\"detailed_p\"\n{key: \"value\", number: 123}", event_p[:content], "Content for p mismatch"
135+
assert_equal "\"detailed_p\"\n{:key=>\"value\", :number=>123}", event_p[:content], "Content for p mismatch"
136136

137137

138138
event_puts = @tracer1.events[1]

0 commit comments

Comments
 (0)