simplecov-cobertura icon indicating copy to clipboard operation
simplecov-cobertura copied to clipboard

Circular require

Open pboling opened this issue 1 year ago • 2 comments

Requiring simplecov has the side-effect of running the code in the standard .simplecov config file.

Therefore, since this gem does require "simplecov" users are not able to properly control when the .simplecov file gets run. Additionally it results in a circular require in a scenario where formatters are loaded inside .simplecov, which is a very normal way to setup SimpleCov.

Examples of other simplecov plugins that do not require simplecov

  • simplecov-html
    • https://github.com/simplecov-ruby/simplecov-html/blob/main/lib/simplecov-html.rb
    • This gem never references the SimpleCov namespace
  • simplecov_json_formatter
    • https://github.com/codeclimate-community/simplecov_json_formatter/blob/master/lib/simplecov_json_formatter/source_file_formatter.rb
    • https://github.com/codeclimate-community/simplecov_json_formatter/blob/master/lib/simplecov_json_formatter/result_hash_formatter.rb
    • This gem references the SimpleCov namespace several times, but never requires it. It is assumed that it will have been loaded prior to this gem.
    • I think this is the approach you might want to take with simplecov-cobertura.

Stack Trace for Circular Require, when this gem is required from .simplecov:

/Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82: warning: /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82: warning: loading in progress, circular require considered harmful - /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/simplecov-0.22.0/lib/simplecov.rb
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb:6:in  '<main>'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb:6:in  'select'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb:21:in  'block in <main>'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'block (2 levels) in replace_require'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'require'
        from /Volumes/bsst/src2/oauth/masq2/test/unit/masq/account_mailer_test.rb:1:in  '<top (required)>'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'block (2 levels) in replace_require'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'require'
        from /Volumes/bsst/src2/oauth/masq2/test/test_helper.rb:26:in  '<top (required)>'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'block (2 levels) in replace_require'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'require'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/simplecov-0.22.0/lib/simplecov.rb:470:in  '<top (required)>'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/simplecov-0.22.0/lib/simplecov.rb:470:in  'require_relative'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/simplecov-0.22.0/lib/simplecov/defaults.rb:40:in  '<top (required)>'
        from <internal:kernel>:168:in  'loop'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/simplecov-0.22.0/lib/simplecov/defaults.rb:44:in  'block in <top (required)>'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/simplecov-0.22.0/lib/simplecov/defaults.rb:44:in  'load'
        from /Volumes/bsst/src2/oauth/masq2/.simplecov:1:in  '<top (required)>'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'block (2 levels) in replace_require'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'require'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/kettle-soup-cover-1.0.4/lib/kettle/soup/cover/config.rb:15:in  '<top (required)>'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/simplecov-0.22.0/lib/simplecov/configuration.rb:178:in  'configure'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/docile-1.4.1/lib/docile.rb:46:in  'dsl_eval'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/docile-1.4.1/lib/docile/execution.rb:35:in  'exec_in_proxy_context'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/docile-1.4.1/lib/docile/execution.rb:35:in  'instance_exec'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/kettle-soup-cover-1.0.4/lib/kettle/soup/cover/config.rb:31:in  'block in <top (required)>'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/kettle-soup-cover-1.0.4/lib/kettle/soup/cover.rb:123:in  'load_formatters'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/kettle-soup-cover-1.0.4/lib/kettle/soup/cover.rb:123:in  'each_with_object'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/kettle-soup-cover-1.0.4/lib/kettle/soup/cover.rb:123:in  'each'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/kettle-soup-cover-1.0.4/lib/kettle/soup/cover.rb:124:in  'block in load_formatters'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'block (2 levels) in replace_require'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'require'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/simplecov-cobertura-2.1.0/lib/simplecov-cobertura.rb:1:in  '<top (required)>'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'block (2 levels) in replace_require'
        from /Users/pboling/.asdf/installs/ruby/3.4.2/lib/ruby/3.4.0/bundled_gems.rb:82:in  'require'

pboling avatar Apr 02 '25 23:04 pboling

Any interest in creating a pull request?

jessebs avatar May 05 '25 00:05 jessebs

Sure! I have a significant amount of maintenance to do on my own gems first, but I'll work on this as soon as I can.

pboling avatar May 05 '25 18:05 pboling