Permalink
Browse files

Better Hello World. Includes example of using QuickCheck as part of y…

…our "cabal test".
  • Loading branch information...
1 parent d4c74fe commit 251c6a4e627920c027dbda3cdd1599342fe17519 @hamishmack hamishmack committed Mar 10, 2012
Showing with 268 additions and 210 deletions.
  1. +49 −0 data/main.lksht
  2. +197 −195 leksah.cabal
  3. +4 −4 src/IDE/Package.hs
  4. +17 −5 src/IDE/Pane/PackageEditor.hs
  5. +1 −6 src/IDE/Workspaces.hs
View
@@ -0,0 +1,49 @@
+{-# LANGUAGE CPP, TemplateHaskell #-}
+-----------------------------------------------------------------------------
+--
+-- Module : @ModuleName@
+-- Copyright : @Copyright@
+-- License : @License@
+--
+-- Maintainer : @Maintainer@
+-- Stability : @Stability@
+-- Portability : @Portability@
+--
+-- |
+--
+-----------------------------------------------------------------------------
+
+module @ModuleName@ (
+ main
+) where
+
+import Control.Monad (unless)
+import Data.List (stripPrefix)
+import System.Exit (exitFailure)
+import Test.QuickCheck.All (quickCheckAll)
+
+-- Simple function to create a hello message.
+hello s = "Hello " ++ s
+
+-- Tell QuickCheck that if you strip "Hello " from the start of
+-- hello s you will be left with s (for any s).
+prop_hello s = stripPrefix "Hello " (hello s) == Just s
+
+-- Hello World
+exeMain = do
+ putStrLn (hello "World")
+
+-- Entry point for unit tests.
+testMain = do
+ allPass <- $quickCheckAll -- Run QuickCheck on all prop_ functions
+ unless allPass exitFailure
+
+-- This is a clunky, but portable, way to use the same Main module file
+-- for both an application and for unit tests.
+-- MAIN_FUNCTION is preprocessor macro set to exeMain or testMain.
+-- That way we can use the same file for both an application and for tests.
+#ifndef MAIN_FUNCTION
+#define MAIN_FUNCTION exeMain
+#endif
+main = MAIN_FUNCTION
+
Oops, something went wrong.

0 comments on commit 251c6a4

Please sign in to comment.