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

Add some specs for bitwise operators in Process::Status #1217

Merged
merged 2 commits into from
Nov 27, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion core/process/status/bit_and_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
require_relative '../../../spec_helper'

describe "Process::Status#&" do
it "needs to be reviewed for spec completeness"
it "returns a bitwise and of the integer status of an exited child" do
suppress_warning do
ruby_exe("exit(29)", exit_status: 29)
($? & 0).should == 0
($? & $?.to_i).should == $?.to_i

# Actual value is implementation specific
platform_is :linux do
# 29 == 0b11101
($? & 0b1011100000000).should == 0b1010100000000
end
end
end

ruby_version_is "3.3" do
it "raises an ArgumentError if mask is negative" do
suppress_warning do
ruby_exe("exit(0)")
-> {
$? & -1
}.should raise_error(ArgumentError, 'negative mask value: -1')
end
end

it "shows a deprecation warning" do
ruby_exe("exit(0)")
-> {
$? & 0
}.should complain(/warning: Process::Status#& is deprecated and will be removed .*use other Process::Status predicates instead/)
end
end
end
31 changes: 30 additions & 1 deletion core/process/status/right_shift_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
require_relative '../../../spec_helper'

describe "Process::Status#>>" do
it "needs to be reviewed for spec completeness"
it "returns a right shift of the integer status of an exited child" do
suppress_warning do
ruby_exe("exit(29)", exit_status: 29)
($? >> 0).should == $?.to_i
($? >> 1).should == $?.to_i >> 1

# Actual value is implementation specific
platform_is :linux do
($? >> 8).should == 29
end
end
end

ruby_version_is "3.3" do
it "raises an ArgumentError if shift value is negative" do
suppress_warning do
ruby_exe("exit(0)")
-> {
$? >> -1
}.should raise_error(ArgumentError, 'negative shift value: -1')
end
end

it "shows a deprecation warning" do
ruby_exe("exit(0)")
-> {
$? >> 0
}.should complain(/warning: Process::Status#>> is deprecated and will be removed .*use other Process::Status attributes instead/)
end
end
end