Last active
August 29, 2015 14:10
-
-
Save timjstewart/281ea4bbfa060e5cec6b to your computer and use it in GitHub Desktop.
Quickly create a scratch cabal sandbox and project complete with hspec/QuickCheck tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
package_name=$(basename `pwd`) | |
log_file=./cabal-init.log | |
function fatal() { | |
echo "$1. Examine ${log_file} for more information." 2>&1 | |
exit 1 | |
} | |
if ! cabal init --quiet \ | |
--package-name=${package_name} \ | |
--category=TBD \ | |
--version=0.1.0 \ | |
--license=BSD3 \ | |
--no-comments \ | |
--minimal \ | |
--author='Your Name' \ | |
[email protected] \ | |
--homepage=www.example.com \ | |
--synopsis='this could be the start of something...' \ | |
--is-library \ | |
--language=Haskell2010 \ | |
--source-dir=src \ | |
--overwrite \ | |
--expose-module=Library > ${log_file} 2>&1 | |
then | |
fatal "cabal init failed" | |
fi | |
if [ ! -d src ] | |
then | |
mkdir src | |
fi | |
if [ ! -d test ] | |
then | |
mkdir test | |
fi | |
cat <<-EOF > test/Main.hs | |
module Main where | |
import Test.Hspec | |
import Test.QuickCheck | |
main :: IO () | |
main = hspec $ do | |
describe "Specs" $ do | |
it "should ..." $ do | |
head [23 ..] \`shouldBe\` (23 :: Int) | |
describe "QuickChecks" $ do | |
it "returns the first element of an *arbitrary* list" $ | |
property $ \x xs -> head (x:xs) == (x :: Int) | |
EOF | |
cat <<EOF > src/Library.hs | |
module Library where | |
foo :: Int | |
foo = 42 | |
EOF | |
cat <<- EOF >> ${package_name}.cabal | |
ghc-options: -Wall | |
test-suite suite-one | |
build-depends: base >=4.7 && <4.8, | |
${package_name}, | |
hspec, | |
QuickCheck | |
hs-source-dirs: test | |
default-language: Haskell2010 | |
type: exitcode-stdio-1.0 | |
main-is: Main.hs | |
ghc-options: -Wall | |
EOF | |
if ! cabal sandbox init >> ${log_file} 2>&1 | |
then | |
fatal "Could not initialize sandbox" | |
fi | |
echo "installing dependencies..." | |
if ! cabal install --only-dependencies --enable-tests >> ${log_file} 2>&1 | |
then | |
fatal "Could not install dependencies" | |
fi | |
if ! cabal configure --enable-tests >> ${log_file} 2>&1 | |
then | |
fatal "Could not configure project" | |
fi | |
echo "building project..." | |
if ! cabal build >> ${log_file} 2>&1 | |
then | |
fatal "Could not build project" | |
fi | |
echo "running tests..." | |
if ! cabal test --show-details=always >> ${log_file} 2>&1 | |
then | |
fatal "Could not run tests or there were test failures" | |
fi | |
rm ${log_file} | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment