1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
From cea6c0ebde0c3c7a0a0976fd9a0e745ccad9dec4 Mon Sep 17 00:00:00 2001
From: hololeap <hololeap@users.noreply.github.com>
Date: Mon, 27 Feb 2023 07:54:10 -0700
Subject: [PATCH] Fix tests
Fix tests for modern 'time' and turn 'runtests' into a proper test
suite.
Signed-off-by: hololeap <hololeap@users.noreply.github.com>
---
HDBC.cabal | 40 +++++++++++++++++-----------------------
testsrc/TestSqlValue.hs | 16 +++++++++++++++-
2 files changed, 32 insertions(+), 24 deletions(-)
diff --git a/HDBC.cabal b/HDBC.cabal
index e189f9a..15d0c15 100644
--- a/HDBC.cabal
+++ b/HDBC.cabal
@@ -24,9 +24,6 @@ source-repository head
flag splitBase
description: Choose the new smaller, split-up base package.
-flag buildtests
- description: Build the executable to run unit tests
- default: False
flag minTime15
description: Use time 1.5 or higher.
default: True
@@ -59,28 +56,25 @@ library
FlexibleInstances, DeriveDataTypeable
Default-Language: Haskell2010
-Executable runtests
- if flag(buildtests)
- Buildable: True
- Build-Depends: HUnit, QuickCheck >= 2.0
+Test-Suite runtests
+ Build-Depends: HUnit, QuickCheck >= 2.0
- if flag(splitBase)
- Build-Depends: base>=3 && <5, old-time, bytestring, containers
- if flag(minTime15)
- Build-Depends: time >= 1.5 && < 1.14
- CPP-Options: -DMIN_TIME_15
- else
- Build-Depends: time >= 1.2 && < 1.5, old-locale
- else
- Build-Depends: base<3
- Build-Depends: mtl, convertible >= 1.1.0.0, utf8-string, text
-
- -- Hack for cabal-install weirdness. cabal-install forces base 3,
- -- though it works fine for Setup.lhs manually. Fix.
- if impl(ghc >= 6.9)
- build-depends: base >= 4
+ if flag(splitBase)
+ Build-Depends: base>=3 && <5, old-time, bytestring, containers
+ if flag(minTime15)
+ Build-Depends: time >= 1.5 && < 1.14
+ CPP-Options: -DMIN_TIME_15
+ else
+ Build-Depends: time >= 1.2 && < 1.5, old-locale
else
- Buildable: False
+ Build-Depends: base<3
+ Build-Depends: mtl, convertible >= 1.1.0.0, utf8-string, text
+
+ -- Hack for cabal-install weirdness. cabal-install forces base 3,
+ -- though it works fine for Setup.lhs manually. Fix.
+ if impl(ghc >= 6.9)
+ build-depends: base >= 4
+ Type: exitcode-stdio-1.0
Main-Is: runtests.hs
Other-Modules: TestSqlValue
Hs-Source-Dirs: ., testsrc
diff --git a/testsrc/TestSqlValue.hs b/testsrc/TestSqlValue.hs
index 7d29453..e6161e8 100644
--- a/testsrc/TestSqlValue.hs
+++ b/testsrc/TestSqlValue.hs
@@ -6,12 +6,18 @@ All rights reserved.
For license and copyright information, see the file COPYRIGHT
-}
+{-# LANGUAGE CPP #-}
+
module TestSqlValue where
import Test.QuickCheck hiding (Result)
import Test.QuickCheck.Property (Result)
import qualified Test.HUnit as HU
import Database.HDBC
+#if MIN_VERSION_time(0,10,0)
+import Data.Time.Format (parseTimeM)
+#else
import Data.Time.Format (parseTime)
+#endif
import Data.Time.LocalTime
import Database.HDBC.Locale (defaultTimeLocale, iso8601DateFormat, oldIso8601DateFormat)
import Data.Maybe
@@ -29,17 +35,25 @@ fromSql_Int x =
testZonedTimeStr = "1989-08-01 15:33:01 -0500"
testZonedTime :: ZonedTime
-testZonedTime = fromJust $ parseTime defaultTimeLocale (iso8601DateFormat (Just "%T %z"))
+testZonedTime = fromJust $ parseTimeM False defaultTimeLocale (iso8601DateFormat (Just "%T %z"))
testZonedTimeStr
testZonedTimeFracStr = "1989-08-01 15:33:01.536 -0500"
testZonedTimeFrac :: ZonedTime
+#if MIN_VERSION_time(0,10,0)
+testZonedTimeFrac = fromJust $ parseTimeM False defaultTimeLocale (iso8601DateFormat (Just "%T%Q %z"))
+#else
testZonedTimeFrac = fromJust $ parseTime defaultTimeLocale (iso8601DateFormat (Just "%T%Q %z"))
+#endif
testZonedTimeFracStr
testZonedTimeTwoDigitYearStr = "89-08-01 15:33:01 -0500"
testZonedTimeTwoDigitYear :: ZonedTime
+#if MIN_VERSION_time(0,10,0)
+testZonedTimeTwoDigitYear = fromJust $ parseTimeM False defaultTimeLocale (oldIso8601DateFormat (Just "%T %z"))
+#else
testZonedTimeTwoDigitYear = fromJust $ parseTime defaultTimeLocale (oldIso8601DateFormat (Just "%T %z"))
+#endif
testZonedTimeTwoDigitYearStr
ztparsenf =
--
2.39.2
|