Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

WIP: Update shared context to minimize loaded stdlibs. #179

Merged
merged 5 commits into from
Feb 16, 2015

Conversation

myronmarston
Copy link
Member

Fixes #177.

More to come here -- I have some other ideas -- but I ran out of time this morning and wanted to push what I had to get travis builds going.

/cc @JonRowe

@myronmarston myronmarston force-pushed the allowed-stdlibs branch 3 times, most recently from 4d098af to 68f700d Compare February 12, 2015 07:11
@JonRowe
Copy link
Member

JonRowe commented Feb 12, 2015

Seems... complex? Not sure I grok it atm

@myronmarston
Copy link
Member Author

Seems... complex? Not sure I grok it atm

Which parts are you confused about? I adapted most of this from https://github.com/rspec/rspec-support/blob/master/lib/rspec/support/spec/prevent_load_time_warnings.rb which we'll be removing once core/expectations/mocks have been updated to use this new example group. Notable changes from that are:

  • Besides tracking warnings when all lib files of the gem are loaded, we also track $" (aka $LOADED_FEATURES) which keeps track of everything that's been loaded. We can then use this to enforce a white list of allowed things that a particular project loads. Over time hopefully we can shrink this list and it ensures we think consciously about it before adding a new stdlib dependency.
  • The specs from the other shared example group are so much slower than the typical core/expectations/mocks specs, so I did a few things here to speed things up:
    • When we shell out to load all lib files we have it track both warnings and loaded features as part of the same spawned ruby program -- that way we don't have to load all lib files twice. We do it in a before(:context) hook so that multiple examples can inspect the results.
    • Since spawning the "load all lib files" and "load spec files" ruby programs is all external I/O, I decided to parallelize them with threads. This speeds things up.
  • Now that this shared example group isn't just about preventing warnings, but is more generally about library-wide checks, I decided to add a thing that prevents malformed whitespace as well. I've seen some PRs from time to time where users use tabs instead of spaces or leave trailing whitespace.

Does that explain it better?

@myronmarston myronmarston force-pushed the allowed-stdlibs branch 3 times, most recently from 5ba43eb to f3d3c6c Compare February 15, 2015 01:41
Previously it was required by rspec-core so we didn’t
notice failures due to not requiring it.
@JonRowe
Copy link
Member

JonRowe commented Feb 15, 2015

Ah ok, I didn't realise Ruby tracked requires in that way... TIL.. :D

@myronmarston
Copy link
Member Author

So the appveyor build is failing and I'm not sure how to fix it. The new "loads only a known set of stdlibs" spec fails with:

 Failure/Error: loaded_features = File.read(loaded_features_outfile).split("\n")
Errno::ENOENT:
  No such file or directory - ./loaded_features.txt

The "issues no warnings when loaded" spec fails with:

Failure/Error: expect(lib_file_results).to have_successful_no_warnings_output

  expected: ["", "", 0]
       got: ["", "", 5]

  (compared using ==)

Does anyone have any ideas for how to fix this? I'll probably just tag these as :failing_on_appveyor. I figure it isn't that important to run these specs on windows...I don't think Ruby's warnings are platform-specific, and allowing a whitelist of stdlibs isn't really a platform issue either.

@@ -1,3 +1,5 @@
require 'rbconfig'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The irony of adding an additional piece of standard library while detecting usage of the standard library amuses me ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I noticed that rspec-core loads rbconfig:

https://github.com/rspec/rspec-core/blob/v3.2.0/lib/rspec/core.rb#L5

...but it's not used in rspec-core anywhere. Originally it was used for the OS detection that got moved here but the require never got moved. It should be here since it is used here. I will be removing it from rspec-core soon.

@myronmarston
Copy link
Member Author

I think this should just be loaded_features.txt on AppVeyor....

Trying that now...

@JonRowe
Copy link
Member

JonRowe commented Feb 16, 2015

Hmm, nope, maybe we should create the full path with Dir.pwd?

Failures:

  1) RSpec::Support behaves like library wide checks issues no warnings when loaded
     Failure/Error: expect(lib_file_results).to have_successful_no_warnings_output
       
       expected: ["", "", 0]
            got: ["", "", 5]
       
       (compared using ==)
     Shared Example Group: "library wide checks" called from ./spec/rspec/support_spec.rb:8

  2) RSpec::Support behaves like library wide checks only loads a known set of stdlibs so gem authors are forced to load libs they use to have passing specs
     Failure/Error: loaded_features = File.read(loaded_features_outfile).split("\n")
     Errno::ENOENT:
       No such file or directory - loaded_features.txt
     Shared Example Group: "library wide checks" called from ./spec/rspec/support_spec.rb:8
@myronmarston
Copy link
Member Author

Hmm, nope, maybe we should create the full path with Dir.pwd?

I don't care enough to put effort into the slow trial-and-error feedback loop of AppVeyor. I just marked them as :failing_on_appveyor and someone else who uses Windows can perhaps come along and fix them. I'm not really concerned about the things these specs enforce differing on Windows, anyway.

JonRowe added a commit that referenced this pull request Feb 16, 2015
WIP: Update shared context to minimize loaded stdlibs.
@JonRowe JonRowe merged commit cb08d42 into master Feb 16, 2015
@JonRowe
Copy link
Member

JonRowe commented Feb 16, 2015

LGTM then...

@JonRowe JonRowe deleted the allowed-stdlibs branch February 16, 2015 22:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add shared example group that we can use in each repo to enforce minimization of stdlib usage
2 participants