@@ -600,6 +600,62 @@ rb_coverage_running(VALUE klass)
600600 * 5. The ending line number the method appears on in the file.
601601 * 6. The ending column number the method appears on in the file.
602602 *
603+ * == Eval \Coverage
604+ *
605+ * Eval coverage can be combined with the coverage types above to track
606+ * coverage for eval.
607+ *
608+ * require "coverage"
609+ * Coverage.start(eval: true, lines: true)
610+ *
611+ * eval(<<~RUBY, nil, "eval 1")
612+ * ary = []
613+ * 10.times do |i|
614+ * ary << "hello" * i
615+ * end
616+ * RUBY
617+ *
618+ * Coverage.result # => {"eval 1" => {lines: [1, 1, 10, nil]}}
619+ *
620+ * Note that the eval must have a filename assigned, otherwise coverage
621+ * will not be measured.
622+ *
623+ * require "coverage"
624+ * Coverage.start(eval: true, lines: true)
625+ *
626+ * eval(<<~RUBY)
627+ * ary = []
628+ * 10.times do |i|
629+ * ary << "hello" * i
630+ * end
631+ * RUBY
632+ *
633+ * Coverage.result # => {"(eval)" => {lines: [nil, nil, nil, nil]}}
634+ *
635+ * Also note that if a line number is assigned to the eval and it is not 1,
636+ * then the resulting coverage will be padded with +nil+ if the line number is
637+ * greater than 1, and truncated if the line number is less than 1.
638+ *
639+ * require "coverage"
640+ * Coverage.start(eval: true, lines: true)
641+ *
642+ * eval(<<~RUBY, nil, "eval 1", 3)
643+ * ary = []
644+ * 10.times do |i|
645+ * ary << "hello" * i
646+ * end
647+ * RUBY
648+ *
649+ * eval(<<~RUBY, nil, "eval 2", -1)
650+ * ary = []
651+ * 10.times do |i|
652+ * ary << "hello" * i
653+ * end
654+ * RUBY
655+ *
656+ * Coverage.result
657+ * # => {"eval 1" => {lines: [nil, nil, 1, 1, 10, nil]}, "eval 2" => {lines: [10, nil]}}
658+ *
603659 * == All \Coverage Modes
604660 *
605661 * You can also run all modes of coverage simultaneously with this shortcut.
0 commit comments