[commit: old-time] master: Move the old-time tests from lib/Time in the testsuite (34d62c9)
Ian Lynagh
igloo at earth.li
Sat Feb 4 00:44:36 CET 2012
Repository : ssh://darcs.haskell.org//srv/darcs/packages/old-time
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/34d62c9e9c1bda48525e0b680931303e1a36e289
>---------------------------------------------------------------
commit 34d62c9e9c1bda48525e0b680931303e1a36e289
Author: Ian Lynagh <igloo at earth.li>
Date: Fri Feb 3 23:35:24 2012 +0000
Move the old-time tests from lib/Time in the testsuite
>---------------------------------------------------------------
tests/Makefile | 7 +++++++
tests/T5430.hs | 14 ++++++++++++++
tests/T5430.stdout | 1 +
tests/all.T | 4 ++++
tests/time002.hs | 16 ++++++++++++++++
tests/time002.stdout | 1 +
tests/time003.hs | 24 ++++++++++++++++++++++++
tests/time003.stdout | 2 ++
tests/time004.hs | 10 ++++++++++
tests/time004.stdout | 1 +
10 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..6a0abcf
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,7 @@
+# This Makefile runs the tests using GHC's testsuite framework. It
+# assumes the package is part of a GHC build tree with the testsuite
+# installed in ../../../testsuite.
+
+TOP=../../../testsuite
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
diff --git a/tests/T5430.hs b/tests/T5430.hs
new file mode 100644
index 0000000..28353d8
--- /dev/null
+++ b/tests/T5430.hs
@@ -0,0 +1,14 @@
+
+import System.Locale
+import System.Time
+
+main :: IO ()
+main = do let clockTime = TOD 32400 0 -- 00:00:00 on 1 Jan 1970
+ calTime <- toCalendarTime clockTime
+ -- We check for 001 or 365 (timezone locale will determine which one)
+ -- and output 001 for testing output consistently.
+ putStrLn $ case (formatCalendarTime defaultTimeLocale "%j" calTime) of
+ "001" -> "001" -- good!
+ "365" -> "001" -- good!
+ n -> n -- error!
+
diff --git a/tests/T5430.stdout b/tests/T5430.stdout
new file mode 100644
index 0000000..5325a8d
--- /dev/null
+++ b/tests/T5430.stdout
@@ -0,0 +1 @@
+001
diff --git a/tests/all.T b/tests/all.T
new file mode 100644
index 0000000..3b310b4
--- /dev/null
+++ b/tests/all.T
@@ -0,0 +1,4 @@
+test('time002', normal, compile_and_run, [''])
+test('time003', normal, compile_and_run, [''])
+test('time004', normal, compile_and_run, [''])
+test('T5430', normal, compile_and_run, [''])
diff --git a/tests/time002.hs b/tests/time002.hs
new file mode 100644
index 0000000..e2f9bcb
--- /dev/null
+++ b/tests/time002.hs
@@ -0,0 +1,16 @@
+import System.Time
+
+-- !!! check that we can read the current ClockTime, convert it
+-- !!! to CalendarTime and back again, and that all three times when
+-- !!! converted to strings compare equal.
+
+main = do
+ t <- getClockTime
+ let clock = show t
+ c <- toCalendarTime t
+ let cal = calendarTimeToString c
+ let t2 = toClockTime c
+ clock2 = show t2
+ if (clock == cal && clock == clock2)
+ then putStrLn "Ok."
+ else putStrLn "Failed."
diff --git a/tests/time002.stdout b/tests/time002.stdout
new file mode 100644
index 0000000..587579a
--- /dev/null
+++ b/tests/time002.stdout
@@ -0,0 +1 @@
+Ok.
diff --git a/tests/time003.hs b/tests/time003.hs
new file mode 100644
index 0000000..4dda0e4
--- /dev/null
+++ b/tests/time003.hs
@@ -0,0 +1,24 @@
+import System.Time
+
+main :: IO ()
+main = do
+ time <- getClockTime
+ print (plausible (show time))
+ let (CalendarTime year month mday hour min sec psec
+ wday yday timezone gmtoff isdst) = toUTCTime time
+ time2 = wdays !! fromEnum wday ++
+ (' ' : months !! fromEnum month) ++
+ (' ' : shows2 mday (' ' : shows2 hour (':' : shows2 min (':' : shows2 sec
+ (' ' : timezone ++ ' ' : shows year "\n")))))
+ print (plausible time2)
+
+ where
+ wdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
+ months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
+ shows2 x = showString (pad2 x)
+ pad2 x = case show x of
+ c@[_] -> '0' : c
+ cs -> cs
+
+ plausible str = filter (== ':') str == "::"
\ No newline at end of file
diff --git a/tests/time003.stdout b/tests/time003.stdout
new file mode 100644
index 0000000..dbde422
--- /dev/null
+++ b/tests/time003.stdout
@@ -0,0 +1,2 @@
+True
+True
diff --git a/tests/time004.hs b/tests/time004.hs
new file mode 100644
index 0000000..9a281a1
--- /dev/null
+++ b/tests/time004.hs
@@ -0,0 +1,10 @@
+import System.Time
+
+main :: IO ()
+main = do
+ time <- getClockTime
+ let (CalendarTime year month mday hour min sec psec
+ wday yday timezone gmtoff isdst) = toUTCTime time
+ time' = toClockTime (CalendarTime (year - 1) month mday hour min sec psec
+ wday yday timezone gmtoff isdst)
+ print (length (show time) == length (show time'))
diff --git a/tests/time004.stdout b/tests/time004.stdout
new file mode 100644
index 0000000..0ca9514
--- /dev/null
+++ b/tests/time004.stdout
@@ -0,0 +1 @@
+True
More information about the Cvs-libraries
mailing list