forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptSpec.hs
More file actions
62 lines (51 loc) · 2.5 KB
/
ScriptSpec.hs
File metadata and controls
62 lines (51 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE TemplateHaskell #-}
-- | Test suite for the GhciScript DSL
module Stack.Ghci.ScriptSpec where
import Data.Monoid
import qualified Data.Set as S
import Distribution.ModuleName
import Test.Hspec
import qualified System.FilePath as FP
import Stack.Ghci.PortableFakePaths
import Path
import Path.Extra (pathToLazyByteString)
import Stack.Ghci.Script
spec :: Spec
spec = do
describe "GHCi" $ do
describe "Script DSL" $ do
describe "script" $ do
it "should seperate commands with a newline" $ do
let dir = $(mkAbsDir $ defaultDrive FP.</> "src" FP.</> "package-a")
script = cmdCdGhc dir
<> cmdAdd [fromString "Lib.A"]
scriptToLazyByteString script `shouldBe`
":cd-ghc " <> pathToLazyByteString dir <> "\n:add Lib.A\n"
describe ":add" $ do
it "should not render empty add commands" $ do
let script = cmdAdd []
scriptToLazyByteString script `shouldBe` ""
it "should ensure that a space exists between each module in an add command" $ do
let script = cmdAdd (S.fromList [fromString "Lib.A", fromString "Lib.B"])
scriptToLazyByteString script `shouldBe` ":add Lib.A Lib.B\n"
describe ":add (by file)" $ do
it "should render a full file path" $ do
let file = $(mkAbsFile $ defaultDrive FP.</> "Users" FP.</> "someone" FP.</> "src" FP.</> "project" FP.</> "package-a" FP.</> "src" FP.</> "Main.hs")
script = cmdAddFile file
scriptToLazyByteString script `shouldBe`
":add " <> pathToLazyByteString file <> "\n"
describe ":cd-ghc" $ do
it "should render a full absolute path" $ do
let dir = $(mkAbsDir $ defaultDrive FP.</> "Users" FP.</> "someone" FP.</> "src" FP.</> "project" FP.</> "package-a")
script = cmdCdGhc dir
scriptToLazyByteString script `shouldBe`
":cd-ghc " <> pathToLazyByteString dir <> "\n"
describe ":module" $ do
it "should render empty module as ':module +'" $ do
let script = cmdModule []
scriptToLazyByteString script `shouldBe` ":module +\n"
it "should ensure that a space exists between each module in a module command" $ do
let script = cmdModule [fromString "Lib.A", fromString "Lib.B"]
scriptToLazyByteString script `shouldBe` ":module + Lib.A Lib.B\n"