Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…our "cabal test".
  • Loading branch information...
commit 251c6a4e627920c027dbda3cdd1599342fe17519 1 parent d4c74fe
@hamishmack hamishmack authored
View
49 data/main.lksht
@@ -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
+
View
392 leksah.cabal
@@ -1,195 +1,197 @@
-name: leksah
-version: 0.12.0.2
-cabal-version: >=1.8
-build-type: Simple
-license: GPL
-license-file: LICENSE
-copyright: 2007-2011 Juergen Nicklisch-Franken, Hamish Mackenzie
-maintainer: maintainer@leksah.org
-stability: provisional
-homepage: http://www.leksah.org
-package-url: http://code.haskell.org/leksah
-bug-reports: http://code.google.com/p/leksah/issues/list
-synopsis: Haskell IDE written in Haskell
-description: An Integrated Development Environment for Haskell written in Haskell.
-category: Development, IDE, Editor
-author: Juergen Nicklisch-Franken, Hamish Mackenzie
-tested-with: GHC == 7.2.2
-data-files: LICENSE
- Readme
-
- data/current.lkshs
- data/candy.lkshc
- data/keymap.lkshk
- data/leksah.menu
- data/prefs.lkshp
- data/prefscoll.lkshp
- data/emacs.lkshk
- data/LICENSE
- data/module.lksht
- data/welcome.txt
-
- language-specs/haskell.lang
- language-specs/haskell-literate.lang
- language-specs/hamlet.lang
- language-specs/cassius.lang
- language-specs/lucius.lang
- language-specs/julius.lang
-
- pics/ide_class.png
- pics/ide_configure.png
- pics/ide_data.png
- pics/ide_error_next.png
- pics/ide_error_prev.png
- pics/ide_function.png
- pics/ide_instance.png
- pics/ide_konstructor.png
- pics/ide_make.png
- pics/ide_method.png
- pics/ide_newtype.png
- pics/ide_other.png
- pics/ide_reexported.png
- pics/ide_rule.png
- pics/ide_run.png
- pics/ide_slot.png
- pics/ide_source.png
- pics/ide_source_local.png
- pics/ide_type.png
- pics/leksah.png
- pics/ide_step.png
- pics/ide_local.png
- pics/ide_module.png
- pics/ide_continue.png
- pics/ide_debug.png
- pics/ide_clean.png
- pics/ide_build.png
- pics/ide_link.png
- pics/ide_rebuild_meta.png
- pics/ide_empty.png
-data-dir: ""
-extra-source-files: Setup.lhs
-extra-tmp-files:
-
-flag yi
- Default: False
- Description: Experimental Yi support
-
-flag dyre
- Default: True
- Description: Experimental Yi support
-
-library
- if os(windows)
- build-depends: Win32 >=2.2.0.0 && <2.3
- extra-libraries: kernel32
--- extra-lib-dirs: C:/cygwin/lib/w32api
- includes: windows.h
--- include-dirs: C:/cygwin/usr/include/w32api
- else
- build-depends: unix >=2.3.1.0 && <2.6
-
- if os(osx)
- build-depends: gtk-mac-integration >= 0.0.0.2 && <0.2
-
- if flag(yi)
- build-depends: yi >=0.6.1 && <0.7
- cpp-options: -DLEKSAH_WITH_YI
-
- if flag(yi) && flag(dyre)
- build-depends: dyre >= 0.8.3 && <0.9
- cpp-options: -DLEKSAH_WITH_YI_DYRE
-
- hs-source-dirs: src
- extensions: CPP
-
- build-depends: Cabal >=1.6.0.1 && <1.15, base >=4.0.0.0 && <4.6, binary >=0.5.0.0 && <0.6,
- bytestring >=0.9.0.1 && <0.10, containers >=0.2.0.0 && <0.5, directory >=1.0.0.2 && <3.1,
- filepath >=1.1.0.1 && <1.4, glib >=0.10 && <0.13, gtk >=0.10 && <0.13,
- gtksourceview2 >=0.10.0 && <0.13, mtl >=1.1.0.2 && <2.1, old-time >=1.0.0.1 && <1.2,
- parsec >=2.1.0.1 && <3.2, pretty >=1.0.1.0 && <1.2,
- regex-tdfa ==1.1.*, regex-base ==0.93.*, utf8-string >=0.3.1.1 && <0.4, array >=0.2.0.0 && <0.5,
- time >=0.1 && <1.5, ltk >= 0.12 && <0.13, binary-shared >= 0.8 && <0.9, deepseq >= 1.1.0.0 && <1.4,
- hslogger >= 1.0.7 && <1.2, leksah-server >=0.12.0.1 && <0.13, network >= 2.2 && <3.0,
- ghc >=6.10.1 && <7.5, strict >= 0.3.2 && <0.4, enumerator >=0.4.14 && <0.5, text >= 0.11.1.5 && < 0.12,
- gio >= 0.12.2 && < 0.13, transformers >=0.2.2.0 && <0.3
-
- exposed-modules:
- IDE.Leksah IDE.Completion IDE.ImportTool
- IDE.Find IDE.Session IDE.Command IDE.Keymap IDE.Utils.GUIUtils IDE.SymbolNavigation
- IDE.Package IDE.YiConfig IDE.OSX
- IDE.GUIHistory IDE.SourceCandy IDE.NotebookFlipper
- IDE.Core.Types IDE.Core.State
- IDE.Metainfo.Provider
- IDE.Pane.Preferences IDE.Pane.PackageEditor
- IDE.Pane.Info IDE.Pane.Log IDE.Pane.SourceBuffer IDE.Pane.Modules
- IDE.Pane.Search IDE.Pane.PackageFlags
- IDE.LogRef IDE.Debug IDE.Pane.Grep IDE.Pane.Files
- IDE.Pane.Breakpoints IDE.Pane.Trace IDE.Pane.Variables
- IDE.Pane.Errors IDE.TextEditor IDE.Workspaces
- IDE.Statusbar IDE.Pane.Workspace IDE.PaneGroups
- IDE.Utils.ServerConnection
- IDE.BufferMode
- IDE.Build
-
- if (impl(ghc > 7))
- other-modules:
- Distribution.PackageDescription.PrettyPrintCopied
- Distribution.PackageDescription.ParseCopied
-
- other-modules: Paths_leksah
-
- ghc-prof-options: -auto-all -prof
- ghc-shared-options: -auto-all
- ghc-options: -fwarn-missing-fields -fwarn-incomplete-patterns -ferror-spans
-
-Executable leksah
- if os(windows)
- build-depends: Win32 >=2.2.0.0 && <2.3
- extra-libraries: kernel32
--- extra-lib-dirs: C:/cygwin/lib/w32api
- includes: windows.h
--- include-dirs: C:/cygwin/usr/include/w32api
- else
- build-depends: unix >=2.3.1.0 && <2.6
-
- if os(osx)
- build-depends: gtk-mac-integration >= 0.0.0.2 && <0.2
-
- if flag(yi)
- cpp-options: -DLEKSAH_WITH_YI
-
- if flag(yi) && flag(dyre)
- cpp-options: -DLEKSAH_WITH_DYRE
-
- if impl(ghc < 7.0) && flag(yi)
- build-depends: yi >=0.6.1 && <0.7
-
- if impl(ghc < 7.0) && flag(yi) && flag(dyre)
- build-depends: dyre >= 0.8.3 && <0.9
-
- if impl(ghc < 7.0)
- hs-source-dirs: src, main
- build-depends: Cabal >=1.6.0.1 && <1.15, base >=4.0.0.0 && <4.6, binary >=0.5.0.0 && <0.6,
- bytestring >=0.9.0.1 && <0.10, containers >=0.2.0.0 && <0.5, directory >=1.0.0.2 && <3.1,
- filepath >=1.1.0.1 && <1.4, glib >=0.10 && <0.13, gtk >=0.10 && <0.13,
- gtksourceview2 >=0.10.0 && <0.13, mtl >=1.1.0.2 && <2.1, old-time >=1.0.0.1 && <1.2,
- parsec >=2.1.0.1 && <3.2, pretty >=1.0.1.0 && <1.2,
- regex-tdfa ==1.1.*, regex-base ==0.93.*, utf8-string >=0.3.1.1 && <0.4, array >=0.2.0.0 && <0.5,
- time >=0.1 && <1.5, ltk >=0.12 && <0.13, binary-shared >= 0.8 && <0.9, deepseq >= 1.1.0.0 && <1.4,
- hslogger >= 1.0.7 && <1.2, leksah-server >=0.12.0.1 && <0.13, network >= 2.2 && <3.0,
- ghc >=6.10.1 && <7.5, strict >= 0.3.2 && <0.4, enumerator >=0.4.14 && <0.5, text >= 0.11.1.5 && < 0.12,
- gio >= 0.12.2 && < 0.13, transformers >=0.2.2.0 && <0.3
- else
- hs-source-dirs: main
- build-depends: leksah ==0.12.0.2, base >=4.0.0.0 && <= 5
-
- main-is: Main.hs
- buildable: True
- extensions: CPP
- ghc-prof-options: -auto-all -prof
- ghc-shared-options: -auto-all
- ghc-options: -fwarn-missing-fields -fwarn-incomplete-patterns -ferror-spans
-
-
-
-
+name: leksah
+version: 0.12.0.3
+cabal-version: >=1.8
+build-type: Simple
+license: GPL
+license-file: LICENSE
+copyright: 2007-2011 Juergen Nicklisch-Franken, Hamish Mackenzie
+maintainer: maintainer@leksah.org
+stability: provisional
+homepage: http://www.leksah.org
+package-url: http://code.haskell.org/leksah
+bug-reports: http://code.google.com/p/leksah/issues/list
+synopsis: Haskell IDE written in Haskell
+description: An Integrated Development Environment for Haskell written in Haskell.
+category: Development, IDE, Editor
+author: Juergen Nicklisch-Franken, Hamish Mackenzie
+tested-with: GHC == 7.2.2
+data-files: LICENSE
+ Readme
+
+ data/current.lkshs
+ data/candy.lkshc
+ data/keymap.lkshk
+ data/leksah.menu
+ data/prefs.lkshp
+ data/prefscoll.lkshp
+ data/emacs.lkshk
+ data/LICENSE
+ data/main.lksht
+ data/module.lksht
+ data/welcome.txt
+
+ language-specs/haskell.lang
+ language-specs/haskell-literate.lang
+ language-specs/hamlet.lang
+ language-specs/cassius.lang
+ language-specs/lucius.lang
+ language-specs/julius.lang
+
+ pics/ide_class.png
+ pics/ide_configure.png
+ pics/ide_data.png
+ pics/ide_error_next.png
+ pics/ide_error_prev.png
+ pics/ide_function.png
+ pics/ide_instance.png
+ pics/ide_konstructor.png
+ pics/ide_make.png
+ pics/ide_method.png
+ pics/ide_newtype.png
+ pics/ide_other.png
+ pics/ide_reexported.png
+ pics/ide_rule.png
+ pics/ide_run.png
+ pics/ide_slot.png
+ pics/ide_source.png
+ pics/ide_source_local.png
+ pics/ide_type.png
+ pics/leksah.png
+ pics/ide_step.png
+ pics/ide_local.png
+ pics/ide_module.png
+ pics/ide_continue.png
+ pics/ide_debug.png
+ pics/ide_clean.png
+ pics/ide_build.png
+ pics/ide_link.png
+ pics/ide_rebuild_meta.png
+ pics/ide_empty.png
+data-dir: ""
+extra-source-files: Setup.lhs
+extra-tmp-files:
+
+flag yi
+ Default: False
+ Description: Experimental Yi support
+
+flag dyre
+ Default: True
+ Description: Experimental Yi support
+
+library
+ if os(windows)
+ build-depends: Win32 >=2.2.0.0 && <2.3
+ extra-libraries: kernel32
+-- extra-lib-dirs: C:/cygwin/lib/w32api
+ includes: windows.h
+-- include-dirs: C:/cygwin/usr/include/w32api
+ else
+ build-depends: unix >=2.3.1.0 && <2.6
+
+ if os(osx)
+ build-depends: gtk-mac-integration >= 0.0.0.2 && <0.2
+
+ if flag(yi)
+ build-depends: yi >=0.6.1 && <0.7
+ cpp-options: -DLEKSAH_WITH_YI
+
+ if flag(yi) && flag(dyre)
+ build-depends: dyre >= 0.8.3 && <0.9
+ cpp-options: -DLEKSAH_WITH_YI_DYRE
+
+ hs-source-dirs: src
+ extensions: CPP
+
+ build-depends: Cabal >=1.6.0.1 && <1.15, base >=4.0.0.0 && <4.6, binary >=0.5.0.0 && <0.6,
+ bytestring >=0.9.0.1 && <0.10, containers >=0.2.0.0 && <0.5, directory >=1.0.0.2 && <3.1,
+ filepath >=1.1.0.1 && <1.4, glib >=0.10 && <0.13, gtk >=0.10 && <0.13,
+ gtksourceview2 >=0.10.0 && <0.13, mtl >=1.1.0.2 && <2.1, old-time >=1.0.0.1 && <1.2,
+ parsec >=2.1.0.1 && <3.2, pretty >=1.0.1.0 && <1.2,
+ regex-tdfa ==1.1.*, regex-base ==0.93.*, utf8-string >=0.3.1.1 && <0.4, array >=0.2.0.0 && <0.5,
+ time >=0.1 && <1.5, ltk >= 0.12 && <0.13, binary-shared >= 0.8 && <0.9, deepseq >= 1.1.0.0 && <1.4,
+ hslogger >= 1.0.7 && <1.2, leksah-server >=0.12.0.3 && <0.13, network >= 2.2 && <3.0,
+ ghc >=6.10.1 && <7.5, strict >= 0.3.2 && <0.4, enumerator >=0.4.14 && <0.5, text >= 0.11.1.5 && < 0.12,
+ gio >=0.12.2 && < 0.13, transformers >=0.2.2.0 && <0.3,
+ QuickCheck >=2.4.2 && QuickCheck <2.5
+
+ exposed-modules:
+ IDE.Leksah IDE.Completion IDE.ImportTool
+ IDE.Find IDE.Session IDE.Command IDE.Keymap IDE.Utils.GUIUtils IDE.SymbolNavigation
+ IDE.Package IDE.YiConfig IDE.OSX
+ IDE.GUIHistory IDE.SourceCandy IDE.NotebookFlipper
+ IDE.Core.Types IDE.Core.State
+ IDE.Metainfo.Provider
+ IDE.Pane.Preferences IDE.Pane.PackageEditor
+ IDE.Pane.Info IDE.Pane.Log IDE.Pane.SourceBuffer IDE.Pane.Modules
+ IDE.Pane.Search IDE.Pane.PackageFlags
+ IDE.LogRef IDE.Debug IDE.Pane.Grep IDE.Pane.Files
+ IDE.Pane.Breakpoints IDE.Pane.Trace IDE.Pane.Variables
+ IDE.Pane.Errors IDE.TextEditor IDE.Workspaces
+ IDE.Statusbar IDE.Pane.Workspace IDE.PaneGroups
+ IDE.Utils.ServerConnection
+ IDE.BufferMode
+ IDE.Build
+
+ if (impl(ghc > 7))
+ other-modules:
+ Distribution.PackageDescription.PrettyPrintCopied
+ Distribution.PackageDescription.ParseCopied
+
+ other-modules: Paths_leksah
+
+ ghc-prof-options: -auto-all -prof
+ ghc-shared-options: -auto-all
+ ghc-options: -fwarn-missing-fields -fwarn-incomplete-patterns -ferror-spans
+
+Executable leksah
+ if os(windows)
+ build-depends: Win32 >=2.2.0.0 && <2.3
+ extra-libraries: kernel32
+-- extra-lib-dirs: C:/cygwin/lib/w32api
+ includes: windows.h
+-- include-dirs: C:/cygwin/usr/include/w32api
+ else
+ build-depends: unix >=2.3.1.0 && <2.6
+
+ if os(osx)
+ build-depends: gtk-mac-integration >= 0.0.0.2 && <0.2
+
+ if flag(yi)
+ cpp-options: -DLEKSAH_WITH_YI
+
+ if flag(yi) && flag(dyre)
+ cpp-options: -DLEKSAH_WITH_DYRE
+
+ if impl(ghc < 7.0) && flag(yi)
+ build-depends: yi >=0.6.1 && <0.7
+
+ if impl(ghc < 7.0) && flag(yi) && flag(dyre)
+ build-depends: dyre >= 0.8.3 && <0.9
+
+ if impl(ghc < 7.0)
+ hs-source-dirs: src, main
+ build-depends: Cabal >=1.6.0.1 && <1.15, base >=4.0.0.0 && <4.6, binary >=0.5.0.0 && <0.6,
+ bytestring >=0.9.0.1 && <0.10, containers >=0.2.0.0 && <0.5, directory >=1.0.0.2 && <3.1,
+ filepath >=1.1.0.1 && <1.4, glib >=0.10 && <0.13, gtk >=0.10 && <0.13,
+ gtksourceview2 >=0.10.0 && <0.13, mtl >=1.1.0.2 && <2.1, old-time >=1.0.0.1 && <1.2,
+ parsec >=2.1.0.1 && <3.2, pretty >=1.0.1.0 && <1.2,
+ regex-tdfa ==1.1.*, regex-base ==0.93.*, utf8-string >=0.3.1.1 && <0.4, array >=0.2.0.0 && <0.5,
+ time >=0.1 && <1.5, ltk >=0.12 && <0.13, binary-shared >= 0.8 && <0.9, deepseq >= 1.1.0.0 && <1.4,
+ hslogger >= 1.0.7 && <1.2, leksah-server >=0.12.0.3 && <0.13, network >= 2.2 && <3.0,
+ ghc >=6.10.1 && <7.5, strict >= 0.3.2 && <0.4, enumerator >=0.4.14 && <0.5, text >= 0.11.1.5 && < 0.12,
+ gio >= 0.12.2 && < 0.13, transformers >=0.2.2.0 && <0.3
+ else
+ hs-source-dirs: main
+ build-depends: leksah ==0.12.0.3, base >=4.0.0.0 && <= 5
+
+ main-is: Main.hs
+ buildable: True
+ extensions: CPP
+ ghc-prof-options: -auto-all -prof
+ ghc-shared-options: -auto-all
+ ghc-options: -fwarn-missing-fields -fwarn-incomplete-patterns -ferror-spans
+
+
+
+
View
8 src/IDE/Package.hs
@@ -455,12 +455,12 @@ getPackageDescriptionAndPath = do
return Nothing))
getEmptyModuleTemplate :: PackageDescription -> String -> IO String
-getEmptyModuleTemplate pd modName = getModuleTemplate pd modName "" ""
+getEmptyModuleTemplate pd modName = getModuleTemplate "module" pd modName "" ""
-getModuleTemplate :: PackageDescription -> String -> String -> String -> IO String
-getModuleTemplate pd modName exports body = catch (do
+getModuleTemplate :: String -> PackageDescription -> String -> String -> String -> IO String
+getModuleTemplate template pd modName exports body = catch (do
dataDir <- getDataDir
- filePath <- getConfigFilePathForLoad standardModuleTemplateFilename Nothing dataDir
+ filePath <- getConfigFilePathForLoad (template ++ leksahTemplateFileExtension) Nothing dataDir
template <- UTF8.readFile filePath
return (foldl' (\ a (from, to) -> replace from to a) template
[ ("@License@" , (show . license) pd)
View
22 src/IDE/Pane/PackageEditor.hs
@@ -268,16 +268,21 @@ packageNew' mbDir activateAction = do
#if MIN_VERSION_Cabal(1,10,0)
specVersionRaw = Right (orLaterVersion (Version [1,2] [])),
#endif
- buildDepends = [Dependency (PackageName "base") anyVersion],
+ buildDepends = [
+ Dependency (PackageName "base") anyVersion
+ , Dependency (PackageName "QuickCheck") anyVersion],
executables = [emptyExecutable {
exeName = (takeBaseName dirName)
, modulePath = "Main.hs"
- , buildInfo = emptyBuildInfo {hsSourceDirs = ["src"]}}]
+ , buildInfo = emptyBuildInfo {
+ hsSourceDirs = ["src"]}}]
#if MIN_VERSION_Cabal(1,10,0)
, testSuites = [emptyTestSuite {
testName = "test-" ++ takeBaseName dirName
- , testInterface = (TestSuiteExeV10 (Version [1,0] []) "Test.hs")
- , testBuildInfo = emptyBuildInfo {hsSourceDirs = ["src"]}}]
+ , testInterface = (TestSuiteExeV10 (Version [1,0] []) "Main.hs")
+ , testBuildInfo = emptyBuildInfo {
+ hsSourceDirs = ["src"]
+ , cppOptions = ["-DMAIN_FUNCTION=testMain"]}}]
#endif
} dirName modules (activateAction True)
return ()
@@ -955,7 +960,14 @@ buildInfoD fp modules i = [
(filesEditor fp FileChooserActionSelectFolder "Select Folder")
]),
(show (i + 1) ++ " Other", VFD emptyParams [
- mkField
+ mkField
+ (paraName <<<- ParaName "Options for C preprocessor"
+ $ paraDirection <<<- ParaDirection Vertical
+ $ emptyParams)
+ (cppOptions . (\a -> a !! i) . bis)
+ (\ a b -> b{bis = update (bis b) i (\bi -> bi{cppOptions = a})})
+ optsEditor
+ , mkField
(paraName <<<- ParaName "Support frameworks for Mac OS X"
$ paraDirection <<<- ParaDirection Vertical $ emptyParams)
(frameworks . (\a -> a !! i) . bis)
View
7 src/IDE/Workspaces.hs
@@ -302,14 +302,9 @@ constructAndOpenMainModule (Just idePackage) =
alreadyExists <- liftIO $ doesFileExist (path </> target)
if alreadyExists
then do
- ideMessage Normal "Main file already exists"
fileOpenThis (path </> target)
else do
- template <- liftIO $ getModuleTemplate pd "Main"
- " main"
- (if isTest
- then "main = putStrLn \"Put your test code here\""
- else "main = putStrLn \"Hello World!\"")
+ template <- liftIO $ getModuleTemplate "main" pd "Main" "" ""
liftIO $ UTF8.writeFile (path </> target) template
fileOpenThis (path </> target)
_ -> return ()
Please sign in to comment.
Something went wrong with that request. Please try again.