Skip to content

Recurse upward looking for .simplecov - #423

Merged
xaviershay merged 1 commit into
simplecov-ruby:masterfrom
alexdowad:config
Nov 29, 2015
Merged

xaviershay merged 1 commit into
simplecov-ruby:masterfrom
alexdowad:config

Conversation

@alexdowad

Copy link
Copy Markdown
Contributor

The SimpleCov documentation states: "To avoid [duplicated configuration], you
can place a file called .simplecov in your project root." However, SimpleCov did
not actually look in the "project root" for this file, unless specially configured
to know where the project root is. Rather, it would simply look in the working
directory. Working directory != project root. (Unfortunately.)

Therefore, when looking for .simplecov, recurse upwards from the working directory
until it is found (or the root directory is reached). This is comparable to the
way that git recurses upwards looking for a .git directory, meaning that you can
use git anywhere in your project root or below.

Since there is no guarantee that you have permissions to read .simplecov, catch
exceptions and display a warning message if one occurs.

@xaviershay

Copy link
Copy Markdown
Collaborator

Prior art:

  • RSpec does not traverse up the directory tree.
  • Git does.

This behaviour seems ok, but I think I'd want RSpec to be consistent (since they're so often used together).

@alexdowad

Copy link
Copy Markdown
Contributor Author

@xaviershay Note that the testing process for a Ruby project is very unlikely to involve running RSpec multiple times, from different subdirectories. git, on the other hand, is very frequently used from a subdirectory.

This patch was prompted by work being done on Racc. Its test suite runs the ./bin/racc script many times, with various inputs, and checks the output. Naturally, ./bin/racc runs with a different working directory than the Rake process which invokes it.

I think that this usecase is not entirely unique to Racc. Many test suites may run Ruby subprocesses, for one reason or another. Those subprocesses may or may not have the same working directory.

The SimpleCov documentation states: "To avoid [duplicated configuration], you
can place a file called .simplecov in your project root." However, SimpleCov did
not actually look in the "project root" for this file, unless specially configured
to know where the project root is. Rather, it would simply look in the working
directory. Working directory != project root. (Unfortunately.)

Therefore, when looking for .simplecov, recurse upwards from the working directory
until it is found (or the root directory is reached). This is comparable to the
way that git recurses upwards looking for a .git directory, meaning that you can
use git anywhere in your project root or below.

Since there is no guarantee that you have permissions to read .simplecov, catch
exceptions and display a warning message if one occurs.
@alexdowad

Copy link
Copy Markdown
Contributor Author

Fixed up the style errors.

@xaviershay

Copy link
Copy Markdown
Collaborator

Last chance for comment, I'm going to merge this later today otherwise.

xaviershay added a commit that referenced this pull request Nov 29, 2015
Recurse upward looking for .simplecov
@xaviershay
xaviershay merged commit 8113d50 into simplecov-ruby:master Nov 29, 2015
jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Dec 2, 2015
0.11.0 2015-11-29 ([changes](simplecov-ruby/simplecov@v0.10.0...v0.10.11))
=================

## Enhancements

* Added `SimpleCov.minimum_coverage_by_file` for per-file coverage thresholds. See [#392](simplecov-ruby/simplecov#392) (thanks @ptashman)
* Added `track_files` configuration option to specify a glob to always include in coverage results, whether or not those files are required. See [#422](simplecov-ruby/simplecov#422) (thanks @hugopeixoto)
* Speed up `root_filter` by an order of magnitude. See [#396](simplecov-ruby/simplecov#396) (thanks @raszi)

## Bugfixes

* Fix warning about global variable `$ERROR_INFO`. See [#400](simplecov-ruby/simplecov#400) (thanks @amatsuda)
* Actually recurse upward looking for `.simplecov`, as claimed by the documentation, rather than only the working directory. See [#423](simplecov-ruby/simplecov#423) (thanks @alexdowad)
msk pushed a commit to msk/pkgsrc that referenced this pull request May 11, 2026
0.11.0 2015-11-29 ([changes](simplecov-ruby/simplecov@v0.10.0...v0.10.11))
=================

## Enhancements

* Added `SimpleCov.minimum_coverage_by_file` for per-file coverage thresholds. See [#392](simplecov-ruby/simplecov#392) (thanks @ptashman)
* Added `track_files` configuration option to specify a glob to always include in coverage results, whether or not those files are required. See [#422](simplecov-ruby/simplecov#422) (thanks @hugopeixoto)
* Speed up `root_filter` by an order of magnitude. See [#396](simplecov-ruby/simplecov#396) (thanks @raszi)

## Bugfixes

* Fix warning about global variable `$ERROR_INFO`. See [#400](simplecov-ruby/simplecov#400) (thanks @amatsuda)
* Actually recurse upward looking for `.simplecov`, as claimed by the documentation, rather than only the working directory. See [#423](simplecov-ruby/simplecov#423) (thanks @alexdowad)
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Oct 13, 2026
0.11.0 2015-11-29 ([changes](simplecov-ruby/simplecov@v0.10.0...v0.10.11))
=================

## Enhancements

* Added `SimpleCov.minimum_coverage_by_file` for per-file coverage thresholds. See [#392](simplecov-ruby/simplecov#392) (thanks @ptashman)
* Added `track_files` configuration option to specify a glob to always include in coverage results, whether or not those files are required. See [#422](simplecov-ruby/simplecov#422) (thanks @hugopeixoto)
* Speed up `root_filter` by an order of magnitude. See [#396](simplecov-ruby/simplecov#396) (thanks @raszi)

## Bugfixes

* Fix warning about global variable `$ERROR_INFO`. See [#400](simplecov-ruby/simplecov#400) (thanks @amatsuda)
* Actually recurse upward looking for `.simplecov`, as claimed by the documentation, rather than only the working directory. See [#423](simplecov-ruby/simplecov#423) (thanks @alexdowad)
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

Successfully merging this pull request may close these issues.

2 participants