Bug #4297

test_time in ruby/test/psych/test_json_tree.rb makes test failure

Added by Motohiro KOSAKI over 3 years ago. Updated almost 3 years ago.

[ruby-core:34641]
Status:Closed
Priority:Normal
Assignee:Aaron Patterson
Category:lib
Target version:1.9.3
ruby -v:ruby 1.9.3dev (2011-01-20 trunk 30611) [x86_64-linux] Backport:

Description

=begin
Recently ruby trunk + linux increase one test failure.


1) Failure:
testtime(Psych::TestJSONTree) [/home/kosaki/linux/ruby-svn/ruby/test/psych/testjson_tree.rb:45]:
Expected "{\"a\": \"2010-10-10 07:00:00.000000000Z\"}\n", not "{\"a\": \"2010-10-09 15:00:00.000000000Z\"}\n".


Becuase the test are using Time.new and it depend on timezone.


 def test_time
   time = Time.new(2010, 10, 10).utc
   assert_equal "{\"a\": \"2010-10-10 00:00:00.000000000Z\"}\n", Psych.to_json({'a' => time })
 end

note: I'm living in japan timezones.

So, It shold be timezone independent.

% svn diff
Index: test/psych/testjsontree.rb
===================================================================
--- test/psych/testjsontree.rb (revision 30611)
+++ test/psych/testjsontree.rb (working copy)
@@ -41,8 +41,8 @@
end

  def test_time
  • time = Time.new(2010, 10, 10).utc
  • assertequal "{\"a\": \"2010-10-10 07:00:00.000000000Z\"}\n", Psych.tojson({'a' => time })
  • time = Time.utc(2010, 10, 10).utc
  •  assert_equal "{\"a\": \"2010-10-10 00:00:00.000000000Z\"}\n", Psych.to_json({'a' => time })
    

    end

    def test_datetime
    =end

History

#1 Updated by Motohiro KOSAKI over 3 years ago

  • Assignee set to Aaron Patterson

=begin

=end

#2 Updated by Benoit Daloze over 3 years ago

=begin
On 20 January 2011 05:05, Motohiro KOSAKI redmine@ruby-lang.org wrote:

% svn diff

Index: test/psych/testjsontree.rb

--- test/psych/testjsontree.rb        (revision 30611)
+++ test/psych/testjsontree.rb        (working copy)
@@ -41,8 +41,8 @@
    end

    def testtime
-      time = Time.new(2010, 10, 10).utc
-      assert
equal "{\"a\": \"2010-10-10 07:00:00.000000000Z\"}\n", Psych.tojson({'a' => time })
+      time = Time.utc(2010, 10, 10).utc
+      assert
equal "{\"a\": \"2010-10-10 00:00:00.000000000Z\"}\n", Psych.to_json({'a' => time })
    end

    def test_datetime

I think the second 'utc' (Time#utc) is unnecessary as the Time is
created with Time.utc.
So the patch should be:

% svn diff
Index: test/psych/testjsontree.rb
===================================================================
--- test/psych/testjsontree.rb (revision 30611)
+++ test/psych/testjsontree.rb (working copy)
@@ -41,8 +41,8 @@
end

 def test_time
  • time = Time.new(2010, 10, 10).utc
  • assertequal "{\"a\": \"2010-10-10 07:00:00.000000000Z\"}\n", Psych.tojson({'a' => time })
  • time = Time.utc(2010, 10, 10)
  •  assert_equal "{\"a\": \"2010-10-10 00:00:00.000000000Z\"}\n",
    

    Psych.to_json({'a' => time })
    end

    def test_datetime

=end

#3 Updated by Anonymous over 3 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r30627.
Motohiro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


fixed a bug in the test suite. Thanks Benoit Daloze!
=end

Also available in: Atom PDF