Project

General

Profile

Actions

Bug #13444

closed

compatibility breaking change: backticks is not evalueted as shell script call while in "unless" operator context

Added by dikderoy (Roman Bulgakov) about 7 years ago. Updated almost 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
[ruby-core:80740]

Description

Ruby versions from 2.0 to 2.3.x while executing shell script via backticks inside of "unless" construction had it executed and evalueted output as condition,
version 2.4 and onwards had condition evaluated as true but script is not executed.

I haven't find any note regarding such change in release-notes for 2.4.0 and 2.4.1

Steps to reproduce:

giving following code:

unless `touch abc.txt`
  raise 'Error'
end

Expected:

cwd has a file abc.txt created

Actual:

cwd has no file abc.txt and no exception has been raised


Test-case (with version comparison via rvm)

file [test.rb]:

unless `touch test-#{RUBY_VERSION}`
  raise 'Error'
end

begin
  puts $?.success?
rescue StandardError => e
  puts "rescued:#{e.message}"
end

s = `ls -l test-#{RUBY_VERSION}`
puts s.lines.length == 1 ? 'OK' : 'NOK'

exec:

$ rvm list


  rvm rubies

   ruby-2.0.0-p648 [ x86_64 ]
   ruby-2.1.10 [ x86_64 ]
   ruby-2.2.6 [ x86_64 ]
   ruby-2.3.3 [ x86_64 ]
 * ruby-2.4.0 [ x86_64 ]
=> ruby-2.4.1 [ x86_64 ]

$ rvm all --verbose do ruby test.rb

ruby-2.1.10: ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-linux] 
true
OK

ruby-2.2.6: ruby 2.2.6p396 (2016-11-15 revision 56800) [x86_64-linux] 
true
OK


ruby-2.0.0-p648: ruby 2.0.0p648 (2015-12-16 revision 53162) [x86_64-linux] 
true
OK

ruby-2.3.3: ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux] 
true
OK

ruby-2.4.0: ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux] 
rescued:undefined method `success?' for nil:NilClass
NOK

ruby-2.4.1: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] 
rescued:undefined method `success?' for nil:NilClass
NOK

$ ls -l test-*

-rw-rw-r-- 1 user user 0 апр.  17 23:50 test-2.0.0
-rw-rw-r-- 1 user user 0 апр.  17 23:50 test-2.1.10
-rw-rw-r-- 1 user user 0 апр.  17 23:50 test-2.2.6
-rw-rw-r-- 1 user user 0 апр.  17 23:50 test-2.3.3

OS: Ubuntu 14.04
cat /etc/debian_version: jessie/sid
uname -isoprvm: Linux 3.13.0-116-generic #163-Ubuntu SMP Fri Mar 31 14:13:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux


Files

test.rb (218 Bytes) test.rb test-case dikderoy (Roman Bulgakov), 04/17/2017 09:02 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0