----------------------------------------------------------------------------- -- | -- Module : Static.Resources.Test -- Copyright : (c) Scrive 2012 -- License : BSD-style (see the LICENSE file in the distribution) -- -- Maintainer : mariusz@scrive.com -- Stability : development -- Portability : portable -- -- Some simple tests module Main ( main ) where import System.IO.HVFS.Utils import Data.List import Control.Monad import Static.Resources.Types import Static.Resources -- | Performs check. Left is error with some description. -- * Fails with css and js files avaible but not listed in spec. -- * Fails with css and js files that are in spec, but not avaible. import Test.Framework as TF (defaultMain, testGroup, Test) import Test.Framework.Providers.HUnit import Test.HUnit import Test.Framework.Providers.QuickCheck2 (testProperty) import System.IO.HVFS.Utils import Control.Monad import Data.Either import Data.Either.Utils import Data.Functor import System.Directory import Data.List main :: IO () main = defaultMain tests tests :: [TF.Test] tests = [ testGroup "Test order" [ testCase "Import order" test_import_order , testCase "Concat order" test_concat_order ] ] test_import_order :: Assertion test_import_order = do sdir <- getCurrentDirectory (ResourceSetsForImport [onlyRSSet] _) <- buildSet1AndChangeDirectory Development assertEqual "Files are in the set and order is preserved" (jsFiles onlyRSSet) ["./file1.js", "./file2.js"] cleanSet1 setCurrentDirectory sdir test_concat_order :: Assertion test_concat_order = do sdir <- getCurrentDirectory (ResourceSetsForImport [onlyRSSet] _) <- buildSet1AndChangeDirectory Production fc <- readFile $ head $ jsFiles onlyRSSet f1c <- readFile "file1.js" f2c <- readFile "file2.js" assertBool "First file appended at the begining" (f1c `isPrefixOf` fc) assertBool "Secound file appended at the end" (f2c `isSuffixOf` fc) setCurrentDirectory sdir set1SpecLocation:: IO (String,String) set1SpecLocation = do let dir = "test_files/set1" let fname = "resources.spec" cdir <- getCurrentDirectory if (dir `isSuffixOf` cdir) then return (".",cdir ++ "/" ++fname) else return (dir,cdir ++ "/" ++ dir ++ "/" ++ fname) buildSet1AndChangeDirectory :: ImportType -> IO (ResourceSetsForImport) buildSet1AndChangeDirectory it = do sdir <- getCurrentDirectory (specDir,specFile) <- set1SpecLocation spec <- parseSpec $ specFile setCurrentDirectory $ specDir res <- generateResources it "." spec "." return res cleanSet1 :: IO () cleanSet1 = do sdir <- getCurrentDirectory (specDir,specFile) <- set1SpecLocation spec <- parseSpec specFile setCurrentDirectory $ specDir cleanResourceFiles "." spec setCurrentDirectory sdir