2018-11-02 19:07:56 -04:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2019-06-01 05:49:40 -04:00
|
|
|
|
require "set"
|
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
|
RSpec.describe "The library itself" do
|
|
|
|
|
def check_for_git_merge_conflicts(filename)
|
|
|
|
|
merge_conflicts_regex = /
|
|
|
|
|
<<<<<<<|
|
|
|
|
|
=======|
|
|
|
|
|
>>>>>>>
|
|
|
|
|
/x
|
|
|
|
|
|
|
|
|
|
failing_lines = []
|
2019-06-27 07:01:30 -04:00
|
|
|
|
each_line(filename) do |line, number|
|
2018-11-02 19:07:56 -04:00
|
|
|
|
failing_lines << number + 1 if line =~ merge_conflicts_regex
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return if failing_lines.empty?
|
|
|
|
|
"#{filename} has unresolved git merge conflicts on lines #{failing_lines.join(", ")}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_for_tab_characters(filename)
|
|
|
|
|
failing_lines = []
|
2019-06-27 07:01:30 -04:00
|
|
|
|
each_line(filename) do |line, number|
|
2022-08-02 23:24:38 -04:00
|
|
|
|
failing_lines << number + 1 if line.include?("\t")
|
2018-11-02 19:07:56 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return if failing_lines.empty?
|
|
|
|
|
"#{filename} has tab characters on lines #{failing_lines.join(", ")}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_for_extra_spaces(filename)
|
|
|
|
|
failing_lines = []
|
2019-06-27 07:01:30 -04:00
|
|
|
|
each_line(filename) do |line, number|
|
2018-11-02 19:07:56 -04:00
|
|
|
|
next if line =~ /^\s+#.*\s+\n$/
|
|
|
|
|
failing_lines << number + 1 if line =~ /\s+\n$/
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return if failing_lines.empty?
|
|
|
|
|
"#{filename} has spaces on the EOL on lines #{failing_lines.join(", ")}"
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-28 11:46:13 -04:00
|
|
|
|
def check_for_straneous_quotes(filename)
|
|
|
|
|
return if File.expand_path(filename) == __FILE__
|
|
|
|
|
|
|
|
|
|
failing_lines = []
|
|
|
|
|
each_line(filename) do |line, number|
|
|
|
|
|
failing_lines << number + 1 if line =~ /’/
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return if failing_lines.empty?
|
|
|
|
|
"#{filename} has an straneous quote on lines #{failing_lines.join(", ")}"
|
|
|
|
|
end
|
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
|
def check_for_expendable_words(filename)
|
|
|
|
|
failing_line_message = []
|
|
|
|
|
useless_words = %w[
|
|
|
|
|
actually
|
|
|
|
|
basically
|
|
|
|
|
clearly
|
|
|
|
|
just
|
|
|
|
|
obviously
|
|
|
|
|
really
|
|
|
|
|
simply
|
|
|
|
|
]
|
|
|
|
|
pattern = /\b#{Regexp.union(useless_words)}\b/i
|
|
|
|
|
|
2019-06-27 07:01:30 -04:00
|
|
|
|
each_line(filename) do |line, number|
|
2018-11-02 19:07:56 -04:00
|
|
|
|
next unless word_found = pattern.match(line)
|
|
|
|
|
failing_line_message << "#{filename}:#{number.succ} has '#{word_found}'. Avoid using these kinds of weak modifiers."
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
failing_line_message unless failing_line_message.empty?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_for_specific_pronouns(filename)
|
|
|
|
|
failing_line_message = []
|
|
|
|
|
specific_pronouns = /\b(he|she|his|hers|him|her|himself|herself)\b/i
|
|
|
|
|
|
2019-06-27 07:01:30 -04:00
|
|
|
|
each_line(filename) do |line, number|
|
2018-11-02 19:07:56 -04:00
|
|
|
|
next unless word_found = specific_pronouns.match(line)
|
|
|
|
|
failing_line_message << "#{filename}:#{number.succ} has '#{word_found}'. Use more generic pronouns in documentation."
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
failing_line_message unless failing_line_message.empty?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "has no malformed whitespace" do
|
2020-10-15 00:20:25 -04:00
|
|
|
|
exempt = /\.gitmodules|fixtures|vendor|LICENSE|vcr_cassettes|rbreadline\.diff|index\.txt$/
|
2018-11-02 19:07:56 -04:00
|
|
|
|
error_messages = []
|
2020-05-08 01:19:04 -04:00
|
|
|
|
tracked_files.each do |filename|
|
|
|
|
|
next if filename =~ exempt
|
|
|
|
|
error_messages << check_for_tab_characters(filename)
|
|
|
|
|
error_messages << check_for_extra_spaces(filename)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
end
|
|
|
|
|
expect(error_messages.compact).to be_well_formed
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-28 11:46:13 -04:00
|
|
|
|
it "has no estraneous quotes" do
|
|
|
|
|
exempt = /vendor|vcr_cassettes|LICENSE|rbreadline\.diff/
|
|
|
|
|
error_messages = []
|
2020-05-08 01:19:04 -04:00
|
|
|
|
tracked_files.each do |filename|
|
|
|
|
|
next if filename =~ exempt
|
|
|
|
|
error_messages << check_for_straneous_quotes(filename)
|
2019-03-28 11:46:13 -04:00
|
|
|
|
end
|
|
|
|
|
expect(error_messages.compact).to be_well_formed
|
|
|
|
|
end
|
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
|
it "does not include any unresolved merge conflicts" do
|
|
|
|
|
error_messages = []
|
2019-08-08 06:07:07 -04:00
|
|
|
|
exempt = %r{lock/lockfile_spec|quality_spec|vcr_cassettes|\.ronn|lockfile_parser\.rb}
|
2020-05-08 01:19:04 -04:00
|
|
|
|
tracked_files.each do |filename|
|
|
|
|
|
next if filename =~ exempt
|
|
|
|
|
error_messages << check_for_git_merge_conflicts(filename)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
end
|
|
|
|
|
expect(error_messages.compact).to be_well_formed
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "maintains language quality of the documentation" do
|
|
|
|
|
included = /ronn/
|
|
|
|
|
error_messages = []
|
2020-05-08 01:19:04 -04:00
|
|
|
|
man_tracked_files.each do |filename|
|
|
|
|
|
next unless filename =~ included
|
|
|
|
|
error_messages << check_for_expendable_words(filename)
|
|
|
|
|
error_messages << check_for_specific_pronouns(filename)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
end
|
|
|
|
|
expect(error_messages.compact).to be_well_formed
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "maintains language quality of sentences used in source code" do
|
|
|
|
|
error_messages = []
|
2020-05-08 01:19:04 -04:00
|
|
|
|
exempt = /vendor|vcr_cassettes|CODE_OF_CONDUCT/
|
|
|
|
|
lib_tracked_files.each do |filename|
|
|
|
|
|
next if filename =~ exempt
|
|
|
|
|
error_messages << check_for_expendable_words(filename)
|
|
|
|
|
error_messages << check_for_specific_pronouns(filename)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
end
|
|
|
|
|
expect(error_messages.compact).to be_well_formed
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "documents all used settings" do
|
|
|
|
|
exemptions = %w[
|
|
|
|
|
forget_cli_options
|
2021-04-21 07:54:29 -04:00
|
|
|
|
gem.changelog
|
|
|
|
|
gem.ci
|
2018-11-02 19:07:56 -04:00
|
|
|
|
gem.coc
|
2021-04-21 07:54:29 -04:00
|
|
|
|
gem.linter
|
2018-11-02 19:07:56 -04:00
|
|
|
|
gem.mit
|
2021-04-21 07:54:29 -04:00
|
|
|
|
gem.rubocop
|
|
|
|
|
gem.test
|
|
|
|
|
git.allow_insecure
|
2018-11-02 19:07:56 -04:00
|
|
|
|
inline
|
2021-04-21 07:54:29 -04:00
|
|
|
|
trust-policy
|
2018-11-02 19:07:56 -04:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
all_settings = Hash.new {|h, k| h[k] = [] }
|
|
|
|
|
documented_settings = []
|
|
|
|
|
|
|
|
|
|
Bundler::Settings::BOOL_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::BOOL_KEYS" }
|
|
|
|
|
Bundler::Settings::NUMBER_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::NUMBER_KEYS" }
|
|
|
|
|
Bundler::Settings::ARRAY_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::ARRAY_KEYS" }
|
2021-04-21 07:54:29 -04:00
|
|
|
|
Bundler::Settings::STRING_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::STRING_KEYS" }
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
|
key_pattern = /([a-z\._-]+)/i
|
|
|
|
|
lib_tracked_files.each do |filename|
|
|
|
|
|
each_line(filename) do |line, number|
|
|
|
|
|
line.scan(/Bundler\.settings\[:#{key_pattern}\]/).flatten.each {|s| all_settings[s] << "referenced at `#{filename}:#{number.succ}`" }
|
2018-11-02 19:07:56 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-12-08 02:36:29 -05:00
|
|
|
|
documented_settings = File.read("lib/bundler/man/bundle-config.1.ronn")[/LIST OF AVAILABLE KEYS.*/m].scan(/^\* `#{key_pattern}`/).flatten
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
documented_settings.each do |s|
|
|
|
|
|
all_settings.delete(s)
|
|
|
|
|
expect(exemptions.delete(s)).to be_nil, "setting #{s} was exempted but was actually documented"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
exemptions.each do |s|
|
|
|
|
|
expect(all_settings.delete(s)).to be_truthy, "setting #{s} was exempted but unused"
|
|
|
|
|
end
|
|
|
|
|
error_messages = all_settings.map do |setting, refs|
|
|
|
|
|
"The `#{setting}` setting is undocumented\n\t- #{refs.join("\n\t- ")}\n"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
expect(error_messages.sort).to be_well_formed
|
|
|
|
|
|
|
|
|
|
expect(documented_settings).to be_sorted
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "can still be built" do
|
2019-08-15 12:58:07 -04:00
|
|
|
|
with_built_bundler do |_gem_path|
|
2019-08-15 12:48:09 -04:00
|
|
|
|
expect(err).to be_empty, "bundler should build as a gem without warnings, but\n#{err}"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
Fix some bundler specs (#2380)
* These seem to consistenly pass already
* Show actual command when running `make test-bundler`
Current the setup command that installs the necessary gems for testing
bundler was printed, but not the actual command that runs the tests.
That was a bit confusing.
* Borrow trick from setproctitle specs
* A title that long doesn't get set sometimes
No idea why, but the test doesn't need that the title is that long.
* Fix most gem helper spec ruby-core failures
* Fix the rest of the gem helper failures
* Fix version spec by improving the assertion
* Remove unnecessary `BUNDLE_RUBY` environment var
We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name
because bundler considers `BUNDLE_*` variables as settings.
* Rename `BUNDLE_GEM` to `GEM_COMMAND`
This is more descriptive I think, and also friendlier for bundler
because `BUNDLE_` env variables are interpreted by bundler as settings,
and this is not a bundler setting.
This fixes one bundler spec failure in config specs against ruby-core.
* Fix quality spec when run in core
Use the proper path helper.
* Fix dummy lib builder to never load default gems
If a dummy library is named as a default gem, when requiring the library
from its executable, the default gem would be loaded when running from
core, because in core all default gems share path with bundler, and thus
they are always in the $LOAD_PATH. We fix the issue by loading lib
relatively inside dummy lib executables.
* More exact assertions
Sometimes I have the problem that I do some "print debugging" inside
specs, and suddently the spec passes. This happens when the assertion is
too relaxed, and the things I print make it match, specially when they
are simple strings like "1.0" than can be easily be part of gem paths
that I print for debugging.
I fix this by making a more exact assertion.
* Detect the correct shebang when ENV["RUBY"] is set
* Relax assertion
So that the spec passes even if another paths containing "ext" are in
the load path. This works to fix a ruby-core issue, but it's a better
assertion in general. We just want to know that the extension path was
added.
* Use folder structure independent path helper
It should fix this spec for ruby-core.
* Fix the last failing spec on ruby-core
* Skip `bundle open <default_gem>` spec when no default gems
2019-08-19 20:46:31 -04:00
|
|
|
|
it "ships the correct set of files" do
|
2021-04-21 07:54:29 -04:00
|
|
|
|
git_list = git_ls_files(ruby_core? ? "lib/bundler lib/bundler.rb libexec/bundle*" : "lib exe CHANGELOG.md LICENSE.md README.md bundler.gemspec")
|
2019-04-14 02:01:35 -04:00
|
|
|
|
|
2020-05-15 08:31:12 -04:00
|
|
|
|
gem_list = loaded_gemspec.files
|
2019-04-14 02:01:35 -04:00
|
|
|
|
|
2021-02-01 10:17:16 -05:00
|
|
|
|
expect(git_list.sort).to eq(gem_list.sort)
|
2019-04-14 02:01:35 -04:00
|
|
|
|
end
|
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
|
it "does not contain any warnings" do
|
2020-05-08 01:19:04 -04:00
|
|
|
|
exclusions = %w[
|
|
|
|
|
lib/bundler/capistrano.rb
|
|
|
|
|
lib/bundler/deployment.rb
|
|
|
|
|
lib/bundler/gem_tasks.rb
|
|
|
|
|
lib/bundler/vlad.rb
|
|
|
|
|
lib/bundler/templates/gems.rb
|
|
|
|
|
]
|
|
|
|
|
files_to_require = lib_tracked_files.grep(/\.rb$/) - exclusions
|
|
|
|
|
files_to_require.reject! {|f| f.start_with?("lib/bundler/vendor") }
|
2020-05-15 08:31:12 -04:00
|
|
|
|
files_to_require.map! {|f| File.expand_path(f, source_root) }
|
2020-05-25 07:12:41 -04:00
|
|
|
|
files_to_require.sort!
|
2020-06-03 14:46:35 -04:00
|
|
|
|
sys_exec("ruby -w") do |input, _, _|
|
2020-05-08 01:19:04 -04:00
|
|
|
|
files_to_require.each do |f|
|
|
|
|
|
input.puts "require '#{f}'"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
end
|
2020-05-08 01:19:04 -04:00
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
|
warnings = last_command.stdboth.split("\n")
|
|
|
|
|
# ignore warnings around deprecated Object#=~ method in RubyGems
|
|
|
|
|
warnings.reject! {|w| w =~ %r{rubygems\/version.rb.*deprecated\ Object#=~} }
|
2019-01-04 08:10:58 -05:00
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
|
expect(warnings).to be_well_formed
|
2018-11-02 19:07:56 -04:00
|
|
|
|
end
|
2019-06-01 05:49:40 -04:00
|
|
|
|
|
|
|
|
|
it "does not use require internally, but require_relative" do
|
2021-01-03 20:11:34 -05:00
|
|
|
|
exempt = %r{templates/|\.5|\.1|vendor/}
|
2020-05-08 01:19:04 -04:00
|
|
|
|
all_bad_requires = []
|
|
|
|
|
lib_tracked_files.each do |filename|
|
|
|
|
|
next if filename =~ exempt
|
|
|
|
|
each_line(filename) do |line, number|
|
|
|
|
|
line.scan(/^ *require "bundler/).each { all_bad_requires << "#{filename}:#{number.succ}" }
|
2019-06-01 05:49:40 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-05-08 01:19:04 -04:00
|
|
|
|
|
|
|
|
|
expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}"
|
2019-06-01 05:49:40 -04:00
|
|
|
|
end
|
2019-06-27 07:01:30 -04:00
|
|
|
|
|
2020-10-15 00:20:25 -04:00
|
|
|
|
private
|
2019-06-27 07:01:30 -04:00
|
|
|
|
|
|
|
|
|
def each_line(filename, &block)
|
|
|
|
|
File.readlines(filename, :encoding => "UTF-8").each_with_index(&block)
|
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
end
|