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

introduce standard formatting and linting #467

Merged
merged 8 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
88 changes: 88 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# from https://evilmartians.com/chronicles/rubocoping-with-legacy-bring-your-ruby-code-up-to-standard
require:
- standard
- standard-custom
- standard-performance
- rubocop-performance
- rubocop-minitest

inherit_gem:
standard: config/base.yml
standard-custom: config/base.yml
standard-performance: config/base.yml

AllCops:
SuggestExtensions: false
TargetRubyVersion: 3.0

Naming/InclusiveLanguage:
Enabled: true

Minitest/AssertInDelta: # new in 0.10
Enabled: true
Minitest/AssertKindOf: # new in 0.10
Enabled: true
Minitest/AssertOperator: # new in 0.32
Enabled: true
Minitest/AssertOutput: # new in 0.10
Enabled: true
Minitest/AssertPathExists: # new in 0.10
Enabled: true
Minitest/AssertPredicate: # new in 0.18
Enabled: true
Minitest/AssertRaisesCompoundBody: # new in 0.21
Enabled: true
Minitest/AssertRaisesWithRegexpArgument: # new in 0.22
Enabled: true
Minitest/AssertSame: # new in 0.26
Enabled: true
Minitest/AssertSilent: # new in 0.10
Enabled: true
Minitest/AssertWithExpectedArgument: # new in 0.11
Enabled: true
Minitest/AssertionInLifecycleHook: # new in 0.10
Enabled: true
Minitest/DuplicateTestRun: # new in 0.19
Enabled: true
Minitest/EmptyLineBeforeAssertionMethods: # new in 0.23
Enabled: false
Minitest/LifecycleHooksOrder: # new in 0.28
Enabled: true
Minitest/LiteralAsActualArgument: # new in 0.10
Enabled: true
Minitest/MultipleAssertions: # new in 0.10
Enabled: true
Minitest/NonExecutableTestMethod: # new in 0.34
Enabled: true
Minitest/NonPublicTestMethod: # new in 0.27
Enabled: true
Minitest/RedundantMessageArgument: # new in 0.34
Enabled: true
Minitest/RefuteInDelta: # new in 0.10
Enabled: true
Minitest/RefuteKindOf: # new in 0.10
Enabled: true
Minitest/RefuteOperator: # new in 0.32
Enabled: true
Minitest/RefutePathExists: # new in 0.10
Enabled: true
Minitest/RefutePredicate: # new in 0.18
Enabled: true
Minitest/RefuteSame: # new in 0.26
Enabled: true
Minitest/ReturnInTestMethod: # new in 0.31
Enabled: true
Minitest/SkipEnsure: # new in 0.20
Enabled: true
Minitest/SkipWithoutReason: # new in 0.24
Enabled: true
Minitest/TestFileName: # new in 0.26
Enabled: true
Minitest/TestMethodName: # new in 0.10
Enabled: true
Minitest/UnreachableAssertion: # new in 0.14
Enabled: true
Minitest/UnspecifiedException: # new in 0.10
Enabled: true
Minitest/UselessAssertion: # new in 0.26
Enabled: true
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ This release drops support for Ruby 2.7. [#453] @flavorjones
- Moved some C code into Ruby. [#451, #455] @tenderlove


### Changed

- Raise `StandardError` in a few places where `Exception` was previously raised.


### Removed

- Remove `SQLite3::VersionProxy` which has been deprecated since v1.3.2. [#453] @flavorjones
Expand Down
18 changes: 13 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ source "https://rubygems.org"

gemspec

gem("minitest", "5.20.0")
gem("rake-compiler", "1.2.5")
gem("rake-compiler-dock", "1.4.0")
gem("rdoc", "6.6.2")
group :development do
gem "minitest", "5.20.0"

gem("ruby_memcheck", "2.3.0") if Gem::Platform.local.os == "linux"
gem "rake-compiler", "1.2.5"
gem "rake-compiler-dock", "1.4.0"

gem "ruby_memcheck", "2.3.0" if Gem::Platform.local.os == "linux"

gem "rdoc", "6.6.2"

gem "rubocop", require: false
gem "standardrb", require: false
gem "rubocop-minitest", require: false
end
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
#
require "bundler"
SQLITE3_SPEC = Bundler.load_gemspec("sqlite3.gemspec")

task default: [:rubocop, :compile, :test]
172 changes: 88 additions & 84 deletions bin/test-gem-file-contents
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ gemfile_contents = Dir.mktmpdir do |dir|
raise "could not unpack gem #{gemfile}"
end

%x(tar -ztf data.tar.gz).split("\n")
`tar -ztf data.tar.gz`.split("\n")
end
end

Expand All @@ -46,7 +46,7 @@ gemspec = Dir.mktmpdir do |dir|
raise "could not unpack gem #{gemfile}"
end

YAML.unsafe_load(%x(gunzip -c metadata.gz))
YAML.unsafe_load(`gunzip -c metadata.gz`)
end
end

Expand Down Expand Up @@ -96,117 +96,121 @@ describe File.basename(gemfile) do
describe "all platforms" do
["lib", "test"].each do |dir|
it "contains every ruby file in #{dir}/" do
expected = %x(git ls-files #{dir}).split("\n").grep(/\.rb$/).sort
expected = `git ls-files #{dir}`.split("\n").grep(/\.rb$/).sort
skip "looks like this isn't a git repository" if expected.empty?
actual = gemfile_contents.select { |f| f.start_with?("#{dir}/") }.grep(/\.rb$/).sort
assert_equal(expected, actual)
end
end
end

describe "ruby platform" do
it "depends on mini_portile2" do
assert(gemspec.dependencies.find { |d| d.name == "mini_portile2" })
end
if gemspec.platform == Gem::Platform::RUBY
describe "ruby platform" do
it "depends on mini_portile2" do
assert(gemspec.dependencies.find { |d| d.name == "mini_portile2" })
end

it "contains extension C and header files" do
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.c", f) })
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.h", f) })
end
it "contains extension C and header files" do
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.c", f) })
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.h", f) })
end

it "includes C files in extra_rdoc_files" do
assert_equal(6, gemspec.extra_rdoc_files.count { |f| File.fnmatch?("ext/**/*.c", f) })
end
it "includes C files in extra_rdoc_files" do
assert_equal(6, gemspec.extra_rdoc_files.count { |f| File.fnmatch?("ext/**/*.c", f) })
end

it "contains the port files" do
dependencies = YAML.load_file(File.join(__dir__, "..", "dependencies.yml"), symbolize_names: true)
sqlite_tarball = File.basename(dependencies[:sqlite3][:files].first[:url])
actual_ports = gemfile_contents.grep(%r{^ports/})
it "contains the port files" do
dependencies = YAML.load_file(File.join(__dir__, "..", "dependencies.yml"), symbolize_names: true)
sqlite_tarball = File.basename(dependencies[:sqlite3][:files].first[:url])
actual_ports = gemfile_contents.grep(%r{^ports/})

assert_equal(["ports/archives/#{sqlite_tarball}"], actual_ports)
end
assert_equal(["ports/archives/#{sqlite_tarball}"], actual_ports)
end

it "contains the patch files" do
assert_equal(Dir.glob("patches/*.patch").length, gemfile_contents.count { |f| File.fnmatch?("patches/*", f) })
end
it "contains the patch files" do
assert_equal(Dir.glob("patches/*.patch").length, gemfile_contents.count { |f| File.fnmatch?("patches/*", f) })
end

it "sets metadata for msys2" do
refute_nil(gemspec.metadata["msys2_mingw_dependencies"])
end
it "sets metadata for msys2" do
refute_nil(gemspec.metadata["msys2_mingw_dependencies"])
end

it "sets required_ruby_version appropriately" do
all_supported_ruby_versions.each do |v|
assert(
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
"required_ruby_version='#{gemspec.required_ruby_version}' should support ruby #{v}",
)
it "sets required_ruby_version appropriately" do
all_supported_ruby_versions.each do |v|
assert(
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
"required_ruby_version='#{gemspec.required_ruby_version}' should support ruby #{v}"
)
end
end
end
end if gemspec.platform == Gem::Platform::RUBY
end

describe "native platform" do
it "does not depend on mini_portile2" do
refute(gemspec.dependencies.find { |d| d.name == "mini_portile2" })
end
if gemspec.platform.is_a?(Gem::Platform) && gemspec.platform.cpu
describe "native platform" do
it "does not depend on mini_portile2" do
refute(gemspec.dependencies.find { |d| d.name == "mini_portile2" })
end

it "contains extension C and header files" do
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.c", f) })
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.h", f) })
end
it "contains extension C and header files" do
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.c", f) })
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.h", f) })
end

it "includes C files in extra_rdoc_files" do
assert_equal(6, gemspec.extra_rdoc_files.count { |f| File.fnmatch?("ext/**/*.c", f) })
end
it "includes C files in extra_rdoc_files" do
assert_equal(6, gemspec.extra_rdoc_files.count { |f| File.fnmatch?("ext/**/*.c", f) })
end

it "does not contain the port files" do
assert_empty(gemfile_contents.grep(%r{^ports/}))
end
it "does not contain the port files" do
assert_empty(gemfile_contents.grep(%r{^ports/}))
end

it "does not contain the patch files" do
assert_empty(gemfile_contents.grep(%r{^patches/}))
end
it "does not contain the patch files" do
assert_empty(gemfile_contents.grep(%r{^patches/}))
end

it "contains expected shared library files " do
platform_supported_ruby_versions.each do |version|
actual = gemfile_contents.find do |p|
File.fnmatch?("lib/sqlite3/#{version}/sqlite3_native.{so,bundle}", p, File::FNM_EXTGLOB)
end
assert(actual, "expected to find shared library file for ruby #{version}")
end

it "contains expected shared library files " do
platform_supported_ruby_versions.each do |version|
actual = gemfile_contents.find do |p|
File.fnmatch?("lib/sqlite3/#{version}/sqlite3_native.{so,bundle}", p, File::FNM_EXTGLOB)
File.fnmatch?("lib/sqlite3/sqlite3_native.{so,bundle}", p, File::FNM_EXTGLOB)
end
assert(actual, "expected to find shared library file for ruby #{version}")
end
refute(actual, "did not expect to find shared library file in lib/sqlite3")

actual = gemfile_contents.find do |p|
File.fnmatch?("lib/sqlite3/sqlite3_native.{so,bundle}", p, File::FNM_EXTGLOB)
actual = gemfile_contents.find_all do |p|
File.fnmatch?("lib/sqlite3/**/*.{so,bundle}", p, File::FNM_EXTGLOB)
end
assert_equal(
platform_supported_ruby_versions.length,
actual.length,
"did not expect extra shared library files"
)
end
refute(actual, "did not expect to find shared library file in lib/sqlite3")

actual = gemfile_contents.find_all do |p|
File.fnmatch?("lib/sqlite3/**/*.{so,bundle}", p, File::FNM_EXTGLOB)
it "sets required_ruby_version appropriately" do
unsupported_versions = all_supported_ruby_versions - platform_supported_ruby_versions
platform_supported_ruby_versions.each do |v|
assert(
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
"required_ruby_version='#{gemspec.required_ruby_version}' should support ruby #{v}"
)
end
unsupported_versions.each do |v|
refute(
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
"required_ruby_version='#{gemspec.required_ruby_version}' should not support ruby #{v}"
)
end
end
assert_equal(
platform_supported_ruby_versions.length,
actual.length,
"did not expect extra shared library files",
)
end

it "sets required_ruby_version appropriately" do
unsupported_versions = all_supported_ruby_versions - platform_supported_ruby_versions
platform_supported_ruby_versions.each do |v|
assert(
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
"required_ruby_version='#{gemspec.required_ruby_version}' should support ruby #{v}",
)
it "does not set metadata for msys2" do
assert_nil(gemspec.metadata["msys2_mingw_dependencies"])
end
unsupported_versions.each do |v|
refute(
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
"required_ruby_version='#{gemspec.required_ruby_version}' should not support ruby #{v}",
)
end
end

it "does not set metadata for msys2" do
assert_nil(gemspec.metadata["msys2_mingw_dependencies"])
end
end if gemspec.platform.is_a?(Gem::Platform) && gemspec.platform.cpu
end
end