fixed many bugs and added Holy grail theme
This commit is contained in:
parent
6fddba4822
commit
627df7c429
1 changed files with 161 additions and 67 deletions
|
@ -1,39 +1,104 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
autoload colors
|
||||
colors
|
||||
for COLOR in RED GREE YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
|
||||
eval $COLOR='$fg_no_bold[${(L)COLOR}]'
|
||||
eval BOLD_$COLOR='$fg_bold[${(L)COLOR}]'
|
||||
done
|
||||
eval RESET='$reset_color'
|
||||
# --- Function declaration and global variables
|
||||
answer=""
|
||||
# Capitalize a string
|
||||
capitalize(){
|
||||
local str="$*"
|
||||
print -- ${${str[1]}:u}${str[2,-1]}
|
||||
}
|
||||
bk(){print -- "${RED}Bridgekeeper: $*${RESET}"}
|
||||
bkn(){print -n -- "${RED}Bridgekeeper: $*${RESET}"}
|
||||
you(){print -- "${BLUE}You: $*${RESET}"}
|
||||
log(){print -- $*}
|
||||
err(){
|
||||
{
|
||||
case $(( $RANDOM % 1 )); in
|
||||
0) bk "What... is your favourite colour?"
|
||||
you "Blue. No, yel..."
|
||||
log "[You are thrown over the edge into the volcano]"
|
||||
you "You: Auuuuuuuuuuuugh"
|
||||
bk " Hee hee heh."
|
||||
;;
|
||||
1) bk "What is the capital of Assyria?"
|
||||
you "I don't know that!"
|
||||
log "[You are thrown over the edge into the volcano]"
|
||||
you "Auuuuuuuuuuuugh"
|
||||
;;
|
||||
esac
|
||||
|
||||
print -- "\n$*"
|
||||
}>&2
|
||||
exit 1
|
||||
}
|
||||
# Ask the user for some information
|
||||
# Search in .gitconfig some hints to provide default value
|
||||
ask(){
|
||||
local elem=$1
|
||||
local gitconfigelem
|
||||
print -n -- "What is your $elem?"
|
||||
bkn "What is your $elem?"
|
||||
[[ -e ~/.gitconfig ]] && {
|
||||
gitconfigelem="$(< ~/.gitconfig| awk '$1 == "'$elem'" {$1="";$2="";gsub("^ *","");print}')"
|
||||
[[ $gitconfigelem = "" ]] || {
|
||||
print -n -- " ($gitconfigelem)"
|
||||
}
|
||||
}
|
||||
print -n ": "
|
||||
read answer
|
||||
print -n "\n> ";read answer
|
||||
[[ $answer = "" ]] && answer=$gitconfigelem
|
||||
}
|
||||
|
||||
print -n -- "What is the name of your project? (start with a capital)"
|
||||
read project
|
||||
# Delete the project directory and show an error message
|
||||
reinit(){
|
||||
cd ..
|
||||
[[ -e $project ]] && \rm -rf $project
|
||||
err "Something went wrong, I removed the project directory"
|
||||
}
|
||||
|
||||
err(){print -- $*>&2;exit 1}
|
||||
|
||||
# --- Start asking questions
|
||||
bk "Stop!"
|
||||
bk "Who would cross the Bridge of Death"
|
||||
bk "must answer me these questions three,"
|
||||
bk "ere the other side he see."
|
||||
you "Ask me the questions, bridgekeeper, I am not afraid.\n"
|
||||
|
||||
# project name
|
||||
bk "What is the name of your project?"
|
||||
print -n "> ";read project
|
||||
|
||||
if perl -e 'exit("'$project'" =~ /^[a-zA-Z0-9]*$/)'; then
|
||||
err "The project name can't contains non ASCII character"
|
||||
fi
|
||||
project=${project:l} # use lowercase for project name
|
||||
module=$(capitalize $project)
|
||||
[[ $project = "" ]] && err "Can't use empty project name"
|
||||
[[ -e $project ]] && err "$project already exists"
|
||||
[[ -e $project ]] && err "$project directory already exists"
|
||||
|
||||
# author name
|
||||
ask name
|
||||
name="$answer"
|
||||
# email
|
||||
ask email
|
||||
email="$answer"
|
||||
print -n -- "A short description of the project: "
|
||||
read description
|
||||
print -n -- "What is your github user name? "
|
||||
read github
|
||||
# github
|
||||
bk "What is your github user name?"
|
||||
print -n "> ";read github
|
||||
# synopsis
|
||||
bk "What is your project in less than ten words?"
|
||||
print -n "> ";read description
|
||||
|
||||
# --- We start the creation of the project files here
|
||||
mkdir $project
|
||||
cd $project
|
||||
|
||||
print -- "Initialize git"
|
||||
git init .
|
||||
|
||||
print -- ".gitignore"
|
||||
|
@ -46,7 +111,8 @@ dist
|
|||
.ghci
|
||||
END
|
||||
|
||||
print -- "$project.cabal"
|
||||
print -- "Create files"
|
||||
print -- "\t$project.cabal"
|
||||
> $project.cabal cat <<END
|
||||
-- Initial $project.cabal generated by cabal init. For further documentation,
|
||||
-- see http://haskell.org/cabal/users-guide/
|
||||
|
@ -66,7 +132,7 @@ build-type: Simple
|
|||
-- extra-source-files:
|
||||
cabal-version: >=1.10
|
||||
|
||||
executable yml
|
||||
executable $project
|
||||
main-is: Main.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
|
@ -76,9 +142,9 @@ executable yml
|
|||
default-language: Haskell2010
|
||||
|
||||
library
|
||||
exposed-modules: $project
|
||||
, $project.Foo
|
||||
, $project.Bar
|
||||
exposed-modules: $module
|
||||
, $module.Swallow
|
||||
, $module.Coconut
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base >=4.6 && <4.7
|
||||
|
@ -86,7 +152,7 @@ library
|
|||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
||||
|
||||
executable test-yml
|
||||
executable test-$project
|
||||
hs-source-dirs: test
|
||||
ghc-options: -Wall
|
||||
main-is: Test.hs
|
||||
|
@ -107,7 +173,6 @@ test-suite Tests
|
|||
Type: exitcode-stdio-1.0
|
||||
default-language: Haskell2010
|
||||
build-depends: base ==4.6.*, Cabal >= 1.16.0
|
||||
, vector
|
||||
, $project
|
||||
, HUnit
|
||||
, QuickCheck
|
||||
|
@ -118,13 +183,13 @@ test-suite Tests
|
|||
, tasty-smallcheck
|
||||
END
|
||||
|
||||
print -- "Setup.hs"
|
||||
print -- "\tSetup.hs"
|
||||
> Setup.hs cat <<END
|
||||
import Distribution.Simple
|
||||
main = defaultMain
|
||||
END
|
||||
|
||||
print -- "LICENSE"
|
||||
print -- "\tLICENSE (MIT)"
|
||||
> LICENSE cat<<END
|
||||
The MIT License (MIT)
|
||||
|
||||
|
@ -151,100 +216,129 @@ END
|
|||
|
||||
mkdir src test
|
||||
|
||||
print -- "test/Test.hs"
|
||||
print -- "\ttest/Test.hs"
|
||||
> test/Test.hs cat <<END
|
||||
module Main where
|
||||
|
||||
import Test.Tasty (defaultMain,testGroup,TestTree)
|
||||
|
||||
import $project.Foo.Test
|
||||
import $project.Bar.Test
|
||||
import $module.Swallow.Test
|
||||
import $module.Coconut.Test
|
||||
|
||||
main :: IO ()
|
||||
main = defaultMain tests
|
||||
|
||||
tests :: TestTree
|
||||
tests = testGroup "All Tests"
|
||||
[ fooSuite
|
||||
, barSuite
|
||||
[ swallowSuite
|
||||
, coconutSuite
|
||||
]
|
||||
END
|
||||
|
||||
mkdir -p src/$project
|
||||
mkdir -p test/$project/{Foo,Bar}
|
||||
mkdir -p src/$module
|
||||
mkdir -p test/$module/{Swallow,Coconut}
|
||||
|
||||
print -- "test/$project/Foo/Test.hs"
|
||||
> test/$project/Foo/Test.hs cat <<END
|
||||
module $project.Foo.Test
|
||||
(fooSuite)
|
||||
print -- "\ttest/$module/Swallow/Test.hs"
|
||||
> test/$module/Swallow/Test.hs cat <<END
|
||||
module $module.Swallow.Test
|
||||
(swallowSuite)
|
||||
where
|
||||
import Test.Tasty (testGroup, TestTree)
|
||||
import Test.Tasty.HUnit
|
||||
import $project.Foo.Test
|
||||
import $module.Swallow
|
||||
|
||||
datasetSuite :: TestTree
|
||||
datasetSuite = testGroup "Foo"
|
||||
[testCase "foo test" testFoo]
|
||||
swallowSuite :: TestTree
|
||||
swallowSuite = testGroup "Swallow"
|
||||
[testCase "swallow test" testSwallow]
|
||||
|
||||
testFoo :: Assertion
|
||||
testFoo = "something" @=? foo "some" "thing"
|
||||
testSwallow :: Assertion
|
||||
testSwallow = "something" @=? swallow "some" "thing"
|
||||
END
|
||||
|
||||
print -- "src/$project/Foo.hs"
|
||||
> src/$project/Foo.hs cat <<END
|
||||
module $project.Foo (foo) where
|
||||
print -- "\tsrc/$module/Swallow.hs"
|
||||
> src/$module/Swallow.hs cat <<END
|
||||
module $module.Swallow (swallow) where
|
||||
|
||||
foo :: String -> String -> String
|
||||
foo prefix suffix = prefix ++ suffix
|
||||
swallow :: String -> String -> String
|
||||
swallow prefix suffix = prefix ++ suffix
|
||||
END
|
||||
|
||||
print -- "test/$project/Bar/Test.hs"
|
||||
> test/$project/Bar/Test.hs cat <<END
|
||||
print -- "\ttest/$module/Coconut/Test.hs"
|
||||
> test/$module/Coconut/Test.hs cat <<END
|
||||
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
module YML.Bar.Test
|
||||
(barSuite)
|
||||
module $module.Coconut.Test
|
||||
(coconutSuite)
|
||||
where
|
||||
|
||||
import Test.Tasty (testGroup, TestTree)
|
||||
import Test.Tasty.HUnit
|
||||
import Test.Tasty.SmallCheck as SC
|
||||
|
||||
import $project.Bar
|
||||
import $module.Coconut
|
||||
|
||||
-- Make instance of BarDataStruct
|
||||
-- Make instance of CoconutDataStruct
|
||||
-- we simply use consN Constr where N is the arity of Constr (SmallCheck)
|
||||
-- we also needed the
|
||||
-- {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
|
||||
import Test.SmallCheck.Series
|
||||
instance Monad m => Serial m BarDataStruct where series = cons1 BarDataStruct
|
||||
-- Now we could test properties with smallcheck on BarDataStruct type.
|
||||
instance Monad m => Serial m CoconutDataStruct where series = cons1 CoconutConstr
|
||||
-- Now we could test properties with smallcheck on CoconutDataStruct type.
|
||||
|
||||
barSuite :: TestTree
|
||||
barSuite = testGroup "bar"
|
||||
[ testCase "bar" testBar
|
||||
, SC.testProperty "bar property" prop_bar
|
||||
coconutSuite :: TestTree
|
||||
coconutSuite = testGroup "coconut"
|
||||
[ testCase "coconut" testCoconut
|
||||
, SC.testProperty "coconut property" prop_coconut
|
||||
]
|
||||
|
||||
testCost :: Assertion
|
||||
testCost = bar @=? 10
|
||||
testCoconut :: Assertion
|
||||
testCoconut = coconut @=? 10
|
||||
|
||||
prop_cost_positive :: Property IO
|
||||
prop_cost_positive = forAll $ \barStruct -> barfunc barStruct >= 0
|
||||
prop_coconut :: Property IO
|
||||
prop_coconut = forAll $ \coconutStruct -> coconutfunc coconutStruct >= 0
|
||||
END
|
||||
|
||||
print -- "src/$project/Bar.hs"
|
||||
> src/$project/Bar.hs cat <<END
|
||||
module $project.Bar (bar,barfunc,BarDataStruct(..)) where
|
||||
data BarDataStruct = BarConstr [Integer]
|
||||
print -- "\tsrc/$module/Coconut.hs"
|
||||
> src/$module/Coconut.hs cat <<END
|
||||
module $module.Coconut (coconut,coconutfunc,CoconutDataStruct(..)) where
|
||||
data CoconutDataStruct = CoconutConstr [Integer] deriving (Show)
|
||||
|
||||
bar :: Integer
|
||||
bar = 10
|
||||
coconut :: Integer
|
||||
coconut = 10
|
||||
|
||||
barfunc :: BarDataStruct -> Int
|
||||
barfunc (BarConstr l) = length l
|
||||
coconutfunc :: CoconutDataStruct -> Int
|
||||
coconutfunc (CoconutConstr l) = length l
|
||||
END
|
||||
|
||||
cabal sandbox init
|
||||
print -- "\tsrc/$module.hs"
|
||||
> "src/$module.hs" cat <<END
|
||||
module $module where
|
||||
import $module.Swallow ()
|
||||
import $module.Coconut ()
|
||||
END
|
||||
|
||||
print -- "\tsrc/Main.hs"
|
||||
> "src/Main.hs" cat <<END
|
||||
module Main where
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "You fight with the strength of many men sir Knight..."
|
||||
putStrLn "You have proved yourself worthy; will you join me?"
|
||||
putStrLn "You make me sad. So be it. Come, Patsy."
|
||||
END
|
||||
|
||||
print -- "Cabal sandboxing, install and test"
|
||||
|
||||
cabal sandbox init || reinit
|
||||
cabal install
|
||||
cabal test
|
||||
|
||||
# -- Final touch
|
||||
print "\n\n"
|
||||
bk "What... is the air-speed velocity of an unladen swallow?"
|
||||
you "What do you mean? An African or European swallow?"
|
||||
bk "Huh? I... I don't know that."
|
||||
log "[the bridgekeeper is thrown over]"
|
||||
bk "Auuuuuuuuuuuugh"
|
||||
log "Sir Bedevere: How do you know so much about swallows?"
|
||||
you "Well, you have to know these things when you're a king, you know."
|
||||
|
|
Loading…
Reference in a new issue