Skip to content

Commit

Permalink
Enabled "cabal test" support and other Cabal fixes.
Browse files Browse the repository at this point in the history
Running "cabal check" no longer complains of anything. Running "cabal
haddock" reports 100% coverage.
  • Loading branch information
malcolmt committed Nov 1, 2011
1 parent 6508e0a commit e91c05e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ html/
*.hi
*.o
*.tix
Suite
CabalTest
ConsoleTest

30 changes: 21 additions & 9 deletions chess-tools.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ Build-type: Simple
Homepage: https://github.com/malcolmt/chess-tools/
Bug-reports: https://github.com/malcolmt/chess-tools/issues

-- Need to list test source files in extra-source-files until a version of
-- Cabal fixing http://hackage.haskell.org/trac/hackage/ticket/792 is in
-- general use.
Extra-source-files: README.md
TODO.otl
src/ChessTools/Test/*.hs

Cabal-version: >= 1.10

Expand All @@ -43,19 +47,27 @@ Source-repository head
Library
Exposed-modules: ChessTools.Board
ChessTools.Board.Internal
ChessTools.Board.Western

Default-language: Haskell2010
Hs-Source-Dirs: src
GHC-Options: -Wall -Werror -O
Build-depends: haskell2010
GHC-Options: -Wall
Build-depends: base < 5.0,
array >= 0.3 && < 1.0


-- TODO: Wrestle this to the ground. Still a little problematic.
Test-Suite test-chess-tools
Type: exitcode-stdio-1.0
Main-is: ChessTools/Test/CabalTest.hs
Hs-source-dirs: src
Default-language: Haskell2010

Build-depends: base < 5.0,
array >= 0.3 && < 1.0,
Cabal >= 1.10,
test-framework >= 0.4.1 && < 1.0,
test-framework-quickcheck2 >= 0.2.10 && < 1.0,
QuickCheck >= 2.4.0.1 && < 3.0

-- Test-Suite test-chess-tools
-- Type: detailed-1.0
-- Test-module: Tests
-- Hs-source-dirs: test
-- Build-depends: haskell2010
-- Cabal >= 1.10
GHC-Options: -Wall

4 changes: 3 additions & 1 deletion src/ChessTools/Board/Western.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import Data.Char (ord, chr)
import ChessTools.Board


-- | The 'BoardSize' for a western-style chessboard.
westernBoardSize :: BoardSize
westernBoardSize = BoardSize 8 8 2

-- XXX: Not yet used; commented out to maintain warning-free build.
-- | A 'CoveringIndexList' appropriate for a western-style chessboard size.
-- coveringIndices :: CoveringIndexList
-- coveringIndices = repIndexList westernBoardSize

Expand All @@ -32,7 +34,7 @@ algebraicToIndex _ = Nothing


-- | Converts an index into a board array back into an algebraic notation
-- square designation, such as "/e5/".
-- square designation, such as /"e5"/.
indexToAlgebraic :: BIndex -> Maybe String
indexToAlgebraic x = case sq of
Just (Square (f, r)) -> Just $ chr (f + ord 'a') : [chr (r + ord '1')]
Expand Down
19 changes: 19 additions & 0 deletions src/ChessTools/Test/CabalTest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{-
- The driver file for running the tests via "cabal test". This is slightly
- different to how we might run them from the command line, since suppressing
- ANSI output is forced in this case (otherwise the log file is completely
- messed up).
-}

module Main (main) where

import Data.Monoid (mempty)
import Test.Framework

import ChessTools.Test.Suite (tests)


main :: IO ()
main = defaultMainWithOpts tests options
where options = (mempty :: RunnerOptions) {ropt_plain_output = Just True}

15 changes: 15 additions & 0 deletions src/ChessTools/Test/ConsoleTest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{-
- Driver file for running tests at a command line prompt. This is the standard
- pass-through to the test-framework package.
-
- Refer to CabalTest.hs for the setup used when running "cabal test".
-}

module Main (main) where

import Test.Framework (defaultMain)
import ChessTools.Test.Suite (tests)

main :: IO ()
main = defaultMain tests

15 changes: 7 additions & 8 deletions src/ChessTools/Test/Suite.hs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
{-
- Runs all the tests and provides a nice summary output, using the
- test-framework library.
- Grouping of tests into groups and giving them readable names.
-
- Useful during development. During deployment situations, "cabal test" is
- going to be more appropriate.
- Runner files for these tests are in ConsoleTest.hs and CabalTest.hs.
-}

import Test.Framework (defaultMain, testGroup, Test)
module ChessTools.Test.Suite (
tests
) where

import Test.Framework (testGroup, Test)
import Test.Framework.Providers.QuickCheck2 (testProperty)

import ChessTools.Test.Board
import ChessTools.Test.WesternBoard


main :: IO ()
main = defaultMain tests

tests :: [Test]
tests = [
testGroup "Board arrays" [
Expand Down

0 comments on commit e91c05e

Please sign in to comment.