Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04]
ruby: ['3.0', '3.1']
os: [ubuntu-24.04]
ruby:
- '3.0'
- '3.1'
- '3.2'
- '3.3'
- '3.4'
include:
- { os: ubuntu-20.04 , ruby: ruby-head }
- { os: ubuntu-20.04 , ruby: jruby, allow-failure: true }
- { os: ubuntu-20.04 , ruby: jruby-head }
- { os: ubuntu-20.04 , ruby: truffleruby }
- { os: ubuntu-20.04 , ruby: truffleruby-head, allow-failure: true }
- { os: ubuntu-24.04 , ruby: ruby-head }
- { os: ubuntu-24.04 , ruby: jruby, allow-failure: true }
- { os: ubuntu-24.04 , ruby: jruby-head }
- { os: ubuntu-24.04 , ruby: truffleruby }
- { os: ubuntu-24.04 , ruby: truffleruby-head, allow-failure: true }
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
continue-on-error: ${{ matrix.allow-failure || false }}
id: bundle
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://www.rubygems.org"

gemspec
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rake/testtask'
require 'rdoc/task'

Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/commands/compare_command.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rubygems/command'
require 'rubygems/version_option'
require 'rubygems/comparator'
Expand Down
9 changes: 5 additions & 4 deletions lib/rubygems/comparator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'tmpdir'
require 'rbconfig'
require 'rainbow'
Expand Down Expand Up @@ -223,15 +225,14 @@ def get_package(gem_name, version)

def download_package(gem_name, version)
spec, source = get_specification(gem_name, version)
gem_file = gem_file_name(gem_name, spec.version.to_s)

Dir.chdir @options[:output] do
gem_file_path = Dir.chdir @options[:output] do
source.download spec
end

package = Gem::Package.new File.join(@options[:output], gem_file)
package = Gem::Package.new(gem_file_path)
use_package(package)
info "#{gem_file} downloaded."
info "#{gem_file_path} downloaded."

package
end
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/comparator/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rainbow'
require 'rubygems/comparator/utils'
require 'rubygems/comparator/report'
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/comparator/dependency_comparator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rubygems/comparator/base'

class Gem::Comparator
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/comparator/dir_utils.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pathname'

class Gem::Comparator
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/comparator/file_list_comparator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'diffy'
require 'rubygems/comparator/base'
require 'rubygems/comparator/dir_utils'
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/comparator/gemfile_comparator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'gemnasium/parser'
require 'rubygems/comparator/base'

Expand Down
6 changes: 4 additions & 2 deletions lib/rubygems/comparator/monitor.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'diffy'
require 'rubygems/comparator/base'
require 'rubygems/comparator/dir_utils'
Expand All @@ -15,7 +17,7 @@ def self.lines_changed(prev_file, curr_file)

def self.compact_files_diff(prev_file, curr_file)
prev_file = prev_file.nil? ? Tempfile.new.path : prev_file
changes = ''
changes = +''
Diffy::Diff.new(
prev_file, curr_file, :source => 'files', :context => 0
).each do |line|
Expand All @@ -29,7 +31,7 @@ def self.compact_files_diff(prev_file, curr_file)

def self.files_diff(prev_file, curr_file)
prev_file = prev_file.nil? ? Tempfile.new.path : prev_file
changes = ''
changes = +''
Diffy::Diff.new(
prev_file, curr_file, :source => 'files', :context => 0, :include_diff_info => true
).each do |line|
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/comparator/report.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rubygems/comparator/report/entry'

class Gem::Comparator
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/comparator/report/entry.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Gem::Comparator
class Report
class Entry
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/comparator/spec_comparator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rubygems/comparator/base'

class Gem::Comparator
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/comparator/utils.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rainbow'
require 'rubygems'
require 'rubygems/user_interaction'
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/comparator/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Gem::Comparator
VERSION = '1.2.1'
end
2 changes: 2 additions & 0 deletions lib/rubygems_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

require 'rubygems/command_manager'
Gem::CommandManager.instance.register_command :compare
2 changes: 2 additions & 0 deletions test/rubygems/comparator/test_dependency_comparator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

class TestDependencyComparator < TestGemComparator
Expand Down
2 changes: 2 additions & 0 deletions test/rubygems/comparator/test_dir_utils.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

class TestDirUtils < TestGemModule
Expand Down
2 changes: 2 additions & 0 deletions test/rubygems/comparator/test_file_list_comparator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

class TestFileListComparator < TestGemComparator
Expand Down
2 changes: 2 additions & 0 deletions test/rubygems/comparator/test_gemfile_comparator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

class TestGemfileComparator < TestGemComparator
Expand Down
2 changes: 2 additions & 0 deletions test/rubygems/comparator/test_monitor.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

class TestMonitor < TestGemModule
Expand Down
2 changes: 2 additions & 0 deletions test/rubygems/comparator/test_report.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../../test_helper'
require 'rubygems/comparator'

Expand Down
2 changes: 2 additions & 0 deletions test/rubygems/comparator/test_spec_comparator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

class TestSpecComparator < TestGemComparator
Expand Down
2 changes: 2 additions & 0 deletions test/rubygems/comparator/test_utils.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../../test_helper'
require 'rubygems/comparator'

Expand Down
86 changes: 86 additions & 0 deletions test/rubygems/mock_gem_ui.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# frozen_string_literal: true

require "rubygems/user_interaction"

##
# This Gem::StreamUI subclass records input and output to StringIO for
# retrieval during tests.

class Gem::MockGemUi < Gem::StreamUI
##
# Raised when you haven't provided enough input to your MockGemUi

class InputEOFError < RuntimeError
def initialize(question)
super "Out of input for MockGemUi on #{question.inspect}"
end
end

class TermError < SystemExit
attr_reader :exit_code

def initialize(exit_code)
super
@exit_code = exit_code
end
end

class SystemExitException < RuntimeError; end

module TTY
attr_accessor :tty

def tty?
@tty = true unless defined?(@tty)
@tty
end

def noecho
yield self
end
end

def initialize(input = "")
require "stringio"
ins = StringIO.new input
outs = StringIO.new
errs = StringIO.new

ins.extend TTY
outs.extend TTY
errs.extend TTY

super ins, outs, errs, true

@terminated = false
end

def ask(question)
raise InputEOFError, question if @ins.eof?

super
end

def input
@ins.string
end

def output
@outs.string
end

def error
@errs.string
end

def terminated?
@terminated
end

def terminate_interaction(status=0)
@terminated = true

raise TermError, status if status != 0
raise SystemExitException
end
end
4 changes: 3 additions & 1 deletion test/rubygems/test_gem_commands_compare_command.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative 'mock_gem_ui'
require 'rubygems/user_interaction'
require 'rubygems/mock_gem_ui'
require 'rubygems/commands/compare_command'

class TestGemCommandsCompareCommand < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'minitest/autorun'
require 'rubygems/comparator'

Expand Down