[commit: packages/time] ghc-head: Regression test for getTimeZone. (9ac8f81)

git at git.haskell.org git at git.haskell.org
Fri Aug 30 17:47:27 CEST 2013


Repository : ssh://git@git.haskell.org/time

On branch  : ghc-head
Link       : http://git.haskell.org/?p=packages/time.git;a=commit;h=9ac8f81ad6a19f995b718e369a1620c1c95ea488

>---------------------------------------------------------------

commit 9ac8f81ad6a19f995b718e369a1620c1c95ea488
Author: oconnorr <oconnorr at google.com>
Date:   Fri Jun 14 19:19:45 2013 +0000

    Regression test for getTimeZone.
    
    The localtime_r call made from getTimeZone may or may not perform a tzset().
    In particular, in glibc, a tzset() will only be performed the first time a process runs localtime_r.
    
    This added regression test will fail on implementations like glibc that only
    perform a tzset() on the first call to localtime_r.
    
    A fix to make getTimeZone always call tzset() can be found in patch:
    
    [Make getTimeZone cross-platform consistent by always considering the TZ environment variable.
    oconnorr at google.com**20130610222254


>---------------------------------------------------------------

9ac8f81ad6a19f995b718e369a1620c1c95ea488
 Test/TestTimeZone.hs |   17 +++++++++++++++++
 Test/Tests.hs        |    4 +++-
 time.cabal           |    5 +++--
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/Test/TestTimeZone.hs b/Test/TestTimeZone.hs
new file mode 100644
index 0000000..8e79baa
--- /dev/null
+++ b/Test/TestTimeZone.hs
@@ -0,0 +1,17 @@
+{-# OPTIONS -Wall -Werror #-}
+
+module Test.TestTimeZone where
+
+import Data.Time
+import System.Posix.Env (putEnv)
+import Test.TestUtil
+
+testTimeZone :: Test
+testTimeZone = ioTest "getTimeZone respects TZ env var" $ do
+  putEnv "TZ=UTC+0"
+  zone1 <- getTimeZone epoch
+  putEnv "TZ=EST+5"
+  zone2 <- getTimeZone epoch
+  return $ diff False (zone1 == zone2)
+ where
+  epoch = UTCTime (ModifiedJulianDay 0) 0
diff --git a/Test/Tests.hs b/Test/Tests.hs
index 512b64e..3900e45 100644
--- a/Test/Tests.hs
+++ b/Test/Tests.hs
@@ -13,6 +13,7 @@ import Test.TestMonthDay
 import Test.TestParseDAT
 import Test.TestParseTime
 import Test.TestTime
+import Test.TestTimeZone
 
 tests :: [Test]
 tests = [ addDaysTest
@@ -25,4 +26,5 @@ tests = [ addDaysTest
         , testMonthDay
         , testParseDAT
         , testParseTime
-        , testTime ]
+        , testTime
+        , testTimeZone ]
diff --git a/time.cabal b/time.cabal
index 5e38d2a..e1f7d79 100644
--- a/time.cabal
+++ b/time.cabal
@@ -114,8 +114,9 @@ test-suite tests
         old-locale,
         process,
         QuickCheck >= 2.5.1,
-        test-framework >= 0.6.1,
-        test-framework-quickcheck2 >= 0.2.12
+        test-framework >= 0.6.1 && < 0.7,
+        test-framework-quickcheck2 >= 0.2.12,
+        unix
     main-is: Test.hs
     other-modules:
         Test.Tests





More information about the ghc-commits mailing list