Skip to content

Commit

Permalink
Fix Incorrect Test Arguments
Browse files Browse the repository at this point in the history
The `system` method automatically quotes arguments based on their content.
ARGV removes quotes from option arguments if they were quoted strings.
Therefore, the `extract_arg` method is unnecessary and has been removed.
  • Loading branch information
shinokaro committed Nov 30, 2023
1 parent 85769fb commit 34cd322
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
- Fixed bugs in tests. All tests can now be executed.
- Improved the speed of manifest file discovery. This manifest file is only required in the RubyInstaller environment.
- Fixed bugs in the regular expressions of GEM_EXTRA_RE. This allows excluding C source files, etc., from the ocran executable package based on command options.
- Quoted strings can be provided as arguments to the `rubyopt` option of the command.
- Quoted strings can be used when providing file paths as command option arguments, including those with spaces.
- Added methods to Ocran::Pathname, making it closer to the implementation of Ruby's Pathname.
- Reimplemented certain parts to match the implementation of Ruby 2.6 era, for compatibility with older Ruby versions. Therefore, the ocran command cannot be executed on Ruby versions earlier than 2.6.

Expand Down
24 changes: 7 additions & 17 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,6 @@ module Ocran
@ediconpath = (ocranpath / "../share/ocran/edicon.exe").expand_path
end

STRING_ARG_RE = /\A(?<q>("|')?)(?<str>.*)\k<q>\z/

class << self
private

def extract_arg(obj)
STRING_ARG_RE.match(obj)&.[](:str)
end
end

def Ocran.parseargs(argv)
usage = <<EOF
ocran [options] script.rb
Expand Down Expand Up @@ -409,10 +399,10 @@ EOF
when /\A--add-all-core\z/
@options[:add_all_core] = true
when /\A--output\z/
path = extract_arg(argv.shift)
path = argv.shift
@options[:output_override] = Pathname.new(path) if path
when /\A--dll\z/
path = extract_arg(argv.shift)
path = argv.shift
@options[:extra_dlls] << path if path
when /\A--quiet\z/
@options[:quiet] = true
Expand All @@ -427,17 +417,17 @@ EOF
when /\A--chdir-first\z/
@options[:chdir_first] = true
when /\A--icon\z/
path = extract_arg(argv.shift)
path = argv.shift
Ocran.fatal_error "Icon file #{path} not found.\n" unless path && File.exist?(path)
@options[:icon_filename] = Pathname.new(path)
when /\A--rubyopt\z/
@options[:rubyopt] = extract_arg(argv.shift)
@options[:rubyopt] = argv.shift
when /\A--gemfile\z/
path = extract_arg(argv.shift)
path = argv.shift
Ocran.fatal_error "Gemfile #{path} not found.\n" unless path && File.exist?(path)
@options[:gemfile] = Pathname.new(path)
when /\A--innosetup\z/
path = extract_arg(argv.shift)
path = argv.shift
Ocran.fatal_error "Inno Script #{path} not found.\n" unless path && File.exist?(path)
@options[:inno_script] = Pathname.new(path)
when /\A--no-autodll\z/
Expand All @@ -463,7 +453,7 @@ EOF
puts usage
exit 0
else
path = extract_arg(arg.dup)
path = arg.dup

if !File.exist?(path) || Dir.empty?(path)
Ocran.fatal_error "#{path} not found!"
Expand Down
2 changes: 1 addition & 1 deletion test/test_ocra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def test_rubyopt_manual
specified_rubyopt = "-rbundler --verbose"
# Starting with Ruby 2.6, Bundler is now the default GEM. To do this, use
# the '--add-all-core' option to include bnundler in the package.
test_args = DefaultArgs + ["--add-all-core", "--rubyopt", "'#{specified_rubyopt}'"]
test_args = DefaultArgs + ["--add-all-core", "--rubyopt", "#{specified_rubyopt}"]
with_fixture 'environment' do
with_env "RUBYOPT" => "-rtime" do
assert system("ruby", ocran, "environment.rb", *test_args)
Expand Down

0 comments on commit 34cd322

Please sign in to comment.