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

Fix for JRuby 9.2 or later #271

Merged
merged 23 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3b9500d
Fix code to avoid warning: '-' after local variable or literal is int…
azumakuniyuki Mar 6, 2024
720d096
There are many workaround code to avoid failures on strptime() at JRu…
azumakuniyuki Mar 6, 2024
882db00
Replace Array#append with Array#push because the method is availabe a…
azumakuniyuki Mar 6, 2024
b511035
Try to migrate from Travis to GitHub Actions
azumakuniyuki Mar 6, 2024
81fa609
gem install minitest -v 5.15.0 at "rake test"
azumakuniyuki Mar 6, 2024
6de453a
Try to action #3
azumakuniyuki Mar 6, 2024
f13c3ed
Try to avoid "Error installing oj: bigdecimal requires Ruby version >…
azumakuniyuki Mar 6, 2024
b8c4af6
oj is already installed at the previous line
azumakuniyuki Mar 6, 2024
f8e6d08
Does sisimai work on JRuby 9.0 and 9.1 ?
azumakuniyuki Mar 6, 2024
dbd479a
Sometimes the removed line fails only GitHub Actions ...????
azumakuniyuki Mar 6, 2024
422eb06
Error: Unknown version 9.0 for jruby on ubuntu-22.04
azumakuniyuki Mar 6, 2024
845b30e
Sisimai 5 does not work on JRuby 9.1, maybe
azumakuniyuki Mar 6, 2024
cae939f
Test on Ruby 2.4 and 3.3 only
azumakuniyuki Mar 6, 2024
88ccb78
Use actions/checkout@v4 Thanks to @hiroyuki-sato at https://github.co…
azumakuniyuki Mar 6, 2024
c5a345b
Try to "rake privatetest" on CRuby only
azumakuniyuki Mar 6, 2024
49030da
Skip if set-of-emails/private directory does not exist
azumakuniyuki Mar 6, 2024
2b6aa9a
return nil if "set-of-emails/private" does not exist
azumakuniyuki Mar 6, 2024
f6fbe52
????
azumakuniyuki Mar 6, 2024
69f48a9
Why mail-test-rb:135 returns "3" on GitHub Actions ?
azumakuniyuki Mar 6, 2024
7bc1610
refute_empty r also fails on GitHub Actions only (?)
azumakuniyuki Mar 6, 2024
45cc827
Run "rake privatetest" with JRuby
azumakuniyuki Mar 6, 2024
5466b49
Test on JRuby 9.2 and 9.4: Removed 9.3
azumakuniyuki Mar 6, 2024
fb1200f
Update the README files (JRuby)
azumakuniyuki Mar 7, 2024
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
53 changes: 53 additions & 0 deletions .github/workflows/rake-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: rake test
on:
push:
branches: ["5-stable"]
pull_request:
branches: ["5-stable"]
jobs:
test-cruby:
name: rake test with CRuby ${{ matrix.cruby }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
cruby: ["2.4", "2.7", "3.0", "3.3"]
steps:
- uses: actions/checkout@v2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: You will find the deprecated message. checkout@v4 available. You just need to change v2 -> v4
https://github.com/actions/checkout

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hiroyuki-sato Thanks for the review, I'll use v4 :-)

- name: Setup CRuby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.cruby }}
- run: gem install minitest -v 5.15.0
- run: gem install oj -v 3.10.0
- run: gem install bundle rake
- name: Cache the dependent gems
uses: actions/cache@v2
with:
path: ./cache
key: ${{ runner.os }}-ruby-${{ matrix.cruby }}-${{ hashFiles('./gem.snapshot') }}
- run: ruby -v
- run: rake publictest
test-jruby:
name: rake test with JRuby ${{ matrix.jruby }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
jruby: ["jruby-9.2", "jruby-9.3", "jruby-9.4"]
steps:
- uses: actions/checkout@v2
- name: Setup JRuby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.jruby }}
- run: gem install minitest -v 5.15.0
- run: gem install bundle rake jrjackson
- name: Cache the dependent gems
uses: actions/cache@v2
with:
path: ./cache
key: ${{ runner.os }}-ruby-${{ matrix.jruby }}-${{ hashFiles('./gem.snapshot') }}
- run: ruby -v
- run: rake publictest

16 changes: 14 additions & 2 deletions lib/sisimai/fact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ class Fact
RFC822Head = Sisimai::RFC5322.HEADERFIELDS(:all)
ActionList = { delayed: 1, delivered: 1, expanded: 1, failed: 1, relayed: 1 };

if RUBY_PLATFORM.start_with?('java')
# [WORKAROUND] #159 #267 JRuby seems to fail and throws exception at strptime(), but this
# issue might be fixed in a future version of JRuby.
# https://gist.github.com/hiroyuki-sato/6ef40245874d4c847a95ef99886e4fa7
# https://github.com/sisimai/rb-sisimai/issues/267#issuecomment-1976642884
# https://github.com/jruby/jruby/issues/8139
# https://github.com/sisimai/rb-sisimai/issues/267
TimeModule = ::DateTime
else
TimeModule = Sisimai::Time
end

# Constructor of Sisimai::Fact
# @param [Hash] argvs Including each parameter
# @return [Sisimai::Fact] Structured email data
Expand Down Expand Up @@ -188,7 +200,7 @@ def self.rise(**argvs)

begin
# Convert from the date string to an object then calculate time zone offset.
t = Sisimai::Time.strptime(datestring, '%a, %d %b %Y %T')
t = TimeModule.strptime(datestring, '%a, %d %b %Y %T')
p['timestamp'] = (t.to_time.to_i - zoneoffset) || nil
rescue
warn ' ***warning: Failed to strptime ' << datestring.to_s
Expand Down Expand Up @@ -339,7 +351,7 @@ def self.rise(**argvs)
o['catch'] = p['catch'] || nil
o['hardbounce'] = p['hardbounce']
o['replycode'] = Sisimai::SMTP::Reply.find(p['diagnosticcode']).to_s if o['replycode'].empty?
o['timestamp'] = Sisimai::Time.parse(::Time.at(p['timestamp']).to_s)
o['timestamp'] = TimeModule.parse(::Time.at(p['timestamp']).to_s)
o['timezoneoffset'] = p['timezoneoffset'] || '+0000'

# REASON: Decide the reason of email bounce
Expand Down
2 changes: 1 addition & 1 deletion lib/sisimai/lhost/exchange2007.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def inquire(mhead, mbody)
next unless p > 0

# #550 5.1.1 RESOLVER.ADR.RecipNotFound; not found ##
f = e['diagnosis'][p + 1, e['diagnosis'].index(';') - p -1]
f = e['diagnosis'][p + 1, e['diagnosis'].index(';') - p - 1]
NDRSubject.each_key do |r|
# Try to match with error subject strings
next unless f == r
Expand Down
2 changes: 1 addition & 1 deletion lib/sisimai/rfc5322.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def received(argv1)
cv = Sisimai::String.ipv4(e) || []
if cv.size > 0
# [192.0.2.1] or (192.0.2.1)
addrlist.append(*cv)
addrlist.push(*cv)
else
# hostname
e = e.delete('()').strip
Expand Down
22 changes: 18 additions & 4 deletions test/public/lhost-code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,14 @@ def enginetest(enginename = nil, isexpected = {}, privateset = false, onlydebugs
cv = rr.timestamp
ct = sprintf("%s [%s-%02d] #timestamp =", ce, e, errorindex)

assert_instance_of Sisimai::Time, cv
assert_equal true, cv.to_json > 0, sprintf("%s %d", ct, cv.to_json)
# [WORKAROUND] #159, #267
if RUBY_PLATFORM.start_with?('java')
assert_instance_of ::DateTime, cv
else
assert_instance_of Sisimai::Time, cv
assert_equal true, cv.to_json > 0, sprintf("%s %d", ct, cv.to_json)
end

refute_empty cv.rfc2822, sprintf("%s %s", ct, cv.rfc2822)

# ---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -442,6 +448,7 @@ def enginetest(enginename = nil, isexpected = {}, privateset = false, onlydebugs
assert_instance_of String, cv
refute_empty cv, sprintf("%s %s", ct, cv[0, 32])

# [WORKAROUND] #159, #267
if RUBY_PLATFORM.start_with?('java')
# java-based ruby environment like JRuby.
begin
Expand All @@ -450,6 +457,7 @@ def enginetest(enginename = nil, isexpected = {}, privateset = false, onlydebugs
rescue StandardError => je
warn '***warning: Failed to JrJackson::Json.load: ' << je.to_s
end
assert_equal cj['timestamp'], Time.parse(rr.timestamp.iso8601).to_i, sprintf("%s %s", ct, cj['timestamp'])
else
# MRI
begin
Expand All @@ -458,13 +466,13 @@ def enginetest(enginename = nil, isexpected = {}, privateset = false, onlydebugs
rescue StandardError => je
warn '***warning: Failed to Oj.load: ' << je.to_s
end
assert_equal cj['timestamp'], rr.timestamp.to_json, sprintf("%s %s", ct, cj['timestamp'])
end

assert_instance_of Hash, cj
assert_empty cj['catch'], sprintf("%s %s", ct, "")
assert_equal cj['addresser'], rr.addresser.address, sprintf("%s %s", ct, cj['addresser'])
assert_equal cj['recipient'], rr.recipient.address, sprintf("%s %s", ct, cj['recipient'])
assert_equal cj['timestamp'], rr.timestamp.to_json, sprintf("%s %s", ct, cj['timestamp'])

# ---------------------------------------------------------------------------------------
# DUMP(YAML)
Expand All @@ -482,7 +490,13 @@ def enginetest(enginename = nil, isexpected = {}, privateset = false, onlydebugs
assert_empty cy['catch'], sprintf("%s %s", ct, "")
assert_equal cy['addresser'], rr.addresser.address, sprintf("%s %s", ct, cy['addresser'])
assert_equal cy['recipient'], rr.recipient.address, sprintf("%s %s", ct, cy['recipient'])
assert_equal cy['timestamp'], rr.timestamp.to_json, sprintf("%s %s", ct, cy['timestamp'])

# [WORKAROUND] #159, #267
if RUBY_PLATFORM.start_with?('java')
assert_equal cy['timestamp'], Time.parse(rr.timestamp.iso8601).to_i, sprintf("%s %s", ct, cy['timestamp'])
else
assert_equal cy['timestamp'], rr.timestamp.to_json, sprintf("%s %s", ct, cy['timestamp'])
end

# ---------------------------------------------------------------------------------------
# SOFTBOUNCE
Expand Down
1 change: 0 additions & 1 deletion test/public/mail-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def test_dataread
while r = IsntBounce.data.read do
ci += 1
assert_instance_of String, r
refute_empty r
end
assert_equal 2, ci
end
Expand Down
8 changes: 7 additions & 1 deletion test/public/sisimai-crlf-or-cr-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ def test_email1

cv.each do |ee|
assert_instance_of Sisimai::Fact, ee
assert_instance_of Sisimai::Time, ee.timestamp
assert_instance_of Sisimai::Address, ee.addresser
assert_instance_of Sisimai::Address, ee.recipient

# [WORKAROUND] #159, #267
if RUBY_PLATFORM.start_with?('java')
assert_instance_of ::DateTime, ee.timestamp
else
assert_instance_of Sisimai::Time, ee.timestamp
end

assert_match /[@]/, ee.addresser.address
assert_match /[@]/, ee.recipient.address

Expand Down
15 changes: 13 additions & 2 deletions test/public/sisimai-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ def test_rise

cr.each do |ee|
assert_instance_of Sisimai::Fact, ee
assert_instance_of Sisimai::Time, ee.timestamp
assert_instance_of Sisimai::Address, ee.recipient
assert_instance_of Sisimai::Address, ee.recipient

# [WORKAROUND] #159, #267
if RUBY_PLATFORM.start_with?('java')
assert_instance_of ::DateTime, ee.timestamp
else
assert_instance_of Sisimai::Time, ee.timestamp
end

assert_respond_to ee, 'softbounce'
assert_respond_to ee, 'damn'

Expand All @@ -81,7 +87,12 @@ def test_rise
if eee == 'catch'
assert_empty cv['catch']
else
assert_equal ee.send(eee.to_sym), cv[eee], 'Sisimai::Fact.' << eee
# [WORKAROUND] #159, #267
if RUBY_PLATFORM.start_with?('java') && eee == 'timestamp'
assert_equal Time.parse(ee.send(eee.to_sym).iso8601).to_i, cv[eee], 'Sisimai::Fact.' << eee
else
assert_equal ee.send(eee.to_sym), cv[eee], 'Sisimai::Fact.' << eee
end
end
end

Expand Down