Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare for stackage lts 22 #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ConfigFile.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: ConfigFile
Version: 1.1.4
Version: 1.1.5
License: BSD3
Maintainer: John Goerzen <[email protected]>
Author: John Goerzen
Expand Down Expand Up @@ -40,7 +40,7 @@ Library
Data.ConfigFile.Parser,
Data.ConfigFile.Monadic
Other-Modules: Data.ConfigFile.Lexer
Extensions: ExistentialQuantification, OverlappingInstances,
Extensions: ExistentialQuantification
UndecidableInstances, TypeSynonymInstances, FlexibleContexts,
FlexibleInstances
Build-Depends: parsec, base < 5,
Expand All @@ -50,12 +50,12 @@ Library
Executable runtests
if flag(buildtests)
Buildable: True
Build-depends: HUnit, testpack
Build-depends: HUnit
else
Buildable: False
Main-Is: runtests.hs
HS-Source-Dirs: testsrc, src, .
Other-Modules: Tests, ConfigParser.Maintest, ConfigParser.Parsertest
Extensions: ExistentialQuantification, OverlappingInstances,
Extensions: ExistentialQuantification
UndecidableInstances, CPP, TypeSynonymInstances, FlexibleContexts,
FlexibleInstances
10 changes: 5 additions & 5 deletions src/Data/ConfigFile.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE UndecidableInstances, OverlappingInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-
Copyright (C) 2004-2008 John Goerzen <[email protected]>

Expand Down Expand Up @@ -104,7 +104,7 @@ import qualified Data.Map as Map
import Data.List
import System.IO(Handle)
import Data.Char
import Control.Monad.Error
import Control.Monad.Except

-- For interpolatingAccess
import Text.ParserCombinators.Parsec.Error (errorMessages, Message(..))
Expand Down Expand Up @@ -436,10 +436,10 @@ The following will produce a False value:
* false -}
get :: MonadError CPError m => ConfigParser -> SectionSpec -> OptionSpec -> m a

instance Get_C String where
instance {-# OVERLAPPING #-} Get_C String where
get cp s o = eitherToMonadError $ (accessfunc cp) cp s o

instance Get_C Bool where
instance {-# OVERLAPPING #-} Get_C Bool where
get = getbool

instance Read t => Get_C t where
Expand Down Expand Up @@ -818,7 +818,7 @@ Error\/IO monad. That is, you will get an IO result back. Here is a full
standalone example of doing that:

>import Data.ConfigFile
>import Control.Monad.Error
>import Control.Monad.Except
>
>main = do
> rv <- runErrorT $
Expand Down
2 changes: 1 addition & 1 deletion src/Data/ConfigFile/Monadic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Data.ConfigFile.Monadic (
set, setshow, remove_option, add_section, remove_section
) where

import Control.Monad.Error
import Control.Monad.Except
import System.IO(Handle)
import Data.ConfigFile as Reexporting (SectionSpec, OptionSpec, ConfigParser(..),
CPErrorData, CPError, emptyCP, Get_C(..), sections, merge, to_string)
Expand Down
2 changes: 1 addition & 1 deletion src/Data/ConfigFile/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Data.ConfigFile.Parser
import Data.Char
import Data.List
import Text.ParserCombinators.Parsec
import Control.Monad.Error(throwError, MonadError)
import Control.Monad.Except(throwError, MonadError)
import Data.ConfigFile.Lexer
import System.IO(Handle, hGetContents)
import Data.ConfigFile.Types
Expand Down
6 changes: 0 additions & 6 deletions src/Data/ConfigFile/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ module Data.ConfigFile.Types (
ParseOutput
) where
import qualified Data.Map as Map
import Data.Char
import Control.Monad.Error

{- | Internal output from parser -}
type ParseOutput = [(String, [(String, String)])]
Expand Down Expand Up @@ -73,10 +71,6 @@ data CPErrorData = ParseError String -- ^ Parse error
of the error. -}
type CPError = (CPErrorData, String)

instance Error CPError where
noMsg = (OtherProblem "", "")
strMsg x = (OtherProblem x, "")

{- Removed due to Hugs incompatibility.

| Basic ConfigParser error handling. The Left value indicates
Expand Down
3 changes: 3 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resolver: lts-22.34
packages:
- .
12 changes: 12 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
snapshots:
- completed:
sha256: edbd50d7e7c85c13ad5f5835ae2db92fab1e9cf05ecf85340e2622ec0a303df1
size: 720020
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/34.yaml
original: lts-22.34
59 changes: 31 additions & 28 deletions testsrc/ConfigParser/Maintest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
module ConfigParser.Maintest(tests) where
import Test.HUnit
import Data.ConfigFile
import Data.Either.Utils
import System.IO.PlafCompat(nullFileName)
import Test.HUnit.Tools
import Control.Exception
import System.IO

nullfile = openFile nullFileName ReadWriteMode
{- | Pulls a "Right" value out of an Either value. If the Either value is
Left, raises an exception with "error". -}
forceEither :: Show e => Either e a -> a
forceEither (Left x) = error (show x)
forceEither (Right x) = x

nullfile = openFile "/dev/null" ReadWriteMode
testfile = "testsrc/ConfigParser/test.cfg"
p inp = forceEither $ readstring emptyCP inp
f msg inp exp conv = TestLabel msg $ TestCase $ assertEqual "" (Right exp) (conv (p inp))
Expand Down Expand Up @@ -78,20 +81,20 @@ test_basic =
Right "o1" @=? get cp "sect1" "v1"
Right "o2" @=? get cp "sect1" "v2"
Right "o1" @=? get cp "DEFAULT" "v1"
, f3 "extensions to string"
, f3 "extensions to string"
"[sect1]\nfoo: bar\nbaz: l1\n l2\n l3\n# c\nquux: asdf"
"[sect1]\nbaz: l1\n l2\n l3\nfoo: bar\nquux: asdf\n\n"
to_string
]

test_defaults =
test_defaults =
let cp = p "def: ault\n[sect1]\nfoo: bar\nbaz: quuz\nint: 2\nfloat: 3\nbool: yes\n[sect4]\ndef: different" in
[
f2 "default item" (Right "ault") (get cp "sect1" "def")
,f2 "normal item" (Right "bar") (get cp "sect1" "foo")
,f2s "no option" (Left (NoOption "abc", "get (sect1/abc)"))
,f2s "no option" (Left (NoOption "abc", "get (sect1/abc)"))
(get cp "sect1" "abc")
,f2s "no section" (Left (NoSection "sect2", "get (sect2/foo)"))
,f2s "no section" (Left (NoSection "sect2", "get (sect2/foo)"))
(get cp "sect2" "foo")
,f2 "default from bad sect" (Right "ault") (get cp "sect2" "def")
,f2 "overriding default" (Right "different") (get cp "sect4" "def")
Expand All @@ -104,12 +107,12 @@ test_defaults =
test_nodefault =
let cp = (p "def: ault\n[sect1]\nfoo: bar\nbaz: quuz\nint: 2\nfloat: 3\nbool: yes\n[sect4]\ndef: different"){usedefault = False} in
[
f2s "default item" (Left (NoOption "def", "get (sect1/def)"))
f2s "default item" (Left (NoOption "def", "get (sect1/def)"))
(get cp "sect1" "def")
,f2 "normal item" (Right "bar") (get cp "sect1" "foo")
,f2s "no option" (Left (NoOption "abc", "get (sect1/abc)"))
,f2s "no option" (Left (NoOption "abc", "get (sect1/abc)"))
(get cp "sect1" "abc")
,f2s "no section" (Left (NoSection "sect2", "get (sect2/foo)"))
,f2s "no section" (Left (NoSection "sect2", "get (sect2/foo)"))
(get cp "sect2" "foo")
,f2s "default bad sect" (Left (NoSection "sect2", "get (sect2/def)"))
(get cp "sect2" "def")
Expand All @@ -120,7 +123,7 @@ test_nodefault =
-- default bool
]

test_instances =
test_instances =
let cp = p "[x]\na: true\nb: 1\nbad: never"
in [f2 "bool 1st" (Right True) (get cp "x" "a"),
f2 "bool 1nd" (Right True) (get cp "x" "b"),
Expand All @@ -136,7 +139,7 @@ test_merge =
,f2 "merge3" (cp2) (merge cp cp2)
,f2 "merge4" (cp) (merge cp2 cp)]

test_remove =
test_remove =
let cp = forceEither $ readstring emptyCP "def:ault\n[sect1]\ns1o1: v1\ns1o2:v2\n[sect2]\ns2o1: v1\ns2o2: v2\n[sect3]"
in [
f2 "setup" ["sect1", "sect2", "sect3"] (sections cp)
Expand All @@ -159,43 +162,43 @@ test_remove =
y <- options x "sect1"
return (sections x, y)
)
,f2 "option err 1" (Left (NoSection "sect4",
,f2 "option err 1" (Left (NoSection "sect4",
"remove_option (sect4/s4o1)"))
(remove_option cp "sect4" "s4o1")
,f2 "option err 2" (Left (NoOption "s1o3",
"remove_option (sect1/s1o3)"))
(remove_option cp "sect1" "s1o3")
]





test_ex_nomonad =
do




test_ex_nomonad =
do
fh <- nullfile
val <- readfile emptyCP testfile
let cp = forceEither val
hPutStr fh "Your setting is:"
hPutStr fh $ forceEither $ get cp "file1" "location"

test_ex_errormonad =
[
TestLabel "chaining1" $ TestCase $
(Right ["opt1", "opt2"]) @=?
test_ex_errormonad =
[
TestLabel "chaining1" $ TestCase $
(Right ["opt1", "opt2"]) @=?
do let cp = emptyCP
cp <- add_section cp "sect1"
cp <- set cp "sect1" "opt1" "foo"
cp <- set cp "sect1" "opt2" "bar"
options cp "sect1"
,TestLabel "chaining2" $ TestCase $
(Left (NoSection "sect2", "set (sect2/opt2)")) @=?
,TestLabel "chaining2" $ TestCase $
(Left (NoSection "sect2", "set (sect2/opt2)")) @=?
do let cp = emptyCP
cp <- add_section cp "sect1"
cp <- set cp "sect1" "opt1" "foo"
cp <- set cp "sect2" "opt2" "bar"
options cp "sect1"
,TestLabel "chaining3" $ TestCase $
,TestLabel "chaining3" $ TestCase $
["opt1", "opt2"] @=? (
forceEither $ do let cp = emptyCP
cp <- add_section cp "sect1"
Expand All @@ -205,7 +208,7 @@ test_ex_errormonad =
)
]

test_interp =
test_interp =
let interpdoc = "[DEFAULT]\narch = i386\n\n[builder]\n" ++
"filename = test_%(arch)s.c\n" ++
"dir = /usr/src/%(filename)s\n" ++
Expand Down
7 changes: 3 additions & 4 deletions testsrc/ConfigParser/Parsertest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module ConfigParser.Parsertest(tests) where
import Test.HUnit
import Data.ConfigFile.Parser
import Data.ConfigFile.Types
import Test.HUnit.Tools
import Control.Exception

test_basic =
Expand Down Expand Up @@ -62,11 +61,11 @@ test_asserts =
f "e test1" "#foo\nthis is bad data"
(Left (ParseError "\"(string)\" (line 2, column 1):\nunexpected \"t\"\nexpecting end of input, whitespace, start of comment, empty line, start of section or option separator", "lexer"))
,f "e test2" "[sect1]\n#iiiiii \n extensionline\n#foo"
(Left (ParseError "\"(string)\" (line 4, column 1):\nunexpected EXTENSIONLINE \"extensionline\"","parser"))
(Left (ParseError "\"(string)\" (line 4, column 1):\nunexpected (\"(string)\" (line 4, column 1),EXTENSIONLINE \"extensionline\")\nexpecting end of input","parser"))
]

{-


assertRaises "e test1" (ErrorCall "Lexer: \"(string)\" (line 1, column 5):\nunexpected \"\\n\"\nexpecting Option separator")
([] @=? parse_string "#foo\nthis is bad data")
Expand Down