Skip to content

Commit

Permalink
QuickCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
ne-sachirou committed Oct 20, 2015
1 parent 13391cf commit 88adcb3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ What IS private-values?
TODO
--
- [ ] Short command name.
- [ ] [QuickCheck](http://itpro.nikkeibp.co.jp/article/COLUMN/20080304/295346/)
- [ ] Release 0.1.0

[1]: http://direnv.net/
Expand Down
12 changes: 8 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ Cucumber::Rake::Task.new :features do |t|
t.cucumber_opts = 'features --format pretty'
end

desc 'Build this project.'
task :build do
readme = Erubis::Eruby.new(File.read("#{__dir__}/src/README.md.erb", mode: 'r:utf-8')).result({
help: File.read("#{__dir__}/src/Help.txt", mode: 'r:utf-8').strip,
})
File.open("#{__dir__}/README.md", 'w:utf-8'){|f| f.write readme }
sh 'stack exec hlint -- . -c'
sh 'stack build -j4'
sh 'stack build'
FileUtils.mkdir 'bin' unless File.exist? 'bin'
FileUtils.cp `stack exec which private-values`.strip, 'bin', preserve: true
FileUtils.cp `stack exec which private-values`.strip, 'bin/', preserve: true
end

task test: [:features]
desc 'Rus tests.'
task test: [:features] do
sh 'stack test'
sh 'stack exec hlint -- . -c'
end
5 changes: 4 additions & 1 deletion private-values.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ library
, containers >= 0.5
, directory >= 1.2
, filepath >= 1.4
, hlint
, MissingH >= 1.3
, regex-tdfa >= 1.2
, split >= 0.2
Expand Down Expand Up @@ -57,6 +56,10 @@ test-suite private-values-test
hs-source-dirs: test
main-is: Spec.hs
build-depends: base
, directory
, hlint
, hspec >= 2.1
, QuickCheck >= 2.8
, private-values
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
Expand Down
14 changes: 7 additions & 7 deletions src/FileUtil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import Data.List ( isPrefixOf )
import Data.Maybe ( fromJust )
import System.Directory ( getHomeDirectory )
import System.FilePath ( addTrailingPathSeparator, normalise )
import System.Path.NameManip ( guess_dotdot, absolute_path )
import System.Path.NameManip ( absolute_path, guess_dotdot )

absolutize :: String -> IO String
absolutize path
| "~" `isPrefixOf` path = do
homePath <- getHomeDirectory
return $ normalise $ addTrailingPathSeparator homePath ++ tail path
| otherwise = do
pathMaybeWithDots <- absolute_path path
return $ fromJust $ guess_dotdot pathMaybeWithDots
| ("~" == path) || ("~/" `isPrefixOf` path) =
do homePath <- getHomeDirectory
return $ normalise $ addTrailingPathSeparator homePath ++ tail path
| otherwise =
do pathMaybeWithDots <- absolute_path path
return $ fromJust $ guess_dotdot pathMaybeWithDots
1 change: 0 additions & 1 deletion src/README.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ What IS private-values?
TODO
--
- [ ] Short command name.
- [ ] [QuickCheck](http://itpro.nikkeibp.co.jp/article/COLUMN/20080304/295346/)
- [ ] Release 0.1.0

[1]: http://direnv.net/
Expand Down
28 changes: 28 additions & 0 deletions test/FileUtilSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module FileUtilSpec where

import Data.List ( isPrefixOf )
import FileUtil
import System.Directory ( getHomeDirectory )
import Test.Hspec
import Test.Hspec.QuickCheck ( prop )
import Test.QuickCheck

genStringStartWithTilde :: Gen String
genStringStartWithTilde = fmap ("~/" ++) arbitrary

spec :: Spec
spec =
describe "absolutize" $ do
it "Root path should be expanded to root" $ do
actual <- absolutize "/"
actual `shouldBe` "/"

it "Home path should be expanded to home" $ do
homePath <- getHomeDirectory
actual <- absolutize "~"
actual `shouldBe` (homePath ++ "/")

prop "~/**/** should be expanded to home" $ forAll genStringStartWithTilde $ \path -> do
homePath <- getHomeDirectory
absolutizedPath <- absolutize path
(homePath `isPrefixOf` absolutizedPath) `shouldBe` True
4 changes: 3 additions & 1 deletion test/Spec.hs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}

main :: IO ()
main = putStrLn "Test suite not yet implemented"
main = putStrLn ""

0 comments on commit 88adcb3

Please sign in to comment.