Move the old-time tests from lib/Time in the testsuite
authorIan Lynagh <igloo@earth.li>
Fri, 3 Feb 2012 23:35:24 +0000 (23:35 +0000)
committerIan Lynagh <igloo@earth.li>
Fri, 3 Feb 2012 23:35:24 +0000 (23:35 +0000)
tests/Makefile [new file with mode: 0644]
tests/T5430.hs [new file with mode: 0644]
tests/T5430.stdout [new file with mode: 0644]
tests/all.T [new file with mode: 0644]
tests/time002.hs [new file with mode: 0644]
tests/time002.stdout [new file with mode: 0644]
tests/time003.hs [new file with mode: 0644]
tests/time003.stdout [new file with mode: 0644]
tests/time004.hs [new file with mode: 0644]
tests/time004.stdout [new file with mode: 0644]

diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644 (file)
index 0000000..6a0abcf
--- /dev/null
@@ -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 (file)
index 0000000..28353d8
--- /dev/null
@@ -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 (file)
index 0000000..5325a8d
--- /dev/null
@@ -0,0 +1 @@
+001
diff --git a/tests/all.T b/tests/all.T
new file mode 100644 (file)
index 0000000..3b310b4
--- /dev/null
@@ -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 (file)
index 0000000..e2f9bcb
--- /dev/null
@@ -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 (file)
index 0000000..587579a
--- /dev/null
@@ -0,0 +1 @@
+Ok.
diff --git a/tests/time003.hs b/tests/time003.hs
new file mode 100644 (file)
index 0000000..4dda0e4
--- /dev/null
@@ -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 (file)
index 0000000..dbde422
--- /dev/null
@@ -0,0 +1,2 @@
+True
+True
diff --git a/tests/time004.hs b/tests/time004.hs
new file mode 100644 (file)
index 0000000..9a281a1
--- /dev/null
@@ -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 (file)
index 0000000..0ca9514
--- /dev/null
@@ -0,0 +1 @@
+True