From 193d0f74514ebd9ca1b232ef203aa7fa26f9ab3a Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Wed, 14 Jan 2026 00:04:03 +0000 Subject: [PATCH] Cabalize test suite --- old-time.cabal | 13 ++++++++ tests/.gitignore | 14 -------- tests/Makefile | 7 ---- tests/T5430.hs | 14 -------- tests/T5430.stdout | 1 - tests/Tests.hs | 78 ++++++++++++++++++++++++++++++++++++++++++++ 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 - 13 files changed, 91 insertions(+), 94 deletions(-) delete mode 100644 tests/.gitignore delete mode 100644 tests/Makefile delete mode 100644 tests/T5430.hs delete mode 100644 tests/T5430.stdout create mode 100644 tests/Tests.hs delete mode 100644 tests/all.T delete mode 100644 tests/time002.hs delete mode 100644 tests/time002.stdout delete mode 100644 tests/time003.hs delete mode 100644 tests/time003.stdout delete mode 100644 tests/time004.hs delete mode 100644 tests/time004.stdout diff --git a/old-time.cabal b/old-time.cabal index d04dcfd5..64ea9fec 100644 --- a/old-time.cabal +++ b/old-time.cabal @@ -76,3 +76,16 @@ Library build-tools: hsc2hs ghc-options: -Wall + +test-suite old-time-tests + type: exitcode-stdio-1.0 + default-language: Haskell2010 + ghc-options: -Wall + main-is: Tests.hs + hs-source-dirs: tests + build-depends: + base, + old-locale < 2, + old-time, + tasty < 2, + tasty-hunit < 1 diff --git a/tests/.gitignore b/tests/.gitignore deleted file mode 100644 index ee046269..00000000 --- a/tests/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -.hpc*/ -*.o -*.hi -*.comp.std* -*.run.std* -*.eventlog -*.genscript -*.exe - -# specific files -/T5430 -/time002 -/time003 -/time004 diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 6a0abcf1..00000000 --- a/tests/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# 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 deleted file mode 100644 index 28353d80..00000000 --- a/tests/T5430.hs +++ /dev/null @@ -1,14 +0,0 @@ - -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 deleted file mode 100644 index 5325a8df..00000000 --- a/tests/T5430.stdout +++ /dev/null @@ -1 +0,0 @@ -001 diff --git a/tests/Tests.hs b/tests/Tests.hs new file mode 100644 index 00000000..73d71b52 --- /dev/null +++ b/tests/Tests.hs @@ -0,0 +1,78 @@ +module Main (main) where + +import System.Locale (defaultTimeLocale) +import System.Time +import Test.Tasty +import Test.Tasty.HUnit + +main :: IO () +main = defaultMain $ testGroup "All" + [ testCase "T5430" t5430 + , testCase "time002" time002 + , testCase "time003" time003 + , testCase "time004" time004 + , testCase "issue18" issue18 + ] + +t5430 :: Assertion +t5430 = 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. + let j = formatCalendarTime defaultTimeLocale "%j" calTime + assertBool "Either 001 or 365" $ + j `elem` ["001", "365"] + +time002 :: Assertion +time002 = do + t <- getClockTime + let clock = show t + c <- toCalendarTime t + let cal = calendarTimeToString c + let t2 = toClockTime c + clock2 = show t2 + assertEqual "calendarTimeToString . toCalendarTime = id" clock cal + assertEqual "show . toClockTime . toCalendarTime = id" clock clock2 + +time003 :: Assertion +time003 = do + time <- getClockTime + assertBool "does show look plausible?" $ + plausible (show time) + + let (CalendarTime year month mday hour minute sec _psec + wday _yday timezone _gmtoff _isdst) = toUTCTime time + time2 = wdays !! fromEnum wday ++ + (' ' : months !! fromEnum month) ++ + (' ' : shows2 mday (' ' : shows2 hour (':' : shows2 minute (':' : shows2 sec + (' ' : timezone ++ ' ' : shows year "\n"))))) + assertBool "does time2 look plausible?" $ + 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 == "::" + +time004 :: Assertion +time004 = do + time <- getClockTime + let (CalendarTime year month mday hour minute sec psec + wday yday timezone gmtoff isdst) = toUTCTime time + time' = toClockTime (CalendarTime (year - 1) month mday hour minute sec psec + wday yday timezone gmtoff isdst) + assertEqual "should have same length" + (length (show time)) (length (show time')) + +issue18 :: Assertion +issue18 = do + let c = TOD ((19078*24+2)*3600+1357) 0 + assertEqual "noTimeDiff should not make a diff" + c (addToClockTime noTimeDiff c) diff --git a/tests/all.T b/tests/all.T deleted file mode 100644 index 3b310b41..00000000 --- a/tests/all.T +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index e2f9bcb7..00000000 --- a/tests/time002.hs +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 587579af..00000000 --- a/tests/time002.stdout +++ /dev/null @@ -1 +0,0 @@ -Ok. diff --git a/tests/time003.hs b/tests/time003.hs deleted file mode 100644 index 4dda0e46..00000000 --- a/tests/time003.hs +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index dbde4226..00000000 --- a/tests/time003.stdout +++ /dev/null @@ -1,2 +0,0 @@ -True -True diff --git a/tests/time004.hs b/tests/time004.hs deleted file mode 100644 index 9a281a10..00000000 --- a/tests/time004.hs +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 0ca95142..00000000 --- a/tests/time004.stdout +++ /dev/null @@ -1 +0,0 @@ -True