Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ruby 3.4.0 branch coverage #1113

Open
bkuhlmann opened this issue Oct 31, 2024 · 2 comments
Open

Fix Ruby 3.4.0 branch coverage #1113

bkuhlmann opened this issue Oct 31, 2024 · 2 comments

Comments

@bkuhlmann
Copy link

bkuhlmann commented Oct 31, 2024

Why

Hello. 👋 With Ruby 3.4.0, Preview 2, I'm experiencing the following issue when running my RSpec test suite:

Assertion failed: (cursor >= list->start), function pm_newline_list_line_column, file pm_newline_list.c, line 93.
Abort trap: 6

How

To reproduce, run the following:

git clone https://github.com/bkuhlmann/core.git
cd core
bundle install
rspec

As a workaround, you can make SimpleCov work by doing the following:

  1. Within the core project directory, open spec/spec_helper.rb in your editor.
  2. Delete this line: enable_coverage :branch.
  3. Delete this line: minimum_coverage_by_file line: 95, branch: 95
  4. Save and exit your editor and then run: rspec

Notice the entire test suite runs as expected and there are no errors reported.

The issue seems to be with enabling branch coverage in Ruby 3.4.0. All of this works fine in Ruby 3.3.0, though.

Notes

Here's what I'm running:

  • Ruby: ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23.6.0]
  • SimpleCov: 0.22.0
  • RSpec: 3.13.0
@Earlopain
Copy link

This seems to be a ruby bug, I openend https://bugs.ruby-lang.org/issues/20866

@bkuhlmann
Copy link
Author

Ah, thanks. 🙇 Will track on Ruby Issues as well.

eightbitraptor added a commit to Shopify/ruby that referenced this issue Nov 20, 2024
This fixes a failed assertion reported to SimpleCov

simplecov-ruby/simplecov#1113

The smallest repro I can make consists of 2 files

test.rb containing the following code:

```
require 'coverage'
Coverage.start(branches: true)
require_relative 'broken.rb'
```

and `broken.rb` containing this

```
@foo&.bar(@baz)
```
eightbitraptor added a commit to Shopify/ruby that referenced this issue Nov 20, 2024
This fixes a failed assertion reported to SimpleCov

simplecov-ruby/simplecov#1113

This can be repro'd as follows:

1. Create a file `test.rb` containing the following code

```
@foo&.(@bar)
```

2. require it with branch coverage enabled

```
ruby -rcoverage -e "Coverage.start(branches: true); require_relative 'test.rb'"
```

The assertion is failing because the Prism compiler is incorrectly
detecting the start and end cursor position of the call site for the
implicit call .()

This patch replicates the parse.y behaviour of setting the default
end_cursor to be the final closing location of the call node.

This behaviour can be verified against `parse.y` by modifying the test
command as follows:

[Bug #20866]

```
ruby --parser=parse.y -rcoverage -e "Coverage.start(branches: true); require_relative 'test.rb'"
```
eightbitraptor added a commit to Shopify/ruby that referenced this issue Nov 20, 2024
This fixes a failed assertion reported to SimpleCov

simplecov-ruby/simplecov#1113

This can be repro'd as follows:

1. Create a file `test.rb` containing the following code

```
@foo&.(@bar)
```

2. require it with branch coverage enabled

```
ruby -rcoverage -e "Coverage.start(branches: true); require_relative 'test.rb'"
```

The assertion is failing because the Prism compiler is incorrectly
detecting the start and end cursor position of the call site for the
implicit call .()

This patch replicates the parse.y behaviour of setting the default
end_cursor to be the final closing location of the call node.

This behaviour can be verified against `parse.y` by modifying the test
command as follows:

```
ruby --parser=parse.y -rcoverage -e "Coverage.start(branches: true); require_relative 'test.rb'"
```

[Bug #20866]
eightbitraptor added a commit to Shopify/ruby that referenced this issue Nov 21, 2024
This fixes a failed assertion reported to SimpleCov

simplecov-ruby/simplecov#1113

This can be repro'd as follows:

1. Create a file `test.rb` containing the following code

```
@foo&.(@bar)
```

2. require it with branch coverage enabled

```
ruby -rcoverage -e "Coverage.start(branches: true); require_relative 'test.rb'"
```

The assertion is failing because the Prism compiler is incorrectly
detecting the start and end cursor position of the call site for the
implicit call .()

This patch replicates the parse.y behaviour of setting the default
end_cursor to be the final closing location of the call node.

This behaviour can be verified against `parse.y` by modifying the test
command as follows:

```
ruby --parser=parse.y -rcoverage -e "Coverage.start(branches: true); require_relative 'test.rb'"
```

[Bug #20866]
eightbitraptor added a commit to ruby/ruby that referenced this issue Nov 21, 2024
This fixes a failed assertion reported to SimpleCov

simplecov-ruby/simplecov#1113

This can be repro'd as follows:

1. Create a file `test.rb` containing the following code

```
@foo&.(@bar)
```

2. require it with branch coverage enabled

```
ruby -rcoverage -e "Coverage.start(branches: true); require_relative 'test.rb'"
```

The assertion is failing because the Prism compiler is incorrectly
detecting the start and end cursor position of the call site for the
implicit call .()

This patch replicates the parse.y behaviour of setting the default
end_cursor to be the final closing location of the call node.

This behaviour can be verified against `parse.y` by modifying the test
command as follows:

```
ruby --parser=parse.y -rcoverage -e "Coverage.start(branches: true); require_relative 'test.rb'"
```

[Bug #20866]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants