TBC-0.0.3: Testing By Convention

Safe HaskellSafe-Infered




Conventions and data structures.

booltest :: TestConventionSource

The test should yield the string True. This should work for tests of type Bool, IO Bool, IO () with a putStrLn, ...

Note the seq in its implementation is not entirely useless: the test may use unsafePerformIO or trace to incidentally output things after True.

exception :: TestConventionSource

The seqed test should throw an exception.

hunit :: TestConventionSource

A HUnit unit test.

quickcheck :: TestConventionSource

A QuickCheck test. We use the quickCheck driver, i.e., the default settings.

stdDirectoryConv :: DirectoryConvention sSource

Skip .darcs and .git directories, and Cabal's dist directory.

Could also imagine skipping subproject directories.

stdTestFileConv :: TestFileConvention sSource

Skip Cabal's Setup.hs.

std :: Conventions sSource

The standard set of conventions.

type DirectoryConvention s = FilePath -> s -> (Action, s)Source

A directory convention maps a directory name into an action.

type TestFileConvention s = FilePath -> s -> (Action, s)Source

A test file convention maps a file name into an action.

type TestConvention = String -> Maybe (Driver -> IO Result)Source

A test convention maps a line in a TestFile into a function that runs the test.

data Action Source

An action tells TBC what to do when it (recursively) encounters a directory or file.



Cease testing.


Skip this file or directory.


Process this file or directory.

data Test Source

A single test.




tName :: String

Each Test in a TestFile must have a different name.

tLocation :: Location
tRun :: Driver -> IO Result

data Result Source

The result of a single Test.



Skip this test.


This test has not yet been written.


Cease testing.


The test succeeded.


The test failed with this explanation.


msg :: [String]


type Renderer s = Verbosity -> RenderFns sSource

A renderer maps a verbosity level into a bunch of functions that tells the user of various events.

data RenderFns s Source

The collection of rendering functions.




rInitialState :: IO s

Allocate a new test state.

rCompilationFailure :: FilePath -> [Test] -> [String] -> s -> IO s

Render a compilation failure. FIXME refine: skipped a file, skipped some tests, some tests told us to skip, ...

rSkip :: FilePath -> s -> IO s

Render a skipped directory or file.

rStop :: FilePath -> s -> IO s

Handle being told to stop.

rTest :: Test -> s -> Result -> IO s

Execute a test and render its result.

rFinal :: s -> IO ExitCode

Yield an ExitCode depending on how the tests went.

data Conventions s Source

A collection of conventions.




cDirectory :: DirectoryConvention s

The directory convention.

cTestFile :: TestFileConvention s

The filename convention.

cTests :: [TestConvention]

The test conventions.

warn :: Verbosity -> String -> IO ()

Non fatal conditions that may be indicative of an error or problem.

We display these at the normal verbosity level.

notice :: Verbosity -> String -> IO ()

Useful status messages.

We display these at the normal verbosity level.

This is for the ordinary helpful status messages that users see. Just enough information to know that things are working but not floods of detail.

info :: Verbosity -> String -> IO ()

More detail on the operation of some action.

We display these messages when the verbosity level is verbose

debug :: Verbosity -> String -> IO ()

Detailed internal debugging information

We display these messages when the verbosity level is deafening

data Location Source

Location of a Test.




lFile :: FilePath
lLine :: Int
lColumn :: Int


mkLocation :: FilePath -> Int -> Int -> LocationSource

Construct a location.

mkTestName :: String -> StringSource

Discern a test name from a string, viz the entirety of the varid starting at the start of the string. FIXME this should follow the Haskell lexical conventions and perhaps be more robust.

traverseDirectories :: Conventions s -> Driver -> RenderFns s -> [FilePath] -> s -> IO sSource

Visit all files in a directory tree. FIXME try to eliminate the . with some refactoring.

applyTestConventions :: [TestConvention] -> FilePath -> String -> [Test]Source

Apply a list of conventions to the guts of a TestFile.

data Driver Source

Interaction with a Haskell system.




hci_send_cmd :: String -> IO [String]

Execute the given Haskell code and return the response as a list of lines.

hci_load_file :: String -> IO [String]

Load a file into the Haskell system.

hci_kill :: IO ()

Terminate with prejudice.

hci_close :: IO ExitCode

Clean exit.



:: Verbosity 
-> String

ghci command name

-> [String]


-> IO Driver 

A driver for GHCi using a slave process.

Top-level drivers.

tbc :: Driver -> [FilePath] -> IO ()Source

A hardwired (conventional) driver.

tbcWithHooks :: Conventions s -> RenderFns s -> Driver -> [FilePath] -> IO ExitCodeSource

A parametrised bells-and-whistles driver.



:: Verbosity 
-> Args

Where are the tests (dirs and files)?

-> Bool 
-> PackageDescription 
-> LocalBuildInfo 
-> IO () 

A driver compatible with Cabal's runTests hook.

However the test infrastructure in Cabal has changed since this was written, and its use is discouraged. Use the TBC binary instead.

This is used by the TBC binary.

defaultMain :: IO ()Source

This is a drop-in replacement for Cabal's defaultMain.

However the test infrastructure in Cabal has changed since this was written, and its use is discouraged. Use the TBC binary instead.