Commits

Bryan O'Sullivan committed a4c735a Merge

Merge pull request #13 from basvandijk/cabal-test-suite

Add a Cabal test-suite section

  • Participants
  • Parent commits 1080a5b, 82670c8

Comments (0)

Files changed (5)

configurator.cabal

 
 extra-source-files:
     README.markdown
-    tests/*.hs
+
+data-files: tests/resources/*.cfg
 
 flag developer
   description: operate in developer mode
     hashable,
     text >= 0.11.1.0,
     unix-compat,
-    unordered-containers	
+    unordered-containers
 
   if flag(developer)
     ghc-options: -Werror
 source-repository head
   type:     mercurial
   location: http://bitbucket.org/bos/configurator
+
+test-suite test-case-insensitive
+  type:           exitcode-stdio-1.0
+  main-is:        Test.hs
+  hs-source-dirs: tests
+  Build-depends:  configurator,
+                  base,
+                  directory,
+                  HUnit,
+                  text,
+                  attoparsec,
+                  unordered-containers,
+                  unix-compat,
+                  hashable,
+                  bytestring
+  Ghc-options:    -Wall -fno-warn-unused-do-bind

tests/Setup.hs

-import Distribution.Simple
-main = defaultMain
 import           System.Environment
 import           System.IO
 import           Test.HUnit
+import           Paths_configurator
 
 main :: IO ()
 main = runTestTT tests >> return ()
     takeMVar w
 
 loadTest :: Assertion
-loadTest = withLoad [Required "resources/pathological.cfg"] $ \cfg -> do
+loadTest = do
+  fp <- getDataFileName "tests/resources/pathological.cfg"
+  withLoad [Required fp] $ \cfg -> do
     aa  <- lookup cfg "aa"
     assertEqual "int property" aa $ (Just 1 :: Maybe Int)
 
     assertEqual "deep bool" deep (Just False :: Maybe Bool)
 
 typesTest :: Assertion
-typesTest = withLoad [Required "resources/pathological.cfg"] $ \ cfg -> do
+typesTest = do
+  fp <- getDataFileName "tests/resources/pathological.cfg"
+  withLoad [Required fp] $ \ cfg -> do
     asInt <- lookup cfg "aa" :: IO (Maybe Int)
     assertEqual "int" asInt (Just 1)
 
     assertEqual "char" asChar (Just 'x')
 
 interpTest :: Assertion
-interpTest = withLoad [Required "resources/pathological.cfg"] $ \ cfg -> do
+interpTest = do
+  fp <- getDataFileName "tests/resources/pathological.cfg"
+  withLoad [Required fp] $ \ cfg -> do
     home    <- getEnv "HOME"
     cfgHome <- lookup cfg "ba"
     assertEqual "home interp" (Just home) cfgHome
 
 importTest :: Assertion
-importTest = withLoad [Required "resources/import.cfg"] $ \ cfg -> do
+importTest = do
+  fp <- getDataFileName "tests/resources/import.cfg"
+  withLoad [Required fp] $ \ cfg -> do
     aa  <- lookup cfg "x.aa" :: IO (Maybe Int)
     assertEqual "simple" aa (Just 1)
     acx <- lookup cfg "x.ac.x" :: IO (Maybe Int)
     assertEqual "nested" acx (Just 1)
 
 reloadTest :: Assertion
-reloadTest = withReload [Required "resources/pathological.cfg"] $ \[Just f] cfg -> do
+reloadTest = do
+  fp <- getDataFileName "tests/resources/pathological.cfg"
+  withReload [Required fp] $ \[Just f] cfg -> do
     aa <- lookup cfg "aa"
     assertEqual "simple property 1" aa $ Just (1 :: Int)
 

tests/configurator-tests.cabal

-Name:                configurator-tests
-Version:             0.1
-Build-type:          Simple
-Cabal-version:       >=1.2
-
-Executable configurator-test
-  Main-is:           Test.hs
-  Hs-source-dirs:    ., ..
-  Build-depends:     base,
-                     directory,
-                     HUnit,
-                     text,
-                     attoparsec-text,
-                     unordered-containers,
-                     unix-compat,
-                     hashable,
-                     bytestring
-  Ghc-options:       -Wall -fhpc -fno-warn-unused-do-bind

tests/runTests.sh

-#!/bin/sh
-cabal configure
-cabal build
-
-rm -f configurator-test.tix
-./dist/build/configurator-test/configurator-test
-
-HPCDIR=dist/hpc
-
-rm -rf $HPCDIR
-mkdir -p $HPCDIR
-
-EXCLUDES='--exclude=Main
-          --exclude=Data.Configurator.Types'
-hpc markup $EXCLUDES --destdir=$HPCDIR configurator-test
-
-rm -f configurator-test.tix