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

Many "instance variable not initialized" warnings #106

Closed
gioele opened this issue Jan 25, 2012 · 13 comments
Closed

Many "instance variable not initialized" warnings #106

gioele opened this issue Jan 25, 2012 · 13 comments

Comments

@gioele
Copy link

gioele commented Jan 25, 2012

SimpleCov version 0.5.4, when used with ruby 1.9.3-p0, produces a series of warning:

lib/simplecov/configuration.rb:152: warning: instance variable @use_merging not initialized
lib/simplecov/configuration.rb:27: warning: instance variable @coverage_dir not initialized
lib/simplecov-html.rb:36: warning: instance variable @asset_output_path not initialized
lib/simplecov/configuration.rb:141: warning: instance variable @project_name not initialized
lib/simplecov/source_file.rb:86: warning: instance variable @lines not initialized
lib/simplecov/configuration.rb:84: warning: instance variable @nocov_token not initialized
lib/simplecov/source_file.rb:86: warning: instance variable @lines not initialized
lib/simplecov/source_file.rb:86: warning: instance variable @lines not initialized
lib/simplecov/result.rb:61: warning: instance variable @covered_lines not initialized
lib/simplecov/result.rb:73: warning: instance variable @missed_lines not initialized
@colszowka
Copy link
Collaborator

I don't think that Ruby 1.9.3 is the issue here as it builds fine on 1.9.3 on Travis CI (see http://travis-ci.org/#!/colszowka/simplecov/jobs/283900) and also works fine for me. Do you run Ruby with a very high warning level? Obviously your Ruby gives warnings for Ruby code that is perfectly valid (in my opinion) as accessing potentially uninitialized instance vars using @foo is a common use case in Ruby.

@gioele
Copy link
Author

gioele commented Jan 27, 2012

I am using the standard ruby 1.9.3 provided by rvm install ruby-1.9.3. It looks like $-W is 2, but I have not set it, so I suppose that it is the default value set by rspec.

@colszowka
Copy link
Collaborator

Hm, for me $-W gives 1.

@colszowka
Copy link
Collaborator

Please also check out http://www.ruby-forum.com/topic/199672 and http://stackoverflow.com/questions/2098742/ruby-instance-variable-not-initialized-warning for further info.

I'm not sure whether this should be fixed in SimpleCov as this by default does not cause warnings and it's perfectly valid ruby code. Initializing all those variables might be a bigger tradeoff for source code readbility than having it cause harmless warnings in verbose ruby mode. Keeping this open for now.

@gioele
Copy link
Author

gioele commented Jan 27, 2012

For some of these instance variable the code was return @var unless @var.nil?. If you use normal variable instead of instance variables (return var unless var.nil?) you will get a fatal error.

@gioele
Copy link
Author

gioele commented Jan 27, 2012

In my pull release I did not fix the @use_merging code. I cannot understand what the code wanted to do and any of my solutions resulted in errors being raised by the test suite.

Could you have a look at #use_merging it to make sure that it is actually doing what it is supposed to do?

@gioele
Copy link
Author

gioele commented Jan 27, 2012

In my case the default warning level seems to be 2:

$ ruby --help | grep warn
  -w              turn warnings on for your script
  -W[level]       set warning level; 0=silence, 1=medium, 2=verbose (default)

@cgriego
Copy link

cgriego commented Jan 30, 2012

Simplecov should be able to run without generating Ruby warnings. With simplecov triggering Ruby warnings, it makes it impossible for library authors using simplecov to measure both coverage and ensure their own code is free of warnings at the same time. Rails and RSpec have both been able to remove all warnings from their own large code bases.

@gioele
Copy link
Author

gioele commented Jan 31, 2012

@colszowka is there a problem with my pull request? Should I change it somehow? The commits in it fix most of these warning with minimal code changes.

@mvz
Copy link
Contributor

mvz commented Mar 10, 2012

What @cgriego said.

@gioele, it might help to set the warning level explicitely in the rake task, so the effect of your changes is more clearly seen.

@gioele
Copy link
Author

gioele commented Mar 10, 2012

@mvz, are you referring to my pull request #108? I am using the maximum warning level and the changes contained in that pull request remove most of the warnings. It also passes all tests in the test suit cleanly.

@mvz
Copy link
Contributor

mvz commented Mar 10, 2012

@gioele, yes, I was commenting on #108.

I meant adding something like t.ruby_opts += ["-W2"] to the task definition in the Rakefile, to make sure that everyone else running the tests also uses the maximum warning level, and hence sees the effect of your changes.

How are you currently setting the warning level?

@colszowka
Copy link
Collaborator

Ok guys, merged @mvz 's pull request, so the warnings should be reduced now. Although I personally think Ruby is being slightly ridiculous with this particular warning I can see that people running their test suite at a higher warning level than I do don't want a test tool like simplecov to mess up their beautiful warning-free output.

v0.6.4 should be released today or tomorrow. Thanks for your patience and effort!

jperkin pushed a commit to TritonDataCenter/pkgsrc-legacy that referenced this issue Dec 9, 2013
v0.6.4, 2012-05-10 ([changes](simplecov-ruby/simplecov@v0.6.3...v0.6.4))
-------------------

  * [BUGFIX] Encoding issues with ISO-8859-encoded source files fixed.
    See simplecov-ruby/simplecov#117. (thanks to @Deradon)
  * [BUGFIX] Ensure ZeroDivisionErrors won't occur when calculating the coverage result, which previously
    could happen in certain cases. See simplecov-ruby/simplecov#128. (thanks to @japgolly)
  * [REFACTORING] Changed a couple instance variable lookups so SimpleCov does not cause a lot of warnings when
    running ruby at a higher warning level. See simplecov-ruby/simplecov#106 and
    simplecov-ruby/simplecov#119. (thanks to @mvz and @gioele)


v0.6.3, 2012-05-10 ([changes](simplecov-ruby/simplecov@v0.6.2...v0.6.3))
-------------------

  * [BUGFIX] Modified the API-changes for newer multi_json versions introduced with #122 and v0.6.2 so
    they are backwards-compatible with older multi_json gems in order to avoid simplecov polluting
    the multi_json minimum version requirement for entire applications.
    See simplecov-ruby/simplecov#132
  * Added appraisal gem to the test setup in order to run the test suite against both 1.0 and 1.3
    multi_json gems and ensure the above actually works :)
jperkin pushed a commit to TritonDataCenter/pkgsrc-legacy that referenced this issue Dec 9, 2013
Make this package to Ruby 1.9.3 only.

v0.7.1, 2012-10-12 ([changes](simplecov-ruby/simplecov@v0.7.0...v0.7.1))
-------------------

  * [BUGFIX] The gem packages of 0.7.0 (both simplecov and simplecov-html) pushed to Rubygems had some file
    permission issues, leading to problems when installing SimpleCov in a root/system Rubygems install and then
    trying to use it as a normal user (see simplecov-ruby/simplecov#171, thanks @envygeeks
    for bringing it up). The gem build process has been changed to always enforce proper permissions before packaging
    to avoid this issue in the future.


v0.7.0, 2012-10-10 ([changes](simplecov-ruby/simplecov@v0.6.4...v0.7.0))
-------------------

  * [FEATURE] The new `maximum_coverage_drop` and `minimum_coverage` now allow you to fail your build when the
    coverage dropped by more than what you allowed or is below a minimum value required. Also, `refuse_coverage_drop` disallows
    any coverage drops between test runs.
    See simplecov-ruby/simplecov#151, simplecov-ruby/simplecov#11,
    simplecov-ruby/simplecov#90, and simplecov-ruby/simplecov#96 (thanks to @infertux)
  * [FEATURE] SimpleCov now ships with a built-in MultiFormatter which allows the easy usage of multiple result formatters at
    the same time without the need to write custom wrapper code.
    See simplecov-ruby/simplecov#158 (thanks to @nikitug)
  * [BUGFIX] The usage of digits, hyphens and underscores in group names could lead to broken tab navigation
    in the default simplecov-html reports. See simplecov-ruby/simplecov-html#14 (thanks to @ebelgarts)
  * [REFACTORING] A few more ruby warnings removed. See simplecov-ruby/simplecov#106 and
    simplecov-ruby/simplecov#139. (thanks to @lukejahnke)
  * A [Pledgie button](simplecov-ruby/simplecov@63cfa99) for those that
    feel generous :)
  * The usual bunch of README fixes and documentation tweaks. Thanks to everyone who contributed those!
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Mar 12, 2014
Make this package to Ruby 1.9.3 only.

v0.7.1, 2012-10-12 ([changes](simplecov-ruby/simplecov@v0.7.0...v0.7.1))
-------------------

  * [BUGFIX] The gem packages of 0.7.0 (both simplecov and simplecov-html) pushed to Rubygems had some file
    permission issues, leading to problems when installing SimpleCov in a root/system Rubygems install and then
    trying to use it as a normal user (see simplecov-ruby/simplecov#171, thanks @envygeeks
    for bringing it up). The gem build process has been changed to always enforce proper permissions before packaging
    to avoid this issue in the future.


v0.7.0, 2012-10-10 ([changes](simplecov-ruby/simplecov@v0.6.4...v0.7.0))
-------------------

  * [FEATURE] The new `maximum_coverage_drop` and `minimum_coverage` now allow you to fail your build when the
    coverage dropped by more than what you allowed or is below a minimum value required. Also, `refuse_coverage_drop` disallows
    any coverage drops between test runs.
    See simplecov-ruby/simplecov#151, simplecov-ruby/simplecov#11,
    simplecov-ruby/simplecov#90, and simplecov-ruby/simplecov#96 (thanks to @infertux)
  * [FEATURE] SimpleCov now ships with a built-in MultiFormatter which allows the easy usage of multiple result formatters at
    the same time without the need to write custom wrapper code.
    See simplecov-ruby/simplecov#158 (thanks to @nikitug)
  * [BUGFIX] The usage of digits, hyphens and underscores in group names could lead to broken tab navigation
    in the default simplecov-html reports. See simplecov-ruby/simplecov-html#14 (thanks to @ebelgarts)
  * [REFACTORING] A few more ruby warnings removed. See simplecov-ruby/simplecov#106 and
    simplecov-ruby/simplecov#139. (thanks to @lukejahnke)
  * A [Pledgie button](simplecov-ruby/simplecov@63cfa99) for those that
    feel generous :)
  * The usual bunch of README fixes and documentation tweaks. Thanks to everyone who contributed those!
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Oct 11, 2014
v0.6.4, 2012-05-10 ([changes](simplecov-ruby/simplecov@v0.6.3...v0.6.4))
-------------------

  * [BUGFIX] Encoding issues with ISO-8859-encoded source files fixed.
    See simplecov-ruby/simplecov#117. (thanks to @Deradon)
  * [BUGFIX] Ensure ZeroDivisionErrors won't occur when calculating the coverage result, which previously
    could happen in certain cases. See simplecov-ruby/simplecov#128. (thanks to @japgolly)
  * [REFACTORING] Changed a couple instance variable lookups so SimpleCov does not cause a lot of warnings when
    running ruby at a higher warning level. See simplecov-ruby/simplecov#106 and
    simplecov-ruby/simplecov#119. (thanks to @mvz and @gioele)


v0.6.3, 2012-05-10 ([changes](simplecov-ruby/simplecov@v0.6.2...v0.6.3))
-------------------

  * [BUGFIX] Modified the API-changes for newer multi_json versions introduced with #122 and v0.6.2 so
    they are backwards-compatible with older multi_json gems in order to avoid simplecov polluting
    the multi_json minimum version requirement for entire applications.
    See simplecov-ruby/simplecov#132
  * Added appraisal gem to the test setup in order to run the test suite against both 1.0 and 1.3
    multi_json gems and ensure the above actually works :)
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Oct 11, 2014
Make this package to Ruby 1.9.3 only.

v0.7.1, 2012-10-12 ([changes](simplecov-ruby/simplecov@v0.7.0...v0.7.1))
-------------------

  * [BUGFIX] The gem packages of 0.7.0 (both simplecov and simplecov-html) pushed to Rubygems had some file
    permission issues, leading to problems when installing SimpleCov in a root/system Rubygems install and then
    trying to use it as a normal user (see simplecov-ruby/simplecov#171, thanks @envygeeks
    for bringing it up). The gem build process has been changed to always enforce proper permissions before packaging
    to avoid this issue in the future.


v0.7.0, 2012-10-10 ([changes](simplecov-ruby/simplecov@v0.6.4...v0.7.0))
-------------------

  * [FEATURE] The new `maximum_coverage_drop` and `minimum_coverage` now allow you to fail your build when the
    coverage dropped by more than what you allowed or is below a minimum value required. Also, `refuse_coverage_drop` disallows
    any coverage drops between test runs.
    See simplecov-ruby/simplecov#151, simplecov-ruby/simplecov#11,
    simplecov-ruby/simplecov#90, and simplecov-ruby/simplecov#96 (thanks to @infertux)
  * [FEATURE] SimpleCov now ships with a built-in MultiFormatter which allows the easy usage of multiple result formatters at
    the same time without the need to write custom wrapper code.
    See simplecov-ruby/simplecov#158 (thanks to @nikitug)
  * [BUGFIX] The usage of digits, hyphens and underscores in group names could lead to broken tab navigation
    in the default simplecov-html reports. See simplecov-ruby/simplecov-html#14 (thanks to @ebelgarts)
  * [REFACTORING] A few more ruby warnings removed. See simplecov-ruby/simplecov#106 and
    simplecov-ruby/simplecov#139. (thanks to @lukejahnke)
  * A [Pledgie button](simplecov-ruby/simplecov@63cfa99) for those that
    feel generous :)
  * The usual bunch of README fixes and documentation tweaks. Thanks to everyone who contributed those!
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

4 participants