Граф коммитов

69 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 7e51cadc2e Fix method coverage comparisons
Although Ruby's hashes preserve the insertion order, the ordering of
method coverage results is inherently nondeterministic, because they
are collected using `ObjectSpace`.
2023-10-16 09:48:05 +09:00
Yusuke Endoh 4f4c1170bc Revert "Don't reset line coverage for evaled code. (#8330)"
This reverts commit 7e0f5df2f9.

https://bugs.ruby-lang.org/issues/19857#note-7
2023-09-04 19:52:08 +09:00
Samuel Williams 7e0f5df2f9
Don't reset line coverage for evaled code. (#8330)
* Add failing test.
2023-09-04 13:31:25 +12:00
Samuel Williams f5ea43a2e6
More coverage tests & specs. (#7171)
* Add spec for eval and line coverage.

* Add test for main file coverage.
2023-01-22 13:49:13 +13:00
Samuel Williams edd00697a8
Test some missing coverage too. (#7041) 2023-01-19 11:59:51 +13:00
Kevin Murphy b3d330c39e
Coverage.supported? recognizes oneshot_lines mode (#7040)
This adds oneshot_lines as a mode of coverage that is supported.
2022-12-29 21:23:25 +13:00
Yusuke Endoh 4a7d6c2852 Fix false LocalJumpError when branch coverage is enabled
`throw TAG_BREAK` instruction makes a jump only if the continuation of
catch of TAG_BREAK exactly matches the instruction immediately following
the "send" instruction that is currently being executed. Otherwise, it
seems to determine break from proc-closure.

Branch coverage may insert some recording instructions after "send"
instruction, which broke the conditions for TAG_BREAK to work properly.

This change forces to set the continuation of catch of TAG_BREAK
immediately after "send" (or "invokesuper") instruction.

[Bug #18991]
2022-11-08 14:37:08 +09:00
yui-knk e4191ac1ec Change a tab to spaces 2022-10-17 11:30:07 +09:00
Samuel Williams bd2fbd3588
Add `Coverage.supported?` to detect what modes are supported. 2022-09-29 09:44:14 +13:00
Samuel Williams 9dd902b831
Add `eval: true/false` flag to `Coverage.setup`. 2022-09-29 09:44:14 +13:00
Samuel Williams 9434a7333c Enable coverage for eval. 2022-09-22 22:19:12 +12:00
Yusuke Endoh a871fc4d86 Fix a regression of b2e58b02ae
At that commit, I fixed a wrong conditional expression that was always
true.  However, that seemed to have caused a regression. [Bug #18906]

This change removes the condition to make the code always enabled.
It had been enabled until that commit, albeit unintentionally, and even
if it is enabled it only consumes a tiny bit of memory, so I believe it
is harmless. [Bug #18906]
2022-07-11 23:38:37 +09:00
Yusuke Endoh 86e3d77abb
Make Coverage suspendable (#4856)
* Make Coverage suspendable

Add `Coverage.suspend`, `Coverage.resume` and some methods.

[Feature #18176] [ruby-core:105321]
2021-10-25 20:00:51 +09:00
eileencodes 31f4d26273 Check type of instruction - can be INSN or ADJUST
If the type is ADJUST we don't want to treat it like an INSN so we have
to check the type before reading from `insn_info.events`.

[Bug #18001] [ruby-core:104371]

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-06-23 11:34:37 -07:00
Yusuke Endoh a3c8ade1b3 test/coverage/test_coverage.rb: Add a test for [Bug #16967] 2020-06-20 09:28:03 +09:00
Yusuke Endoh f9e5c74cd2 compile.c: stop wrong peephole optimization when covearge is enabled
jump-jump optimization ignores the event flags of the jump instruction
being skipped, which leads to overlook of line events.

This changeset stops the wrong optimization when coverage measurement is
neabled and when the jump instruction has any event flag.

Note that this issue is not only for coverage but also for TracePoint,
and this change does not fix TracePoint.
However, fixing it fundamentally is tough (which requires revamp of
the compiler).  This issue is critical in terms of coverage measurement,
but minor for TracePoint (ko1 said), so we here choose a stopgap
measurement.

[Bug #15980] [Bug #16397]

Note for backporters: this changeset can be viewed by `git diff -w`.
2019-12-04 10:40:54 +09:00
ktsj 9738f96fcf Introduce pattern matching [EXPERIMENTAL]
[ruby-core:87945] [Feature #14912]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 06:48:03 +00:00
nobu 1bc6c3f407 Revert r63383, r63248 "compile.c: copy a short insn with leave"
When copying `leave` insn, TRACE also should be copied if it is
present, but this optimization is trivial and not worth the
complexity.  [ruby-core:91366] [Bug #15578]

4cae5353c0
5afd479de6

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-01 05:11:08 +00:00
mame 9613af6f34 compile.c (iseq_set_sequence): fix branch coverage table
Not only TRACE_ELEMENT but also INSN_ELEMENT may have events.
The old pc2branchindex was created using only events of TRACE_ELEMENTs.
This change uses events of INSN_ELEMENTs too for pc2branchindex table.

[Bug #15476]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 03:03:17 +00:00
mame d58bada6cc compile.c: support branch coverage for `a&.foo = 1`
[Bug #15475]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 01:50:57 +00:00
mame 4130969ea1 Revert r66670 because of wrong ticket number
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 01:47:14 +00:00
mame 67a257cac0 compile.c: support branch coverage for `a&.foo = 1`
[Bug #15476]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 01:41:23 +00:00
mame ab2da43ce4 ext/coverage/lib/coverage.rb (Coverage.line_stub): use only line events
It wrongly used all linenos of ISeq#trace_points which includes not only
line events but also call, return, and other events.  So, the result
included some linenos that can not be covered at all by line coverage.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-20 10:17:37 +00:00
mame 47ea999b46 ext/coverage/: add the oneshot mode
This patch introduces "oneshot_lines" mode for `Coverage.start`, which
checks "whether each line was executed at least once or not", instead of
"how many times each line was executed".  A hook for each line is fired
at most once, and after it is fired, the hook flag was removed; it runs
with zero overhead.

See [Feature #15022] in detail.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20 05:33:04 +00:00
mame 100bf27574 compile.c: remove tracecoverage instruction for line coverage
Line coverage was based on special instruction "tracecoverage".
Now, instead, it uses the mechanism of trace hook [Feature #14104].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22 11:09:47 +00:00
mame d65f7458bc parse.y: remove coverage-related code fragments
The code fragments that initializes coverage data were scattered into
both parse.y and compile.c.  parse.y allocated a coverage data, and
compile.c initialize the data.

To remove this cross-cutting concern, this change moves the allocation
from "coverage" function of parse.y to "rb_iseq_new_top" of iseq.c.
For the sake, parse.y just counts the line number of the original source
code, and the number is passed via rb_ast_body_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22 10:38:56 +00:00
mame 799db969e9 test/coverage/test_coverage.rb: make the expected value the same as 2.4
A follow up of r61350

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-20 04:45:05 +00:00
mame 2e24a66b88 iseq.c (finish_iseq_build): fix coverage leakage [Bug #14191]
Before this change, coverage.so had failed to measure some multiple-line
code fragments.  This is because removing trace instructions (#14104)
changed TracePoint's lineno (new lineno), and coverage counter array was
based on old lineno.
This change initializes coverage counter array based on new lineno.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-18 02:44:36 +00:00
yui-knk bf2321412a ext/coverage/coverage.c: Add test cases
* ext/coverage/coverage.c (test_method_coverage_for_define_method):
  Add test cases for method coverages which test do-end block
  define_method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12 13:19:40 +00:00
mame 9b1d8ab7d0 ext/coverage/coverage.c: remove COVERAGE_EXPERIMENTAL_MODE
A NEWS entry is also added.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12 00:20:58 +00:00
mame f6556c5c39 ext/coverage/coverage.c: method coverage has column info. of method def.
This change makes method coverage result have not only first lineno of
method defintion, but also code range (i.e. first lineno, first column,
last lineno, and last column).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61026 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-05 08:56:51 +00:00
mame 0a6816ecd7 Revamp method coverage to support define_method
Traditionally, method coverage measurement was implemented by inserting
`trace2` instruction to the head of method iseq.  So, it just measured
methods defined by `def` keyword.

This commit drastically changes the measuring mechanism of method
coverage; at `RUBY_EVENT_CALL`, it keeps a hash from rb_method_entry_t*
to runs (i.e., it counts the runs per method entry), and at
`Coverage.result`, it creates the result hash by enumerating all
`rb_method_entry_t*` objects (by `ObjectSpace.each_object`).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-05 07:16:42 +00:00
yui-knk 7fbab01f77 Add a last location to branch coverage
* compile.c (DECL_BRANCH_BASE, ADD_TRACE_BRANCH_COVERAGE): Add
  a last location to arguments.

* compile.c (compile_if, compile_case, compile_case2, compile_loop, iseq_compile_each0):
  Pass a last location to macros.

* ext/coverage/coverage.c (branch_coverage): Add a last location to
  a return value.

* test/coverage/test_coverage.rb: Follow-up these changes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16 03:36:20 +00:00
yui-knk 8bbdbf9e75 Add test cases for branch coverage
* test/coverage/test_coverage.rb (test_branch_coverage_for_while_statement):
  Add test cases for modifier while/until.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 13:25:59 +00:00
yui-knk 588ac3ee1f Add test cases for branch coverage
* test/coverage/test_coverage.rb (test_branch_coverage_for_if_statement):
  Add a test case for ternary operator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 14:13:50 +00:00
yui-knk ef29f8db80 Add test cases for branch coverage
* test/coverage/test_coverage.rb (test_branch_coverage_for_if_statement):
  Add test cases for modifier if/unless.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 13:58:55 +00:00
yui-knk ecdac92e50 Add test cases for branch coverage
* test/coverage/test_coverage.rb (test_branch_coverage_for_if_statement):
  Add test cases for if/unless without else clauses.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 13:49:41 +00:00
yui-knk de482ab143 test/coverage/test_coverage.rb: Use `<<~` to ease to calculate column of target codes
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 13:34:24 +00:00
yui-knk 755dd9f461 Add column numbers to branch coverage
* compile.c (DECL_BRANCH_BASE, ADD_TRACE_BRANCH_COVERAGE): Add
  column to arguments.

* compile.c (compile_if, compile_case, compile_when, compile_loop, iseq_compile_each0):
  Pass column numbers to macros.

* ext/coverage/coverage.c (branch_coverage): Add column numbers to
  a return value.

* test/coverage/test_coverage.rb: Follow-up these changes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 13:18:40 +00:00
mame 6975993882 test/coverage/test_coverage.rb: Refactor coverage tests.
Add `assert_coverage` to invoke Ruby script under coverage measurement
and to compare the result with an expected value.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-23 23:58:24 +00:00
yui-knk 7da13f05fd Enable to take branch coverages for safe method invocations
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-23 00:17:35 +00:00
mame 3c8c17d30d Introduce NODE_UNLESS for branch coverage
`unless` statement was a syntactic sugar for `if` statement,
which made the result of branch coverage hard to understand.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 05:27:02 +00:00
mame 78cf46078e Add method coverage
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 05:12:34 +00:00
mame 3155da024c Fix the lineno of case statement that has no expression
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 04:42:23 +00:00
mame 1f7abf7283 Add branch coverage for case-when statement
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 04:32:58 +00:00
mame 16ab236b88 Add branch coverage for while and until statements
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 03:36:05 +00:00
mame ce570370f0 Add branch coverage for if statement
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 03:25:36 +00:00
nobu d446f15c97 compile.c: pop coverage trace
* compile.c (iseq_compile_each0): pop trace for coverage only and
  clear its corresponding line.  [ruby-core:82726] [Bug #13886]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-10 16:19:40 +00:00
nobu 0cbcb5f580 test_coverage.rb: suppress warnings
* test/coverage/test_coverage.rb (test_nonpositive_linenumber):
  suppress method redefinition warnings.

* test/coverage/test_coverage.rb (test_eval): suppress literal in
  void context warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-03 00:13:15 +00:00
nobu 3b55682529 test_coverage.rb: use real path
* test/coverage/test_coverage.rb (test_restarting_coverage): use
  real directory path for the case $TMPDIR contains symlinks.  on
  macOS, it is defaulted to a path under /var which is a symlink
  to /private/var.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-03 00:02:23 +00:00